aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorys9693 <ys9693@att.com>2020-01-19 13:50:02 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-01-22 12:33:31 +0000
commit16a9fce0e104a38371a9e5a567ec611ae3fc7f33 (patch)
tree03a2aff3060ddb5bc26a90115805a04becbaffc9 /catalog-be/src/main
parentaa83a2da4f911c3ac89318b8e9e8403b072942e1 (diff)
Catalog alignment
Issue-ID: SDC-2724 Signed-off-by: ys9693 <ys9693@att.com> Change-Id: I52b4aacb58cbd432ca0e1ff7ff1f7dd52099c6fe
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/AuditEventFactory.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditBaseEventFactory.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java36
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IComponentMessage.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IMessageQueueHandlerProducer.java (renamed from catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java)15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IStatus.java43
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/ITypeMessage.java (renamed from catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java)12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ChangeTypeEnum.java30
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ResultStatusEnum.java30
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/ComponentMessage.java151
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducer.java140
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducerHealth.java194
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java679
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java46
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/AaiRequestHandler.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java62
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DME2EndpointIteratorCreator.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java24
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapClientFactory.java81
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapConsumer.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapHealth.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java57
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ICambriaHandler.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDmaapNotificationData.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/rest/MSORestClient.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java328
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/health/PortalHealthCheckBuilder.java230
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java22
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java3851
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java24
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java299
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CADIHealthCheck.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogic.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java524
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java1935
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java38
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java356
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ExternalRefsBusinessLogic.java70
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GenericArtifactBrowserBusinessLogic.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java353
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java118
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java223
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java102
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogic.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java499
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java81
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementBusinessLogic.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java9580
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java515
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java942
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/AafPermission.java66
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/AafRoles.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/PermissionAllowed.java32
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/RoleAuthorizationHandler.java82
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByActionStatusComponentException.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByResponseFormatComponentException.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java64
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java125
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/instance/GroupMembersUpdateOperation.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/lock/LockingTransactional.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdater.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyVersionUpdater.java104
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/version/OnChangeVersionCommand.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/version/VesionUpdateHandler.java66
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java158
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java301
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java28
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java236
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/StartCertificationTransition.java141
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/RelationsComparator.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/TopologyComparator.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolver.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommand.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBL.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolver.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommand.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsMergeCommand.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogic.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentCapabilitiesPropertiesMergeBL.java1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java40
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesPropertiesMerge.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceForwardingPathMerge.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMerge.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInterfacesMerge.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogic.java24
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeInterface.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMerge.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeCommand.java75
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolder.java28
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommand.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilder.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyValueMerger.java14
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogic.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtils.java56
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/path/ForwardingPathValidator.java90
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java29
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java75
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java55
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/ComponentsCleanBusinessLogic.java1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/upgrade/UpgradeBusinessLogic.java29
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java28
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java37
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java21
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java66
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java67
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java81
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java30
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java103
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java109
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java80
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java124
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java48
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java108
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java30
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java75
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java71
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java74
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java68
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ContainerInstanceTypesData.java62
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java24
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java122
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java635
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionCatalogServlet.java632
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java773
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/dto/ExternalRefDTO.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java203
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalPropertiesEnum.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java155
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/exception/RestrictionAccessFilterException.java (renamed from catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java)16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java2157
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java895
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java35
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java447
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/CatalogOperation.java83
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/FacadeOperationUtils.java41
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/UserOperation.java61
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeCadiServletFilter.java180
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeRestrictionAccessFilter.java54
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java176
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/FilterConfiguration.java80
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/GatewayFilter.java147
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/PortalConfiguration.java150
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/ReqValidationFilter.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java96
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java757
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/DownloadArtifactLogic.java140
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ForwardingPathUtils.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessInfo.java132
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/mixin/ComponentInstanceInputMixin.java42
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/mixin/ComponentInstancePropertyMixin.java43
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/mixin/InputDefinitionMixin.java (renamed from catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessList.java)38
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PropertyDefinitionMixin.java77
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java90
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java170
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AdditionalInformationServlet.java1246
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java405
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java1612
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java634
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java279
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java190
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java350
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java699
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentInstanceServlet.java3216
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java956
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java930
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java468
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java123
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java337
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java1515
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ExceptionHandlerEndpoint.java69
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java222
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java256
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java503
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java166
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java1154
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java703
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java395
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java869
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java168
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java329
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java700
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java91
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java138
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java70
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java163
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java534
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java602
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java553
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java1494
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java59
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java764
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadEndpoint.java65
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java824
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java730
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ConstraintViolationExceptionMapper.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/PropertyConstraintExceptionMapper.java57
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java21
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/togglz/CassandraCustomStateRepository.java92
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/togglz/ToggleConfiguration.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java33
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java2232
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java297
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/CapabilityFilter.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java7
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java637
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogicExt.java130
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/UserMessage.java70
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/user/UserOperationEnum.java25
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/view/MixinTarget.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java124
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java63
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java96
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphCommitHandler.java52
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphRollbackHandler.java55
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java86
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java101
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java298
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/config/CatalogBESpringConfig.java50
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/config/HttpClientFactory.java110
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/config/ObjectMapperProvider.java (renamed from catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java)44
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/externalupload/utils/ServiceUtils.java29
-rw-r--r--catalog-be/src/main/resources/application-context.xml16
-rw-r--r--catalog-be/src/main/resources/cadi.properties55
-rw-r--r--catalog-be/src/main/resources/config/configuration.yaml148
-rw-r--r--catalog-be/src/main/resources/config/distribution-engine-configuration.yaml1
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml1460
-rw-r--r--catalog-be/src/main/resources/config/logback.xml562
-rw-r--r--catalog-be/src/main/resources/elasticsearch.yml399
-rw-r--r--catalog-be/src/main/resources/import/tosca/heat-types/extVl/extVl.yml2
-rw-r--r--catalog-be/src/main/resources/portal.properties7
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py2
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py3
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py1
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py23
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py96
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py282
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py4
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py6
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json32
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py1
-rw-r--r--catalog-be/src/main/resources/swagger/index.html17
-rw-r--r--catalog-be/src/main/resources/swagger/o2c.html17
-rw-r--r--catalog-be/src/main/webapp/WEB-INF/web.xml449
-rw-r--r--catalog-be/src/main/webapp/index.html17
341 files changed, 35279 insertions, 33612 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/AuditEventFactory.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/AuditEventFactory.java
index 387e17b596..99c1ac3528 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/AuditEventFactory.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/api/AuditEventFactory.java
@@ -30,7 +30,4 @@ public interface AuditEventFactory {
String getLogMessage();
AuditingGenericEvent getDbEvent();
List<Pair<String, String>> getQueryParams();
-
- //TODO remove together with ES related code
- String getAuditingEsType();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditBaseEventFactory.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditBaseEventFactory.java
index 89bd6add7b..91212ad11e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditBaseEventFactory.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditBaseEventFactory.java
@@ -126,11 +126,6 @@ public abstract class AuditBaseEventFactory implements AuditEventFactory {
}
@Override
- public String getAuditingEsType() {
- return this.action.getAuditingEsType();
- }
-
- @Override
public final String getLogMessage() {
return String.format(getLogPattern(), getLogArgs());
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java
index 8c0054af32..9176a1aa93 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditConsumerEventFactory.java
@@ -43,7 +43,7 @@ public class AuditConsumerEventFactory extends AuditBaseEventFactory {
}
private AuditConsumerEventFactory(AuditingActionEnum action, CommonAuditData commonFields,
- String ecompUser, String modifier) {
+ String ecompUser, String modifier) {
super(action);
event = new ConsumerEvent(getAction().getName(), commonFields, ecompUser, modifier);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java
index 4e2b85eeb6..0f94ad2ce7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/auditing/impl/AuditingManager.java
@@ -22,16 +22,17 @@
package org.openecomp.sdc.be.auditing.impl;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
-import org.openecomp.sdc.be.dao.impl.AuditingDao;
import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.common.log.elements.LogFieldsMdcHandler;
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.enums.Severity;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.slf4j.MarkerFactory;
import org.springframework.stereotype.Component;
@Component
@@ -39,13 +40,10 @@ public class AuditingManager {
private static final Logger log = Logger.getLogger(AuditingManager.class.getName());
- private final AuditingDao auditingDao;
private final AuditCassandraDao cassandraDao;
private final ConfigurationProvider configurationProvider;
- @Autowired
- public AuditingManager(AuditingDao auditingDao, AuditCassandraDao cassandraDao, ConfigurationProvider configurationProvider) {
- this.auditingDao = auditingDao;
+ public AuditingManager(AuditCassandraDao cassandraDao, ConfigurationProvider configurationProvider) {
this.cassandraDao = cassandraDao;
this.configurationProvider = configurationProvider;
}
@@ -57,23 +55,27 @@ public class AuditingManager {
String msg = factory.getLogMessage();
logAuditEvent(msg);
- //TODO - remove this method after we got rid of ES
- saveEventToElasticSearch(factory);
saveEventToCassandra(factory.getDbEvent());
return msg;
}
- private void saveEventToCassandra(AuditingGenericEvent event) {
- CassandraOperationStatus result = cassandraDao.saveRecord(event);
- if (!result.equals(CassandraOperationStatus.OK)) {
- log.warn("Failed to persist to cassandra auditing event: {}", result.name());
+ public String auditEvent(AuditEventFactory factory, LoggerSdcAudit audit) {
+ String msg = auditEvent(factory);
+ logAuditEvent(msg, audit, factory.getDbEvent().getRequestId());
+ return msg;
+ }
+
+ private void logAuditEvent(String msg, LoggerSdcAudit audit, String requestId) {
+ if(audit != null) {
+ audit.logEntry(LogLevel.INFO, Severity.OK, msg,
+ MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), requestId);
}
}
- private void saveEventToElasticSearch(AuditEventFactory factory) {
- ActionStatus addRecordStatus = auditingDao.addRecord(factory.getDbEvent(), factory.getAuditingEsType());
- if (!addRecordStatus.equals(ActionStatus.OK)) {
- log.warn("Failed to persist auditing event: {}", addRecordStatus.name());
+ private void saveEventToCassandra(AuditingGenericEvent event) {
+ CassandraOperationStatus result = cassandraDao.saveRecord(event);
+ if (result != CassandraOperationStatus.OK) {
+ log.warn("Failed to persist to cassandra auditing event: {}", result.name());
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IComponentMessage.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IComponentMessage.java
new file mode 100644
index 0000000000..42a869137b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IComponentMessage.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.catalog.api;
+
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
+import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
+
+import java.io.Serializable;
+
+
+
+/**
+ * Represent Component (service, resource etc...) change message added to the
+ * message queue by sdc backend.<br>
+ *
+ * @author ms172g
+ *
+ */
+public interface IComponentMessage extends Serializable, ITypeMessage {
+ /**
+ * Change Type
+ * @return
+ */
+ ChangeTypeEnum getChangeType();
+ CatalogUpdateTimestamp getCatalogUpdateTimestamp();
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IMessageQueueHandlerProducer.java
index 3aa2e9a9d7..21c3ac8f2e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBType.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IMessageQueueHandlerProducer.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,10 +18,11 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.common.transaction.api;
+package org.openecomp.sdc.be.catalog.api;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
+public interface IMessageQueueHandlerProducer {
+
+ IStatus pushMessage(ITypeMessage message);
+ IStatus init();
-public interface IDBType {
- DBTypeEnum getDBType();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IStatus.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IStatus.java
new file mode 100644
index 0000000000..dd21c2985d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IStatus.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.catalog.api;
+
+import org.openecomp.sdc.be.catalog.enums.ResultStatusEnum;
+
+@FunctionalInterface
+public interface IStatus {
+
+ static IStatus getSuccessStatus() {
+
+ return () -> ResultStatusEnum.SUCCESS;
+ }
+
+ static IStatus getFailStatus() {
+ return () -> ResultStatusEnum.FAIL;
+ }
+
+ static IStatus getServiceDisabled() {
+ return () -> ResultStatusEnum.SERVICE_DISABLED;
+ }
+
+ ResultStatusEnum getResultStatus();
+
+} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/ITypeMessage.java
index 20763d04f8..a58e5f87c1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/IDBAction.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/ITypeMessage.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,8 +18,8 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.common.transaction.api;
+package org.openecomp.sdc.be.catalog.api;
-public interface IDBAction {
- <T> T doAction();
+public interface ITypeMessage {
+ String getMessageType();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ChangeTypeEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ChangeTypeEnum.java
new file mode 100644
index 0000000000..5107468af4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ChangeTypeEnum.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.catalog.enums;
+
+/**
+ * Represents The change type SDC Backend requests on the Component.<br>
+ * @author ms172g
+ *
+ */
+public enum ChangeTypeEnum {
+ LIFECYCLE, DELETE, ARCHIVE, RESTORE
+} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ResultStatusEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ResultStatusEnum.java
new file mode 100644
index 0000000000..53a242380c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ResultStatusEnum.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.catalog.enums;
+
+/**
+ * Simple Status Enum
+ * @author ms172g
+ *
+ */
+public enum ResultStatusEnum {
+ SUCCESS, FAIL , SERVICE_DISABLED
+} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/ComponentMessage.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/ComponentMessage.java
new file mode 100644
index 0000000000..82b646714e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/ComponentMessage.java
@@ -0,0 +1,151 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.catalog.impl;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openecomp.sdc.be.catalog.api.IComponentMessage;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.catalog.CatalogComponent;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+
+import java.util.List;
+
+public class ComponentMessage extends CatalogComponent implements IComponentMessage {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3233307722573636520L;
+ @JsonProperty("changeTypeEnum")
+ ChangeTypeEnum changeTypeEnum;
+ @JsonProperty("catalogUpdateTimestamp")
+ private CatalogUpdateTimestamp catalogUpdateTimestamp;
+ private Boolean isArchived;
+
+ public ComponentMessage(Component component, ChangeTypeEnum changeTypeEnum,
+ CatalogUpdateTimestamp catalogUpdateTimestamp) {
+ super();
+
+ this.changeTypeEnum = changeTypeEnum;
+ this.catalogUpdateTimestamp = catalogUpdateTimestamp;
+
+ setUniqueId(component.getUniqueId());// uniqueId
+ setUuid(component.getUUID()); // uuid
+ setInvariantUUID(component.getInvariantUUID()); // invariantUUID
+
+ // View Fields
+ setName(component.getName()); // name
+ setSystemName(component.getSystemName()); // systemName
+
+ setVersion(component.getVersion());// version
+ setLifecycleState(component.getLifecycleState()
+ .name()); // lifecycleState
+ setIcon(component.getIcon()); // icon
+
+ ComponentTypeEnum componentType = component.getComponentType();
+ setComponentType(componentType);// componentType
+
+ buildCategories(component.getCategories()); // categoryNormalizedName,
+ // subCategoryNormalizedName
+ if (componentType == ComponentTypeEnum.SERVICE) {
+ Service service = (Service) component;
+ setDistributionStatus(service.getDistributionStatus()
+ .name()); // distributionStatus
+ } else {
+ Resource r = (Resource) component;
+ this.setResourceType(r.getResourceType()
+ .name()); // resourceType
+ }
+ setIsArchived(component.isArchived()); // isArchived
+ setIsHighestVersion(component.isHighestVersion()); // isHighestVersion
+ setDescription(component.getDescription()); // description
+ if (component.getTags() != null) {
+ setTags(component.getTags()); // tags
+ }
+ setLastUpdateDate(component.getLastUpdateDate());// lastUpdateDate
+ setLastUpdaterUserId(component.getLastUpdaterUserId());
+ }
+
+ private void buildCategories(List<CategoryDefinition> categories) {
+ if (categories != null) {
+ setCategories(categories);
+ CategoryDefinition categoryDefinition = categories.get(0);
+
+ if (categoryDefinition != null) {
+ setCategoryNormalizedName(categoryDefinition.getName());
+ List<SubCategoryDefinition> subcategories = categoryDefinition.getSubcategories();
+ if (null != subcategories) {
+ SubCategoryDefinition subCategoryDefinition = subcategories.get(0);
+
+ if (subCategoryDefinition != null) {
+ setSubCategoryNormalizedName(subCategoryDefinition.getName());
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public ChangeTypeEnum getChangeType() {
+ return changeTypeEnum;
+ }
+
+ @Override
+ public CatalogUpdateTimestamp getCatalogUpdateTimestamp() {
+ return catalogUpdateTimestamp;
+ }
+
+ @Override
+ public String toString() {
+ return "ComponentMessage [ getChangeType()=" + getChangeType() + ", getCatalogUpdateTimestamp()="
+ + getCatalogUpdateTimestamp() + ", getIsArchived()=" + getIsArchived() + ", getUuid()=" + getUuid()
+ + ", getInvariantUUID()=" + getInvariantUUID() + ", getSystemName()=" + getSystemName()
+ + ", getDescription()=" + getDescription() + ", getIsHighestVersion()=" + getIsHighestVersion()
+ + ", getCategoryNormalizedName()=" + getCategoryNormalizedName() + ", getSubCategoryNormalizedName()="
+ + getSubCategoryNormalizedName() + ", getResourceType()=" + getResourceType() + ", getName()="
+ + getName() + ", getLastUpdateDate()=" + getLastUpdateDate() + ", getVersion()=" + getVersion()
+ + ", getComponentType()=" + getComponentType() + ", getIcon()=" + getIcon() + ", getUniqueId()="
+ + getUniqueId() + ", getLifecycleState()=" + getLifecycleState() + ", getDistributionStatus()="
+ + getDistributionStatus() + ", getTags()=" + getTags() + ", getCategories()=" + getCategories()
+ + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString()
+ + "]";
+ }
+
+ public Boolean getIsArchived() {
+ return isArchived;
+ }
+
+ public void setIsArchived(Boolean isArchived) {
+ this.isArchived = isArchived;
+ }
+
+
+ @Override
+ public String getMessageType() {
+ return getClass().getSimpleName();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducer.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducer.java
new file mode 100644
index 0000000000..40bea7b79c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducer.java
@@ -0,0 +1,140 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.catalog.impl;
+
+import com.att.nsa.mr.client.MRBatchingPublisher;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.openecomp.sdc.be.catalog.api.IMessageQueueHandlerProducer;
+import org.openecomp.sdc.be.catalog.api.IStatus;
+import org.openecomp.sdc.be.catalog.api.ITypeMessage;
+import org.openecomp.sdc.be.catalog.enums.ResultStatusEnum;
+import org.openecomp.sdc.be.components.distribution.engine.DmaapClientFactory;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DmaapProducerConfiguration;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+@Component
+public class DmaapProducer implements IMessageQueueHandlerProducer {
+ private static final Logger LOG = Logger.getLogger(DmaapProducer.class.getName());
+ private static final Logger metricLog = Logger.getLogger(DmaapProducer.class.getName());
+
+ @Autowired
+ private DmaapClientFactory dmaapClientFactory;
+ private ConfigurationManager configurationManager = ConfigurationManager.getConfigurationManager();
+ private MRBatchingPublisher publisher;
+ @Autowired
+ private DmaapProducerHealth dmaapHealth;
+
+ public MRBatchingPublisher getPublisher() {
+ return publisher;
+ }
+
+ @Override
+ public IStatus pushMessage(ITypeMessage message) {
+ try {
+ DmaapProducerConfiguration producerConfiguration = configurationManager.getConfiguration()
+ .getDmaapProducerConfiguration();
+ if (!producerConfiguration.getActive()) {
+ LOG.info(
+ "[Microservice DMAAP] producer is disabled [re-enable in configuration->isActive],message not sent.");
+ dmaapHealth.report(false);
+ return IStatus.getServiceDisabled();
+ }
+ if (publisher == null) {
+ IStatus initStatus = init();
+ if (initStatus.getResultStatus() != ResultStatusEnum.SUCCESS) {
+
+ return initStatus;
+ }
+ }
+ ObjectMapper mapper = new ObjectMapper();
+ String jsonInString = mapper.writeValueAsString(message);
+ if (publisher != null) {
+ LOG.info("before send message . response {}", jsonInString);
+
+ LOG.invoke("Dmaap Producer", "DmaapProducer-pushMessage", DmaapProducer.class.getName(), message.toString());
+
+ int pendingMsg = publisher.send(jsonInString);
+ LOG.info("sent message . response {}", pendingMsg);
+ LOG.invokeReturn(producerConfiguration.getConsumerId(), "Dmaap Producer", StatusCode.COMPLETE.getStatusCodeEnum(), "DmaapProducer-pushMessage",message.toString(), pendingMsg );
+
+ }
+
+
+
+ dmaapHealth.report(true);
+ } catch (Exception e) {
+ LOG.error("Failed to send message . Exception {}", e.getMessage());
+ return IStatus.getFailStatus();
+ }
+
+ return IStatus.getSuccessStatus();
+ }
+
+ @PostConstruct
+ @Override
+ public IStatus init() {
+ LOG.debug("MessageQueueHandlerProducer:: Start initializing");
+ DmaapProducerConfiguration configuration = configurationManager.getConfiguration()
+ .getDmaapProducerConfiguration();
+ if (configuration.getActive()) {
+ try {
+ publisher = dmaapClientFactory.createProducer(configuration);
+ if (publisher == null) {
+ LOG.error("Failed to connect to topic ");
+ dmaapHealth.report(false);
+ return IStatus.getFailStatus();
+ }
+
+ } catch (Exception e) {
+ LOG.error("Failed to connect to topic . Exeption {}", e.getMessage());
+ dmaapHealth.report(false);
+ return IStatus.getFailStatus();
+ }
+ dmaapHealth.report(true);
+ return IStatus.getSuccessStatus();
+ }
+ LOG.info("[Microservice DMAAP] producer is disabled [re-enable in configuration->isActive],message not sent.");
+ dmaapHealth.report(false);
+ return IStatus.getServiceDisabled();
+ }
+
+ @PreDestroy
+ public void shutdown() {
+ LOG.debug("DmaapProducer::shutdown...");
+ try {
+ if (publisher != null) {
+ publisher.close();
+ }
+ } catch (Exception e) {
+ LOG.error("Failed to close messageQ . Exeption {}", e.getMessage());
+
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducerHealth.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducerHealth.java
new file mode 100644
index 0000000000..b62df86b4b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducerHealth.java
@@ -0,0 +1,194 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.catalog.impl;
+
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DmaapProducerConfiguration;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+@Component("dmaapProducerHealth")
+public class DmaapProducerHealth {
+
+
+ private static final String DMAAP_HEALTH_LOG_CONTEXT = "dmaapProducer.healthcheck";
+ private static final String DMAAP_HEALTH_CHECK_STR = "dmaapProducerHealthCheck";
+ private static final Logger log = Logger.getLogger(DmaapProducerHealth.class.getName());
+ private static final Logger logHealth = Logger.getLogger(DMAAP_HEALTH_LOG_CONTEXT);
+ private HealthCheckInfo healthCheckInfo = DmaapProducerHealth.HealthCheckInfoResult.UNAVAILABLE.getHealthCheckInfo();
+ private long healthCheckReadTimeout = 20;
+ private long reconnectInterval = 5;
+ private HealthCheckScheduledTask healthCheckScheduledTask = null ;
+ private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
+ private ScheduledFuture<?> scheduledFuture = null;
+ private DmaapProducerConfiguration configuration = null ;
+
+ private volatile AtomicBoolean lastHealthState = new AtomicBoolean(false);
+ private volatile AtomicBoolean reportedHealthState = null;
+
+ public enum HealthCheckInfoResult {
+ OK(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.UP, null, DmaapStatusDescription.OK.getDescription())),
+ UNAVAILABLE(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.DOWN, null, DmaapStatusDescription.UNAVAILABLE.getDescription())),
+ DOWN(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.DOWN, null, DmaapStatusDescription.DOWN.getDescription()));
+
+ private HealthCheckInfo healthCheckInfo;
+ HealthCheckInfoResult(HealthCheckInfo healthCheckInfo) {
+ this.healthCheckInfo = healthCheckInfo;
+ }
+ public HealthCheckInfo getHealthCheckInfo() {
+ return healthCheckInfo;
+ }
+ }
+
+ public enum DmaapStatusDescription {
+ OK("OK"), UNAVAILABLE("DmaapProducer is not available"),DOWN("DOWN"), NOT_CONFIGURED("DmaapProducer configuration is missing/wrong ");
+
+ private String desc;
+ DmaapStatusDescription(String desc) {
+ this.desc = desc;
+ }
+ public String getDescription() {
+ return desc;
+ }
+
+ }
+
+ @PostConstruct
+ public DmaapProducerHealth init() {
+ log.trace("Enter init method of DmaapProducer health");
+ synchronized (DmaapProducerHealth.class){
+ this.configuration = ConfigurationManager.getConfigurationManager().getConfiguration().getDmaapProducerConfiguration();
+
+ Integer pollingInterval = configuration.getPollingInterval();
+ if (pollingInterval != null && pollingInterval!=0) {
+ reconnectInterval = pollingInterval;
+ }
+ Integer healthCheckReadTimeoutConfig = configuration.getTimeoutMs();
+ if (healthCheckReadTimeoutConfig != null) {
+ this.healthCheckReadTimeout = healthCheckReadTimeoutConfig;
+ }
+ this.healthCheckScheduledTask = new HealthCheckScheduledTask( configuration ); //what is the representation? csv? delimiter? json or other
+ startHealthCheckTask(true);
+ }
+ log.trace("Exit init method of DistributionEngineClusterHealth");
+ return this;
+ }
+
+ @PreDestroy
+ protected void destroy() {
+ if (scheduledFuture != null) {
+ scheduledFuture.cancel(true);
+ scheduledFuture = null;
+ }
+ if (scheduler != null) {
+ scheduler.shutdown();
+ }
+ }
+
+ /**
+ * Start health check task.
+ *
+ * @param startTask
+ */
+ private void startHealthCheckTask(boolean startTask) {
+ synchronized (DmaapProducerHealth.class){
+ if (startTask && this.scheduledFuture == null) {
+ this.scheduledFuture = this.scheduler.scheduleAtFixedRate(this.healthCheckScheduledTask , 0, reconnectInterval, TimeUnit.SECONDS);
+ }
+ }
+ }
+
+ void report(Boolean isUp){
+ if (reportedHealthState == null)
+ reportedHealthState = new AtomicBoolean(isUp);
+ reportedHealthState.set(isUp);
+ }
+
+
+ public HealthCheckInfo getHealthCheckInfo() {
+ return healthCheckInfo;
+ }
+
+ /**
+ * Health Check Task Scheduler - infinite check.
+ */
+ public class HealthCheckScheduledTask implements Runnable {
+ private final DmaapProducerConfiguration config;
+ private static final int TIMEOUT = 8192;
+
+ HealthCheckScheduledTask(final DmaapProducerConfiguration config){
+ this.config = config;
+ }
+ @Override
+ public void run() {
+ logHealth.trace("Executing Dmaap Health Check Task - Start");
+ boolean prevIsReachable;
+ boolean reachable;
+ //first try simple ping
+ try{
+ if ( reportedHealthState != null ){
+ reachable = reportedHealthState.get();
+ }
+ else{
+ reachable = false;
+ }
+ prevIsReachable = lastHealthState.getAndSet( reachable );
+ healthCheckInfo = reachable ? HealthCheckInfoResult.OK.healthCheckInfo : HealthCheckInfoResult.DOWN.healthCheckInfo;
+ }
+ catch( Exception e ){
+ log.debug("{} - cannot check connectivity -> {}",DMAAP_HEALTH_CHECK_STR, e );
+ prevIsReachable = lastHealthState.getAndSet(false);
+ healthCheckInfo = HealthCheckInfoResult.UNAVAILABLE.healthCheckInfo;
+ }
+ if (prevIsReachable != lastHealthState.get())
+ logAlarm( lastHealthState.get() );
+ }
+
+
+
+
+ private void logAlarm(boolean lastHealthState) {
+ try{
+ if ( lastHealthState ) {
+ BeEcompErrorManager.getInstance().logDmaapHealthCheckRecovery( DMAAP_HEALTH_CHECK_STR );
+ } else {
+ BeEcompErrorManager.getInstance().logDmaapHealthCheckError( DMAAP_HEALTH_CHECK_STR );
+ }
+ }catch( Exception e ){
+ log.debug("cannot logAlarm -> {}" ,e );
+ }
+ }
+
+ }
+
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
index f94cd38670..0192516bf0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java
@@ -26,6 +26,8 @@ import com.google.gson.JsonObject;
import fj.data.Either;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
@@ -35,6 +37,7 @@ import org.openecomp.sdc.be.components.impl.CsarValidationUtils;
import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.config.Configuration.VfModuleProperty;
@@ -47,7 +50,16 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
import org.openecomp.sdc.be.info.MergedArtifactInfo;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.heat.HeatParameterType;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
@@ -64,16 +76,27 @@ import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.OptionalInt;
+import java.util.Scanner;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.FAILED_UPLOAD_ARTIFACT_TO_COMPONENT;
import static org.openecomp.sdc.be.tosca.CsarUtils.ARTIFACTS_PATH;
@@ -89,6 +112,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private static final String ARTIFACT_WITH_NAME_AND_TYPE_ALREADY_EXIST_WITH_TYPE = "Artifact with name {} and type {} already exist with type {}";
private final Gson gson = new Gson();
private static final Pattern pattern = Pattern.compile("\\..(.*?)\\..");
+ private static final String LABEL_COUNTER_DELIMITER = "[^0-9]+";
protected final ArtifactsBusinessLogic artifactsBusinessLogic;
private final GroupBusinessLogic groupBusinessLogic;
@@ -108,13 +132,12 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
public Either<Resource, ResponseFormat> createResourceArtifactsFromCsar(CsarInfo csarInfo, Resource resource,
- String artifactsMetaFile, String artifactsMetaFileName, List<ArtifactDefinition> createdArtifacts,
- boolean shouldLock, boolean inTransaction) {
+ String artifactsMetaFile, String artifactsMetaFileName, List<ArtifactDefinition> createdArtifacts) {
log.debug("parseResourceArtifactsInfoFromFile start");
return parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName)
.left()
- .bind( p-> createResourceArtifacts(csarInfo, resource, p, createdArtifacts,shouldLock, inTransaction))
+ .bind( p-> createResourceArtifacts(csarInfo, resource, p, createdArtifacts))
.right()
.map(rf -> { componentsUtils.auditResource(rf, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE); return rf;})
.left()
@@ -137,35 +160,34 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
List<GroupDefinition> groups = updatedResource.getGroups();
- Map<String, ArtifactDefinition> deplymentArtifact = updatedResource.getDeploymentArtifacts();
- if (deplymentArtifact == null || deplymentArtifact.isEmpty()) {
- if(groups != null){
- List<GroupDefinition> listToDelete = groups.stream().filter(g -> g.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)).collect(Collectors.toList());
- groupBusinessLogic.deleteGroups(updatedResource, listToDelete);
- }
+ Map<String, ArtifactDefinition> deploymentArtifact = updatedResource.getDeploymentArtifacts();
+ if (MapUtils.isEmpty(deploymentArtifact)) {
+ deleteGroupsByType(groups, Constants.DEFAULT_GROUP_VF_MODULE, updatedResource);
return createResourceArtifacts(csarInfo, updatedResource, parseResourceInfoFromYamlEither.left().value(),
- createdNewArtifacts, shouldLock, inTransaction);
+ createdNewArtifacts);
}
- List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete = deplymentArtifact.values().stream().collect(Collectors.toList());
-
- int labelCounter = createdDeplymentArtifactsAfterDelete.size();
+ List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete = deploymentArtifact.values().stream()
+ .collect(Collectors.toList());
+ int labelCounter = createdDeploymentArtifactsAfterDelete
+ .stream()
+ .map(ArtifactDefinition::getArtifactLabel)
+ .filter(this::isLastCharacterInLabelADigit)
+ .map(this::getNextInt)
+ .flatMapToInt(this::toStream)
+ .max()
+ .orElse(-1) + 1;
////////////////////////////////////// create set parsed
////////////////////////////////////// artifacts///////////////////////////////////////////
Map<String, List<ArtifactTemplateInfo>> parsedArtifactsMap = parseResourceInfoFromYamlEither.left().value();
-
- List<ArtifactTemplateInfo> artifactsWithoutGroups = null;
- if (parsedArtifactsMap.containsKey(ArtifactTemplateInfo.CSAR_ARTIFACT)) {
- artifactsWithoutGroups = parsedArtifactsMap.get(ArtifactTemplateInfo.CSAR_ARTIFACT);
- parsedArtifactsMap.remove(ArtifactTemplateInfo.CSAR_ARTIFACT);
- }
+ List<ArtifactTemplateInfo> artifactsWithoutGroups = parsedArtifactsMap.remove(ArtifactTemplateInfo.CSAR_ARTIFACT);
Collection<List<ArtifactTemplateInfo>> parsedArifactsCollection = parsedArtifactsMap.values();
Either<Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>>, ResponseFormat> parsedArtifactsPerGroupEither = createArtifactsTemplateCollection(csarInfo, updatedResource, createdNewArtifacts, shouldLock, inTransaction,
- createdDeplymentArtifactsAfterDelete, labelCounter, parsedArifactsCollection);
+ createdDeploymentArtifactsAfterDelete, labelCounter, parsedArifactsCollection);
if(parsedArtifactsPerGroupEither.isRight()){
log.error("Failed to parse artifacts. Status is {} ", parsedArtifactsPerGroupEither.right().value());
return Either.right(parsedArtifactsPerGroupEither.right().value());
@@ -175,20 +197,20 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
// find master in group
Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupArtifact = findMasterArtifactInGroup(
- groups, deplymentArtifact);
+ groups, deploymentArtifact);
///////////////////////////////// find artifacts to
///////////////////////////////// delete////////////////////////////////////////////////////
Map<String, List<ArtifactDefinition>> groupToDelete = new HashMap<>();
- Set<ArtifactDefinition> artifactsToDelete = findArtifactThatNotInGroupToDelete(parsedGroup, createdDeplymentArtifactsAfterDelete);
+ Set<ArtifactDefinition> artifactsToDelete = findArtifactThatNotInGroupToDelete(parsedGroup, createdDeploymentArtifactsAfterDelete);
Set<ArtifactTemplateInfo> jsonMasterArtifacts = parsedGroup.keySet();
Map<GroupDefinition, MergedArtifactInfo> mergedgroup = mergeGroupInUpdateFlow(groupArtifact, parsedGroup,
- artifactsToDelete, groupToDelete, jsonMasterArtifacts, createdDeplymentArtifactsAfterDelete);
+ artifactsToDelete, groupToDelete, jsonMasterArtifacts, createdDeploymentArtifactsAfterDelete);
- List<ArtifactDefinition> deletedArtifacts = new ArrayList<>();;
+ List<ArtifactDefinition> deletedArtifacts = new ArrayList<>();
Either<Resource, ResponseFormat> deletedArtifactsEither = deleteArtifactsInUpdateCsarFlow(
updatedResource, csarInfo.getModifier(), shouldLock, inTransaction, artifactsToDelete, groupToDelete, deletedArtifacts);
if (deletedArtifactsEither.isRight()) {
@@ -200,97 +222,60 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
updatedResource = deletedArtifactsEither.left().value();
// need to update resource if we updated artifacts
- if (!deletedArtifacts.isEmpty()) {
- for (ArtifactDefinition deletedArtifact : deletedArtifacts) {
- ArtifactDefinition artToRemove = null;
- for (ArtifactDefinition artFromResource : createdDeplymentArtifactsAfterDelete) {
- if (deletedArtifact.getUniqueId().equalsIgnoreCase(artFromResource.getUniqueId())) {
- artToRemove = artFromResource;
- break;
- }
- }
- if (artToRemove != null) {
- createdDeplymentArtifactsAfterDelete.remove(artToRemove);
- }
-
- }
- }
+ excludeDeletedArtifacts(deletedArtifacts, createdDeploymentArtifactsAfterDelete);
////////////// dissociate, associate or create
////////////// artifacts////////////////////////////
Either<Resource, ResponseFormat> assDissotiateEither = associateAndDissociateArtifactsToGroup(csarInfo,
- updatedResource, createdNewArtifacts, labelCounter, inTransaction,
- createdDeplymentArtifactsAfterDelete, mergedgroup, deletedArtifacts);
+ updatedResource, createdNewArtifacts, labelCounter,
+ createdDeploymentArtifactsAfterDelete, mergedgroup, deletedArtifacts);
groups = updatedResource.getGroups();
if (assDissotiateEither.isRight()) {
log.debug("Failed to delete artifacts. Status is {} ", assDissotiateEither.right().value());
-
return Either.right(assDissotiateEither.right().value());
-
}
+
updatedResource = assDissotiateEither.left().value();
- deplymentArtifact = updatedResource.getDeploymentArtifacts();
- createdDeplymentArtifactsAfterDelete.clear();
- if (deplymentArtifact != null && !deplymentArtifact.isEmpty()) {
- for (Entry<String, ArtifactDefinition> entry : deplymentArtifact.entrySet()) {
- createdDeplymentArtifactsAfterDelete.add(entry.getValue());
- }
- }
+ deploymentArtifact = updatedResource.getDeploymentArtifacts();
+ createdDeploymentArtifactsAfterDelete = deploymentArtifact.values().stream()
+ .collect(Collectors.toList());
+
// update vfModule names
Set<GroupDefinition> groupForAssociateWithMembers = mergedgroup.keySet();
- if (groups != null && !groups.isEmpty()) {
- Either<List<GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic
- .validateUpdateVfGroupNamesOnGraph(groups, updatedResource);
- if (validateUpdateVfGroupNamesRes.isRight()) {
- return Either.right(validateUpdateVfGroupNamesRes.right().value());
- }
- List<GroupDefinition> heatGroups = null;
-
- heatGroups = groups.stream().filter(e -> e.getMembers() != null).collect(Collectors.toList());
-
- for (GroupDefinition updatedGroupDef : groupForAssociateWithMembers) {
-
- if (updatedGroupDef.getMembers() != null && !updatedGroupDef.getMembers().isEmpty()) {
- updatedGroupDef.getMembers().clear();
- }
- Map<String, String> members = new HashMap<>();
- Set<String> artifactsGroup = new HashSet<>();
- artifactsGroup.addAll(updatedGroupDef.getArtifacts());
- associateMembersToArtifacts(createdNewArtifacts, createdDeplymentArtifactsAfterDelete, heatGroups,
- artifactsGroup, members);
- if (!members.isEmpty()) {
- updatedGroupDef.setMembers(members);
-
- }
-
- }
-
- }
+ Either<Resource, ResponseFormat> validateUpdateVfGroupNamesRes = updateVfModuleNames(createdNewArtifacts,
+ updatedResource, groups, createdDeploymentArtifactsAfterDelete, groupForAssociateWithMembers);
+ if (validateUpdateVfGroupNamesRes != null) return validateUpdateVfGroupNamesRes;
//////////////// create new artifacts in update
//////////////// flow////////////////////////////
- List<ArtifactTemplateInfo> newArtifactsGroup = new ArrayList<>();
+ List<ArtifactTemplateInfo> newArtifactsGroup = createNewArtifcats(parsedGroup, groupArtifact);
+ Either<Resource, ResponseFormat> validateGroupNamesRes = handleArtifactsInGroup(csarInfo, createdNewArtifacts,
+ updatedResource, groups, createdDeploymentArtifactsAfterDelete, labelCounter, newArtifactsGroup);
+ if (validateGroupNamesRes != null) return validateGroupNamesRes;
- for (Entry<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroupSetEntry : parsedGroup.entrySet()) {
- ArtifactTemplateInfo parsedArtifactMaster = parsedGroupSetEntry.getKey();
- boolean isNewGroup = true;
- for (Entry<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupListEntry : groupArtifact
- .entrySet()) {
- Map<ArtifactDefinition, List<ArtifactDefinition>> groupArtifacts = groupListEntry.getValue();
- Set<ArtifactDefinition> group = groupArtifacts.keySet();
- for (ArtifactDefinition artifactInfo : group) {
- if (parsedArtifactMaster.getFileName().equalsIgnoreCase(artifactInfo.getArtifactName())) {
- parsedArtifactMaster.setGroupName(groupListEntry.getKey().getName());
- isNewGroup = false;
- }
- }
- }
- if (isNewGroup) {
- newArtifactsGroup.add(parsedArtifactMaster);
+ // updatedGroup
+ Either<Resource, ResponseFormat> updateVersionEither = updateGroupVersion(updatedResource, groupForAssociateWithMembers);
+ if (updateVersionEither != null) return updateVersionEither;
+ if (!CollectionUtils.isEmpty(artifactsWithoutGroups)) {
+ for (ArtifactTemplateInfo t : artifactsWithoutGroups) {
+ List<ArtifactTemplateInfo> artifacts = new ArrayList<>();
+ artifacts.add(t);
+ Either<Resource, ResponseFormat> resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, updatedResource,
+ artifacts, createdNewArtifacts, createdDeploymentArtifactsAfterDelete, labelCounter);
+ if (checkResponse(resStatus)) return resStatus;
}
}
+
+ Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(updatedResource.getUniqueId());
+ return mapResult(eitherGetResource, updatedResource);
+ }
+
+ private Either<Resource, ResponseFormat> handleArtifactsInGroup(CsarInfo csarInfo, List<ArtifactDefinition> createdNewArtifacts,
+ Resource updatedResource, List<GroupDefinition> groups,
+ List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete,
+ int labelCounter, List<ArtifactTemplateInfo> newArtifactsGroup) {
if (!newArtifactsGroup.isEmpty()) {
Collections.sort(newArtifactsGroup, ArtifactTemplateInfo::compareByGroupName);
int startGroupCounter = groupBusinessLogic.getNextVfModuleNameCounter(groups);
@@ -300,18 +285,33 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
return Either.right(validateGroupNamesRes.right().value());
}
Either<Resource, ResponseFormat> resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, updatedResource,
- newArtifactsGroup, createdNewArtifacts, createdDeplymentArtifactsAfterDelete, labelCounter,
- shouldLock, inTransaction);
- if (resStatus.isRight()) {
- return resStatus;
+ newArtifactsGroup, createdNewArtifacts, createdDeploymentArtifactsAfterDelete, labelCounter);
+ checkResponse(resStatus);
+ }
+ return null;
+ }
+
+ private boolean checkResponse(Either<Resource, ResponseFormat> resStatus) {
+ return (resStatus.isRight());
+ }
+
+ private Either<Resource, ResponseFormat> updateVfModuleNames(List<ArtifactDefinition> createdNewArtifacts, Resource updatedResource, List<GroupDefinition> groups, List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete, Set<GroupDefinition> groupForAssociateWithMembers) {
+ if (!CollectionUtils.isEmpty(groups)) {
+ Either<List<GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic
+ .validateUpdateVfGroupNamesOnGraph(groups, updatedResource);
+ if (validateUpdateVfGroupNamesRes.isRight()) {
+ return Either.right(validateUpdateVfGroupNamesRes.right().value());
}
+ updateGroupMemebers(groups, groupForAssociateWithMembers, createdNewArtifacts, createdDeploymentArtifactsAfterDelete);
}
+ return null;
+ }
- // updatedGroup
+ private Either<Resource, ResponseFormat> updateGroupVersion(Resource updatedResource, Set<GroupDefinition> groupForAssociateWithMembers) {
if (!groupForAssociateWithMembers.isEmpty()) {
- List<GroupDefinition> groupsId = groupForAssociateWithMembers.stream().map(e -> e)
- .collect(Collectors.toList());
+ List<GroupDefinition> groupsId = groupForAssociateWithMembers.stream()
+ .collect(Collectors.toList());
Either<List<GroupDefinition>, ResponseFormat> updateVersionEither = groupBusinessLogic
.updateGroups(updatedResource, groupsId, true);
@@ -322,46 +322,131 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
}
- if (artifactsWithoutGroups != null && !artifactsWithoutGroups.isEmpty()) {
- for (ArtifactTemplateInfo t : artifactsWithoutGroups) {
- List<ArtifactTemplateInfo> arrtifacts = new ArrayList<>();
- arrtifacts.add(t);
- Either<Resource, ResponseFormat> resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, updatedResource,
- arrtifacts, createdNewArtifacts, createdDeplymentArtifactsAfterDelete, labelCounter, shouldLock,
- inTransaction);
- if (resStatus.isRight()) {
- return resStatus;
+ return null;
+ }
+
+ private IntStream toStream(OptionalInt optionalInt) {
+ if (optionalInt.isPresent()) {
+ return IntStream.of(optionalInt.getAsInt());
+ }
+ return IntStream.empty();
+ }
+
+ private OptionalInt getNextInt(String artifactLabel) {
+ try(Scanner scanner = new Scanner(artifactLabel).useDelimiter(LABEL_COUNTER_DELIMITER)) {
+ if (scanner.hasNextInt()) {
+ return OptionalInt.of(scanner.nextInt());
+ }
+ return OptionalInt.empty();
+ }
+ }
+
+ private boolean isLastCharacterInLabelADigit(String artifactLabel) {
+ return Character.isDigit(artifactLabel.charAt(artifactLabel.length()-1));
+ }
+
+ private Either<Resource, ResponseFormat> mapResult(Either<Resource, StorageOperationStatus> result, Resource resource) {
+ return result.right()
+ .map(status -> componentsUtils.getResponseFormatByResource(
+ componentsUtils.convertFromStorageResponse(status), resource));
+ }
+
+
+ private void updateGroupMemebers(List<GroupDefinition> groups, Set<GroupDefinition> groupForAssociateWithMembers, List<ArtifactDefinition> createdNewArtifacts, List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete) {
+ List<GroupDefinition> heatGroups = collectGroupsWithMembers(groups);
+
+ for (GroupDefinition updatedGroupDef : groupForAssociateWithMembers) {
+ Map<String, String> members = new HashMap<>();
+ Set<String> artifactsGroup = new HashSet<>();
+ artifactsGroup.addAll(updatedGroupDef.getArtifacts());
+ associateMembersToArtifacts(createdNewArtifacts, createdDeploymentArtifactsAfterDelete, heatGroups,
+ artifactsGroup, members);
+
+ updatedGroupDef.setMembers(members);
+ }
+ }
+
+
+ /**
+ * @param groups
+ * @return
+ */
+ private List<GroupDefinition> collectGroupsWithMembers(List<GroupDefinition> groups) {
+ return groups.stream()
+ .filter(e -> e.getMembers() != null)
+ .collect(Collectors.toList());
+ }
+
+
+ /**
+ * Exclude deleted Artificats from Deployment Artifcats
+ * @param deletedArtifacts
+ * @param createdDeploymentArtifactsAfterDelete
+ */
+ private void excludeDeletedArtifacts(List<ArtifactDefinition> deletedArtifacts, List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete) {
+ for (ArtifactDefinition deletedArtifact : deletedArtifacts) {
+ ArtifactDefinition artToRemove = null;
+ for (ArtifactDefinition artFromResource : createdDeploymentArtifactsAfterDelete) {
+ if (deletedArtifact.getUniqueId().equalsIgnoreCase(artFromResource.getUniqueId())) {
+ artToRemove = artFromResource;
+ break;
}
}
+ if (artToRemove != null) {
+ createdDeploymentArtifactsAfterDelete.remove(artToRemove);
+ }
}
+ }
- Either<Resource, StorageOperationStatus> eitherGerResource = toscaOperationFacade
- .getToscaElement(updatedResource.getUniqueId());
- if (eitherGerResource.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), updatedResource);
- return Either.right(responseFormat);
+ private void deleteGroupsByType(List<GroupDefinition> groups, String groupType, Resource resource) {
+ if(groups != null){
+ List<GroupDefinition> listToDelete = groups.stream()
+ .filter(g -> g.getType().equals(groupType))
+ .collect(Collectors.toList());
+
+ groupBusinessLogic.deleteGroups(resource, listToDelete);
+ }
+ }
+
+
+ private List<ArtifactTemplateInfo> createNewArtifcats(Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup, Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupArtifact) {
+ List<ArtifactTemplateInfo> newArtifactsGroup = new ArrayList<>();
+
+ for (Entry<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroupSetEntry : parsedGroup.entrySet()) {
+ ArtifactTemplateInfo parsedArtifactMaster = parsedGroupSetEntry.getKey();
+ boolean isNewGroup = true;
+ for (Entry<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupListEntry : groupArtifact
+ .entrySet()) {
+ Map<ArtifactDefinition, List<ArtifactDefinition>> groupArtifacts = groupListEntry.getValue();
+ Set<ArtifactDefinition> group = groupArtifacts.keySet();
+ for (ArtifactDefinition artifactInfo : group) {
+ if (parsedArtifactMaster.getFileName().equalsIgnoreCase(artifactInfo.getArtifactName())) {
+ parsedArtifactMaster.setGroupName(groupListEntry.getKey().getName());
+ isNewGroup = false;
+ }
+ }
+ }
+ if (isNewGroup) {
+ newArtifactsGroup.add(parsedArtifactMaster);
+ }
}
- return Either.left(eitherGerResource.left().value());
+ return newArtifactsGroup;
}
private Set<ArtifactDefinition> findArtifactThatNotInGroupToDelete(
Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup,
- List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete) {
+ List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete) {
Set<ArtifactDefinition> artifactsToDelete = new HashSet<>();
for (Entry<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroupSetEntry : parsedGroup.entrySet()) {
Set<ArtifactTemplateInfo> artifactsNames = parsedGroupSetEntry.getValue();
for (ArtifactTemplateInfo template : artifactsNames) {
if(template.getType().equals(ArtifactTypeEnum.HEAT_ARTIFACT.getType())){
- Optional<ArtifactDefinition> op = createdDeplymentArtifactsAfterDelete.stream().filter(a -> a.getArtifactName().equalsIgnoreCase(template.getFileName())).findAny();
- if(op.isPresent()){
- if(!op.get().getArtifactType().equalsIgnoreCase(template.getType())){
- artifactsToDelete.add(op.get());
- }
-
+ Optional<ArtifactDefinition> op = createdDeploymentArtifactsAfterDelete.stream().filter(a -> a.getArtifactName().equalsIgnoreCase(template.getFileName())).findAny();
+ if (op.isPresent() && !op.get().getArtifactType().equalsIgnoreCase(template.getType())) {
+ artifactsToDelete.add(op.get());
}
}
}
@@ -373,7 +458,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private Either<Resource, ResponseFormat> createResourceArtifacts(CsarInfo csarInfo, Resource resource,
Map<String, List<ArtifactTemplateInfo>> artifactsMap,
- List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction) {
+ List<ArtifactDefinition> createdArtifacts) {
Either<Resource, ResponseFormat> resStatus = Either.left(resource);
@@ -382,7 +467,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
for (List<ArtifactTemplateInfo> groupTemplateList : arifactsCollection) {
if (groupTemplateList != null) {
resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo, resource, groupTemplateList,
- createdArtifacts, 0, shouldLock, inTransaction);
+ createdArtifacts, 0);
if (resStatus.isRight()) {
return resStatus;
}
@@ -396,7 +481,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private Either<Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>>, ResponseFormat> createArtifactsTemplateCollection(CsarInfo csarInfo, Resource resource,
List<ArtifactDefinition> createdNewArtifacts, boolean shouldLock, boolean inTransaction,
- List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete, int labelCounter,
+ List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete, int labelCounter,
Collection<List<ArtifactTemplateInfo>> parsedArifactsCollection) {
Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup = new HashMap<>();
@@ -417,8 +502,8 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
List<ArtifactTemplateInfo> arrtifacts = new ArrayList<>();
arrtifacts.add(parsedGroupTemplate);
Either<Resource, ResponseFormat> resStatus = createGroupDeploymentArtifactsFromCsar(csarInfo,
- resource, arrtifacts, createdNewArtifacts, createdDeplymentArtifactsAfterDelete,
- labelCounter, shouldLock, inTransaction);
+ resource, arrtifacts, createdNewArtifacts, createdDeploymentArtifactsAfterDelete,
+ labelCounter);
if (resStatus.isRight()) {
return Either.right(resStatus.right().value());
}
@@ -440,20 +525,20 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
JsonElement importStructureElement = jsonElement.get(Constants.IMPORT_STRUCTURE);
if (importStructureElement == null || importStructureElement.isJsonNull()) {
- log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME, artifactFileName);
+ log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME, artifactFileName);
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
return Either
.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
}
- Map<String, List<Map<String, Object>>> artifactTemplateMap = new HashMap<>();
+ Map<String, List<Map<String, Object>>> artifactTemplateMap;
artifactTemplateMap = ComponentsUtils.parseJsonToObject(importStructureElement.toString(), HashMap.class);
if (artifactTemplateMap.isEmpty()) {
- log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME, artifactFileName);
+ log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME, artifactFileName);
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
return Either
.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
@@ -482,7 +567,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME, artifactFileName);
log.debug("failed with exception.", e);
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
}
@@ -496,17 +581,17 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
Either<List<ArtifactTemplateInfo>, ResponseFormat> artifactTemplateInfoListPairStatus = createArtifactTemplateInfoModule(
artifactsTypeKey, o);
if (artifactTemplateInfoListPairStatus.isRight()) {
- log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME, artifactFileName);
+ log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME, artifactFileName);
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
return Either.right(artifactTemplateInfoListPairStatus.right().value());
}
List<ArtifactTemplateInfo> artifactTemplateInfoList = artifactTemplateInfoListPairStatus.left().value();
if (artifactTemplateInfoList == null) {
- log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME, artifactFileName);
+ log.debug(ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME, artifactFileName);
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
return Either.right(
componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, artifactFileName));
@@ -542,14 +627,11 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private Either<Resource, ResponseFormat> createGroupDeploymentArtifactsFromCsar(CsarInfo csarInfo,
Resource resource, List<ArtifactTemplateInfo> artifactsTemplateList,
- List<ArtifactDefinition> createdArtifacts, int labelCounter, boolean shouldLock, boolean inTransaction) {
- Either<Resource, ResponseFormat> resStatus = Either.left(resource);
+ List<ArtifactDefinition> createdArtifacts, int labelCounter) {
List<GroupDefinition> createdGroups = resource.getGroups();
List<GroupDefinition> heatGroups = null;
- if (createdGroups != null && !createdGroups.isEmpty()) {
-
- heatGroups = createdGroups.stream().filter(e -> e.getMembers() != null).collect(Collectors.toList());
-
+ if (!CollectionUtils.isEmpty(createdGroups)) {
+ heatGroups = collectGroupsWithMembers(createdGroups);
}
List<GroupDefinition> needToCreate = new ArrayList<>();
for (ArtifactTemplateInfo groupTemplateInfo : artifactsTemplateList) {
@@ -558,12 +640,14 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
Set<String> artifactsUUIDGroup = new HashSet<>();
log.debug("createDeploymentArtifactsFromCsar start");
- resStatus = createDeploymentArtifactFromCsar(csarInfo, ARTIFACTS_PATH, resource, artifactsGroup,
- artifactsUUIDGroup, groupTemplateInfo, createdArtifacts, labelCounter, shouldLock, inTransaction);
+ Either<Resource, ResponseFormat> resStatus = createDeploymentArtifactFromCsar(csarInfo, ARTIFACTS_PATH, resource, artifactsGroup,
+ artifactsUUIDGroup, groupTemplateInfo, createdArtifacts, labelCounter);
log.debug("createDeploymentArtifactsFromCsar end");
if (resStatus.isRight()) {
return resStatus;
}
+ Map<String, ArtifactDefinition> createdArtifactsMap = createdArtifacts.stream().collect(Collectors.toMap(artifact -> artifact.getArtifactLabel(), artifact -> artifact));
+ resource.setDeploymentArtifacts(createdArtifactsMap);
if (groupName != null && !groupName.isEmpty()) {
Either<GroupDefinition, ResponseFormat> groupDefinitionEither = buildGroupDefinition(createdArtifacts, heatGroups, groupTemplateInfo,
@@ -574,29 +658,16 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
needToCreate.add(groupDefinitionEither.left().value());
}
}
-
- ComponentParametersView componentParametersView = new ComponentParametersView();
- componentParametersView.disableAll();
- componentParametersView.setIgnoreUsers(false);
- componentParametersView.setIgnoreArtifacts(false);
- componentParametersView.setIgnoreGroups(false);
-
- componentParametersView.setIgnoreComponentInstances(false);
-
- Either<Resource, StorageOperationStatus> component = toscaOperationFacade
- .getToscaElement(resource.getUniqueId(), componentParametersView);
-
- if (component.isRight()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
+ Map<String, ArtifactDefinition> createdArtifactsMap = createdArtifacts.stream().collect(Collectors.toMap(artifact -> artifact.getArtifactLabel(), artifact -> artifact));
+ resource.setDeploymentArtifacts(createdArtifactsMap);
Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic
- .addGroups(component.left().value(), needToCreate, false);
+ .addGroups(resource, needToCreate, false);
if (createGroups.isRight()) {
return Either.right(createGroups.right().value());
}
- return Either.left(component.left().value());
+ return Either.left(resource);
}
private Either<GroupDefinition, ResponseFormat> buildGroupDefinition(List<ArtifactDefinition> createdArtifacts,
@@ -639,8 +710,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private Either<Resource, ResponseFormat> createDeploymentArtifactFromCsar(CsarInfo csarInfo, String artifactPath,
Resource resource, Set<String> artifactsGroup, Set<String> artifactsUUIDGroup,
- ArtifactTemplateInfo artifactTemplateInfo, List<ArtifactDefinition> createdArtifacts, int labelCounter,
- boolean shoudLock, boolean inTransaction) {
+ ArtifactTemplateInfo artifactTemplateInfo, List<ArtifactDefinition> createdArtifacts, int labelCounter) {
Either<Resource, ResponseFormat> resStatus = Either.left(resource);
String artifactUid = "";
@@ -669,14 +739,11 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(newArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET
|| artifactType == ArtifactTypeEnum.HEAT_VOL) {
- Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactsBusinessLogic
- .createHeatEnvPlaceHolder(newArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME,
+ ArtifactDefinition createHeatEnvPlaceHolder = artifactsBusinessLogic
+ .createHeatEnvPlaceHolder(createdArtifacts, newArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME,
resource.getUniqueId(), NodeTypeEnum.Resource, resource.getName(),
csarInfo.getModifier(), resource, null);
- if (createHeatEnvPlaceHolder.isRight()) {
- return Either.right(createHeatEnvPlaceHolder.right().value());
- }
- artifactEnvUid = createHeatEnvPlaceHolder.left().value().getUniqueId();
+ artifactEnvUid = createHeatEnvPlaceHolder.getUniqueId();
}
}else{
artifactUid = createdArtifact.getUniqueId();
@@ -693,8 +760,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
if (relatedArtifacts != null) {
for (ArtifactTemplateInfo relatedArtifactTemplateInfo : relatedArtifacts) {
resStatus = createDeploymentArtifactFromCsar(csarInfo, artifactPath, resource, artifactsGroup,
- artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, labelCounter, shoudLock,
- inTransaction);
+ artifactsUUIDGroup, relatedArtifactTemplateInfo, createdArtifacts, labelCounter);
if (resStatus.isRight()) {
return resStatus;
}
@@ -724,7 +790,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
log.debug(ARTIFACT_WITH_NAME_AND_TYPE_ALREADY_EXIST_WITH_TYPE, artifactFileName,
artifactTemplateInfo.getType(), res.getArtifactType());
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
return Either.right(componentsUtils.getResponseFormat(
ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName,
@@ -741,16 +807,16 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
int label) {
int updatedlabel = label;
final String artifactFileName = artifactTemplateInfo.getFileName();
- Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils
- .getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), artifactPath + artifactFileName,
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContentStatus = CsarValidationUtils
+ .getArtifactContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), artifactPath + artifactFileName,
artifactFileName, componentsUtils);
- if (artifactContententStatus.isRight()) {
- return Either.right(artifactContententStatus.right().value());
+ if (artifactContentStatus.isRight()) {
+ return Either.right(artifactContentStatus.right().value());
}
updatedlabel += createdArtifacts.size();
Map<String, Object> json = ArtifactUtils.buildJsonForArtifact(artifactTemplateInfo,
- artifactContententStatus.left().value().getValue(), updatedlabel, true);
+ artifactContentStatus.left().value().getValue(), updatedlabel, true);
Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = createOrUpdateCsarArtifactFromJson(
resource, csarInfo.getModifier(), json,
@@ -789,17 +855,17 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
Either<ArtifactDefinition, ResponseFormat> resStatus = Either.left(currentInfo);
if (artifactTemplateInfo.getEnv() != null && !artifactTemplateInfo.getEnv().isEmpty()) {
- Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactparamsStatus = CsarValidationUtils
- .getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(),
+ Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactParamsStatus = CsarValidationUtils
+ .getArtifactContent(csarInfo.getCsarUUID(), csarInfo.getCsar(),
CsarUtils.ARTIFACTS_PATH + artifactTemplateInfo.getEnv(), artifactTemplateInfo.getEnv(),
componentsUtils);
- if (artifactparamsStatus.isRight()) {
- resStatus = Either.right(artifactparamsStatus.right().value());
+ if (artifactParamsStatus.isRight()) {
+ resStatus = Either.right(artifactParamsStatus.right().value());
return resStatus;
}
Either<List<HeatParameterDefinition>, ResponseFormat> propsStatus = extractHeatParameters(
ArtifactTypeEnum.HEAT_ENV.getType(), artifactTemplateInfo.getEnv(),
- artifactparamsStatus.left().value().getValue(), false);
+ artifactParamsStatus.left().value().getValue(), false);
if (propsStatus.isLeft()) {
List<HeatParameterDefinition> updatedHeatEnvParams = propsStatus.left().value();
@@ -811,44 +877,27 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
}
if (isUpdateEnv) {
- ComponentParametersView parametersView = new ComponentParametersView();
- parametersView.disableAll();
- parametersView.setIgnoreComponentInstances(false);
- parametersView.setIgnoreUsers(false);
- parametersView.setIgnoreArtifacts(false);
- parametersView.setIgnoreGroups(false);
-
- Either<Resource, StorageOperationStatus> eitherGerResource = toscaOperationFacade
- .getToscaElement(updatedResource.getUniqueId(), parametersView);
-
- if (eitherGerResource.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), updatedResource);
-
- resStatus = Either.right(responseFormat);
- return resStatus;
-
- }
-
- updatedResource = eitherGerResource.left().value();
Map<String, ArtifactDefinition> artifacts = updatedResource.getDeploymentArtifacts();
Optional<ArtifactDefinition> op = artifacts.values().stream().filter(
p -> p.getGeneratedFromId() != null && p.getGeneratedFromId().equals(currentInfo.getUniqueId()))
.findAny();
if (op.isPresent()) {
ArtifactDefinition artifactInfoHeatEnv = op.get();
- Either<ArtifactDefinition, StorageOperationStatus> updateArifactOnResource = artifactToscaOperation
- .updateArtifactOnResource(artifactInfoHeatEnv, updatedResource.getUniqueId(),
- artifactInfoHeatEnv.getUniqueId(), null, null);
- if (updateArifactOnResource.isRight()) {
+ artifactInfoHeatEnv.setHeatParamUpdated(true);
+ Either<ArtifactDefinition, StorageOperationStatus> updateArtifactOnResource = artifactToscaOperation
+ .updateArtifactOnResource(artifactInfoHeatEnv, updatedResource,
+ artifactInfoHeatEnv.getUniqueId(), null, null,true);
+ if (updateArtifactOnResource.isRight()) {
log.debug("Failed to update heat env on CSAR flow for component {} artifact {} label {}",
updatedResource.getUniqueId(), artifactInfoHeatEnv.getUniqueId(),
artifactInfoHeatEnv.getArtifactLabel());
return Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(updateArifactOnResource.right().value())));
+ componentsUtils.convertFromStorageResponse(updateArtifactOnResource.right().value())));
}
- resStatus = Either.left(updateArifactOnResource.left().value());
+ resource.getDeploymentArtifacts().put(updateArtifactOnResource.left().value().getArtifactLabel(), updateArtifactOnResource.left().value());
+ resStatus = Either.left(updateArtifactOnResource.left().value());
}
+
}
return resStatus;
}
@@ -908,43 +957,42 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
}
currentInfo.setListHeatParameters(currentHeatEnvParams);
- Either<ArtifactDefinition, StorageOperationStatus> updateArifactOnResource = artifactToscaOperation
- .updateArtifactOnResource(currentInfo, resource.getUniqueId(), currentInfo.getUniqueId(),
- null, null);
- if (updateArifactOnResource.isRight()) {
+ Either<ArtifactDefinition, StorageOperationStatus> updateArtifactOnResource = artifactToscaOperation
+ .updateArtifactOnResource(currentInfo, resource, currentInfo.getUniqueId(),
+ null, null, true);
+ if (updateArtifactOnResource.isRight()) {
log.debug(
- "Failed to update heat paratemers of heat on CSAR flow for component {} artifact {} label {}",
+ "Failed to update heat parameters of heat on CSAR flow for component {} artifact {} label {}",
resource.getUniqueId(), currentInfo.getUniqueId(), currentInfo.getArtifactLabel());
return Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(updateArifactOnResource.right().value())));
+ componentsUtils.convertFromStorageResponse(updateArtifactOnResource.right().value())));
}
- resStatus = Either.left(updateArifactOnResource.left().value());
+ resource.getDeploymentArtifacts().put(currentInfo.getArtifactLabel(), currentInfo);
+ resStatus = Either.left(updateArtifactOnResource.left().value());
}
return resStatus;
}
-
-
-
public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> createOrUpdateCsarArtifactFromJson(
Resource resource, User user, Map<String, Object> json, ArtifactOperationInfo operation) {
String jsonStr = gson.toJson(json);
-
- String origMd5 = GeneralUtility.calculateMD5Base64EncodedByString(jsonStr);
ArtifactDefinition artifactDefinitionFromJson = RepresentationUtils.convertJsonToArtifactDefinition(jsonStr,
- ArtifactDefinition.class);
-
- String artifactUniqueId = artifactDefinitionFromJson == null ? null : artifactDefinitionFromJson.getUniqueId();
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = artifactsBusinessLogic
- .validateAndHandleArtifact(resource.getUniqueId(), ComponentTypeEnum.RESOURCE, operation,
- artifactUniqueId, artifactDefinitionFromJson, origMd5, jsonStr, null, null, user,
- resource, false, true, false);
- if (uploadArtifactToService.isRight()) {
- return Either.right(uploadArtifactToService.right().value());
- }
+ ArtifactDefinition.class, false);
- return Either.left(uploadArtifactToService.left().value());
+ Either<ArtifactDefinition, Operation> result;
+ try {
+ result = artifactsBusinessLogic.handleLoadedArtifact(
+ resource, user, operation, false, true, ComponentTypeEnum.RESOURCE, artifactDefinitionFromJson);
+ } catch (ComponentException e) {
+ log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, ComponentTypeEnum.RESOURCE, resource.getName());
+ return Either.right(componentsUtils.getResponseFormat(e));
+ } catch (Exception e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ log.debug("Exception occurred when createOrUpdateCsarArtifactFromJson, error is:{}", e.getMessage(), e);
+ return Either.right(responseFormat);
+ }
+ return Either.left(result);
}
private void associateMembersToArtifacts(List<ArtifactDefinition> createdArtifacts,
@@ -954,14 +1002,13 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
for (GroupDefinition heatGroup : heatGroups) {
List<GroupProperty> grpoupProps = heatGroup.convertToGroupProperties();
if (grpoupProps != null) {
- associatemembersToVFgroups(createdArtifacts, artifactsFromResource, grpoupProps, artifactsGroup, heatGroup, members);
+ associateMembersToVFgroups(createdArtifacts, artifactsFromResource, grpoupProps, artifactsGroup, heatGroup, members);
}
}
-
}
}
- private void associatemembersToVFgroups(List<ArtifactDefinition> createdArtifacts,List<ArtifactDefinition> artifactsFromResource, List<GroupProperty> grpoupProps, Set<String> artifactsGroup, GroupDefinition heatGroup, Map<String, String> members){
+ private void associateMembersToVFgroups(List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> artifactsFromResource, List<GroupProperty> grpoupProps, Set<String> artifactsGroup, GroupDefinition heatGroup, Map<String, String> members){
Optional<GroupProperty> op = grpoupProps.stream()
.filter(p -> p.getName().equals(Constants.HEAT_FILE_PROPS)).findAny();
if (op.isPresent()) {
@@ -974,22 +1021,16 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
for (String artifactId : artifactsGroup) {
Optional<ArtifactDefinition> opArt = createdArtifacts.stream()
.filter(p -> p.getUniqueId().equals(artifactId)).findAny();
- if (opArt.isPresent()) {
- artifacts.add(opArt.get());
- }
+ opArt.ifPresent(artifacts::add);
if (artifactsFromResource != null) {
opArt = artifactsFromResource.stream().filter(p -> p.getUniqueId().equals(artifactId))
.findAny();
- if (opArt.isPresent()) {
- artifacts.add(opArt.get());
- }
+ opArt.ifPresent(artifacts::add);
}
}
Optional<ArtifactDefinition> resOp = artifacts.stream()
.filter(p -> heatFileNAme.contains(p.getArtifactName())).findAny();
- if (resOp.isPresent()) {
- members.putAll(heatGroup.getMembers());
- }
+ resOp.ifPresent(artifactDefinition -> members.putAll(heatGroup.getMembers()));
}
}
@@ -1060,7 +1101,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupArtifact,
Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup, Set<ArtifactDefinition> artifactsToDelete,
Map<String, List<ArtifactDefinition>> groupToDelete, Set<ArtifactTemplateInfo> jsonMasterArtifacts,
- List<ArtifactDefinition> createdDeplymentArtifacts) {
+ List<ArtifactDefinition> createdDeploymentArtifacts) {
Map<GroupDefinition, MergedArtifactInfo> mergedgroup = new HashMap<>();
for (Entry<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupListEntry : groupArtifact
.entrySet()) {
@@ -1068,36 +1109,15 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
boolean isNeedToDeleteGroup = true;
List<ArtifactDefinition> listToDelete = null;
for (ArtifactDefinition maserArtifact : createdArtifactMap.keySet()) {
- listToDelete = createdArtifactMap.get(maserArtifact);
- for (ArtifactDefinition artToDelete : listToDelete) {
- findArtifactToDelete(parsedGroup, artifactsToDelete, artToDelete, createdDeplymentArtifacts);
- }
+ listToDelete = prepareArtifactsToDelete(parsedGroup, artifactsToDelete, createdDeploymentArtifacts, createdArtifactMap, maserArtifact);
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());
-
- }
- }
+ deleteArtifacts(artifactsToDelete, group);
}
for (ArtifactTemplateInfo jsonMasterArtifact : jsonMasterArtifacts) {
- if (maserArtifact.getArtifactName().equalsIgnoreCase(jsonMasterArtifact.getFileName())) {
- MergedArtifactInfo mergedGroup = new MergedArtifactInfo();
- mergedGroup.setJsonArtifactTemplate(jsonMasterArtifact);
- mergedGroup.setCreatedArtifact(createdArtifactMap.get(maserArtifact));
- mergedgroup.put(groupListEntry.getKey(), mergedGroup);
- isNeedToDeleteGroup = false;
-
- }
+ isNeedToDeleteGroup = isNeedToDeleteGroup(mergedgroup, groupListEntry, createdArtifactMap, isNeedToDeleteGroup, maserArtifact, jsonMasterArtifact);
}
}
@@ -1109,14 +1129,50 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
return mergedgroup;
}
+ private boolean isNeedToDeleteGroup(Map<GroupDefinition, MergedArtifactInfo> mergedgroup, Entry<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupListEntry, Map<ArtifactDefinition, List<ArtifactDefinition>> createdArtifactMap, boolean isNeedToDeleteGroup, ArtifactDefinition maserArtifact, ArtifactTemplateInfo jsonMasterArtifact) {
+ if (maserArtifact.getArtifactName().equalsIgnoreCase(jsonMasterArtifact.getFileName())) {
+ MergedArtifactInfo mergedGroup = new MergedArtifactInfo();
+ mergedGroup.setJsonArtifactTemplate(jsonMasterArtifact);
+ mergedGroup.setCreatedArtifact(createdArtifactMap.get(maserArtifact));
+ mergedgroup.put(groupListEntry.getKey(), mergedGroup);
+ isNeedToDeleteGroup = false;
+
+ }
+ return isNeedToDeleteGroup;
+ }
+
+ private List<ArtifactDefinition> prepareArtifactsToDelete(Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup, Set<ArtifactDefinition> artifactsToDelete, List<ArtifactDefinition> createdDeploymentArtifacts, Map<ArtifactDefinition, List<ArtifactDefinition>> createdArtifactMap, ArtifactDefinition maserArtifact) {
+ List<ArtifactDefinition> listToDelete;
+ listToDelete = createdArtifactMap.get(maserArtifact);
+ for (ArtifactDefinition artToDelete : listToDelete) {
+ findArtifactToDelete(parsedGroup, artifactsToDelete, artToDelete, createdDeploymentArtifacts);
+ }
+ return listToDelete;
+ }
+
+ private void deleteArtifacts(Set<ArtifactDefinition> artifactsToDelete, GroupDefinition group) {
+ 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());
+
+ }
+ }
+ }
+
private void findArtifactToDelete(Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup,
Set<ArtifactDefinition> artifactsToDelete, ArtifactDefinition artifact,
- List<ArtifactDefinition> createdDeplymentArtifacts) {
+ List<ArtifactDefinition> createdDeploymentArtifacts) {
boolean isNeedToDeleteArtifact = true;
String artifactType = artifact.getArtifactType();
ArtifactDefinition generatedFromArt = null;
if (artifact.getGeneratedFromId() != null && !artifact.getGeneratedFromId().isEmpty()) {
- Optional<ArtifactDefinition> op = createdDeplymentArtifacts.stream()
+ Optional<ArtifactDefinition> op = createdDeploymentArtifacts.stream()
.filter(p -> p.getUniqueId().equals(artifact.getGeneratedFromId())).findAny();
if (op.isPresent()) {
generatedFromArt = op.get();
@@ -1124,6 +1180,12 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
+ isNeedToDeleteArtifact(parsedGroup, artifactsToDelete, artifact, isNeedToDeleteArtifact, artifactType, generatedFromArt);
+ }
+
+ private void isNeedToDeleteArtifact(Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup, Set<ArtifactDefinition>
+ artifactsToDelete, ArtifactDefinition artifact, boolean isNeedToDeleteArtifact, String artifactType, ArtifactDefinition generatedFromArt) {
+
for (Entry<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroupSetEntry : parsedGroup.entrySet()) {
Set<ArtifactTemplateInfo> artifactsNames = parsedGroupSetEntry.getValue();
for (ArtifactTemplateInfo template : artifactsNames) {
@@ -1152,7 +1214,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
private Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> findMasterArtifactInGroup(
- List<GroupDefinition> groups, Map<String, ArtifactDefinition> deplymentArtifact) {
+ List<GroupDefinition> groups, Map<String, ArtifactDefinition> deploymentArtifact) {
Map<GroupDefinition, Map<ArtifactDefinition, List<ArtifactDefinition>>> groupArtifact = new HashMap<>();
for (GroupDefinition group : groups) {
@@ -1161,7 +1223,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
List<String> artifactsList = group.getArtifacts();
if (artifactsList != null && !artifactsList.isEmpty()) {
- ArtifactDefinition masterArtifact = ArtifactUtils.findMasterArtifact(deplymentArtifact, artifacts,
+ ArtifactDefinition masterArtifact = ArtifactUtils.findMasterArtifact(deploymentArtifact, artifacts,
artifactsList);
if (masterArtifact != null) {
gupsMap.put(masterArtifact, artifacts);
@@ -1246,7 +1308,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private Either<Resource, ResponseFormat> createGroupDeploymentArtifactsFromCsar(CsarInfo csarInfo,
Resource resource, List<ArtifactTemplateInfo> artifactsTemplateList,
List<ArtifactDefinition> createdNewArtifacts, List<ArtifactDefinition> artifactsFromResource,
- int labelCounter, boolean shouldLock, boolean inTransaction) {
+ int labelCounter) {
Resource updatedResource = resource;
@@ -1254,7 +1316,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
List<GroupDefinition> createdGroups = updatedResource.getGroups();
List<GroupDefinition> heatGroups = null;
if (createdGroups != null && !createdGroups.isEmpty()) {
- heatGroups = createdGroups.stream().filter(e -> e.getMembers() != null).collect(Collectors.toList());
+ heatGroups = collectGroupsWithMembers(createdGroups);
}
List<GroupDefinition> needToAdd = new ArrayList<>();
@@ -1264,12 +1326,11 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
Set<String> artifactsUUIDGroup = new HashSet<>();
resStatus = createDeploymentArtifactsFromCsar(csarInfo, updatedResource, artifactsGroup, artifactsUUIDGroup,
- groupTemplateInfo, createdNewArtifacts, artifactsFromResource, labelCounter, shouldLock,
- inTransaction);
+ groupTemplateInfo, createdNewArtifacts, artifactsFromResource, labelCounter);
if (resStatus.isRight()) {
return resStatus;
}
- if (groupName != null && !groupName.isEmpty()) {
+ if (!StringUtils.isEmpty(groupName)) {
Map<String, String> members = new HashMap<>();
associateMembersToArtifacts(createdNewArtifacts, artifactsFromResource, heatGroups, artifactsGroup,
members);
@@ -1332,8 +1393,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private Either<Resource, ResponseFormat> createDeploymentArtifactsFromCsar(CsarInfo csarInfo, Resource resource,
Set<String> artifactsGroup, Set<String> artifactsUUIDGroup, ArtifactTemplateInfo artifactTemplateInfo,
- List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> artifactsFromResource, int labelCounter,
- boolean shoudLock, boolean inTransaction) {
+ List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> artifactsFromResource, int labelCounter) {
Either<Resource, ResponseFormat> resStatus = Either.left(resource);
String artifactFileName = artifactTemplateInfo.getFileName();
String artifactUid = "";
@@ -1351,7 +1411,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
log.debug(ARTIFACT_WITH_NAME_AND_TYPE_ALREADY_EXIST_WITH_TYPE, artifactFileName,
artifactTemplateInfo.getType(), artifactFromResource.getArtifactType());
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
return Either.right(componentsUtils.getResponseFormat(
ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName,
@@ -1375,7 +1435,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
log.debug(ARTIFACT_WITH_NAME_AND_TYPE_ALREADY_EXIST_WITH_TYPE, artifactFileName,
artifactTemplateInfo.getType(), createdArtifact.getArtifactType());
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
return Either.right(componentsUtils.getResponseFormat(
ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName,
@@ -1403,14 +1463,11 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(newArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET
|| artifactType == ArtifactTypeEnum.HEAT_VOL) {
- Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactsBusinessLogic
- .createHeatEnvPlaceHolder(newArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME,
+ ArtifactDefinition createHeatEnvPlaceHolder = artifactsBusinessLogic
+ .createHeatEnvPlaceHolder(createdArtifacts, newArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME,
resource.getUniqueId(), NodeTypeEnum.Resource, resource.getName(),
csarInfo.getModifier(), resource, null);
- if (createHeatEnvPlaceHolder.isRight()) {
- return Either.right(createHeatEnvPlaceHolder.right().value());
- }
- artifactEnvUid = createHeatEnvPlaceHolder.left().value().getUniqueId();
+ artifactEnvUid = createHeatEnvPlaceHolder.getUniqueId();
}
}
@@ -1424,8 +1481,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
if (relatedArtifacts != null) {
for (ArtifactTemplateInfo relatedArtifactTemplateInfo : relatedArtifacts) {
resStatus = createDeploymentArtifactsFromCsar(csarInfo, resource, artifactsGroup, artifactsUUIDGroup,
- relatedArtifactTemplateInfo, createdArtifacts, artifactsFromResource, labelCounter, shoudLock,
- inTransaction);
+ relatedArtifactTemplateInfo, createdArtifacts, artifactsFromResource, labelCounter);
if (resStatus.isRight()) {
return resStatus;
}
@@ -1436,11 +1492,11 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private Either<Resource, ResponseFormat> associateAndDissociateArtifactsToGroup(CsarInfo csarInfo,
Resource resource, List<ArtifactDefinition> createdNewArtifacts, int labelCounter,
- boolean inTransaction, List<ArtifactDefinition> createdDeplymentArtifactsAfterDelete,
+ List<ArtifactDefinition> createdDeploymentArtifactsAfterDelete,
Map<GroupDefinition, MergedArtifactInfo> mergedgroup, List<ArtifactDefinition> deletedArtifacts) {
Map<GroupDefinition, List<ArtifactTemplateInfo>> artifactsToAssotiate = new HashMap<>();
Map<GroupDefinition, List<ImmutablePair<ArtifactDefinition, ArtifactTemplateInfo>>> artifactsToUpdateMap = new HashMap<>();
- Either<Resource, ResponseFormat> resEither = Either.left(resource);
+ Either<Resource, ResponseFormat> resEither;
for (Entry<GroupDefinition, MergedArtifactInfo> entry : mergedgroup.entrySet()) {
List<ArtifactDefinition> dissArtifactsInGroup = entry.getValue()
.getListToDissotiateArtifactFromGroup(deletedArtifacts);
@@ -1517,7 +1573,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
// in
// resource
boolean isCreate = true;
- for (ArtifactDefinition createdArtifact : createdDeplymentArtifactsAfterDelete) {
+ for (ArtifactDefinition createdArtifact : createdDeploymentArtifactsAfterDelete) {
if (artifactTemplate.getFileName().equalsIgnoreCase(createdArtifact.getArtifactName())) {
arifactsUids.add(createdArtifact.getUniqueId());
arifactsUuids.add(createdArtifact.getArtifactUUID());
@@ -1525,10 +1581,10 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
String heatEnvId = checkAndGetHeatEnvId(createdArtifact);
if (!heatEnvId.isEmpty()) {
arifactsUids.add(heatEnvId);
- Optional<ArtifactDefinition> op = createdDeplymentArtifactsAfterDelete.stream()
+ Optional<ArtifactDefinition> op = createdDeploymentArtifactsAfterDelete.stream()
.filter(p -> p.getUniqueId().equals(heatEnvId)).findAny();
if (op.isPresent()) {
- this.artifactToscaOperation.updateHeatEnvPlaceholder(op.get(), resource.getUniqueId(),
+ this.artifactToscaOperation.updateHeatEnvPlaceholder(op.get(), resource,
resource.getComponentType().getNodeType());
}
@@ -1566,14 +1622,11 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(createdArtifact.getArtifactType());
if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET
|| artifactType == ArtifactTypeEnum.HEAT_VOL) {
- Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactsBusinessLogic
- .createHeatEnvPlaceHolder(createdArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME,
+ ArtifactDefinition createHeatEnvPlaceHolder = artifactsBusinessLogic
+ .createHeatEnvPlaceHolder(new ArrayList<>(), createdArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME,
resource.getUniqueId(), NodeTypeEnum.Resource, resource.getName(),
csarInfo.getModifier(), resource, null);
- if (createHeatEnvPlaceHolder.isRight()) {
- return Either.right(createHeatEnvPlaceHolder.right().value());
- }
- String heatEnvId = createHeatEnvPlaceHolder.left().value().getUniqueId();
+ String heatEnvId = createHeatEnvPlaceHolder.getUniqueId();
arifactsUids.add(heatEnvId);
}
}
@@ -1624,7 +1677,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
log.debug("Artifact with name {} and type {} already updated with type {}", artifactFileName,
artifactTemplateInfo.getType(), updatedArtifact.getArtifactType());
BeEcompErrorManager.getInstance().logInternalDataError(
- ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMATR_FILE_NAME1 + artifactFileName,
+ ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName,
ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
resStatus = Either.right(componentsUtils.getResponseFormat(
ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName,
@@ -1638,7 +1691,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
}
Either<ImmutablePair<String, byte[]>, ResponseFormat> artifactContententStatus = CsarValidationUtils
- .getArtifactsContent(csarInfo.getCsarUUID(), csarInfo.getCsar(),
+ .getArtifactContent(csarInfo.getCsarUUID(), csarInfo.getCsar(),
CsarUtils.ARTIFACTS_PATH + artifactFileName, artifactFileName, componentsUtils);
if (artifactContententStatus.isRight()) {
resStatus = Either.right(artifactContententStatus.right().value());
@@ -1658,22 +1711,24 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
resStatus = Either.right(uploadArtifactToService.right().value());
return resStatus;
}
+ ArtifactDefinition previousInfo = uploadArtifactToService.left().value().left().value();
ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value();
updatedArtifacts.add(currentInfo);
Either<ArtifactDefinition, ResponseFormat> updateEnvEither = updateHeatParamsFromCsar(resource, csarInfo,
artifactTemplateInfo, currentInfo, true);
+
if (updateEnvEither.isRight()) {
log.debug("failed to update parameters to artifact {}", artifactFileName);
resStatus = Either.right(updateEnvEither.right().value());
return resStatus;
}
+ artifactsBusinessLogic.updateGroupForHeat(previousInfo, updateEnvEither.left().value(), resource);
+
updatedArtifacts.add(updateEnvEither.left().value());
resStatus = Either.left(currentInfo);
-
return resStatus;
-
}
public Either<Resource, ResponseFormat> deleteVFModules(Resource resource, CsarInfo csarInfo, boolean shouldLock, boolean inTransaction) {
@@ -1681,7 +1736,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
List<GroupDefinition> groupsToDelete = updatedResource.getGroups();
if(groupsToDelete != null && !groupsToDelete.isEmpty()){
List<GroupDefinition> vfGroupsToDelete = groupsToDelete.stream().filter(g -> g.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)).collect(Collectors.toList());
- if(vfGroupsToDelete != null && !vfGroupsToDelete.isEmpty()){
+ if(!vfGroupsToDelete.isEmpty()){
for(GroupDefinition gr : vfGroupsToDelete){
List<String> artifacts = gr.getArtifacts();
for (String artifactId : artifacts) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
index af914e9019..e16f08b859 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
@@ -185,6 +185,6 @@ public class CsarBusinessLogic extends BaseBusinessLogic {
private void auditAndThrowException(Resource resource, User user, AuditingActionEnum auditingAction, ActionStatus status, String... params){
ResponseFormat errorResponse = componentsUtils.getResponseFormat(status, params);
componentsUtils.auditResource(errorResponse, user, resource, auditingAction);
- throw new ByResponseFormatComponentException(errorResponse);
+ throw new ByResponseFormatComponentException(errorResponse, params);
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
index 05c36b3ae0..ce6d60bd3c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java
@@ -42,10 +42,18 @@ import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.yaml.snakeyaml.Yaml;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.PriorityQueue;
+import java.util.Queue;
import java.util.regex.Pattern;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.*;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement;
public class CsarInfo {
private static final Logger log = Logger.getLogger(CsarInfo.class);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index cff6c26e58..b86348d3a7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -39,20 +39,58 @@ import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.NodeTypeInfo;
+import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
+import org.openecomp.sdc.be.model.UploadArtifactInfo;
+import org.openecomp.sdc.be.model.UploadCapInfo;
+import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
+import org.openecomp.sdc.be.model.UploadPropInfo;
+import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.parser.ParserException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.*;
-import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.*;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaListElement;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaMapElement;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.loadYamlAsStrictMap;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.CAPABILITIES;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.CAPABILITY;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT_VALUE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.FILE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.GET_INPUT;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.GROUPS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.IS_PASSWORD;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MEMBERS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.PROPERTIES;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIREMENTS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES;
/**
* A handler class designed to parse the YAML file of the service template for a JAVA object
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/AaiRequestHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/AaiRequestHandler.java
index 6121293c58..52179b49f5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/AaiRequestHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/AaiRequestHandler.java
@@ -46,7 +46,7 @@ public class AaiRequestHandler {
private static final Logger logger = Logger.getLogger(AaiRequestHandler.class);
private ExternalServiceConfig aaiConfig;
-
+
protected static final String OPERATIONAL_ENV_RESOURCE_CONFIG_PARAM = "operationalEnvironments";
protected static final String OPERATIONAL_ENV_RESOURCE = "/operational-environment";
@@ -55,27 +55,30 @@ public class AaiRequestHandler {
logger.debug("AaiRequestHandler has been initialized.");
aaiConfig = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getAaiConfig();
+ aaiConfig.getHttpClientConfig().setEnableMetricLogging(true);
logger.debug("AaiRequestHandler Configuration={}", aaiConfig);
}
public HttpResponse<String> getOperationalEnvById(String id) {
Properties headers = createHeaders();
- String url = String.format("%s%s%s/%s",
- aaiConfig.getHttpRequestConfig().getServerRootUrl(),
- aaiConfig.getHttpRequestConfig().getResourceNamespaces().get(OPERATIONAL_ENV_RESOURCE_CONFIG_PARAM),
+ String url = String.format("%s%s%s/%s",
+ aaiConfig.getHttpRequestConfig().getServerRootUrl(),
+ aaiConfig.getHttpRequestConfig().getResourceNamespaces().get(OPERATIONAL_ENV_RESOURCE_CONFIG_PARAM),
OPERATIONAL_ENV_RESOURCE, id);
-
+
SupplierThrows<HttpResponse<String>, Exception> httpGet = () -> HttpRequest.get(url, headers, aaiConfig.getHttpClientConfig());
long maxRetries = aaiConfig.getHttpClientConfig().getNumOfRetries();
try {
return FunctionalInterfaces.retryMethodOnException(httpGet, this::retryOnException, maxRetries);
- }
- catch (Exception e) {
+
+ } catch (Exception e) {
logger.debug("Request failed with exception {}", getCause(e).getMessage());
return Responses.INTERNAL_SERVER_ERROR;
}
}
+
+
private boolean retryOnException(Exception e) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java
index 045bde699b..f8f6726db8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ArtifactInfoImpl.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.components.distribution.engine;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.ComponentInstance;
@@ -77,7 +76,6 @@ public class ArtifactInfoImpl implements IArtifactInfo {
ret.add(artifactInfoImpl);
}
}
- ret.stream().forEach(ArtifactInfoImpl::updateArtifactTimeout);
return ret;
}
@@ -195,11 +193,5 @@ public class ArtifactInfoImpl implements IArtifactInfo {
public void setGeneratedFromUUID(String generatedFromUUID) {
this.generatedFromUUID = generatedFromUUID;
}
-
- public void updateArtifactTimeout(){
- int currentConfigTimeout = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getCurrentArtifactInstallationTimeout();
- if(artifactTimeout == null || artifactTimeout < currentConfigTimeout)
- artifactTimeout = currentConfigTimeout;
- }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
index 359330b81d..3f8abccb21 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
@@ -23,13 +23,19 @@ package org.openecomp.sdc.be.components.distribution.engine;
import com.att.nsa.apiClient.credentials.ApiCredential;
import com.att.nsa.apiClient.http.HttpException;
import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
-import com.att.nsa.cambria.client.*;
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import com.att.nsa.cambria.client.CambriaClient;
import com.att.nsa.cambria.client.CambriaClient.CambriaApiException;
+import com.att.nsa.cambria.client.CambriaClientBuilders;
+import com.att.nsa.cambria.client.CambriaClientBuilders.AbstractAuthenticatedManagerBuilder;
import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder;
import com.att.nsa.cambria.client.CambriaClientBuilders.IdentityManagerBuilder;
import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
import com.att.nsa.cambria.client.CambriaClientBuilders.TopicManagerBuilder;
+import com.att.nsa.cambria.client.CambriaConsumer;
+import com.att.nsa.cambria.client.CambriaIdentityManager;
import com.att.nsa.cambria.client.CambriaPublisher.message;
+import com.att.nsa.cambria.client.CambriaTopicManager;
import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import fj.data.Either;
@@ -53,7 +59,7 @@ import java.util.regex.Pattern;
import static java.util.concurrent.TimeUnit.SECONDS;
@Component("cambriaHandler")
-public class CambriaHandler {
+public class CambriaHandler implements ICambriaHandler{
private static final Logger log = Logger.getLogger(CambriaHandler.class.getName());
private static final String PARTITION_KEY = "asdc" + "aa";
@@ -62,6 +68,9 @@ public class CambriaHandler {
.getDistributionEngineConfiguration()
.getDistributionStatusTopic()
.getConsumerId();
+ private static final boolean USE_HTTPS_WITH_DMAAP = ConfigurationManager.getConfigurationManager()
+ .getDistributionEngineConfiguration()
+ .isUseHttpsWithDmaap();
private final Gson gson = new Gson();
@@ -119,12 +128,13 @@ public class CambriaHandler {
* @param hostSet
* @return
*/
+ @Override
public Either<Set<String>, CambriaErrorResponse> getTopics(List<String> hostSet) {
CambriaTopicManager createTopicManager = null;
try {
- createTopicManager = buildCambriaClient(new TopicManagerBuilder().usingHosts(hostSet));
+ createTopicManager = buildCambriaClient(createTopicManagerBuilder(hostSet));
Set<String> topics = createTopicManager.getTopics();
@@ -251,14 +261,15 @@ public class CambriaHandler {
* @param replicationCount
* @return
*/
+ @Override
public CambriaErrorResponse createTopic(Collection<String> hostSet, String apiKey, String secretKey, String topicName, int partitionCount, int replicationCount) {
CambriaTopicManager createTopicManager = null;
try {
- createTopicManager = buildCambriaClient(new TopicManagerBuilder().usingHosts(hostSet)
- .authenticatedBy(apiKey, secretKey));
-
+ AbstractAuthenticatedManagerBuilder<CambriaTopicManager> clientBuilder = createTopicManagerBuilder(hostSet, apiKey, secretKey);
+ createTopicManager = buildCambriaClient(clientBuilder);
+
createTopicManager.createTopic(topicName, "ASDC distribution notification topic", partitionCount, replicationCount);
}
@@ -282,13 +293,14 @@ public class CambriaHandler {
return new CambriaErrorResponse(CambriaOperationStatus.OK);
}
-
+ @Override
public CambriaErrorResponse unRegisterFromTopic(Collection<String> hostSet, String managerApiKey, String managerSecretKey, String subscriberApiKey, SubscriberTypeEnum subscriberTypeEnum, String topicName) {
String methodName = "unRegisterFromTopic";
CambriaTopicManager createTopicManager = null;
try {
- createTopicManager = buildCambriaClient(new TopicManagerBuilder().usingHosts(hostSet)
- .authenticatedBy(managerApiKey, managerSecretKey));
+ AbstractAuthenticatedManagerBuilder<CambriaTopicManager> clientBuilder = createTopicManagerBuilder(hostSet, managerApiKey, managerSecretKey);
+
+ createTopicManager = buildCambriaClient(clientBuilder);
if (subscriberTypeEnum == SubscriberTypeEnum.PRODUCER) {
createTopicManager.revokeProducer(topicName, subscriberApiKey);
@@ -324,6 +336,20 @@ public class CambriaHandler {
return new CambriaErrorResponse(CambriaOperationStatus.OK, HttpStatus.SC_OK);
}
+ private AbstractAuthenticatedManagerBuilder<CambriaTopicManager> createTopicManagerBuilder(Collection<String> hostSet, String managerApiKey, String managerSecretKey) {
+ AbstractAuthenticatedManagerBuilder<CambriaTopicManager> clientBuilder = createTopicManagerBuilder(hostSet)
+ .authenticatedBy(managerApiKey, managerSecretKey);
+ if (USE_HTTPS_WITH_DMAAP) {
+ clientBuilder = clientBuilder.usingHttps();
+ }
+
+ return clientBuilder;
+ }
+
+ private AbstractAuthenticatedManagerBuilder<CambriaTopicManager> createTopicManagerBuilder(Collection<String> hostSet) {
+ return new TopicManagerBuilder().usingHosts(hostSet);
+ }
+
/**
* register a public key (subscriberId) to a given topic as a CONSUMER or PRODUCER
*
@@ -335,13 +361,14 @@ public class CambriaHandler {
* @param topicName
* @return
*/
+ @Override
public CambriaErrorResponse registerToTopic(Collection<String> hostSet, String managerApiKey, String managerSecretKey, String subscriberApiKey, SubscriberTypeEnum subscriberTypeEnum, String topicName) {
String methodName = "registerToTopic";
CambriaTopicManager createTopicManager = null;
try {
- createTopicManager = buildCambriaClient(new TopicManagerBuilder().usingHosts(hostSet)
- .authenticatedBy(managerApiKey, managerSecretKey));
+ AbstractAuthenticatedManagerBuilder<CambriaTopicManager> clientBuilder = createTopicManagerBuilder(hostSet, managerApiKey, managerSecretKey);
+ createTopicManager = buildCambriaClient(clientBuilder);
if (subscriberTypeEnum == SubscriberTypeEnum.PRODUCER) {
createTopicManager.allowProducer(topicName, subscriberApiKey);
@@ -392,6 +419,7 @@ public class CambriaHandler {
* @return
* @throws Exception
*/
+ @Override
public CambriaConsumer createConsumer(Collection<String> hostSet, String topicName, String apiKey, String secretKey, String consumerId, String consumerGroup, int timeoutMS) throws Exception {
CambriaConsumer consumer = new ConsumerBuilder().authenticatedBy(apiKey, secretKey)
@@ -418,6 +446,7 @@ public class CambriaHandler {
* @param topicConsumer
* @return
*/
+ @Override
public Either<Iterable<String>, CambriaErrorResponse> fetchFromTopic(CambriaConsumer topicConsumer) {
String methodName = "fetchFromTopic";
@@ -454,6 +483,7 @@ public class CambriaHandler {
* @param data
* @return
*/
+ @Override
public CambriaErrorResponse sendNotification(String topicName, String uebPublicKey, String uebSecretKey, List<String> uebServers, INotificationData data) {
CambriaBatchingPublisher createSimplePublisher = null;
@@ -497,7 +527,7 @@ public class CambriaHandler {
}
}
}
-
+ @Override
public CambriaErrorResponse sendNotificationAndClose(String topicName, String uebPublicKey, String uebSecretKey, List<String> uebServers, INotificationData data, long waitBeforeCloseTimeout) {
String methodName = "sendNotificationAndClose";
CambriaBatchingPublisher createSimplePublisher;
@@ -564,7 +594,7 @@ public class CambriaHandler {
return response;
}
-
+ @Override
public CambriaErrorResponse getApiKey(String server, String apiKey) {
CambriaErrorResponse response;
@@ -586,7 +616,7 @@ public class CambriaHandler {
return response;
}
-
+ @Override
public Either<ApiCredential, CambriaErrorResponse> createUebKeys(List<String> hostSet) {
Either<ApiCredential, CambriaErrorResponse> result;
@@ -610,7 +640,7 @@ public class CambriaHandler {
}
@VisibleForTesting
- <T extends CambriaClient> T buildCambriaClient(CambriaClientBuilders.AbstractAuthenticatedManagerBuilder<? extends CambriaClient> client) throws MalformedURLException, GeneralSecurityException {
- return (T) client.build();
+ <T extends CambriaClient> T buildCambriaClient(CambriaClientBuilders.AbstractAuthenticatedManagerBuilder<T> client) throws MalformedURLException, GeneralSecurityException {
+ return client.build();
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DME2EndpointIteratorCreator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DME2EndpointIteratorCreator.java
index d5b28b344c..630815d26a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DME2EndpointIteratorCreator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DME2EndpointIteratorCreator.java
@@ -21,7 +21,6 @@
package org.openecomp.sdc.be.components.distribution.engine;
import com.att.aft.dme2.api.DME2Exception;
-import com.att.aft.dme2.api.DME2Manager;
import com.att.aft.dme2.iterator.DME2EndpointIterator;
import com.att.aft.dme2.iterator.factory.DME2EndpointIteratorFactory;
import org.springframework.stereotype.Component;
@@ -30,9 +29,7 @@ import org.springframework.stereotype.Component;
public class DME2EndpointIteratorCreator {
public DME2EndpointIterator create(String lookupURI) throws DME2Exception {
- // Initializing DME2Manager instance
- DME2Manager manager = DME2Manager.getDefaultInstance();
// Returning an instance of the DME2EndpointIteratorFactory
- return (DME2EndpointIterator) DME2EndpointIteratorFactory.getInstance().getIterator(lookupURI, null, null, manager);
+ return (DME2EndpointIterator) DME2EndpointIteratorFactory.getInstance().getIterator(lookupURI, null, null);
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java
index fa8d1ee507..3fd8579c2c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java
@@ -20,18 +20,6 @@
package org.openecomp.sdc.be.components.distribution.engine;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.annotation.Resource;
-
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.validation.ServiceDistributionValidation;
@@ -43,15 +31,26 @@ import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.YamlToObjectConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+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.concurrent.atomic.AtomicBoolean;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
@Component("distributionEngine")
public class DistributionEngine implements IDistributionEngine {
- private static final Logger LOGGER = LoggerFactory.getLogger(DistributionEngine.class);
+ private static final Logger logger = Logger.getLogger(DistributionEngine.class.getName());
private static final Pattern FQDN_PATTERN = Pattern.compile("^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*(:[0-9]{2,4})*$", Pattern.CASE_INSENSITIVE);
@Autowired
@@ -73,6 +72,26 @@ public class DistributionEngine implements IDistributionEngine {
private Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>();
private Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
+ /**
+ * The main method for testing only
+ * @param args
+ */
+ public static void main(String[] args) {
+
+ List<String> servers = new ArrayList<>();
+ String server = "uebsb91kcdc.it.att.com:3904";
+ servers.add(server);
+ servers.add(server);
+ servers.add(server);
+
+ YamlToObjectConverter converter = new YamlToObjectConverter();
+ DistributionEngineConfiguration distributionEngineConfiguration = converter.convert("src/test/resources/config/catalog-be/distribEngine1/distribution-engine-configuration.yaml", DistributionEngineConfiguration.class);
+
+ DistributionEngineInitTask distributionEngineInitTask = new DistributionEngineInitTask(2l, distributionEngineConfiguration, "PROD", new AtomicBoolean(false), null, null, null);
+ distributionEngineInitTask.startTask();
+
+ }
+
@Override
public boolean isActive() {
@@ -91,14 +110,14 @@ public class DistributionEngine implements IDistributionEngine {
@PostConstruct
private void init() {
- LOGGER.trace("Enter init method of DistributionEngine");
+ logger.trace("Enter init method of DistributionEngine");
DistributionEngineConfiguration distributionEngineConfiguration = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration();
boolean startDistributionEngine = distributionEngineConfiguration.isStartDistributionEngine();
- LOGGER.debug("Distribution engine activation parameter is {}", startDistributionEngine);
+ logger.debug("Distribution engine activation parameter is {}", startDistributionEngine);
if (!startDistributionEngine) {
- LOGGER.info("The disribution engine is disabled");
+ logger.info("The distribution engine is disabled");
this.distributionEngineClusterHealth.setHealthCheckUebIsDisabled();
@@ -117,21 +136,21 @@ public class DistributionEngine implements IDistributionEngine {
List<String> environments = distributionEngineConfiguration.getEnvironments();
for (String envName : environments) {
- LOGGER.debug("init task for environment {}", envName);
+ logger.debug("init task for environment {}", envName);
AtomicBoolean status = new AtomicBoolean(false);
envNamePerStatus.put(envName, status);
environmentsEngine.connectUebTopicForDistributionConfTopic(envName, status, envNamePerInitTask, envNamePerPollingTask);
}
- LOGGER.debug("init UEB health check");
+ logger.debug("init UEB health check");
distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
- LOGGER.trace("Exit init method of DistributionEngine");
+ logger.trace("Exit init method of DistributionEngine");
}
@PreDestroy
public void shutdown() {
- LOGGER.info("distribution engine shutdown - start");
+ logger.info("distribution engine shutdown - start");
if (envNamePerInitTask != null) {
for (DistributionEngineInitTask task : envNamePerInitTask.values()) {
task.destroy();
@@ -147,16 +166,14 @@ public class DistributionEngine implements IDistributionEngine {
/**
* validate mandatory configuration parameters received
- *
- * @param deConfiguration
- * @return
+ * @param deConfiguration: distribution engine configuration
+ * @return boolean result: true of false
*/
protected boolean validateConfiguration(DistributionEngineConfiguration deConfiguration) {
String methodName = "validateConfiguration";
- boolean result = true;
- result = isValidServers(deConfiguration.getUebServers(), methodName, "uebServers") && result;
+ boolean result = isValidServers(deConfiguration.getUebServers(), methodName, "uebServers");
result = isValidParam(deConfiguration.getEnvironments(), methodName, "environments") && result;
result = isValidParam(deConfiguration.getUebPublicKey(), methodName, "uebPublicKey") && result;
result = isValidParam(deConfiguration.getUebSecretKey(), methodName, "uebSecretKey") && result;
@@ -203,7 +220,7 @@ public class DistributionEngine implements IDistributionEngine {
return matcher.matches();
} catch (Exception e) {
- LOGGER.debug("Failed to match value of address {}", serverFqdn, e);
+ logger.debug("Failed to match value of address {}", serverFqdn, e);
return false;
}
}
@@ -287,15 +304,16 @@ public class DistributionEngine implements IDistributionEngine {
public ActionStatus notifyService(String distributionId, Service service, INotificationData notificationData, String envName, User modifier) {
return notifyService(distributionId, service, notificationData, envName, envName, modifier);
}
+
@Override
- public ActionStatus notifyService(String distributionId, Service service, INotificationData notificationData, String envId, String envName, User modifier) {
- LOGGER.debug("Received notify service request. distributionId = {}, serviceUuid = {} serviceUid = {}, envName = {}, modifier {}", distributionId, service.getUUID(), service.getUniqueId(), envName, modifier);
+ public ActionStatus notifyService(String distributionId, Service service, INotificationData notificationData, String envId, String envName, User modifier) {
+ logger.debug("Received notify service request. distributionId = {}, serviceUuid = {} serviceUid = {}, envName = {}, userId = {}, modifierName {}", distributionId, service.getUUID(), service.getUniqueId(), envName, service.getLastUpdaterUserId(), modifier);
String topicName = buildTopicName(envName);
ActionStatus notifyServiceStatus = Optional.ofNullable(environmentsEngine.getEnvironmentById(envId))
.map(EnvironmentMessageBusData::new)
.map(messageBusData -> distributionNotificationSender.sendNotification(topicName, distributionId, messageBusData, notificationData, service, modifier))
.orElse(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE);
- LOGGER.debug("Finish notifyService. status is {}", notifyServiceStatus);
+ logger.debug("Finish notifyService. status is {}", notifyServiceStatus);
return notifyServiceStatus;
}
@@ -321,6 +339,11 @@ public class DistributionEngine implements IDistributionEngine {
}
@Override
+ public OperationalEnvironmentEntry getEnvironmentByDmaapUebAddress(List<String> dmaapUebAddress) {
+ return environmentsEngine.getEnvironmentByDmaapUebAddress(dmaapUebAddress);
+ }
+
+ @Override
public INotificationData buildServiceForDistribution(Service service, String distributionId, String workloadContext) {
INotificationData value = serviceDistributionArtifactsBuilder.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
value = serviceDistributionArtifactsBuilder.buildServiceForDistribution(value, service);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java
index e803730566..ec58cad146 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java
@@ -35,7 +35,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@Component("distribution-engine-cluster-health")
public class DistributionEngineClusterHealth {
@@ -66,7 +72,8 @@ public class DistributionEngineClusterHealth {
OK(new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.UP, null, ClusterStatusDescription.OK.getDescription())),
UNAVAILABLE(new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.UNAVAILABLE.getDescription())),
NOT_CONFIGURED(new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.NOT_CONFIGURED.getDescription())),
- DISABLED(new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.DISABLED.getDescription()));
+ DISABLED(new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.DISABLED.getDescription())),
+ UNKNOWN(new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.UNKNOWN, null, ClusterStatusDescription.UNKNOWN.getDescription()));
private HealthCheckInfo healthCheckInfo;
@@ -80,7 +87,7 @@ public class DistributionEngineClusterHealth {
}
- private HealthCheckInfo healthCheckInfo = HealthCheckInfoResult.UNAVAILABLE.getHealthCheckInfo();
+ private HealthCheckInfo healthCheckInfo = HealthCheckInfoResult.UNKNOWN.getHealthCheckInfo();
private Map<String, AtomicBoolean> envNamePerStatus = null;
@@ -97,7 +104,7 @@ public class DistributionEngineClusterHealth {
public enum ClusterStatusDescription {
- OK("OK"), UNAVAILABLE("U-EB cluster is not available"), NOT_CONFIGURED("U-EB cluster is not configured"), DISABLED("DE is disabled in configuration");
+ OK("OK"), UNAVAILABLE("U-EB cluster is not available"), NOT_CONFIGURED("U-EB cluster is not configured"), DISABLED("DE is disabled in configuration"), UNKNOWN("U-EB cluster is currently unknown (try again in few minutes)");
private String desc;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java
index 276ef68b92..933d3ef4a1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEnginePollingTask.java
@@ -32,6 +32,7 @@ import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionS
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -41,6 +42,7 @@ import java.util.concurrent.TimeUnit;
public class DistributionEnginePollingTask implements Runnable {
public static final String DISTRIBUTION_STATUS_POLLING = "distributionEngineStatusPolling";
+ private static final String PARTNER_NAME = "UNKNOWN";
private String topicName;
private ComponentsUtils componentUtils;
@@ -56,6 +58,7 @@ public class DistributionEnginePollingTask implements Runnable {
private ScheduledExecutorService scheduledPollingService = Executors.newScheduledThreadPool(1, new BasicThreadFactory.Builder().namingPattern("TopicPollingThread-%d").build());
private static final Logger logger = Logger.getLogger(DistributionEnginePollingTask.class.getName());
+ private static LoggerSdcAudit audit = new LoggerSdcAudit(DistributionEnginePollingTask.class);
ScheduledFuture<?> scheduledFuture = null;
private CambriaConsumer cambriaConsumer = null;
@@ -96,9 +99,7 @@ public class DistributionEnginePollingTask implements Runnable {
}
} catch (Exception e) {
logger.debug("unexpected error occured", e);
- String methodName = new Object() {
- }.getClass().getEnclosingMethod().getName();
-
+ String methodName = Object.class.getEnclosingMethod().getName();
BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(methodName, e.getMessage());
}
}
@@ -154,7 +155,8 @@ public class DistributionEnginePollingTask implements Runnable {
logger.trace("received message {}", message);
try {
DistributionStatusNotification notification = gson.fromJson(message, DistributionStatusNotification.class);
- handleDistributionNotificationMsg(notification);
+ audit.startAuditFetchLog(PARTNER_NAME, DistributionEnginePollingTask.class.getName());
+ handleDistributionNotificationMsg(notification, audit);
distributionEngineClusterHealth.setHealthCheckOkAndReportInCaseLastStateIsDown();
} catch (Exception e) {
logger.debug("failed to convert message to object", e);
@@ -163,18 +165,18 @@ public class DistributionEnginePollingTask implements Runnable {
}
} catch (Exception e) {
- logger.debug("unexpected error occured", e);
- String methodName = new Object() {
- }.getClass().getEnclosingMethod().getName();
-
+ logger.debug("unexpected error occurred", e);
+ String methodName = Object.class.getEnclosingMethod().getName();
BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(methodName, e.getMessage());
}
}
- private void handleDistributionNotificationMsg(DistributionStatusNotification notification) {
- componentUtils.auditDistributionStatusNotification(notification.getDistributionID(), notification.getConsumerID(), topicName, notification.getArtifactURL(),
- String.valueOf(notification.getTimestamp()), notification.getStatus().name(), notification.getErrorReason());
+ private void handleDistributionNotificationMsg(DistributionStatusNotification notification, LoggerSdcAudit audit) {
+ componentUtils.auditDistributionStatusNotification(notification.getDistributionID(),
+ notification.getConsumerID(), topicName, notification.getArtifactURL(),
+ String.valueOf(notification.getTimestamp()), notification.getStatus().name(),
+ notification.getErrorReason(), audit);
if (notification.isDistributionCompleteNotification()) {
distributionCompleteReporter.reportDistributionComplete(notification);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java
index 006aa26082..430b8bec24 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionStatusNotification.java
@@ -78,7 +78,7 @@ public class DistributionStatusNotification {
}
public boolean isDistributionCompleteNotification() {
- return DistributionStatusNotificationEnum.DISTRIBUTION_COMPLETE_OK.equals(status) || DistributionStatusNotificationEnum.DISTRIBUTION_COMPLETE_ERROR.equals(status);
+ return DistributionStatusNotificationEnum.DISTRIBUTION_COMPLETE_OK == status || DistributionStatusNotificationEnum.DISTRIBUTION_COMPLETE_ERROR == status;
}
@Override
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapClientFactory.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapClientFactory.java
index f62c1bca60..4fb4122984 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapClientFactory.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapClientFactory.java
@@ -20,12 +20,14 @@
package org.openecomp.sdc.be.components.distribution.engine;
+import com.att.nsa.mr.client.MRBatchingPublisher;
import com.att.nsa.mr.client.MRClientFactory;
import com.att.nsa.mr.client.MRConsumer;
import fj.data.Either;
+import org.onap.sdc.security.SecurityUtil;
import org.openecomp.sdc.be.config.DmaapConsumerConfiguration;
+import org.openecomp.sdc.be.config.DmaapProducerConfiguration;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.security.SecurityUtil;
import org.springframework.stereotype.Component;
import java.io.File;
@@ -46,11 +48,24 @@ public class DmaapClientFactory {
* @return an instance object of type MRConsumer
* @throws IOException
*/
- public MRConsumer create(DmaapConsumerConfiguration parameters) throws Exception {
+ public MRConsumer create(DmaapConsumerConfiguration parameters) throws GeneralSecurityException, IOException {
MRConsumer consumer = MRClientFactory.createConsumer(buildProperties(parameters));
logger.info("MRConsumer created for topic {}", parameters.getTopic());
return consumer;
}
+
+ /**
+ * Creates DMAAP consumer according to received parameters
+ * @param parameters
+ * @return an instance object of type MRConsumer
+ * @throws IOException
+ */
+ public MRBatchingPublisher createProducer(DmaapProducerConfiguration parameters) throws Exception {
+ Properties prop = buildProducerProperties(parameters);
+ MRBatchingPublisher producer = MRClientFactory.createBatchingPublisher(prop);
+ logger.info("MRBatchingPublisher created for topic {}", parameters.getTopic());
+ return producer;
+ }
private Properties buildProperties(DmaapConsumerConfiguration parameters) throws GeneralSecurityException, IOException {
Properties props = new Properties();
@@ -80,6 +95,13 @@ public class DmaapClientFactory {
props.setProperty("AFT_DME2_EP_CONN_TIMEOUT", Integer.toString(parameters.getAftDme2ConnectionTimeoutMs()));
props.setProperty("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", Integer.toString(parameters.getAftDme2RoundtripTimeoutMs()));
props.setProperty("AFT_DME2_EP_READ_TIMEOUT_MS", Integer.toString(parameters.getAftDme2ReadTimeoutMs()));
+
+ props.setProperty("AFT_DME2_SSL_ENABLE", Boolean.toString(parameters.isAftDme2SslEnable()));
+ props.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", Boolean.toString(parameters.isAftDme2ClientIgnoreSslConfig()));
+ props.setProperty("AFT_DME2_CLIENT_KEYSTORE", parameters.getAftDme2ClientKeystore());
+ props.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", parameters.getAftDme2ClientKeystorePassword());
+ props.setProperty("AFT_DME2_CLIENT_SSL_CERT_ALIAS", parameters.getAftDme2ClientSslCertAlias());
+
String dme2PreferredRouterFilePath = parameters.getDme2preferredRouterFilePath();
ensureFileExists(dme2PreferredRouterFilePath);
@@ -98,6 +120,61 @@ public class DmaapClientFactory {
return props;
}
+ private Properties buildProducerProperties(DmaapProducerConfiguration parameters) throws GeneralSecurityException, IOException {
+ logger.info("The DmaapProducerConfiguration is {} ", parameters);
+ Properties props = new Properties();
+ Either<String,String> passkey = SecurityUtil.INSTANCE.decrypt(parameters.getCredential().getPassword() );
+ if (passkey.isRight()){
+ throw new GeneralSecurityException("invalid password, cannot build properties");
+ }
+ props.setProperty("Latitude", Double.toString(parameters.getLatitude()));
+ props.setProperty("Longitude", Double.toString(parameters.getLongitude()));
+ props.setProperty("Version", parameters.getVersion());
+ props.setProperty("ServiceName", parameters.getServiceName());
+ props.setProperty("Environment", parameters.getEnvironment());
+ props.setProperty("Partner", parameters.getPartner());
+ props.setProperty("routeOffer", parameters.getRouteOffer());
+ props.setProperty("Protocol", parameters.getProtocol());
+ props.setProperty("username", parameters.getCredential().getUsername());
+ props.setProperty("password", passkey.left().value() );
+ props.setProperty("contenttype", parameters.getContenttype());
+ props.setProperty("host", parameters.getHosts());
+ props.setProperty("topic", parameters.getTopic());
+ props.setProperty("group", parameters.getConsumerGroup());
+ props.setProperty("id", parameters.getConsumerId());
+ props.setProperty("AFT_DME2_REQ_TRACE_ON", Boolean.toString(parameters.isDme2TraceOn()));
+ props.setProperty("AFT_ENVIRONMENT", parameters.getAftEnvironment());
+ props.setProperty("AFT_DME2_EP_CONN_TIMEOUT", Integer.toString(parameters.getAftDme2ConnectionTimeoutMs()));
+ props.setProperty("AFT_DME2_ROUNDTRIP_TIMEOUT_MS", Integer.toString(parameters.getAftDme2RoundtripTimeoutMs()));
+ props.setProperty("AFT_DME2_EP_READ_TIMEOUT_MS", Integer.toString(parameters.getAftDme2ReadTimeoutMs()));
+
+ props.setProperty("AFT_DME2_SSL_ENABLE", Boolean.toString(parameters.isAftDme2SslEnable()));
+ props.setProperty("AFT_DME2_CLIENT_IGNORE_SSL_CONFIG", Boolean.toString(parameters.isAftDme2ClientIgnoreSslConfig()));
+ props.setProperty("AFT_DME2_CLIENT_KEYSTORE", parameters.getAftDme2ClientKeystore());
+ props.setProperty("AFT_DME2_CLIENT_KEYSTORE_PASSWORD", parameters.getAftDme2ClientKeystorePassword());
+ props.setProperty("AFT_DME2_CLIENT_SSL_CERT_ALIAS", parameters.getAftDme2ClientSslCertAlias());
+
+ String dme2PreferredRouterFilePath = parameters.getDme2preferredRouterFilePath();
+ ensureFileExists(dme2PreferredRouterFilePath);
+ props.setProperty("DME2preferredRouterFilePath", dme2PreferredRouterFilePath);
+ props.setProperty("TransportType", "HTTPAAF");
+ props.setProperty("SubContextPath", "/");
+ props.setProperty("MethodType", "POST");
+ props.setProperty("authKey", "");
+ props.setProperty("authDate", "");
+ props.setProperty("AFT_DME2_EXCHANGE_REQUEST_HANDLERS", "");
+ props.setProperty("AFT_DME2_EXCHANGE_REPLY_HANDLERS", "");
+ props.setProperty("sessionstickinessrequired", "no");
+
+ props.setProperty("maxBatchSize","1");
+ props.setProperty("maxAgeMs","250");
+ props.setProperty("partition","1");
+ props.setProperty("MessageSentThreadOccurance","10");
+ props.setProperty("Authorization","Basic bTEzMzMxQGNjZC5hdHQuY29tOkFhMTIzNDU2");
+
+ return props;
+ }
+
private void ensureFileExists(String filePath) throws IOException {
File file = new File(filePath);
if(file.createNewFile()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapConsumer.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapConsumer.java
index 6388083a57..681b3021bb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapConsumer.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapConsumer.java
@@ -23,6 +23,7 @@ package org.openecomp.sdc.be.components.distribution.engine;
import com.att.nsa.mr.client.MRConsumer;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.DmaapConsumerConfiguration;
+import org.openecomp.sdc.common.log.elements.LogFieldsMdcHandler;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -39,10 +40,12 @@ import java.util.function.Consumer;
*/
@Service
public class DmaapConsumer {
+ private static final String LOG_PARTNER_NAME = "SDC.BE";
private static final Logger logger = Logger.getLogger(DmaapClientFactory.class.getName());
private final ExecutorFactory executorFactory;
private final DmaapClientFactory dmaapClientFactory;
private final DmaapHealth dmaapHealth;
+ private static LogFieldsMdcHandler mdcFieldsHandler = new LogFieldsMdcHandler();
/**
* Allows to create an object of type DmaapConsumer
* @param executorFactory
@@ -75,6 +78,7 @@ public class DmaapConsumer {
pollExecutor.scheduleWithFixedDelay(() -> {
logger.info("Trying to fetch messages from topic: {}", topic);
boolean isTopicAvailable = false;
+ mdcFieldsHandler.addInfoForErrorAndDebugLogging(LOG_PARTNER_NAME);
try {
Iterable<String> messages = consumer.fetch();
isTopicAvailable = true ;
@@ -87,7 +91,7 @@ public class DmaapConsumer {
//successfully fetched
}
catch (Exception e) {
- logger.error("The exception occured upon fetching DMAAP message", e);
+ logger.error("The exception occurred upon fetching DMAAP message", e);
}
dmaapHealth.report( isTopicAvailable );
}, 0L, dmaapConsumerParams.getPollingInterval(), TimeUnit.SECONDS);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapHealth.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapHealth.java
index 17d81e9b3c..0515b08b2e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapHealth.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapHealth.java
@@ -178,7 +178,7 @@ public class DmaapHealth {
healthCheckInfo = reachable ? HealthCheckInfoResult.OK.healthCheckInfo : HealthCheckInfoResult.DOWN.healthCheckInfo;
}
catch( Exception e ){
- log.debug("{} | cannot check connectivity -> {}",DMAAP_HEALTH_CHECK_STR, e );
+ log.debug("{} - cannot check connectivity -> {}",DMAAP_HEALTH_CHECK_STR, e );
prevIsReachable = lastHealthState.getAndSet(false);
healthCheckInfo = HealthCheckInfoResult.UNAVAILABLE.healthCheckInfo;
}
@@ -196,7 +196,7 @@ public class DmaapHealth {
String hostname = getUrlHost(config.getHosts());
return InetAddress.getByName( hostname ).isReachable(TIMEOUT);
}catch( URISyntaxException e ){
- log.debug("{} | malformed host configuration -> ",DMAAP_HEALTH_CHECK_STR , e);
+ log.debug("{} - malformed host configuration -> ",DMAAP_HEALTH_CHECK_STR , e);
}
return false;
}
@@ -222,10 +222,10 @@ public class DmaapHealth {
if (validator.isValid(qualifiedHost)){
return URIUtils.extractHost(new URI(qualifiedHost)).getHostName();
}else{
- log.debug("{} | invalid url format, continuing ", DMAAP_HEALTH_CHECK_STR );
+ log.debug("{} - invalid url format, continuing ", DMAAP_HEALTH_CHECK_STR );
}
}catch(URISyntaxException e){
- log.debug("{} | invalid url format, continuing {} ", DMAAP_HEALTH_CHECK_STR , e);
+ log.debug("{} - invalid url format, continuing {} ", DMAAP_HEALTH_CHECK_STR , e);
}
//endregion
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java
index 0adf93f365..97d2440c11 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java
@@ -34,10 +34,11 @@ import org.apache.http.HttpStatus;
import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.DmaapActionEnum;
import org.openecomp.sdc.be.components.distribution.engine.IDmaapNotificationData.OperationaEnvironmentTypeEnum;
import org.openecomp.sdc.be.components.distribution.engine.report.DistributionCompleteReporter;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
import org.openecomp.sdc.be.config.DmaapConsumerConfiguration;
-import org.openecomp.sdc.be.config.DmeConfiguration;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
import org.openecomp.sdc.be.datatypes.enums.EnvironmentStatusEnum;
@@ -47,17 +48,25 @@ import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.http.client.api.HttpResponse;
+import org.openecomp.sdc.common.log.elements.LogFieldsMdcHandler;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.glassfish.jersey.internal.guava.Predicates.not;
import static org.openecomp.sdc.common.datastructure.FunctionalInterfaces.runMethodWithTimeOut;
/**
@@ -69,6 +78,7 @@ public class EnvironmentsEngine implements INotificationHandler {
private static final String MESSAGE_BUS = "MessageBus";
private static final String UNKNOWN = "Unknown";
private static final Logger log = Logger.getLogger(EnvironmentsEngine.class.getName());
+ private static final String LOG_PARTNER_NAME = "SDC.BE";
private ConfigurationManager configurationManager = ConfigurationManager.getConfigurationManager();
private Map<String, OperationalEnvironmentEntry> environments = new HashMap<>();
@@ -84,6 +94,7 @@ public class EnvironmentsEngine implements INotificationHandler {
private final CambriaHandler cambriaHandler;
private final DistributionEngineClusterHealth distributionEngineClusterHealth;
private final DistributionCompleteReporter distributionCompleteReporter;
+ private static LogFieldsMdcHandler mdcFieldsHandler = new LogFieldsMdcHandler();
public EnvironmentsEngine(DmaapConsumer dmaapConsumer, OperationalEnvironmentDao operationalEnvironmentDao, DME2EndpointIteratorCreator epIterCreator, AaiRequestHandler aaiRequestHandler, ComponentsUtils componentUtils, CambriaHandler cambriaHandler, DistributionEngineClusterHealth distributionEngineClusterHealth, DistributionCompleteReporter distributionCompleteReporter) {
this.dmaapConsumer = dmaapConsumer;
@@ -100,6 +111,7 @@ public class EnvironmentsEngine implements INotificationHandler {
@PostConstruct
void init() {
try {
+ mdcFieldsHandler.addInfoForErrorAndDebugLogging(LOG_PARTNER_NAME);
environments = populateEnvironments();
createUebTopicsForEnvironments();
initDmeGlobalConfig();
@@ -121,9 +133,9 @@ public class EnvironmentsEngine implements INotificationHandler {
log.warn("cannot read dmaap configuration file,DME might not be initialized properly");
return;
}
- System.setProperty("AFT_ENVIRONMENT", dmaapConsumerParams.getEnvironment()); // AFTPRD for production
- System.setProperty("AFT_LATITUDE", dmaapConsumerParams.getLatitude()!=null ? dmaapConsumerParams.getLatitude().toString() : "1.0"); // Replace with actual latitude
- System.setProperty("AFT_LONGITUDE", dmaapConsumerParams.getLongitude()!=null ? dmaapConsumerParams.getLongitude().toString() : "1.0"); // Replace with actual longitude
+ System.setProperty("AFT_ENVIRONMENT", dmaapConsumerParams.getAftEnvironment()); // AFTPRD for production
+ System.setProperty("AFT_LATITUDE", dmaapConsumerParams.getLatitude() != null ? dmaapConsumerParams.getLatitude().toString() : "1.0"); // Replace with actual latitude
+ System.setProperty("AFT_LONGITUDE", dmaapConsumerParams.getLongitude() != null ? dmaapConsumerParams.getLongitude().toString() : "1.0"); // Replace with actual longitude
}
public void connectUebTopicTenantIsolation(OperationalEnvironmentEntry opEnvEntry,
@@ -233,7 +245,7 @@ public class EnvironmentsEngine implements INotificationHandler {
}
} catch (Exception e) {
- log.debug("handle message for operational environmet failed for notification: {} with error :{}",
+ log.debug("handle message for operational environment failed for notification: {} with error :{}",
notification, e.getMessage(), e);
errorWrapper.setInnerElement(false);
@@ -307,19 +319,20 @@ public class EnvironmentsEngine implements INotificationHandler {
void retrieveUebAddressesFromAftDme(Wrapper<Boolean> errorWrapper, OperationalEnvironmentEntry opEnvEntry) {
log.debug("handle message - Get List Of UEB Addresses From AFT_DME");
+ log.invoke(opEnvEntry.getEnvironmentId(), "retrieveUebAddressesFromAftDme", opEnvEntry.getStatus(), EnvironmentsEngine.class.getName(), errorWrapper.toString() );
try {
boolean isKeyFieldsValid = !isEmpty(opEnvEntry.getTenant()) && !isEmpty(opEnvEntry.getEcompWorkloadContext());
if (isKeyFieldsValid) {
String opEnvKey = map2OpEnvKey(opEnvEntry);
- String environmentId = opEnvEntry.getEnvironmentId();
- List<String> uebHosts = discoverUebHosts(opEnvKey, environmentId);
+ List<String> uebHosts = discoverUebHosts(opEnvKey);
opEnvEntry.setDmaapUebAddress(uebHosts.stream().collect(Collectors.toSet()));
+ log.invokeReturn(opEnvEntry.getEnvironmentId(), "retrieveUebAddressesFromAftDme", opEnvEntry.getStatus(), "SDC-BE", errorWrapper.toString() );
} else {
errorWrapper.setInnerElement(false);
log.debug("Can Not Build AFT DME Key from workLoad & Tenant Fields.");
}
- } catch (DME2Exception e) {
+ } catch (Exception e) {
errorWrapper.setInnerElement(false);
log.error("Failed to retrieve Ueb Addresses From DME. ", e);
}
@@ -425,14 +438,14 @@ public class EnvironmentsEngine implements INotificationHandler {
}
}
- public List<String> discoverUebHosts(String opEnvKey, String env) throws DME2Exception {
- DmeConfiguration dmeConfiguration = configurationManager.getConfiguration().getDmeConfiguration();
- List<String> uebHosts = new LinkedList<>();
+ public List<String> discoverUebHosts(String opEnvKey) throws DME2Exception {
+ String lookupUriFormat = configurationManager.getConfiguration().getDmeConfiguration().getLookupUriFormat();
+ String environment = configurationManager.getConfiguration().getDmaapConsumerConfiguration().getEnvironment();
+ String lookupURI = String.format(lookupUriFormat, opEnvKey, environment);
+ log.debug("DME2 GRM URI: {}", lookupURI);
- String lookupURI = String.format("http://%s/service=%s/version=1.0.0/envContext=%s/partner=*", dmeConfiguration.getDme2Search(), opEnvKey,
- env);
+ List<String> uebHosts = new LinkedList<>();
DME2EndpointIterator iterator = epIterCreator.create(lookupURI);
-
// Beginning iteration
while (iterator.hasNext()) {
DME2EndpointReference ref = iterator.next();
@@ -469,6 +482,7 @@ public class EnvironmentsEngine implements INotificationHandler {
String envName = distributionEngineConfiguration.getEnvironments().size() == 1
? distributionEngineConfiguration.getEnvironments().get(0) : UNKNOWN;
entry.setEnvironmentId(envName);
+ entry.setIsProduction(true);
if (log.isDebugEnabled()) {
log.debug("Enviroment read from configuration: {}", entry);
@@ -494,7 +508,9 @@ public class EnvironmentsEngine implements INotificationHandler {
}
void createUebTopicsForEnvironments() {
- environments.values().forEach(this::createUebTopicsForEnvironment);
+ environments.values().stream()
+ .filter(not(OperationalEnvironmentEntry::getIsProduction))
+ .forEach(this::createUebTopicsForEnvironment);
}
public void createUebTopicsForEnvironment(OperationalEnvironmentEntry opEnvEntry) {
@@ -515,6 +531,15 @@ public class EnvironmentsEngine implements INotificationHandler {
return environments;
}
+ public OperationalEnvironmentEntry getEnvironmentByDmaapUebAddress(List<String> dmaapUebAddress) {
+ return environments.values().stream()
+ .filter(e -> e.getDmaapUebAddress().stream()
+ .filter(dmaapUebAddress::contains).findAny().isPresent())
+ .findFirst()
+ .orElseThrow(() -> new ByActionStatusComponentException(ActionStatus.DISTRIBUTION_ENV_DOES_NOT_EXIST,dmaapUebAddress.toString()));
+ }
+
+
public Either<OperationalEnvInfo, Integer> getOperationalEnvById(String id) {
HttpResponse<String> resp = aaiRequestHandler.getOperationalEnvById(id);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ICambriaHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ICambriaHandler.java
new file mode 100644
index 0000000000..60ab20d292
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ICambriaHandler.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.distribution.engine;
+
+import com.att.nsa.apiClient.credentials.ApiCredential;
+import com.att.nsa.cambria.client.CambriaConsumer;
+import fj.data.Either;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+public interface ICambriaHandler {
+
+ Either<Set<String>, CambriaErrorResponse> getTopics(List<String> hostSet);
+ CambriaErrorResponse createTopic(Collection<String> hostSet, String apiKey, String secretKey, String topicName, int partitionCount, int replicationCount);
+ CambriaErrorResponse unRegisterFromTopic(Collection<String> hostSet, String managerApiKey, String managerSecretKey, String subscriberApiKey, SubscriberTypeEnum subscriberTypeEnum, String topicName);
+ CambriaErrorResponse registerToTopic(Collection<String> hostSet, String managerApiKey, String managerSecretKey, String subscriberApiKey, SubscriberTypeEnum subscriberTypeEnum, String topicName);
+ CambriaConsumer createConsumer(Collection<String> hostSet, String topicName, String apiKey, String secretKey, String consumerId, String consumerGroup, int timeoutMS) throws Exception;
+ Either<Iterable<String>, CambriaErrorResponse> fetchFromTopic(CambriaConsumer topicConsumer);
+ CambriaErrorResponse sendNotification(String topicName, String uebPublicKey, String uebSecretKey, List<String> uebServers, INotificationData data);
+ CambriaErrorResponse sendNotificationAndClose(String topicName, String uebPublicKey, String uebSecretKey, List<String> uebServers, INotificationData data, long waitBeforeCloseTimeout);
+ CambriaErrorResponse getApiKey(String server, String apiKey);
+ Either<ApiCredential, CambriaErrorResponse> createUebKeys(List<String> hostSet);
+
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java
index bbc9c3a284..1c58112293 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDistributionEngine.java
@@ -26,6 +26,8 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
+import java.util.List;
+
public interface IDistributionEngine {
boolean isActive();
@@ -50,4 +52,6 @@ public interface IDistributionEngine {
INotificationData buildServiceForDistribution(Service service, String distributionId, String workloadContext);
OperationalEnvironmentEntry getEnvironmentById(String opEnvId);
+
+ OperationalEnvironmentEntry getEnvironmentByDmaapUebAddress(List<String> dmaapUebAddress);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDmaapNotificationData.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDmaapNotificationData.java
index 7b974e8a96..ee90867d02 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDmaapNotificationData.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/IDmaapNotificationData.java
@@ -29,10 +29,6 @@ public interface IDmaapNotificationData {
DmaapActionEnum getAction();
-
-
-
-
enum DmaapActionEnum {
DELETE("Delete"),
CREATE("Create"),
@@ -53,7 +49,8 @@ public interface IDmaapNotificationData {
public static DmaapActionEnum findByName(String actionName){
return getEnumValueByFieldValue(actionName, DmaapActionEnum.values(), DmaapActionEnum::getActionName, UNKONW, false);
}
- };
+ }
+
enum OperationaEnvironmentTypeEnum {
ECOMP("ECOMP"),
UNKONW("UNKONW")
@@ -71,6 +68,5 @@ public interface IDmaapNotificationData {
public static OperationaEnvironmentTypeEnum findByName(String operationalEnvironmentTypeName){
return getEnumValueByFieldValue(operationalEnvironmentTypeName, OperationaEnvironmentTypeEnum.values(), OperationaEnvironmentTypeEnum::getEventTypenName, UNKONW, false);
}
- };
-
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
index 7f8e814897..4a12cec213 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorService.java
@@ -24,7 +24,11 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.concurrent.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
public class NotificationExecutorService {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java
index de695d6501..ef43c43bf5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/ServiceDistributionArtifactsBuilder.java
@@ -24,11 +24,15 @@ import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.IArtifactOperation;
+import org.openecomp.sdc.be.model.operations.impl.ArtifactOperation;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -54,7 +58,7 @@ public class ServiceDistributionArtifactsBuilder {
InterfaceLifecycleOperation interfaceLifecycleOperation;
@javax.annotation.Resource
- IArtifactOperation artifactOperation;
+ ArtifactOperation artifactOperation;
private final ToscaOperationFacade toscaOperationFacade;
@@ -164,7 +168,6 @@ public class ServiceDistributionArtifactsBuilder {
private List<ArtifactInfoImpl> convertToArtifactsInfoImpl(Service service, ComponentInstance resourceInstance) {
List<ArtifactInfoImpl> artifacts = ArtifactInfoImpl.convertToArtifactInfoImpl(service, resourceInstance, getArtifactsWithPayload(resourceInstance));
- artifacts.stream().forEach(ArtifactInfoImpl::updateArtifactTimeout);
return artifacts;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java
index 1fcc071f58..bed0aaecc1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/UebHealthCheckCall.java
@@ -55,6 +55,9 @@ public class UebHealthCheckCall implements Callable<Boolean> {
logger.debug("After running Health check towards ueb server {}. Error code is {}. Set result to true", server, cambriaErrorResponse.httpCode);
result = true;
}
+ else {
+ logger.debug("After running Health check towards ueb server {}. Error code is {}. Set result to false", server, cambriaErrorResponse.httpCode);
+ }
healthLogger.trace("Result after running health check towards ueb server {} is {}. Returned result is {} ", server, cambriaErrorResponse, result);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java
index 2f119c96a4..c566c1c0ee 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/VfModuleArtifactPayload.java
@@ -27,7 +27,11 @@ import org.openecomp.sdc.be.model.GroupInstanceProperty;
import org.openecomp.sdc.be.model.GroupProperty;
import org.openecomp.sdc.common.api.Constants;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
public class VfModuleArtifactPayload {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/rest/MSORestClient.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/rest/MSORestClient.java
index de335d7625..fb0310bf7c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/rest/MSORestClient.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/rest/MSORestClient.java
@@ -27,7 +27,12 @@ import org.apache.http.entity.StringEntity;
import org.eclipse.jetty.util.URIUtil;
import org.openecomp.sdc.be.components.distribution.engine.DistributionStatusNotificationEnum;
import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.common.http.client.api.*;
+import org.openecomp.sdc.common.http.client.api.HttpExecuteException;
+import org.openecomp.sdc.common.http.client.api.HttpRequest;
+import org.openecomp.sdc.common.http.client.api.HttpResponse;
+import org.openecomp.sdc.common.http.client.api.Responses;
+import org.openecomp.sdc.common.http.client.api.RestUtils;
+import org.openecomp.sdc.common.http.client.api.RetryHandlers;
import org.openecomp.sdc.common.http.config.BasicAuthorization;
import org.openecomp.sdc.common.http.config.ExternalServiceConfig;
import org.openecomp.sdc.common.http.config.HttpClientConfig;
@@ -52,6 +57,7 @@ public class MSORestClient {
if ( numOfRetries > 0 ) {
httpClientConfig.setRetryHandler(RetryHandlers.getDefault(numOfRetries));
}
+ serviceConfig.getHttpClientConfig().setEnableMetricLogging(true);
}
public HttpResponse<String> notifyDistributionComplete(String distributionId, DistributionStatusNotificationEnum distributionStatusEnum, String errReason) {
@@ -67,7 +73,6 @@ public class MSORestClient {
private HttpResponse<String> doNotifyDistributionComplete(String distributionId, DistributionStatusNotificationEnum distributionStatusEnum, String errReason) throws HttpExecuteException {
StringEntity entity = new StringEntity(gson.toJson(new DistributionStatusRequest(distributionStatusEnum.name(), errReason)), ContentType.APPLICATION_JSON);
HttpResponse<String> response = HttpRequest.patch(buildMsoDistributionUrl(distributionId), buildReqHeader(), entity, serviceConfig.getHttpClientConfig());
- logger.info("response from mso - status code: {}, status description: {}, response: {}, ", response.getStatusCode(), response.getDescription(), response.getResponse());
return response;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java
index 857fd1bdd7..e411433baf 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java
@@ -22,15 +22,17 @@ package org.openecomp.sdc.be.components.health;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
+import org.openecomp.sdc.be.catalog.impl.DmaapProducerHealth;
import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth;
import org.openecomp.sdc.be.components.distribution.engine.DmaapHealth;
+import org.openecomp.sdc.be.components.impl.CADIHealthCheck;
import org.openecomp.sdc.be.components.impl.CassandraHealthCheck;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.impl.EsHealthCheckDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.switchover.detector.SwitchoverDetector;
import org.openecomp.sdc.common.api.HealthCheckInfo;
@@ -39,6 +41,7 @@ import org.openecomp.sdc.common.http.client.api.HttpRequest;
import org.openecomp.sdc.common.http.client.api.HttpResponse;
import org.openecomp.sdc.common.http.config.HttpClientConfig;
import org.openecomp.sdc.common.http.config.Timeouts;
+import org.openecomp.sdc.common.log.elements.LogFieldsMdcHandler;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.HealthCheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
@@ -61,7 +64,13 @@ import static java.lang.String.format;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR;
import static org.apache.http.HttpStatus.SC_OK;
-import static org.openecomp.sdc.common.api.Constants.*;
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_BE;
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_CASSANDRA;
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_DCAE;
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_DMAAP_PRODUCER;
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_ECOMP_PORTAL;
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_JANUSGRAPH;
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_ON_BOARDING;
import static org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus.DOWN;
import static org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus.UP;
import static org.openecomp.sdc.common.impl.ExternalConfiguration.getAppVersion;
@@ -70,31 +79,33 @@ import static org.openecomp.sdc.common.impl.ExternalConfiguration.getAppVersion;
@Component("healthCheckBusinessLogic")
public class HealthCheckBusinessLogic {
- protected static final String BE_HEALTH_LOG_CONTEXT = "be.healthcheck";
+ private static String hcUrl = "%s://%s:%s%s";
private static final String BE_HEALTH_CHECK_STR = "beHealthCheck";
+ private static final String LOG_PARTNER_NAME = "SDC.BE";
private static final String COMPONENT_CHANGED_MESSAGE = "BE Component %s state changed from %s to %s";
private static final Logger log = Logger.getLogger(HealthCheckBusinessLogic.class.getName());
private static final HealthCheckUtil healthCheckUtil = new HealthCheckUtil();
private final ScheduledExecutorService healthCheckScheduler = newSingleThreadScheduledExecutor((Runnable r) -> new Thread(r, "BE-Health-Check-Task"));
private HealthCheckScheduledTask healthCheckScheduledTask = null;
+ private static LogFieldsMdcHandler mdcFieldsHandler = new LogFieldsMdcHandler();
+
@Resource
private JanusGraphGenericDao janusGraphGenericDao;
@Resource
- private EsHealthCheckDao esHealthCheckDao;
- @Resource
private DistributionEngineClusterHealth distributionEngineClusterHealth;
@Resource
private DmaapHealth dmaapHealth;
@Resource
+ private DmaapProducerHealth dmaapProducerHealth;
+ @Resource
private CassandraHealthCheck cassandraHealthCheck;
- private final SwitchoverDetector switchoverDetector;
- private volatile List<HealthCheckInfo> prevBeHealthCheckInfos = null;
- private ScheduledFuture<?> scheduledFuture = null;
+ @Resource
+ private PortalHealthCheckBuilder portalHealthCheck;
@Autowired
- public HealthCheckBusinessLogic(SwitchoverDetector switchoverDetector) {
- this.switchoverDetector = switchoverDetector;
- }
+ private SwitchoverDetector switchoverDetector;
+ private volatile List<HealthCheckInfo> prevBeHealthCheckInfos = null;
+ private ScheduledFuture<?> scheduledFuture = null;
@PostConstruct
public void init() {
@@ -114,7 +125,7 @@ public class HealthCheckBusinessLogic {
public boolean isDistributionEngineUp() {
HealthCheckInfo healthCheckInfo = distributionEngineClusterHealth.getHealthCheckInfo();
- return !healthCheckInfo.getHealthCheckStatus().equals(DOWN);
+ return healthCheckInfo.getHealthCheckStatus() != DOWN;
}
public Pair<Boolean, List<HealthCheckInfo>> getBeHealthCheckInfosStatus() {
@@ -129,103 +140,98 @@ public class HealthCheckBusinessLogic {
List<HealthCheckInfo> healthCheckInfos = new ArrayList<>();
//Dmaap
- getDmaapHealthCheck(healthCheckInfos);
+ HealthCheckInfo info;
+ if ((info = getDmaapHealthCheck()) != null) {
+ healthCheckInfos.add(info);
+ }
+
+ //DmaapProducer
+ healthCheckInfos.add(getDmaapProducerHealthCheck());
// BE
- getBeHealthCheck(healthCheckInfos);
+ healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_BE, UP, getAppVersion(), "OK"));
// JanusGraph
- getJanusGraphHealthCheck(healthCheckInfos);
- // ES
- getEsHealthCheck(healthCheckInfos);
+ healthCheckInfos.add(getJanusGraphHealthCheck());
// Distribution Engine
- getDistributionEngineCheck(healthCheckInfos);
+ healthCheckInfos.add(distributionEngineClusterHealth.getHealthCheckInfo());
//Cassandra
- getCassandraHealthCheck(healthCheckInfos);
+ healthCheckInfos.add(getCassandraHealthCheck());
// Amdocs
- getAmdocsHealthCheck(healthCheckInfos);
+ healthCheckInfos.add(getHostedComponentsBeHealthCheck(HC_COMPONENT_ON_BOARDING, buildOnBoardingHealthCheckUrl()));
//DCAE
- getDcaeHealthCheck(healthCheckInfos);
-
- return healthCheckInfos;
- }
+ healthCheckInfos.add(getHostedComponentsBeHealthCheck(HC_COMPONENT_DCAE, buildDcaeHealthCheckUrl()));
- private List<HealthCheckInfo> getEsHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+ //ECOMP Portal
+ healthCheckInfos.add(portalHealthCheck.getHealthCheckInfo());
- // ES health check and version
- String appVersion = getAppVersion();
- HealthCheckStatus healthCheckStatus;
- String description;
-
- try {
- healthCheckStatus = esHealthCheckDao.getClusterHealthStatus();
- } catch (Exception e) {
- healthCheckStatus = DOWN;
- description = "ES cluster error: " + e.getMessage();
- healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_ES, healthCheckStatus, appVersion, description));
- log.error(description, e);
- return healthCheckInfos;
- }
- if (healthCheckStatus.equals(DOWN)) {
- description = "ES cluster is down";
- } else {
- description = "OK";
- }
- healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_ES, healthCheckStatus, appVersion, description));
- return healthCheckInfos;
- }
+ //CADI
+ healthCheckInfos.add(CADIHealthCheck.getCADIHealthCheckInstance().getCADIStatus());
- private List<HealthCheckInfo> getBeHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
- String appVersion = getAppVersion();
- String description = "OK";
- healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_BE, UP, appVersion, description));
return healthCheckInfos;
}
- private List<HealthCheckInfo> getDmaapHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+ private HealthCheckInfo getDmaapHealthCheck() {
+ HealthCheckInfo healthCheckInfo = null;
if(ConfigurationManager.getConfigurationManager().getConfiguration().getDmaapConsumerConfiguration().isActive()){
String appVersion = getAppVersion();
dmaapHealth.getHealthCheckInfo().setVersion(appVersion);
- healthCheckInfos.add(dmaapHealth.getHealthCheckInfo());
+ healthCheckInfo = dmaapHealth.getHealthCheckInfo();
} else {
log.debug("Dmaap health check disabled");
}
-
- return healthCheckInfos;
+ return healthCheckInfo;
}
+ private HealthCheckInfo getDmaapProducerHealthCheck() {
+ HealthCheckInfo healthCheckInfo = null;
+ if(ConfigurationManager.getConfigurationManager().getConfiguration().getDmaapConsumerConfiguration().isActive()){
+ String appVersion = getAppVersion();
+ dmaapProducerHealth.getHealthCheckInfo().setVersion(appVersion);
+ healthCheckInfo = dmaapProducerHealth.getHealthCheckInfo();
+ } else {
+ log.debug("Dmaap health check disabled");
+ String description = ("Dmaap health check disabled");
+ healthCheckInfo = new HealthCheckInfo(HC_COMPONENT_DMAAP_PRODUCER, DOWN, null, description);
+ }
+ return healthCheckInfo;
+ }
- public List<HealthCheckInfo> getJanusGraphHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+ public HealthCheckInfo getJanusGraphHealthCheck() {
// JanusGraph health check and version
String description;
boolean isJanusGraphUp;
+ HealthCheckInfo healthCheckInfo = new HealthCheckInfo(HC_COMPONENT_JANUSGRAPH, DOWN, null, null);
try {
isJanusGraphUp = janusGraphGenericDao.isGraphOpen();
} catch (Exception e) {
- description = "JanusGraph error: ";
- healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_JANUSGRAPH, DOWN, null, description));
- log.error(description, e);
- return healthCheckInfos;
+ description = "JanusGraph error: " + e.getMessage();
+ healthCheckInfo.setDescription(description);
+ log.error(description);
+ return healthCheckInfo;
}
if (isJanusGraphUp) {
description = "OK";
- healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_JANUSGRAPH, UP, null, description));
+ healthCheckInfo.setDescription(description);
+ healthCheckInfo.setHealthCheckStatus(HealthCheckInfo.HealthCheckStatus.UP);
+
} else {
description = "JanusGraph graph is down";
- healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_JANUSGRAPH, DOWN, null, description));
+ healthCheckInfo.setDescription(description);
}
- return healthCheckInfos;
+ return healthCheckInfo;
}
- private List<HealthCheckInfo> getCassandraHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
+ private HealthCheckInfo getCassandraHealthCheck() {
String description;
boolean isCassandraUp = false;
+ HealthCheckInfo healthCheckInfo = new HealthCheckInfo(HC_COMPONENT_CASSANDRA, DOWN, null, null);
try {
isCassandraUp = cassandraHealthCheck.getCassandraStatus();
@@ -235,33 +241,15 @@ public class HealthCheckBusinessLogic {
}
if (isCassandraUp) {
description = "OK";
- healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_CASSANDRA, UP, null, description));
+// healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_CASSANDRA, UP, null, description));
+ healthCheckInfo.setHealthCheckStatus(HealthCheckStatus.UP);
+ healthCheckInfo.setDescription(description);
} else {
description = "Cassandra is down";
- healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_CASSANDRA, DOWN, null, description));
+// healthCheckInfos.add(new HealthCheckInfo(HC_COMPONENT_CASSANDRA, DOWN, null, description));
+ healthCheckInfo.setDescription(description);
}
- return healthCheckInfos;
-
- }
-
- private void getDistributionEngineCheck(List<HealthCheckInfo> healthCheckInfos) {
-
- HealthCheckInfo healthCheckInfo = distributionEngineClusterHealth.getHealthCheckInfo();
-
- healthCheckInfos.add(healthCheckInfo);
-
- }
-
- private List<HealthCheckInfo> getAmdocsHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
- HealthCheckInfo beHealthCheckInfo = getHostedComponentsBeHealthCheck(HC_COMPONENT_ON_BOARDING, buildOnBoardingHealthCheckUrl());
- healthCheckInfos.add(beHealthCheckInfo);
- return healthCheckInfos;
- }
-
- private List<HealthCheckInfo> getDcaeHealthCheck(List<HealthCheckInfo> healthCheckInfos) {
- HealthCheckInfo beHealthCheckInfo = getHostedComponentsBeHealthCheck(HC_COMPONENT_DCAE, buildDcaeHealthCheckUrl());
- healthCheckInfos.add(beHealthCheckInfo);
- return healthCheckInfos;
+ return healthCheckInfo;
}
private HealthCheckInfo getHostedComponentsBeHealthCheck(String componentName, String healthCheckUrl) {
@@ -277,35 +265,26 @@ public class HealthCheckBusinessLogic {
int statusCode = httpResponse.getStatusCode();
String aggDescription = "";
- if (statusCode == SC_OK || statusCode == SC_INTERNAL_SERVER_ERROR) {
+ if ((statusCode == SC_OK || statusCode == SC_INTERNAL_SERVER_ERROR) && !componentName.equals(HC_COMPONENT_ECOMP_PORTAL)) {
String response = httpResponse.getResponse();
log.trace("{} Health Check response: {}", componentName, response);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> healthCheckMap = mapper.readValue(response, new TypeReference<Map<String, Object>>() {
});
- version = healthCheckMap.get("sdcVersion") != null ? healthCheckMap.get("sdcVersion").toString() : null;
+ version = getVersion(healthCheckMap);
if (healthCheckMap.containsKey("componentsInfo")) {
componentsInfo = mapper.convertValue(healthCheckMap.get("componentsInfo"), new TypeReference<List<HealthCheckInfo>>() {
});
}
-
- if (!componentsInfo.isEmpty()) {
- aggDescription = healthCheckUtil.getAggregateDescription(componentsInfo, null);
- } else {
- componentsInfo.add(new HealthCheckInfo(HC_COMPONENT_BE, DOWN, null, null));
- }
+ aggDescription = getAggDescription(componentsInfo, aggDescription);
} else {
log.trace("{} Health Check Response code: {}", componentName, statusCode);
}
if (statusCode != SC_OK) {
healthCheckStatus = DOWN;
- description = aggDescription.length() > 0
- ? aggDescription
- : componentName + " is Down, specific reason unknown";//No inner component returned DOWN, but the status of HC is still DOWN.
- if (componentsInfo.isEmpty()) {
- componentsInfo.add(new HealthCheckInfo(HC_COMPONENT_BE, DOWN, null, description));
- }
+ description = getDescription(componentName, aggDescription);
+ setDescriptionToObject(description, componentsInfo);
} else {
healthCheckStatus = UP;
description = "OK";
@@ -315,19 +294,49 @@ public class HealthCheckBusinessLogic {
log.error("{} unexpected response: ", componentName, e);
healthCheckStatus = DOWN;
description = componentName + " unexpected response: " + e.getMessage();
- if (componentsInfo != null && componentsInfo.isEmpty()) {
- componentsInfo.add(new HealthCheckInfo(HC_COMPONENT_BE, DOWN, null, description));
- }
+ addToHealthCheckInfoObject(description, componentsInfo);
}
} else {
healthCheckStatus = DOWN;
description = componentName + " health check Configuration is missing";
componentsInfo.add(new HealthCheckInfo(HC_COMPONENT_BE, DOWN, null, description));
}
-
return new HealthCheckInfo(componentName, healthCheckStatus, version, description, componentsInfo);
}
+ private void addToHealthCheckInfoObject(String description, List<HealthCheckInfo> componentsInfo) {
+ if (componentsInfo != null && componentsInfo.isEmpty()) {
+ componentsInfo.add(new HealthCheckInfo(HC_COMPONENT_BE, DOWN, null, description));
+ }
+ }
+
+ private void setDescriptionToObject(String description, List<HealthCheckInfo> componentsInfo) {
+ if (componentsInfo.isEmpty()) {
+ componentsInfo.add(new HealthCheckInfo(HC_COMPONENT_BE, DOWN, null, description));
+ }
+ }
+
+ private String getDescription(String componentName, String aggDescription) {
+ String description;
+ description = aggDescription.length() > 0
+ ? aggDescription
+ : componentName + " is Down, specific reason unknown";//No inner component returned DOWN, but the status of HC is still DOWN.
+ return description;
+ }
+
+ private String getVersion(Map<String, Object> healthCheckMap) {
+ return healthCheckMap.get("sdcVersion") != null ? healthCheckMap.get("sdcVersion").toString() : null;
+ }
+
+ private String getAggDescription(List<HealthCheckInfo> componentsInfo, String aggDescription) {
+ if (!componentsInfo.isEmpty()) {
+ aggDescription = healthCheckUtil.getAggregateDescription(componentsInfo);
+ } else {
+ componentsInfo.add(new HealthCheckInfo(HC_COMPONENT_BE, DOWN, null, null));
+ }
+ return aggDescription;
+ }
+
@PreDestroy
protected void destroy() {
@@ -364,92 +373,93 @@ public class HealthCheckBusinessLogic {
int prevSize = prevValues.size();
if (currentSize != prevSize) {
-
result = true; //extra/missing component
-
- Map<String, HealthCheckStatus> notPresent = null;
- if (currentValues.keySet().containsAll(prevValues.keySet())) {
- notPresent = new HashMap<>(currentValues);
- notPresent.keySet().removeAll(prevValues.keySet());
- } else {
- notPresent = new HashMap<>(prevValues);
- notPresent.keySet().removeAll(currentValues.keySet());
- }
-
- for (String component : notPresent.keySet()) {
- logAlarm(format(COMPONENT_CHANGED_MESSAGE, component, prevValues.get(component), currentValues.get(component)));
- }
-
+ updateHealthCheckStatusMap(currentValues, prevValues);
} else {
-
- for (Entry<String, HealthCheckStatus> entry : currentValues.entrySet()) {
- String key = entry.getKey();
- HealthCheckStatus value = entry.getValue();
-
- if (!prevValues.containsKey(key)) {
- result = true; //component missing
- logAlarm(format(COMPONENT_CHANGED_MESSAGE, key, prevValues.get(key), currentValues.get(key)));
- break;
- }
-
- HealthCheckStatus prevHealthCheckStatus = prevValues.get(key);
-
- if (value != prevHealthCheckStatus) {
- result = true; //component status changed
- logAlarm(format(COMPONENT_CHANGED_MESSAGE, key, prevValues.get(key), currentValues.get(key)));
- break;
- }
- }
+ result = isHealthStatusChanged(result, currentValues, prevValues);
}
}
} else if (beHealthCheckInfos == null && prevBeHealthCheckInfos == null) {
result = false;
} else {
- logAlarm(format(COMPONENT_CHANGED_MESSAGE, "", prevBeHealthCheckInfos == null ? "null" : "true", prevBeHealthCheckInfos == null ? "true" : "null"));
+ writeLogAlarm(prevBeHealthCheckInfos);
result = true;
}
return result;
}
- private String buildOnBoardingHealthCheckUrl() {
+ private void writeLogAlarm(List<HealthCheckInfo> prevBeHealthCheckInfos) {
+ logAlarm(format(COMPONENT_CHANGED_MESSAGE, "", prevBeHealthCheckInfos == null ? "null" : "true", prevBeHealthCheckInfos == null ? "true" : "null"));
+ }
- Configuration.OnboardingConfig onboardingConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getOnboarding();
+ private boolean isHealthStatusChanged(boolean result, Map<String, HealthCheckStatus> currentValues, Map<String, HealthCheckStatus> prevValues) {
+ for (Entry<String, HealthCheckStatus> entry : currentValues.entrySet()) {
+ String key = entry.getKey();
+ HealthCheckStatus value = entry.getValue();
- if (onboardingConfig != null) {
- String protocol = onboardingConfig.getProtocol();
- String host = onboardingConfig.getHost();
- Integer port = onboardingConfig.getPort();
- String uri = onboardingConfig.getHealthCheckUri();
+ if (!prevValues.containsKey(key)) {
+ result = true; //component missing
+ logAlarm(format(COMPONENT_CHANGED_MESSAGE, key, prevValues.get(key), currentValues.get(key)));
+ break;
+ }
+
+ HealthCheckStatus prevHealthCheckStatus = prevValues.get(key);
+
+ if (value != prevHealthCheckStatus) {
+ result = true; //component status changed
+ logAlarm(format(COMPONENT_CHANGED_MESSAGE, key, prevValues.get(key), currentValues.get(key)));
+ break;
+ }
+ }
+ return result;
+ }
- return protocol + "://" + host + ":" + port + uri;
+ private void updateHealthCheckStatusMap(Map<String, HealthCheckStatus> currentValues, Map<String, HealthCheckStatus> prevValues) {
+ Map<String, HealthCheckStatus> notPresent;
+ if (currentValues.keySet().containsAll(prevValues.keySet())) {
+ notPresent = new HashMap<>(currentValues);
+ notPresent.keySet().removeAll(prevValues.keySet());
+ } else {
+ notPresent = new HashMap<>(prevValues);
+ notPresent.keySet().removeAll(currentValues.keySet());
}
- log.error("onboarding health check configuration is missing.");
+ for (String component : notPresent.keySet()) {
+ logAlarm(format(COMPONENT_CHANGED_MESSAGE, component, prevValues.get(component), currentValues.get(component)));
+ }
+ }
+ @VisibleForTesting
+ String buildOnBoardingHealthCheckUrl() {
+
+ Configuration.OnboardingConfig onboardingConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getOnboarding();
+ if (onboardingConfig != null) {
+ return String.format(hcUrl, onboardingConfig.getProtocol(), onboardingConfig.getHost(),
+ onboardingConfig.getPort(),onboardingConfig.getHealthCheckUri());
+ }
+ log.error("Onboarding health check configuration is missing.");
return null;
}
- private String buildDcaeHealthCheckUrl() {
+ @VisibleForTesting
+ String buildDcaeHealthCheckUrl() {
Configuration.DcaeConfig dcaeConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getDcae();
if (dcaeConfig != null) {
- String protocol = dcaeConfig.getProtocol();
- String host = dcaeConfig.getHost();
- Integer port = dcaeConfig.getPort();
- String uri = dcaeConfig.getHealthCheckUri();
-
- return protocol + "://" + host + ":" + port + uri;
+ return String.format(hcUrl, dcaeConfig.getProtocol(), dcaeConfig.getHost(),
+ dcaeConfig.getPort(),dcaeConfig.getHealthCheckUri());
}
- log.error("dcae health check configuration is missing.");
+ log.error("DCAE health check configuration is missing.");
return null;
}
public class HealthCheckScheduledTask implements Runnable {
@Override
public void run() {
+ mdcFieldsHandler.addInfoForErrorAndDebugLogging(LOG_PARTNER_NAME);
Configuration config = ConfigurationManager.getConfigurationManager().getConfiguration();
log.trace("Executing BE Health Check Task");
@@ -475,6 +485,8 @@ public class HealthCheckBusinessLogic {
BeEcompErrorManager.getInstance().logBeHealthCheckError(BE_HEALTH_CHECK_STR);
}
}
+
+
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/PortalHealthCheckBuilder.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/PortalHealthCheckBuilder.java
new file mode 100644
index 0000000000..f9281e1ef2
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/PortalHealthCheckBuilder.java
@@ -0,0 +1,230 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.health;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang.StringUtils;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.Configuration.EcompPortalConfig;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.ecomp.PortalPropertiesEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
+import org.openecomp.sdc.common.http.client.api.HttpExecuteException;
+import org.openecomp.sdc.common.http.client.api.HttpRequest;
+import org.openecomp.sdc.common.http.client.api.HttpResponse;
+import org.openecomp.sdc.common.http.config.HttpClientConfig;
+import org.openecomp.sdc.common.http.config.Timeouts;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import java.security.InvalidParameterException;
+import java.util.Base64;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.http.HttpStatus.SC_OK;
+import static org.onap.portalsdk.core.onboarding.util.CipherUtil.decryptPKC;
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_ECOMP_PORTAL;
+import static org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus.DOWN;
+import static org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus.UP;
+
+@Component("portalHealthCheckBusinessLogic")
+public class PortalHealthCheckBuilder {
+
+ private static final Logger log = Logger.getLogger(HealthCheckBusinessLogic.class.getName());
+ private static final String PORTAL_NOT_AVAILABLE = HC_COMPONENT_ECOMP_PORTAL + " is not available";
+ private static final String PROPERTY_NOT_SET = "Property is not found %s";
+ private static final String CONFIG_IS_MISSING = HC_COMPONENT_ECOMP_PORTAL + " health check configuration is missing";
+ private static final String PORTAL_ERROR = HC_COMPONENT_ECOMP_PORTAL + " responded with %s status code";
+ private String decryptedPortalUser;
+ private String decryptedPortalPass;
+ private EcompPortalConfig configuration = null ;
+ private long healthCheckReadTimeout = 20;
+ private long reconnectInterval = 5;
+ private HealthCheckScheduledTask healthCheckScheduledTask = null ;
+ private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
+ private ScheduledFuture<?> scheduledFuture = null;
+ private HealthCheckInfo healthCheckInfo = new HealthCheckInfo
+ (HC_COMPONENT_ECOMP_PORTAL, HealthCheckStatus.DOWN, null, CONFIG_IS_MISSING, null);
+
+ @VisibleForTesting
+ PortalHealthCheckBuilder init(EcompPortalConfig configuration) throws CipherUtilException {
+ log.trace("Enter init method of Portal healthcheck");
+ decryptedPortalUser = decryptPKC
+ (getPortalProperty(PortalPropertiesEnum.USER.value()));
+ decryptedPortalPass = decryptPKC
+ (getPortalProperty(PortalPropertiesEnum.PASSWORD.value()));
+ synchronized (PortalHealthCheckBuilder.class){
+ if (configuration != null) {
+ Integer pollingInterval = configuration.getPollingInterval();
+ if (pollingInterval != null && pollingInterval != 0) {
+ reconnectInterval = pollingInterval;
+ }
+ Integer healthCheckReadTimeoutConfig = configuration.getTimeoutMs();
+ if (healthCheckReadTimeoutConfig != null) {
+ this.healthCheckReadTimeout = healthCheckReadTimeoutConfig;
+ }
+ this.healthCheckScheduledTask = new HealthCheckScheduledTask(configuration);
+ startHealthCheckTask(true);
+ }
+ else {
+ log.error("ECOMP Portal health check configuration is missing.");
+ }
+ }
+ log.trace("Exit init method of Portal healthcheck");
+ return this;
+ }
+
+ @PostConstruct
+ public PortalHealthCheckBuilder init() throws CipherUtilException {
+ return init(ConfigurationManager.getConfigurationManager().getConfiguration().getEcompPortal());
+ }
+
+
+ @PreDestroy
+ protected void destroy() {
+ if (scheduledFuture != null) {
+ scheduledFuture.cancel(true);
+ scheduledFuture = null;
+ }
+ if (scheduler != null) {
+ scheduler.shutdown();
+ }
+ }
+
+ /**
+ * Start health check task.
+ *
+ * @param startTask
+ */
+ private void startHealthCheckTask(boolean startTask) {
+ synchronized (PortalHealthCheckBuilder.class){
+ if (startTask && this.scheduledFuture == null) {
+ this.scheduledFuture = this.scheduler.scheduleAtFixedRate(this.healthCheckScheduledTask , 0, reconnectInterval, TimeUnit.SECONDS);
+ }
+ }
+ }
+
+ @VisibleForTesting
+ void runTask() {
+ healthCheckScheduledTask.run();
+ }
+
+ public HealthCheckInfo getHealthCheckInfo() {
+ return healthCheckInfo;
+ }
+
+ /**
+ * Health Check Task Scheduler - infinite check.
+ */
+ public class HealthCheckScheduledTask implements Runnable {
+ private final EcompPortalConfig config;
+ String healthCheckUrl = buildPortalHealthCheckUrl();
+ HealthCheckStatus healthCheckStatus = DOWN;
+ String componentName = HC_COMPONENT_ECOMP_PORTAL;
+ String description;
+ final int timeout = 3000;
+
+ HealthCheckScheduledTask(final EcompPortalConfig config){
+ this.config = config;
+ }
+ @Override
+ public void run() {
+ if (healthCheckUrl != null) {
+ try {
+ int statusCode = getStatusCode(healthCheckUrl, timeout);
+ log.trace("{} Health Check response code: {}", componentName, statusCode);
+ if (statusCode != SC_OK) {
+ description = String.format(PORTAL_ERROR, statusCode);
+ } else {
+ healthCheckStatus = UP;
+ description = "OK";
+ }
+ } catch (Exception e) {
+ log.error("{} is not available: ", componentName, e.getMessage());
+ description = PORTAL_NOT_AVAILABLE;
+ }
+ } else {
+ description = CONFIG_IS_MISSING;
+ }
+
+ healthCheckInfo.setHealthCheckStatus(healthCheckStatus);
+ healthCheckInfo.setDescription(description);
+ }
+ }
+
+ private static String getPortalProperty(String key) {
+ String value = PortalApiProperties.getProperty(key);
+ if (StringUtils.isEmpty(value)) {
+ throw new InvalidParameterException(String.format(PROPERTY_NOT_SET, key));
+ }
+ return value;
+ }
+
+ String buildPortalHealthCheckUrl() {
+ final String hcUrl = "%s://%s:%s%s";
+ Configuration.EcompPortalConfig configuration = ConfigurationManager.getConfigurationManager().getConfiguration().getEcompPortal();
+ if (configuration != null) {
+ return String.format(hcUrl, configuration.getProtocol(), configuration.getHost(),
+ configuration.getPort(), configuration.getHealthCheckUri());
+ }
+ log.error("ECOMP Portal health check configuration is missing.");
+ return null;
+ }
+
+ private Properties createHeaders(){
+ Properties headers = new Properties();
+ String encodedBasicAuthCred = Base64.getEncoder()
+ .encodeToString((decryptedPortalUser + ":" +
+ decryptedPortalPass)
+ .getBytes());
+ headers.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
+ headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
+ headers.put(Constants.X_TRANSACTION_ID_HEADER, UUID.randomUUID().toString());
+ headers.put("Authorization", "Basic " + encodedBasicAuthCred);
+ headers.put("cache-control", "no-cache");
+ headers.put("uebkey", PortalApiProperties.getProperty("ueb_app_key"));
+ return headers;
+ }
+
+ int getStatusCode(String healthCheckUrl, int timeout) throws HttpExecuteException {
+ HttpResponse<String> httpResponse = HttpRequest.get(healthCheckUrl, createHeaders(), new HttpClientConfig(new Timeouts(timeout, timeout)));
+ return httpResponse.getStatusCode();
+ }
+
+ @VisibleForTesting
+ public EcompPortalConfig getConfiguration() {
+ return ConfigurationManager.getConfigurationManager().getConfiguration().getEcompPortal();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
index f0ccffa633..712cba74b7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java
@@ -32,12 +32,12 @@ import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
-import org.openecomp.sdc.be.model.operations.api.IAdditionalInformationOperation;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.AdditionalInformationOperation;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
@@ -68,7 +68,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
private static final Logger log = Logger.getLogger(AdditionalInformationBusinessLogic.class.getName());
private static final String FAILED_TO_LOCK_COMPONENT_ERROR = "Failed to lock component {} error - {}";
- private final IAdditionalInformationOperation additionalInformationOperation;
+ private final AdditionalInformationOperation additionalInformationOperation;
@Autowired
public AdditionalInformationBusinessLogic(IElementOperation elementDao,
@@ -77,7 +77,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
IGroupTypeOperation groupTypeOperation,
InterfaceOperation interfaceOperation,
InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
- IAdditionalInformationOperation additionalInformationOperation,
+ AdditionalInformationOperation additionalInformationOperation,
ArtifactsOperations artifactToscaOperation) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
@@ -102,7 +102,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
*/
public Either<AdditionalInfoParameterInfo, ResponseFormat> createAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String userId) {
- validateUserExists(userId, "create Additional Information", false);
+ validateUserExists(userId);
Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
@@ -113,7 +113,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
// lock component
StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
- if (!lockResult.equals(StorageOperationStatus.OK)) {
+ if (lockResult != StorageOperationStatus.OK) {
BeEcompErrorManager.getInstance().logBeFailedLockObjectError(CREATE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
log.info(FAILED_TO_LOCK_COMPONENT_ERROR, resourceId, lockResult);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
@@ -323,7 +323,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
*/
public Either<AdditionalInfoParameterInfo, ResponseFormat> updateAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String userId) {
- validateUserExists(userId, "create Additional Information", false);
+ validateUserExists(userId);
Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
@@ -333,7 +333,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
}
// lock component
StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
- if (!lockResult.equals(StorageOperationStatus.OK)) {
+ if (lockResult != StorageOperationStatus.OK) {
BeEcompErrorManager.getInstance().logBeFailedLockObjectError(UPDATE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
log.info(FAILED_TO_LOCK_COMPONENT_ERROR, resourceId, lockResult);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
@@ -389,7 +389,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
*/
public Either<AdditionalInfoParameterInfo, ResponseFormat> deleteAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String userId) {
- validateUserExists(userId, "delete Additional Information", false);
+ validateUserExists(userId);
Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
ResponseFormat responseFormat = verifyCanWorkOnComponent(nodeType, resourceId, userId);
@@ -398,7 +398,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
}
// lock component
StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, nodeType);
- if (!lockResult.equals(StorageOperationStatus.OK)) {
+ if (lockResult != StorageOperationStatus.OK) {
BeEcompErrorManager.getInstance().logBeFailedLockObjectError(DELETE_ADDITIONAL_INFORMATION, nodeType.getName(), resourceId);
log.info(FAILED_TO_LOCK_COMPONENT_ERROR, resourceId, lockResult);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
@@ -450,7 +450,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
*/
public Either<AdditionalInfoParameterInfo, ResponseFormat> getAdditionalInformation(NodeTypeEnum nodeType, String resourceId, AdditionalInfoParameterInfo additionalInfoParameterInfo, String userId) {
- validateUserExists(userId, "get Additional Information", false);
+ validateUserExists(userId);
Either<AdditionalInfoParameterInfo, ResponseFormat> result = null;
try {
@@ -485,7 +485,7 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic {
*/
public Either<AdditionalInformationDefinition, ResponseFormat> getAllAdditionalInformation(NodeTypeEnum nodeType, String resourceId, String userId) {
- validateUserExists(userId, "get All Additional Information", false);
+ validateUserExists(userId);
Either<AdditionalInformationDefinition, ResponseFormat> result = null;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java
index 84a07fca78..b0af789f28 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java
@@ -30,7 +30,11 @@ import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
import org.springframework.stereotype.Component;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java
index c836e91b9b..15e9a77b15 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java
@@ -23,12 +23,14 @@ package org.openecomp.sdc.be.components.impl;
import com.google.common.annotations.VisibleForTesting;
import fj.data.Either;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.validation.AccessValidations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.facade.operations.CatalogOperation;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentParametersView;
@@ -40,10 +42,18 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
+import static org.openecomp.sdc.common.datastructure.FunctionalInterfaces.wrapWithTryCatch;
+
+
@org.springframework.stereotype.Component
public class ArchiveBusinessLogic {
@@ -54,13 +64,16 @@ public class ArchiveBusinessLogic {
private final ArchiveOperation archiveOperation;
private final ToscaOperationFacade toscaOperationFacade;
private final ComponentsUtils componentUtils;
+ private final CatalogOperation catalogOperations;
- public ArchiveBusinessLogic(JanusGraphDao janusGraphDao, AccessValidations accessValidations, ArchiveOperation archiveOperation, ToscaOperationFacade tof, ComponentsUtils componentsUtils) {
+ public ArchiveBusinessLogic(JanusGraphDao janusGraphDao, AccessValidations accessValidations, ArchiveOperation archiveOperation, ToscaOperationFacade tof, ComponentsUtils componentsUtils,
+ CatalogOperation catalogOperations) {
this.janusGraphDao = janusGraphDao;
this.accessValidations = accessValidations;
this.archiveOperation = archiveOperation;
this.toscaOperationFacade = tof;
this.componentUtils = componentsUtils;
+ this.catalogOperations = catalogOperations;
}
public void archiveComponent(String containerComponentType, String userId, String componentId) {
@@ -71,6 +84,8 @@ public class ArchiveBusinessLogic {
throw new ByActionStatusComponentException(result.right().value(), componentId);
}
this.auditAction(ArchiveOperation.Action.ARCHIVE, result.left().value(), user, containerComponentType);
+ // Send Archive Notification To Facade
+ wrapWithTryCatch(() -> sendNotificationToFacade(componentId, ChangeTypeEnum.ARCHIVE));
}
public void restoreComponent(String containerComponentType, String userId, String componentId) {
@@ -80,6 +95,8 @@ public class ArchiveBusinessLogic {
throw new ByActionStatusComponentException(result.right().value(), componentId);
}
this.auditAction(ArchiveOperation.Action.RESTORE, result.left().value(), user, containerComponentType);
+ // Send Archive Notification To Facade
+ wrapWithTryCatch(() -> sendNotificationToFacade(componentId, ChangeTypeEnum.RESTORE));
}
public List<String> onVspArchive(String userId, List<String> csarUuids){
@@ -100,7 +117,7 @@ public class ArchiveBusinessLogic {
for (String csarUuid : csarUuids) {
try {
- if (action.equals(ArchiveOperation.Action.ARCHIVE)) {
+ if (action == ArchiveOperation.Action.ARCHIVE) {
actionStatus = this.archiveOperation.onVspArchived(csarUuid);
} else {
actionStatus = this.archiveOperation.onVspRestored(csarUuid);
@@ -128,8 +145,6 @@ public class ArchiveBusinessLogic {
public Map<String, List<CatalogComponent>> getArchiveComponents(String userId, List<OriginTypeEnum> excludeTypes) {
try {
- accessValidations.validateUserExist(userId, "GET ARCHIVED COMPONENTS");
-
Either<List<CatalogComponent>, StorageOperationStatus> components = toscaOperationFacade.getCatalogOrArchiveComponents(false, excludeTypes);
if (components.isLeft()) {
List<CatalogComponent> comps = components.left().value();
@@ -174,4 +189,16 @@ public class ArchiveBusinessLogic {
}
}
}
+ protected Either<Component, ResponseFormat> sendNotificationToFacade(String componentId,
+ ChangeTypeEnum changeStatus) {
+ log.debug("build {} notification for facade start", changeStatus.name());
+ Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(componentId);
+ Component component = toscaElement.left()
+ .value();
+ ActionStatus status = catalogOperations.updateCatalog(changeStatus, component);
+ if (status != ActionStatus.OK) {
+ return Either.right(componentUtils.getResponseFormat(status));
+ }
+ return Either.left(component);
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java
index d0a1273210..66dce60641 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactResolverImpl.java
@@ -23,9 +23,19 @@ package org.openecomp.sdc.be.components.impl;
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.components.ArtifactsResolver;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.*;
+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.InterfaceDefinition;
+import org.openecomp.sdc.be.model.Service;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
import java.util.stream.Collectors;
@org.springframework.stereotype.Component("artifact-resolver")
@@ -64,7 +74,7 @@ public class ArtifactResolverImpl implements ArtifactsResolver {
}
Map<String, ArtifactDefinition> serviceApiArtifacts = Collections.emptyMap();
- if (componentType.equals(ComponentTypeEnum.SERVICE)) {
+ if (componentType == ComponentTypeEnum.SERVICE) {
serviceApiArtifacts = Optional.ofNullable(((Service) component).getServiceApiArtifacts()).orElse(Collections.emptyMap());
}
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 9eae363afb..103edd6497 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
@@ -22,21 +22,23 @@
package org.openecomp.sdc.be.components.impl;
+import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fj.data.Either;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.elasticsearch.common.Strings;
import org.openecomp.sdc.be.components.ArtifactsResolver;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactTypeToPayloadTypeSelector;
import org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
@@ -48,11 +50,12 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.HeatParameterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -76,19 +79,20 @@ import org.openecomp.sdc.be.model.heat.HeatParameterType;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTemplateOperation;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.IHeatParametersOperation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
-import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation;
import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.resources.data.DAOArtifactData;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
@@ -97,7 +101,6 @@ import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.be.tosca.ToscaError;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.be.tosca.ToscaRepresentation;
-import org.openecomp.sdc.be.user.IUserBusinessLogic;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.be.utils.TypeUtils;
@@ -136,10 +139,13 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
+import static org.openecomp.sdc.be.dao.api.ActionStatus.MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE;
+
@org.springframework.stereotype.Component("artifactBusinessLogic")
public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private static final String RESOURCE_INSTANCE = "resource instance";
@@ -159,13 +165,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
public static final String HEAT_ENV_SUFFIX = "env";
private static final String ARTIFACT_PLACEHOLDER_FILE_EXTENSION = "fileExtension";
- private static final Logger log = Logger.getLogger(ArtifactsBusinessLogic.class);
+ private static final Logger log = Logger.getLogger(ArtifactsBusinessLogic.class.getName());
private static final String FAILED_UPDATE_GROUPS = "Failed to update groups of the component {}. ";
private static final String FAILED_UPDATE_ARTIFACT = "Failed to delete or update the artifact {}. Parent uniqueId is {}";
private static final String FAILED_SAVE_ARTIFACT = "Failed to save the artifact.";
+ public static final String ARTIFACT_ACTION_LOCK = "Artifact action - lock ";
private static final String UPDATE_ARTIFACT_LOCK = "Update Artifact - lock ";
private static final String FAILED_DOWNLOAD_ARTIFACT = "Download artifact {} failed";
- private static final String FAILED_UPLOAD_ARTIFACT_TO_COMPONENT = "Failed to upload artifact to component with type {} and uuid {}. Status is {}. ";
+ public static final String FAILED_UPLOAD_ARTIFACT_TO_COMPONENT = "Failed to upload artifact to component with type {} and uuid {}. Status is {}. ";
private static final String FAILED_UPLOAD_ARTIFACT_TO_INSTANCE = "Failed to upload artifact to component instance {} of component with type {} and uuid {}. Status is {}. ";
private static final String FAILED_FETCH_COMPONENT = "Could not fetch component with type {} and uuid {}. Status is {}. ";
private static final String NULL_PARAMETER = "One of the function parameteres is null";
@@ -180,31 +187,28 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
@javax.annotation.Resource
private IInterfaceLifecycleOperation interfaceLifecycleOperation;
@javax.annotation.Resource
- private IUserAdminOperation userOperaton;
+ private UserAdminOperation userOperaton;
@javax.annotation.Resource
private IElementOperation elementOperation;
@javax.annotation.Resource
- private UserBusinessLogic userAdminManager;
-
- @javax.annotation.Resource
private IHeatParametersOperation heatParametersOperation;
- private final ArtifactCassandraDao artifactCassandraDao;
- private final ToscaExportHandler toscaExportUtils;
- private final CsarUtils csarUtils;
- private final LifecycleBusinessLogic lifecycleBusinessLogic;
- private final IUserBusinessLogic userBusinessLogic;
- private final ArtifactsResolver artifactsResolver;
+ private ArtifactCassandraDao artifactCassandraDao;
+ private ToscaExportHandler toscaExportUtils;
+ private CsarUtils csarUtils;
+ private LifecycleBusinessLogic lifecycleBusinessLogic;
+ private UserBusinessLogic userBusinessLogic;
+ private ArtifactsResolver artifactsResolver;
private NodeTemplateOperation nodeTemplateOperation;
@Autowired
public ArtifactsBusinessLogic(ArtifactCassandraDao artifactCassandraDao, ToscaExportHandler toscaExportUtils,
- CsarUtils csarUtils, LifecycleBusinessLogic lifecycleBusinessLogic, IUserBusinessLogic userBusinessLogic,
- ArtifactsResolver artifactsResolver, IElementOperation elementDao, IGroupOperation groupOperation,
- IGroupInstanceOperation groupInstanceOperation, IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation) {
+ CsarUtils csarUtils, LifecycleBusinessLogic lifecycleBusinessLogic, UserBusinessLogic userBusinessLogic,
+ ArtifactsResolver artifactsResolver, IElementOperation elementDao, IGroupOperation groupOperation,
+ IGroupInstanceOperation groupInstanceOperation, IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation,
+ InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
this.artifactCassandraDao = artifactCassandraDao;
@@ -250,13 +254,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
// new flow US556184
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleArtifactRequest(String componentId, String userId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo,
- String origMd5, String originData, String interfaceUuid, String operationUuid, String parentId, String containerComponentType) {
- return handleArtifactRequest(componentId, userId, componentType, operation, artifactId, artifactInfo, origMd5, originData, interfaceUuid, operationUuid, parentId, containerComponentType, true, false);
- }
-
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleArtifactRequest(String componentId, String userId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo,
- String origMd5, String originData, String interfaceUuid, String operationUuid, String parentId, String containerComponentType, boolean shouldLock, boolean inTransaction) {
+ public Either<ArtifactDefinition, Operation> handleArtifactRequest(String componentId, String userId, ComponentTypeEnum componentType,
+ ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo,
+ String origMd5, String originData, String interfaceName, String operationName,
+ String parentId, String containerComponentType, boolean shouldLock, boolean inTransaction) {
// step 1 - detect auditing type
AuditingActionEnum auditingAction = detectAuditingType(operation, origMd5);
@@ -265,40 +266,33 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
log.debug("handleArtifactRequest - no HTTP_CSP_HEADER , component id {}", componentId);
handleAuditing(auditingAction, null, componentId, null, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
// step 3 - check user existence
- Either<User, ResponseFormat> userResult = validateUserExists(userId, auditingAction, componentId, artifactId, componentType, inTransaction);
- if (userResult.isRight()) {
- return Either.right(userResult.right().value());
- }
-
// step 4 - check user's role
- User user = userResult.left().value();
- Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(user, auditingAction, componentId, artifactId, componentType, operation);
- if (validateUserRole.isRight()) {
- return Either.right(validateUserRole.right().value());
- }
+ User user = validateUserExists(userId, auditingAction, componentId, artifactId, componentType, inTransaction);
+ validateUserRole(user, auditingAction, componentId, artifactId, componentType, operation);
// steps 5 - 6 - 7
// 5. check service/resource existence
// 6. check service/resource check out
// 7. user is owner of checkout state
- org.openecomp.sdc.be.model.Component component = null;
+ Component component = null;
String realComponentId = componentType == ComponentTypeEnum.RESOURCE_INSTANCE ? parentId : componentId;
- Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(realComponentId, auditingAction, user, artifactId, componentType, containerComponentType);
- if (validateComponent.isRight()) {
- return Either.right(validateComponent.right().value());
- }
- component = validateComponent.left().value();
- Either<Boolean, ResponseFormat> validateWorkOnResource = validateWorkOnComponent(component, userId, auditingAction, user, artifactId, operation);
- if (validateWorkOnResource.isRight()) {
- return Either.right(validateWorkOnResource.right().value());
+ component = validateComponentExists(realComponentId, auditingAction, user, artifactId, componentType, containerComponentType);
+ validateWorkOnComponent(component, userId, auditingAction, user, artifactId, operation);
+ if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
+ validateResourceInstanceById(component, componentId);
}
// step 8
- return validateAndHandleArtifact(componentId, componentType, operation, artifactId, artifactInfo, origMd5, originData, interfaceUuid, operationUuid, user, component,
- shouldLock, inTransaction, true);
+ return validateAndHandleArtifact(componentId, componentType, operation, artifactId, artifactInfo, origMd5,
+ originData, interfaceName, operationName, user, component, shouldLock, inTransaction, true);
+ }
+
+ public Either<ArtifactDefinition, Operation> handleArtifactRequest(String componentId, String userId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo,
+ String origMd5, String originData, String interfaceName, String operationName, String parentId, String containerComponentType) {
+ return handleArtifactRequest(componentId, userId, componentType, operation, artifactId, artifactInfo, origMd5, originData, interfaceName, operationName, parentId, containerComponentType, true, false);
}
/**
@@ -308,78 +302,75 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
*
* @return
*/
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> validateAndHandleArtifact(String componentUniqueId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactUniqueId,
- ArtifactDefinition artifactDefinition, String origMd5, String originData, String interfaceUuid, String operationName, User user, Component component, boolean shouldLock, boolean inTransaction, boolean needUpdateGroup) {
- Component parent = component;
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
-
+ public Either<ArtifactDefinition, Operation> validateAndHandleArtifact(
+ String componentUniqueId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactUniqueId,
+ ArtifactDefinition artifactDefinition, String origMd5, String originData, String interfaceName,
+ String operationName, User user, Component component, boolean shouldLock, boolean inTransaction, boolean needUpdateGroup) {
AuditingActionEnum auditingAction = detectAuditingType(operation, origMd5);
- artifactDefinition = validateArtifact(componentUniqueId, componentType, operation, artifactUniqueId, artifactDefinition, auditingAction, user, component, parent, errorWrapper, shouldLock, inTransaction);
-
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result;
- if (errorWrapper.isEmpty()) {
- // step 10
- result = doAction(componentUniqueId, componentType, operation, artifactUniqueId, artifactDefinition, origMd5, originData, interfaceUuid, operationName, auditingAction, user, parent, shouldLock, inTransaction, needUpdateGroup);
- }
- else {
- result = Either.right(errorWrapper.getInnerElement());
- }
+ artifactDefinition = validateArtifact(componentUniqueId, componentType, operation,
+ artifactUniqueId, artifactDefinition, auditingAction, user,
+ component, shouldLock, inTransaction);
+
+ // step 10
+ Either<ArtifactDefinition, Operation> result = doAction(componentUniqueId, componentType, operation, artifactUniqueId, artifactDefinition,
+ origMd5, originData, interfaceName, operationName, auditingAction, user, component, shouldLock, inTransaction, needUpdateGroup);
+ //TODO: audit positive action
return result;
}
- private ArtifactDefinition validateArtifact(String componentId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, User user,
- Component component, Component parent, Wrapper<ResponseFormat> errorWrapper, boolean shouldLock, boolean inTransaction) {
- ArtifactDefinition validatedArtifactInfo = artifactInfo;
- if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.UPDATE || operation.getArtifactOperationEnum() == ArtifactOperationEnum.DELETE || operation
- .getArtifactOperationEnum() == ArtifactOperationEnum.DOWNLOAD) {
- Either<ArtifactDefinition, ResponseFormat> validateArtifact = validateArtifact(componentId, componentType, artifactId, component);
- if (validateArtifact.isRight()) {
- ResponseFormat responseFormat = validateArtifact.right().value();
- handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
- errorWrapper.setInnerElement(validateArtifact.right().value());
- }
- else if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.DOWNLOAD) {
- validatedArtifactInfo = validateArtifact.left().value();
- handleHeatEnvDownload(componentId, componentType, user, component, validateArtifact, errorWrapper, shouldLock, inTransaction);
+ @VisibleForTesting
+ ArtifactDefinition validateArtifact(String componentId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, User user,
+ Component component, boolean shouldLock, boolean inTransaction) {
+ ArtifactDefinition artifactInfoToReturn = artifactInfo;
+ ArtifactOperationEnum operationEnum = operation.getArtifactOperationEnum();
+ if (operationEnum == ArtifactOperationEnum.UPDATE || operationEnum == ArtifactOperationEnum.DELETE || operationEnum == ArtifactOperationEnum.DOWNLOAD) {
+ ArtifactDefinition dbArtifact = getArtifactIfBelongsToComponent(componentId, componentType, artifactId, component);
+ if (operationEnum == ArtifactOperationEnum.DOWNLOAD) {
+ artifactInfoToReturn = dbArtifact;
+ handleHeatEnvDownload(componentId, componentType, user, component, dbArtifact, shouldLock, inTransaction);
}
}
- return validatedArtifactInfo;
+ return artifactInfoToReturn;
}
- private void handleHeatEnvDownload(String componentId, ComponentTypeEnum componentType, User user, org.openecomp.sdc.be.model.Component component, Either<ArtifactDefinition,
- ResponseFormat> validateArtifact, Wrapper<ResponseFormat> errorWrapper, boolean shouldLock, boolean inTransaction) {
- ArtifactDefinition validatedArtifact = validateArtifact.left().value();
+ @VisibleForTesting
+ void handleHeatEnvDownload(String componentId, ComponentTypeEnum componentType, User user, Component component,
+ ArtifactDefinition artifactDefinition, boolean shouldLock, boolean inTransaction) {
- if (validatedArtifact.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV.getType())
+ if (artifactDefinition.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV.getType())
&& ComponentTypeEnum.SERVICE == component.getComponentType()) {
ComponentInstance componentInstance = component.getComponentInstances()
- .stream()
- .filter(p -> p.getUniqueId().equals(componentId))
- .findAny()
- .get();
+ .stream()
+ .filter(p -> p.getUniqueId().equals(componentId))
+ .findAny()
+ .orElse(null);
+ if (componentInstance == null) {
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentId,
+ "instance", "Service", component.getName());
+ }
Map<String, ArtifactDefinition> deploymentArtifacts = componentInstance.getDeploymentArtifacts();
ArtifactDefinition heatEnvWithHeatParams = deploymentArtifacts.values()
- .stream()
- .filter(p -> p.getUniqueId()
- .equals(validatedArtifact.getUniqueId()))
- .findAny()
- .get();
- Either<ArtifactDefinition, ResponseFormat> eitherGenerated = generateHeatEnvArtifact(heatEnvWithHeatParams, componentType, component, componentInstance
- .getName(), user, componentId, shouldLock, inTransaction);
+ .stream()
+ .filter(p -> p.getUniqueId()
+ .equals(artifactDefinition.getUniqueId()))
+ .findAny()
+ .orElse(null);
+ Either<ArtifactDefinition, ResponseFormat> eitherGenerated = generateHeatEnvArtifact(heatEnvWithHeatParams,
+ componentType, component, componentInstance.getName(), user, componentId, shouldLock, inTransaction);
if (eitherGenerated.isRight()) {
- errorWrapper.setInnerElement(eitherGenerated.right().value());
+ throw new ByResponseFormatComponentException((eitherGenerated.right().value()));
}
}
}
- private boolean artifactGenerationRequired(org.openecomp.sdc.be.model.Component component, ArtifactDefinition artifactInfo) {
+ private boolean artifactGenerationRequired(Component component, ArtifactDefinition artifactInfo) {
boolean needGenerate;
needGenerate = artifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.TOSCA && (component.getLifecycleState() == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN || component
.getLifecycleState() == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
needGenerate = needGenerate || (ComponentTypeEnum.RESOURCE == component.getComponentType() && (artifactInfo.getArtifactType()
- .equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV
- .getType()) || isAbstractVfcEmptyCsar((Resource) component, artifactInfo)));
+ .equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV
+ .getType()) || isAbstractVfcEmptyCsar((Resource) component, artifactInfo)));
return needGenerate;
}
@@ -389,139 +380,183 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
.equals(ArtifactTypeEnum.TOSCA_CSAR.getType()) && StringUtils.isEmpty(artifactInfo.getArtifactChecksum());
}
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateAndSaveToscaArtifact(
- ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component,
+ public Either<ArtifactDefinition, Operation> generateAndSaveToscaArtifact(
+ ArtifactDefinition artifactDefinition, Component component,
User user, boolean isInCertificationRequest, boolean shouldLock, boolean inTransaction,
boolean fetchTemplatesFromDB) {
-
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generated = generateToscaArtifact(component, artifactDefinition, isInCertificationRequest, fetchTemplatesFromDB);
- if (generated.isRight()) {
- return generated;
- }
+ generateToscaArtifact(component, artifactDefinition, isInCertificationRequest, fetchTemplatesFromDB);
byte[] decodedPayload = artifactDefinition.getPayloadData();
artifactDefinition.setEsId(artifactDefinition.getUniqueId());
artifactDefinition.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(decodedPayload));
- return lockComponentAndUpdateArtifact(component.getUniqueId(), artifactDefinition, AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, artifactDefinition
- .getUniqueId(), user, component.getComponentType(), component, decodedPayload, null, null,
- shouldLock, inTransaction);
-
+ return lockComponentAndUpdateArtifact(component.getUniqueId(), artifactDefinition, AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, artifactDefinition.getUniqueId(),
+ user, component.getComponentType(), component, decodedPayload, null, null, shouldLock, inTransaction);
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateToscaArtifact(Component parent, ArtifactDefinition artifactInfo, boolean isInCertificationRequest, boolean fetchTemplatesFromDB) {
+ private ArtifactDefinition generateToscaArtifact(Component parent, ArtifactDefinition artifactInfo, boolean isInCertificationRequest, boolean fetchTemplatesFromDB) {
log.debug("tosca artifact generation");
- if (artifactInfo.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())) {
+ if (ArtifactTypeEnum.TOSCA_CSAR.getType().equals(artifactInfo.getArtifactType())) {
Either<byte[], ResponseFormat> generated = csarUtils.createCsar(parent, fetchTemplatesFromDB, isInCertificationRequest);
-
if (generated.isRight()) {
- log.debug("Failed to export tosca csar for component {} error {}", parent.getUniqueId(), generated.right()
- .value());
-
- return Either.right(generated.right().value());
+ ResponseFormat error = generated.right().value();
+ log.debug("Failed to generate tosca csar for component {} error {}", parent.getUniqueId(), error);
+ throw new ByResponseFormatComponentException(error);
}
- byte[] value = generated.left().value();
- artifactInfo.setPayload(value);
+ artifactInfo.setPayload(generated.left().value());
}
else {
Either<ToscaRepresentation, ToscaError> exportComponent = toscaExportUtils.exportComponent(parent);
if (exportComponent.isRight()) {
- log.debug("Failed export tosca yaml for component {} error {}", parent.getUniqueId(), exportComponent.right()
- .value());
- ActionStatus status = componentsUtils.convertFromToscaError(exportComponent.right().value());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(status);
- return Either.right(responseFormat);
+ ToscaError toscaError = exportComponent.right().value();
+ log.debug("Failed export tosca yaml for component {} error {}", parent.getUniqueId(), toscaError);
+ ActionStatus status = componentsUtils.convertFromToscaError(toscaError);
+ throw new ByActionStatusComponentException(status);
}
log.debug("Tosca yaml exported for component {} ", parent.getUniqueId());
- String payload = exportComponent.left().value().getMainYaml();
- artifactInfo.setPayloadData(payload);
+ artifactInfo.setPayloadData(exportComponent.left().value().getMainYaml());
}
- return Either.left(Either.left(artifactInfo));
+ return artifactInfo;
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> doAction(String componentId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo, String origMd5,
- String originData, String interfaceName, String operationName, AuditingActionEnum auditingAction, User user, org.openecomp.sdc.be.model.Component parent, boolean shouldLock, boolean inTransaction, boolean needUpdateGroup) {
- switch (operation.getArtifactOperationEnum()) {
- case DOWNLOAD:
- if (artifactGenerationRequired(parent, artifactInfo)) {
- return generateNotSavedArtifact(parent, artifactInfo);
- }
- return handleDownload(componentId, artifactId, user, auditingAction, componentType, parent);
- case DELETE:
- return handleDelete(componentId, artifactId, user, auditingAction, componentType, parent, shouldLock, inTransaction);
- case UPDATE:
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result = null;
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
- if (componentType.equals(ComponentTypeEnum.RESOURCE_INSTANCE)
- && (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_VOL || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_ENV)) {
- result = handleUpdateHeatEnv(componentId, artifactInfo, auditingAction, artifactId, user, componentType, parent, originData, origMd5, operation, shouldLock, inTransaction);
- if (needUpdateGroup && result.isLeft()) {
- Either<ArtifactDefinition, Operation> updateResult = result.left().value();
- ActionStatus error = updateGroupInstance(artifactInfo, updateResult.left()
- .value(), parent, componentType, componentId);
- if (error != ActionStatus.OK) {
- result = Either.right(componentsUtils.getResponseFormat(error));
- }
- }
- }
- else {
- if (componentType.equals(ComponentTypeEnum.RESOURCE) && artifactType == ArtifactTypeEnum.HEAT_ENV) {
- result = handleUpdateHeatWithHeatEnvParams(componentId, artifactInfo, auditingAction, artifactId, user, componentType, parent, originData, origMd5, operation, shouldLock, inTransaction, needUpdateGroup);
- }
- }
- if (result == null) {
- result = handleUpdate(componentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, origMd5, originData, interfaceName, operationName, shouldLock, inTransaction);
- if (needUpdateGroup && result.isLeft()) {
- Either<ArtifactDefinition, Operation> updateResult = result.left().value();
-
- ActionStatus error = updateGroupForHeat(artifactInfo, updateResult.left()
- .value(), parent, componentType);
- if (error != ActionStatus.OK) {
- result = Either.right(componentsUtils.getResponseFormat(error));
- }
+ private Either<ArtifactDefinition, Operation> doAction(String componentId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactId, ArtifactDefinition artifactInfo, String origMd5,
+ String originData, String interfaceName, String operationName, AuditingActionEnum auditingAction, User user, Component parent, boolean shouldLock, boolean inTransaction, boolean needUpdateGroup) {
+ if (interfaceName != null && operationName != null) {
+ interfaceName = interfaceName.toLowerCase();
+ operationName = operationName.toLowerCase();
+ }
+ if (shouldLock) {
+ lockComponent(componentType, artifactId, auditingAction, user, parent);
+ }
+ Either<ArtifactDefinition, Operation> result;
+ boolean operationSucceeded = false;
+ try {
+ switch (operation.getArtifactOperationEnum()) {
+ case DOWNLOAD:
+ if (artifactGenerationRequired(parent, artifactInfo)) {
+ result = Either.left(generateNotSavedArtifact(parent, artifactInfo));
+ } else {
+ result = Either.left(handleDownload(componentId, artifactId, componentType, parent));
}
+ break;
+ case DELETE:
+ result = Either.left(handleDeleteInternal(componentId, artifactId, componentType, parent));
+ break;
+ case UPDATE:
+ result = handleUpdate(componentId, componentType, operation, artifactId, artifactInfo, null, origMd5, originData, interfaceName, operationName,
+ auditingAction, user, parent, needUpdateGroup);
+ break;
+ case CREATE:
+ result = handleCreate(componentId, artifactInfo, operation, auditingAction, user, componentType, parent, origMd5, originData, interfaceName,
+ operationName);
+ break;
+ case LINK:
+ result = Either.left(handleLink(componentId, artifactInfo, componentType, parent));
+ break;
+ default:
+ throw new UnsupportedOperationException("In ArtifactsBusinessLogic received illegal operation: " + operation.getArtifactOperationEnum());
+ }
+ operationSucceeded = true;
+ return result;
+ }
+ finally {
+ handleLockingAndCommit(parent, shouldLock, inTransaction, operationSucceeded);
+ }
+ }
+
+ private void lockComponent(ComponentTypeEnum componentType, String artifactId, AuditingActionEnum auditingAction, User user, Component parent) {
+ try {
+ lockComponent(parent, ARTIFACT_ACTION_LOCK);
+ }catch (ComponentException e){
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), user, null, null, artifactId, e.getResponseFormat(),
+ componentType, null);
+ throw e;
+ }
+ }
+
+ @VisibleForTesting
+ public Either<ArtifactDefinition, Operation> handleUpdate(String componentId, ComponentTypeEnum componentType, ArtifactOperationInfo operation, String artifactId,
+ ArtifactDefinition artifactInfo, byte[] decodedPayload, String origMd5, String originData, String interfaceName,
+ String operationName, AuditingActionEnum auditingAction, User user, Component parent,
+ boolean needUpdateGroup) {
+ Either<ArtifactDefinition, Operation> result;
+ ArtifactTypeEnum artifactType = validateAndReturnArtifactType(artifactInfo);
+ if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE
+ && (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_VOL || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_ENV)) {
+ result = handleUpdateHeatEnvAndHeatMeta(componentId, artifactInfo, auditingAction, artifactId, user, componentType, parent, originData, origMd5, operation);
+ if (needUpdateGroup) {
+ ActionStatus error = updateGroupInstance(artifactInfo, result.left().value(), parent, componentId);
+ if (error != ActionStatus.OK) {
+ throw new ByActionStatusComponentException(error);
}
- return result;
- case CREATE:
- return handleCreate(componentId, artifactInfo, operation, auditingAction, user, componentType, parent, origMd5, originData, interfaceName, operationName, shouldLock, inTransaction);
- case LINK:
- return handleLink(componentId, artifactInfo, auditingAction, user, componentType, parent, shouldLock, inTransaction);
+ }
+ }
+ else if (componentType == ComponentTypeEnum.RESOURCE && artifactType == ArtifactTypeEnum.HEAT_ENV) {
+ result = handleUpdateHeatWithHeatEnvParams(componentId, artifactInfo, auditingAction, componentType, parent, originData, origMd5, operation, needUpdateGroup);
+ }
+ else {
+ if (decodedPayload == null) {
+ decodedPayload = validateInput(componentId, artifactInfo, operation, auditingAction, artifactId, user,
+ componentType, parent, origMd5, originData, interfaceName, operationName);
+ }
+ result = updateArtifactFlow(parent, componentId, artifactId, artifactInfo, decodedPayload, componentType, auditingAction, interfaceName, operationName);
+ if (needUpdateGroup && result.isLeft()) {
+ ArtifactDefinition updatedArtifact = result.left().value();
+ updateGroupForHeat(artifactInfo, updatedArtifact, parent);
+ }
+ }
+ return result;
+ }
+
+ private ArtifactTypeEnum validateAndReturnArtifactType(ArtifactDefinition artifactInfo) {
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
+ if (artifactType == null) {
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
}
- return null;
+ return artifactType;
+ }
+
+ public ActionStatus updateGroupForHeatEnv(ArtifactDefinition artifactInfo, ArtifactDefinition artAfterUpdate, Component parent) {
+ return ActionStatus.OK;
}
- private ActionStatus updateGroupForHeat(ArtifactDefinition artifactInfo, ArtifactDefinition artAfterUpdate, Component parent, ComponentTypeEnum componentType) {
+ @VisibleForTesting
+ public ActionStatus updateGroupForHeat(ArtifactDefinition artifactInfo, ArtifactDefinition artAfterUpdate, Component parent) {
List<GroupDefinition> groups = parent.getGroups();
if (groups != null && !groups.isEmpty()) {
List<GroupDataDefinition> groupToUpdate = groups.stream()
- .filter(g -> g.getArtifacts() != null && g.getArtifacts()
- .contains(artifactInfo
- .getUniqueId()))
- .collect(Collectors.toList());
+ .filter(g -> g.getArtifacts() != null && g.getArtifacts()
+ .contains(artifactInfo
+ .getUniqueId()))
+ .collect(Collectors.toList());
if (groupToUpdate != null && !groupToUpdate.isEmpty()) {
groupToUpdate.forEach(g -> {
g.getArtifacts().remove(artifactInfo.getUniqueId());
g.getArtifactsUuid().remove(artifactInfo.getArtifactUUID());
g.getArtifacts().add(artAfterUpdate.getUniqueId());
g.getArtifactsUuid().add(artAfterUpdate.getArtifactUUID());
+ if(!artifactInfo.getArtifactUUID().equals(artAfterUpdate.getArtifactUUID())){
+ g.setGroupUUID(UniqueIdBuilder.generateUUID());
+ }
});
Either<List<GroupDefinition>, StorageOperationStatus> status = toscaOperationFacade.updateGroupsOnComponent(parent, groupToUpdate);
if (status.isRight()) {
log.debug(FAILED_UPDATE_GROUPS, parent.getUniqueId());
- return componentsUtils.convertFromStorageResponse(status.right().value());
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status.right().value()));
}
}
}
return ActionStatus.OK;
}
- private ActionStatus updateGroupForHeat(ArtifactDefinition artifactInfoHeat, ArtifactDefinition artHeatAfterUpdate, ArtifactDefinition artifactInfoHeatE, ArtifactDefinition artHEAfterUpdate, Component parent, ComponentTypeEnum componentType) {
+ @VisibleForTesting
+ ActionStatus updateGroupForHeat(ArtifactDefinition artifactInfoHeat, ArtifactDefinition artHeatAfterUpdate, ArtifactDefinition artifactInfoHeatE, ArtifactDefinition artHEAfterUpdate, Component parent) {
List<GroupDefinition> groups = parent.getGroups();
if (groups != null && !groups.isEmpty()) {
List<GroupDataDefinition> groupToUpdate = groups.stream()
- .filter(g -> g.getArtifacts() != null && g.getArtifacts()
- .contains(artifactInfoHeat
- .getUniqueId()))
- .collect(Collectors.toList());
+ .filter(g -> g.getArtifacts() != null && g.getArtifacts()
+ .contains(artifactInfoHeat
+ .getUniqueId()))
+ .collect(Collectors.toList());
if (groupToUpdate != null && !groupToUpdate.isEmpty()) {
groupToUpdate.forEach(g -> {
g.getArtifacts().remove(artifactInfoHeat.getUniqueId());
@@ -541,13 +576,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return ActionStatus.OK;
}
- private ActionStatus updateGroupInstance(ArtifactDefinition artifactInfo, ArtifactDefinition artAfterUpdate, Component parent, ComponentTypeEnum componentType, String parentId) {
+ private ActionStatus updateGroupInstance(ArtifactDefinition artifactInfo, ArtifactDefinition artAfterUpdate, Component parent, String parentId) {
List<GroupInstance> updatedGroupInstances = new ArrayList<>();
List<GroupInstance> groupInstances = null;
Optional<ComponentInstance> componentInstOp = parent.getComponentInstances()
- .stream()
- .filter(ci -> ci.getUniqueId().equals(parentId))
- .findFirst();
+ .stream()
+ .filter(ci -> ci.getUniqueId().equals(parentId))
+ .findFirst();
if (componentInstOp.isPresent()) {
groupInstances = componentInstOp.get().getGroupInstances();
}
@@ -556,15 +591,15 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
for (GroupInstance groupInstance : groupInstances) {
isUpdated = false;
if (CollectionUtils.isNotEmpty(groupInstance.getGroupInstanceArtifacts()) && groupInstance.getGroupInstanceArtifacts()
- .contains(artifactInfo
- .getUniqueId())) {
+ .contains(artifactInfo
+ .getUniqueId())) {
groupInstance.getGroupInstanceArtifacts().remove(artifactInfo.getUniqueId());
groupInstance.getGroupInstanceArtifacts().add(artAfterUpdate.getUniqueId());
isUpdated = true;
}
if (CollectionUtils.isNotEmpty(groupInstance.getGroupInstanceArtifactsUuid()) && groupInstance.getGroupInstanceArtifactsUuid()
- .contains(artifactInfo
- .getArtifactUUID())) {
+ .contains(artifactInfo
+ .getArtifactUUID())) {
groupInstance.getGroupInstanceArtifactsUuid().remove(artifactInfo.getArtifactUUID());
groupInstance.getGroupInstanceArtifacts().add(artAfterUpdate.getArtifactUUID());
isUpdated = true;
@@ -582,121 +617,77 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return ActionStatus.OK;
}
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateNotSavedArtifact(Component parent, ArtifactDefinition artifactInfo) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result;
+ ArtifactDefinition generateNotSavedArtifact(Component parent, ArtifactDefinition artifactInfo) {
if (artifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.TOSCA) {
- result = generateToscaArtifact(parent, artifactInfo, false, false);
+ return generateToscaArtifact(parent, artifactInfo, false, false);
}
else {
String heatArtifactId = artifactInfo.getGeneratedFromId();
Either<ArtifactDefinition, StorageOperationStatus> heatRes = artifactToscaOperation.getArtifactById(parent.getUniqueId(), heatArtifactId);
if (heatRes.isRight()) {
- log.debug("Failed to fetch heat artifact by generated id {} for heat env {}", heatArtifactId, artifactInfo
- .getUniqueId());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(heatRes
- .right()
- .value()), "");
- return Either.right(responseFormat);
+ log.debug("Failed to fetch heat artifact by generated id {} for heat env {}", heatArtifactId, artifactInfo.getUniqueId());
+ throw new StorageException(heatRes.right().value());
}
String generatedPayload = generateHeatEnvPayload(heatRes.left().value());
artifactInfo.setPayloadData(generatedPayload);
- result = Either.left(Either.left(artifactInfo));
+ return artifactInfo;
}
- return result;
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleUpdateHeatWithHeatEnvParams(String componentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, String artifactId, User user,
- ComponentTypeEnum componentType, Component parent, String originData, String origMd5, ArtifactOperationInfo operation, boolean shouldLock, boolean inTransaction, boolean needToUpdateGroup) {
- convertParentType(componentType);
- String parentId = parent.getUniqueId();
+ private Either<ArtifactDefinition, Operation> handleUpdateHeatWithHeatEnvParams(String componentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction,
+ ComponentTypeEnum componentType, Component parent, String originData, String origMd5, ArtifactOperationInfo operation,
+ boolean needToUpdateGroup) {
Either<ArtifactDefinition, StorageOperationStatus> artifactHeatRes = artifactToscaOperation.getArtifactById(componentId, artifactInfo
.getGeneratedFromId());
ArtifactDefinition currHeatArtifact = artifactHeatRes.left().value();
-
if (origMd5 != null) {
- Either<Boolean, ResponseFormat> validateMd5 = validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
- if (validateMd5.isRight()) {
- ResponseFormat responseFormat = validateMd5.right().value();
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
- }
-
- if (artifactInfo.getPayloadData() != null && artifactInfo.getPayloadData().length != 0) {
-
- Either<byte[], ResponseFormat> payloadEither = handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
- if (payloadEither.isRight()) {
- ResponseFormat responseFormat = payloadEither.right().value();
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
- }
- }
- else { // duplicate
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD);
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
+ validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
+ if (ArrayUtils.isNotEmpty(artifactInfo.getPayloadData())) {
+ handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
+ } else { // duplicate
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD);
}
}
+ return updateHeatParams(componentId, artifactInfo, auditingAction, parent, componentType, currHeatArtifact, needToUpdateGroup);
+ }
- // lock resource
- if (shouldLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, UPDATE_ARTIFACT_LOCK);
- if (lockComponent.isRight()) {
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, lockComponent.right()
- .value(), componentType, null);
- return Either.right(lockComponent.right().value());
+ private void handleLockingAndCommit(Component parent, boolean shouldLock, boolean inTransaction, boolean actionSucceeded) {
+ if (actionSucceeded) {
+ log.debug(COMMIT);
+ if (!inTransaction) {
+ janusGraphDao.commit();
}
- }
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
- try {
- resultOp = updateHeatParams(componentId, artifactId, artifactInfo, user, auditingAction, parent, componentType, currHeatArtifact, needToUpdateGroup);
- return resultOp;
-
- }
- finally {
- // unlock resource
- if (resultOp == null || resultOp.isRight()) {
- log.debug(ROLLBACK);
- if (!inTransaction) {
+ } else {
+ log.debug(ROLLBACK);
+ if (!inTransaction) {
janusGraphDao.rollback();
- }
- }
- else {
- log.debug(COMMIT);
- if (!inTransaction) {
- janusGraphDao.commit();
- }
- }
- if (shouldLock) {
- graphLockOperation.unlockComponent(parent.getUniqueId(), parent.getComponentType().getNodeType());
}
}
+ if (shouldLock) {
+ graphLockOperation.unlockComponent(parent.getUniqueId(), parent.getComponentType().getNodeType());
+ }
}
- public Either<ImmutablePair<String, byte[]>, ResponseFormat> handleDownloadToscaModelRequest(Component component, ArtifactDefinition csarArtifact) {
+ public ImmutablePair<String, byte[]> handleDownloadToscaModelRequest(Component component, ArtifactDefinition csarArtifact) {
if (artifactGenerationRequired(component, csarArtifact)) {
Either<byte[], ResponseFormat> generated = csarUtils.createCsar(component, false, false);
if (generated.isRight()) {
log.debug("Failed to export tosca csar for component {} error {}", component.getUniqueId(), generated.right()
- .value());
-
- return Either.right(generated.right().value());
+ .value());
+ throw new ByResponseFormatComponentException(generated.right().value());
}
- return Either.left(new ImmutablePair<String, byte[]>(csarArtifact.getArtifactName(), generated.left()
- .value()));
+ return new ImmutablePair<>(csarArtifact.getArtifactName(), generated.left().value());
}
return downloadArtifact(csarArtifact);
}
- public Either<ImmutablePair<String, byte[]>, ResponseFormat> handleDownloadRequestById(String componentId, String artifactId, String userId, ComponentTypeEnum componentType, String parentId, String containerComponentType) {
+ public ImmutablePair<String, byte[]> handleDownloadRequestById(String componentId, String artifactId, String userId, ComponentTypeEnum componentType, String parentId, String containerComponentType) {
// perform all validation in common flow
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> result = handleArtifactRequest(componentId, userId, componentType, new ArtifactOperationInfo(false, false, ArtifactOperationEnum.DOWNLOAD), artifactId, null, null, null, null,
+ Either<ArtifactDefinition, Operation> result = handleArtifactRequest(componentId, userId, componentType, new ArtifactOperationInfo(false, false, ArtifactOperationEnum.DOWNLOAD), artifactId, null, null, null, null,
null, parentId, containerComponentType);
- if (result.isRight()) {
- return Either.right(result.right().value());
- }
ArtifactDefinition artifactDefinition;
- Either<ArtifactDefinition, Operation> insideValue = result.left().value();
+ Either<ArtifactDefinition, Operation> insideValue = result;
if (insideValue.isLeft()) {
artifactDefinition = insideValue.left().value();
}
@@ -705,39 +696,35 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
// for tosca artifacts and heat env on VF level generated on download without saving
if (artifactDefinition.getPayloadData() != null) {
- return Either.left(new ImmutablePair<String, byte[]>(artifactDefinition.getArtifactName(), artifactDefinition
+ return (new ImmutablePair<>(artifactDefinition.getArtifactName(), artifactDefinition
.getPayloadData()));
}
return downloadArtifact(artifactDefinition);
}
- public Either<Map<String, ArtifactDefinition>, ResponseFormat> handleGetArtifactsByType(String containerComponentType, String parentId, ComponentTypeEnum componentType, String componentId, String artifactGroupType, String userId) {
+ public Map<String, ArtifactDefinition> handleGetArtifactsByType(String containerComponentType, String parentId, ComponentTypeEnum componentType, String componentId, String artifactGroupType, String userId) {
// step 1
// detect auditing type
Map<String, ArtifactDefinition> resMap = null;
- Either<Map<String, ArtifactDefinition>, ResponseFormat> resultOp = null;
+// Either<Map<String, ArtifactDefinition>, ResponseFormat> resultOp = null;
new Wrapper<>();
// step 2
// check header
if (userId == null) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
log.debug("handleGetArtifactsByType - no HTTP_CSP_HEADER , component id {}", componentId);
-
- resultOp = Either.right(responseFormat);
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
// step 3
// check user existence
// step 4
// check user's role
- validateUserExists(userId, "get artifacts", false);
+ validateUserExists(userId);
// steps 5 - 6 - 7
// 5. check service/resource existence
// 6. check service/resource check out
// 7. user is owner of checkout state
- org.openecomp.sdc.be.model.Component component = null;
String realComponentId = componentType == ComponentTypeEnum.RESOURCE_INSTANCE ? parentId : componentId;
ComponentParametersView componentFilter = new ComponentParametersView();
componentFilter.disableAll();
@@ -746,68 +733,50 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
componentFilter.setIgnoreComponentInstances(false);
}
- Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExistsByFilter(realComponentId, ComponentTypeEnum
+ Component component = validateComponentExistsByFilter(realComponentId, ComponentTypeEnum
.findByParamName(containerComponentType), componentFilter);
-
- if (validateComponent.isRight()) {
- resultOp = Either.right(validateComponent.right().value());
- return resultOp;
- }
- component = validateComponent.left().value();
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, UPDATE_ARTIFACT_LOCK);
- if (lockComponent.isRight()) {
-
- resultOp = Either.right(lockComponent.right().value());
- return resultOp;
- }
-
+ lockComponent(component, ARTIFACT_ACTION_LOCK);
+ boolean failed = false;
try {
ArtifactGroupTypeEnum groupType = ArtifactGroupTypeEnum.findType(artifactGroupType);
if (groupType == null) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
- log.debug("handleGetArtifactsByType - not falid groupType {} , component id {}", artifactGroupType, componentId);
-
- resultOp = Either.right(responseFormat);
- return resultOp;
-
+ log.debug("handleGetArtifactsByType - not failed groupType {} , component id {}", artifactGroupType, componentId);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
if (groupType == ArtifactGroupTypeEnum.DEPLOYMENT) {
List<ArtifactDefinition> list = getDeploymentArtifacts(component, componentType.getNodeType(), componentId);
if (list != null && !list.isEmpty()) {
- resMap = list.stream().collect(Collectors.toMap(a -> a.getArtifactLabel(), a -> a));
+ resMap = list.stream().collect(Collectors.toMap(ArtifactDataDefinition::getArtifactLabel, Function.identity()));
}
else {
resMap = new HashMap<>();
}
- resultOp = Either.left(resMap);
- return resultOp;
- }
- else {
+ return resMap;
+ } else {
Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifactsMapStatus = getArtifacts(realComponentId, componentType
.getNodeType(), groupType, componentId);
if (artifactsMapStatus.isRight()) {
if (artifactsMapStatus.right().value() != StorageOperationStatus.NOT_FOUND) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
- log.debug("handleGetArtifactsByType - not falid groupType {} , component id {}", artifactGroupType, componentId);
- resultOp = Either.right(responseFormat);
+ log.debug("handleGetArtifactsByType - not failed groupType {} , component id {}", artifactGroupType, componentId);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
else {
resMap = new HashMap<>();
- resultOp = Either.left(resMap);
}
}
else {
resMap = artifactsMapStatus.left().value();
- resultOp = Either.left(resMap);
}
- return resultOp;
+ return resMap;
}
- }
- finally {
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ } finally {
// unlock resource
- if (resultOp == null || resultOp.isRight()) {
+ if (failed) {
log.debug(ROLLBACK);
janusGraphDao.rollback();
}
@@ -823,30 +792,15 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
- private Either<ArtifactDefinition, ResponseFormat> validateArtifact(String componentId, ComponentTypeEnum componentType, String artifactId, Component component) {
- // step 9
+ private ArtifactDefinition getArtifactIfBelongsToComponent(String componentId, ComponentTypeEnum componentType, String artifactId, Component component) {
// check artifact existence
- Either<ArtifactDefinition, StorageOperationStatus> artifactResult = artifactToscaOperation.getArtifactById(componentId, artifactId, componentType, component
- .getUniqueId());
+ Either<ArtifactDefinition, StorageOperationStatus> artifactResult = artifactToscaOperation.getArtifactById(componentId, artifactId,
+ componentType, component.getUniqueId());
if (artifactResult.isRight()) {
- if (artifactResult.right().value().equals(StorageOperationStatus.ARTIFACT_NOT_FOUND)) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, "");
- log.debug("addArtifact - artifact {} not found", artifactId);
- return Either.right(responseFormat);
-
- }
- else {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(artifactResult
- .right()
- .value()));
- log.debug("addArtifact - failed to fetch artifact {}, error {}", artifactId, artifactResult.right()
- .value());
- return Either.right(responseFormat);
- }
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ARTIFACT_NOT_FOUND, artifactId, componentId);
}
- // step 9.1
- // check artifact belong to component
- boolean found = false;
+ // verify artifact belongs to component
+ boolean found;
switch (componentType) {
case RESOURCE:
case SERVICE:
@@ -856,137 +810,86 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
found = checkArtifactInResourceInstance(component, componentId, artifactId);
break;
default:
-
+ found = false;
}
if (!found) {
- String componentName = componentType.name().toLowerCase();
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ARTIFACT_NOT_FOUND, componentName);
- log.debug("addArtifact - Component artifact not found component Id {}, artifact id {}", componentId, artifactId);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ARTIFACT_NOT_FOUND, artifactId, componentType.name().toLowerCase());
}
- return Either.left(artifactResult.left().value());
+ return artifactResult.left().value();
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleCreate(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, User user, ComponentTypeEnum componentType,
- org.openecomp.sdc.be.model.Component parent, String origMd5, String originData, String interfaceType, String operationName, boolean shouldLock, boolean inTransaction) {
-
- String artifactId = null;
-
- // step 11
- Either<byte[], ResponseFormat> payloadEither = validateInput(componentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, origMd5, originData, interfaceType, operationName);
- if (payloadEither.isRight()) {
- return Either.right(payloadEither.right().value());
- }
- byte[] decodedPayload = payloadEither.left().value();
- convertParentType(componentType);
+ private Either<ArtifactDefinition, Operation> handleCreate(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, User user, ComponentTypeEnum componentType,
+ Component parent, String origMd5, String originData, String interfaceType, String operationName) {
+ byte[] decodedPayload = validateInput(componentId, artifactInfo, operation, auditingAction, null, user, componentType, parent, origMd5, originData, interfaceType, operationName);
+ return createArtifact(parent, componentId, artifactInfo, decodedPayload, componentType, auditingAction, interfaceType, operationName);
+ }
- if (shouldLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, "Upload Artifact - lock ");
- if (lockComponent.isRight()) {
- handleAuditing(auditingAction, parent, componentId, user, null, null, null, lockComponent.right()
- .value(), componentType, null);
- return Either.right(lockComponent.right().value());
- }
+ private ArtifactDefinition handleLink(String componentId, ArtifactDefinition artifactInfo, ComponentTypeEnum componentType,
+ Component parent) {
+ ComponentInstance foundInstance = findComponentInstance(componentId, parent);
+ String instanceId = null;
+ if (foundInstance != null) {
+ instanceId = foundInstance.getUniqueId();
}
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
-
- try {
- resultOp = createArtifact(parent, componentId, artifactInfo, decodedPayload, user, componentType, auditingAction, interfaceType, operationName);
- return resultOp;
+ NodeTypeEnum nodeType = convertParentType(componentType);
+ Either<ArtifactDefinition, StorageOperationStatus> artifactDefinitionEither = artifactToscaOperation.addArtifactToComponent(artifactInfo, parent,
+ nodeType, true, instanceId);
+ if (artifactDefinitionEither.isRight()) {
+ throw new StorageException(artifactDefinitionEither.right().value(), artifactInfo.getArtifactDisplayName());
}
- finally {
- if (shouldLock) {
- unlockComponent(resultOp, parent, inTransaction);
- }
-
+ if (generateCustomizationUUIDOnInstance(parent.getUniqueId(), componentId, componentType) != StorageOperationStatus.OK) {
+ throw new StorageException(artifactDefinitionEither.right().value(), artifactInfo.getArtifactDisplayName());
}
-
+ return artifactDefinitionEither.left().value();
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleLink(String componentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, User user, ComponentTypeEnum componentType,
- Component parent, boolean shouldLock, boolean inTransaction) {
-
- if (shouldLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, "Upload Artifact - lock ");
- if (lockComponent.isRight()) {
- handleAuditing(auditingAction, parent, componentId, user, null, null, null, lockComponent.right()
- .value(), componentType, null);
- return Either.right(lockComponent.right().value());
- }
- }
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
+ private Either<ArtifactDefinition, Operation> lockComponentAndUpdateArtifact(
+ String parentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, String artifactId,
+ User user, ComponentTypeEnum componentType, Component parent, byte[] decodedPayload, String interfaceType,
+ String operationName, boolean shouldLock, boolean inTransaction) {
+ Either<ArtifactDefinition, Operation> resultOp = null;
+ boolean failed = false;
+ boolean writeAudit = true;
try {
- resultOp = createAndLinkArtifact(parent, componentId, artifactInfo, user, componentType, auditingAction);
+ lockComponent(parent, shouldLock, ARTIFACT_ACTION_LOCK);
+ writeAudit = false;
+ resultOp = updateArtifactFlow(parent, parentId, artifactId, artifactInfo, decodedPayload, componentType, auditingAction, interfaceType, operationName);
return resultOp;
}
- finally {
- if (shouldLock) {
- unlockComponent(resultOp, parent, inTransaction);
+ catch (ComponentException ce) {
+ if(writeAudit) {
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, ce.getResponseFormat(), componentType, null);
}
-
+ failed = true;
+ throw ce;
}
-
- }
-
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> lockComponentAndUpdateArtifact(String parentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, String artifactId, User user,
- ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component parent, byte[] decodedPayload, String interfaceType, String operationName, boolean shouldLock, boolean inTransaction) {
-
- convertParentType(componentType);
-
- // lock resource
- if (shouldLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, UPDATE_ARTIFACT_LOCK);
-
- if (lockComponent.isRight()) {
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, lockComponent.right()
- .value(), componentType, null);
- return Either.right(lockComponent.right().value());
- }
- }
-
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
- try {
- resultOp = updateArtifactFlow(parent, parentId, artifactId, artifactInfo, user, decodedPayload, componentType, auditingAction, interfaceType, operationName);
- return resultOp;
-
+ catch (StorageException se) {
+ //TODO: audit
+ failed = true;
+ throw se;
}
finally {
if (shouldLock) {
- unlockComponent(resultOp, parent, inTransaction);
+ unlockComponent(failed, parent, inTransaction);
}
}
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleUpdate(String parentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, String artifactId, User user,
- ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component parent, String origMd5, String originData, String interfaceType, String operationName, boolean shouldLock, boolean inTransaction) {
-
- Either<byte[], ResponseFormat> payloadEither = validateInput(parentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, origMd5, originData, interfaceType, operationName);
-
- if (payloadEither.isRight()) {
- return Either.right(payloadEither.right().value());
- }
- byte[] decodedPayload = payloadEither.left().value();
-
- return lockComponentAndUpdateArtifact(parentId, artifactInfo, auditingAction, artifactId, user, componentType, parent, decodedPayload, interfaceType, operationName, shouldLock, inTransaction);
+ private byte[] validateInput(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, String artifactId, User user, ComponentTypeEnum componentType,
+ Component parent, String origMd5, String originData, String interfaceType, String operationName) {
+ validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
+ return getValidPayload(componentId, artifactInfo, operation, auditingAction, artifactId, user, componentType, parent, interfaceType, operationName);
}
- private Either<byte[], ResponseFormat> validateInput(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction, String artifactId, User user, ComponentTypeEnum componentType,
- Component parent, String origMd5, String originData, String interfaceType, String operationName) {
- // Md5 validations
- Either<Boolean, ResponseFormat> validateMd5 = validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
- if (validateMd5.isRight()) {
- ResponseFormat responseFormat = validateMd5.right().value();
- handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
- }
-
+ private byte[] getValidPayload(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, AuditingActionEnum auditingAction,
+ String artifactId, User user, ComponentTypeEnum componentType, Component parent, String interfaceType, String operationName) {
// step 11
Either<ArtifactDefinition, ResponseFormat> validateResult = validateInput(componentId, artifactInfo, operation, artifactId, user, interfaceType, operationName, componentType, parent);
if (validateResult.isRight()) {
ResponseFormat responseFormat = validateResult.right().value();
handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(validateResult.right().value());
+ throw new ByResponseFormatComponentException(responseFormat);
}
Either<byte[], ResponseFormat> payloadEither = handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
@@ -994,24 +897,24 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
ResponseFormat responseFormat = payloadEither.right().value();
handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
log.debug("Error during handle payload");
- return Either.right(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
-
// validate heat parameters. this part must be after the parameters are
// extracted in "handlePayload"
- Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParamers = validateAndConvertHeatParamers(artifactInfo, artifactInfo
+ Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParameters = validateAndConvertHeatParameters(artifactInfo, artifactInfo
.getArtifactType());
- if (validateAndConvertHeatParamers.isRight()) {
- ResponseFormat responseFormat = validateAndConvertHeatParamers.right().value();
+ if (validateAndConvertHeatParameters.isRight()) {
+ ResponseFormat responseFormat = validateAndConvertHeatParameters.right().value();
handleAuditing(auditingAction, parent, componentId, user, artifactInfo, null, artifactId, responseFormat, componentType, null);
log.debug("Error during handle payload");
- return Either.right(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
- return payloadEither;
+ return payloadEither.left().value();
}
- public void handleAuditing(AuditingActionEnum auditingActionEnum, Component component, String componentId, User user, ArtifactDefinition artifactDefinition, String prevArtifactUuid, String currentArtifactUuid, ResponseFormat responseFormat,
- ComponentTypeEnum componentTypeEnum, String resourceInstanceName) {
+ public void handleAuditing(AuditingActionEnum auditingActionEnum, Component component, String componentId, User user,
+ ArtifactDefinition artifactDefinition, String prevArtifactUuid, String currentArtifactUuid,
+ ResponseFormat responseFormat, ComponentTypeEnum componentTypeEnum, String resourceInstanceName) {
if (componentsUtils.isExternalApiEvent(auditingActionEnum)) {
return;
@@ -1077,10 +980,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private String getResourceInstanceNameFromComponent(Component component, String componentId) {
ComponentInstance resourceInstance = component.getComponentInstances()
- .stream()
- .filter(p -> p.getUniqueId().equals(componentId))
- .findFirst()
- .orElse(null);
+ .stream()
+ .filter(p -> p.getUniqueId().equals(componentId))
+ .findFirst()
+ .orElse(null);
String resourceInstanceName = null;
if (resourceInstance != null) {
resourceInstanceName = resourceInstance.getName();
@@ -1088,83 +991,40 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return resourceInstanceName;
}
- private String buildAuditingArtifactData(ArtifactDefinition artifactDefinition) {
- StringBuilder sb = new StringBuilder();
- if (artifactDefinition != null) {
- sb.append(artifactDefinition.getArtifactGroupType().getType())
- .append(",")
- .append("'")
- .append(artifactDefinition.getArtifactLabel())
- .append("'")
- .append(",")
- .append(artifactDefinition.getArtifactType())
- .append(",")
- .append(artifactDefinition.getArtifactName())
- .append(",")
- .append(artifactDefinition.getTimeout())
- .append(",")
- .append(artifactDefinition.getEsId());
-
- sb.append(",");
- if (artifactDefinition.getArtifactVersion() != null) {
-
- sb.append(artifactDefinition.getArtifactVersion());
- }
- else {
- sb.append(" ");
- }
- sb.append(",");
- if (artifactDefinition.getArtifactUUID() != null) {
- sb.append(artifactDefinition.getArtifactUUID());
+ private void validateMd5(String origMd5, String originData, byte[] payload, ArtifactOperationInfo operation) {
+ if (origMd5 == null) {
+ if (ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum()) && ArrayUtils.isNotEmpty(payload)) {
+ log.debug("Missing md5 header during artifact create");
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_INVALID_MD5);
}
- else {
- sb.append(" ");
+ // Update metadata
+ if (ArrayUtils.isNotEmpty(payload)) {
+ log.debug("Cannot have payload while md5 header is missing");
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
- }
- return sb.toString();
- }
-
- private Either<Boolean, ResponseFormat> validateMd5(String origMd5, String originData, byte[] payload, ArtifactOperationInfo operation) {
-
- if (origMd5 != null) {
+ } else {
String encodeBase64Str = GeneralUtility.calculateMD5Base64EncodedByString(originData);
if (!encodeBase64Str.equals(origMd5)) {
log.debug("The calculated md5 is different then the received one");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_INVALID_MD5));
- }
- }
- else {
- if (ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum()) && payload != null && payload.length != 0) {
- log.debug("Missing md5 header during artifact create");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_INVALID_MD5));
- }
- // Update metadata
- if (payload != null && payload.length != 0) {
- log.debug("Cannot have payload while md5 header is missing");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_INVALID_MD5);
}
}
- return Either.left(true);
}
private Either<ArtifactDefinition, ResponseFormat> validateInput(String componentId, ArtifactDefinition artifactInfo, ArtifactOperationInfo operation, String artifactId, User user, String interfaceName, String operationName,
ComponentTypeEnum componentType, Component parentComponent) {
- Either<ArtifactDefinition, ResponseFormat> artifactById = findArtifactOnParentComponent(parentComponent, componentType, componentId, operation, artifactId);
- if (artifactById.isRight()) {
- return Either.right(artifactById.right().value());
- }
- ArtifactDefinition currentArtifactInfo = artifactById.left().value();
-
+ ArtifactDefinition currentArtifactInfo = findArtifactOnParentComponent(parentComponent, componentType, componentId, operation, artifactId);
ignoreUnupdateableFieldsInUpdate(operation, artifactInfo, currentArtifactInfo);
- Either<Boolean, ResponseFormat> validateInformationalArtifactRes = validateInformationalArtifact(artifactInfo, parentComponent);
- if (validateInformationalArtifactRes.isRight()) {
- return Either.right(validateInformationalArtifactRes.right().value());
- }
- Either<Boolean, ResponseFormat> validateAndSetArtifactname = validateAndSetArtifactname(artifactInfo);
+ validateInformationalArtifact(artifactInfo, parentComponent);
+ Either<Boolean, ResponseFormat> validateAndSetArtifactname = validateAndSetArtifactName(
+ artifactInfo);
if (validateAndSetArtifactname.isRight()) {
return Either.right(validateAndSetArtifactname.right().value());
}
+ if (!validateArtifactNameUniqueness(componentId, parentComponent, artifactInfo, componentType)) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_EXIST));
+ }
if (operationName != null && interfaceName != null) {
operationName = operationName.toLowerCase();
interfaceName = interfaceName.toLowerCase();
@@ -1196,15 +1056,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.right(validateGroupType.right().value());
}
}
+ // TODO TEMP !!!
NodeTypeEnum parentType = convertParentType(componentType);
+ // TODO TEMP !!!
boolean isCreate = ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum());
if (isDeploymentArtifact(artifactInfo)) {
- Either<Boolean, ResponseFormat> deploymentValidationResult = validateDeploymentArtifact(parentComponent, componentId, isCreate, artifactInfo, currentArtifactInfo, parentType);
- if (deploymentValidationResult.isRight()) {
- return Either.right(deploymentValidationResult.right().value());
- }
+ validateDeploymentArtifact(parentComponent, componentId, isCreate, artifactInfo, currentArtifactInfo, parentType);
}
else {
artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
@@ -1215,8 +1074,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.right(descriptionResult.right().value());
}
- if (currentArtifactInfo != null && currentArtifactInfo.getArtifactGroupType()
- .equals(ArtifactGroupTypeEnum.SERVICE_API)) {
+ if (currentArtifactInfo != null && currentArtifactInfo.getArtifactGroupType() == ArtifactGroupTypeEnum.SERVICE_API) {
Either<ActionStatus, ResponseFormat> validateServiceApiType = validateArtifactType(user.getUserId(), artifactInfo, parentType);
if (validateServiceApiType.isRight()) {
return Either.right(validateServiceApiType.right().value());
@@ -1256,32 +1114,28 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
private void ignoreUnupdateableFieldsInUpdate(ArtifactOperationInfo operation, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifactInfo) {
- if (operation.getArtifactOperationEnum().equals(ArtifactOperationEnum.UPDATE)) {
+ if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.UPDATE) {
artifactInfo.setArtifactType(currentArtifactInfo.getArtifactType());
artifactInfo.setArtifactGroupType(currentArtifactInfo.getArtifactGroupType());
artifactInfo.setArtifactLabel(currentArtifactInfo.getArtifactLabel());
}
}
- private Either<ArtifactDefinition, ResponseFormat> findArtifactOnParentComponent(Component parentComponent, ComponentTypeEnum componentType, String parentId, ArtifactOperationInfo operation, String artifactId) {
+ private ArtifactDefinition findArtifactOnParentComponent(Component parentComponent, ComponentTypeEnum componentType, String parentId, ArtifactOperationInfo operation, String artifactId) {
- Either<ArtifactDefinition, ResponseFormat> result = null;
ArtifactDefinition foundArtifact = null;
if (StringUtils.isNotEmpty(artifactId)) {
foundArtifact = findArtifact(parentComponent, componentType, parentId, artifactId);
}
if (foundArtifact != null && ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum())) {
log.debug("Artifact {} already exist", artifactId);
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_EXIST, foundArtifact.getArtifactLabel()));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_EXIST, foundArtifact.getArtifactLabel());
}
if (foundArtifact == null && !ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum())) {
log.debug("The artifact {} was not found on parent {}. ", artifactId, parentId);
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ""));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, "");
}
- if (result == null) {
- result = Either.left(foundArtifact);
- }
- return result;
+ return foundArtifact;
}
private ArtifactDefinition findArtifact(Component parentComponent, ComponentTypeEnum componentType, String parentId, String artifactId) {
@@ -1296,41 +1150,38 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return foundArtifact;
}
- private Either<Boolean, ResponseFormat> validateInformationalArtifact(ArtifactDefinition artifactInfo, Component parentComponent) {
+ private void validateInformationalArtifact(ArtifactDefinition artifactInfo, Component parentComponent) {
ComponentTypeEnum parentComponentType = parentComponent.getComponentType();
ArtifactGroupTypeEnum groupType = artifactInfo.getArtifactGroupType();
- Either<Boolean, ResponseFormat> validationResult = Either.left(true);
ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
if (artifactType == null) {
- validationResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo
- .getArtifactType()));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
}
else if (parentComponentType == ComponentTypeEnum.RESOURCE && groupType == ArtifactGroupTypeEnum.INFORMATIONAL) {
String artifactTypeName = artifactType.getType();
ResourceTypeEnum parentResourceType = ((Resource) parentComponent).getResourceType();
Map<String, ArtifactTypeConfig> resourceInformationalArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceInformationalArtifacts();
+ .getConfiguration()
+ .getResourceInformationalArtifacts();
Set<String> validArtifactTypes = resourceInformationalArtifacts.keySet();
if (!validArtifactTypes.contains(artifactTypeName)) {
- validationResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactTypeName));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactTypeName);
}
else {
List<String> validResourceType = resourceInformationalArtifacts.get(artifactTypeName)
- .getValidForResourceTypes();
+ .getValidForResourceTypes();
if (!validResourceType.contains(parentResourceType.name())) {
- validationResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactTypeName));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactTypeName);
}
}
}
- return validationResult;
}
private NodeTypeEnum convertParentType(ComponentTypeEnum componentType) {
- if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ if (componentType == ComponentTypeEnum.RESOURCE) {
return NodeTypeEnum.Resource;
}
- else if (componentType.equals(ComponentTypeEnum.RESOURCE_INSTANCE)) {
+ else if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
return NodeTypeEnum.ResourceInstance;
}
else {
@@ -1338,213 +1189,133 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
+ // This method is here for backward compatibility - when other parts of the code are cleaned can change to use the internal version
public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete(String parentId, String artifactId, User user, AuditingActionEnum auditingAction, ComponentTypeEnum componentType, Component parent,
boolean shouldLock, boolean inTransaction) {
+ ResponseFormat responseFormat;
+ boolean operationSucceeded = false;
+ if (shouldLock) {
+ lockComponent(componentType, artifactId, auditingAction, user, parent);
+ }
+ try {
+ ArtifactDefinition artifactDefinition = handleDeleteInternal(parentId, artifactId, componentType, parent);
+ operationSucceeded = true;
+ return Either.left(Either.left(artifactDefinition));
+ }
+ catch (ComponentException ce) {
+ responseFormat = componentsUtils.getResponseFormat(ce);
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ }
+ catch (StorageException se) {
+ responseFormat = componentsUtils.getResponseFormat(se);
+ handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
+ return Either.right(responseFormat);
+ } finally {
+ handleLockingAndCommit(parent, shouldLock, inTransaction, operationSucceeded);
+ }
+ }
+ private ArtifactDefinition handleDeleteInternal(String parentId, String artifactId, ComponentTypeEnum componentType, Component parent) {
NodeTypeEnum parentType = convertParentType(componentType);
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
- Either<ImmutablePair<ArtifactDefinition, ComponentInstance>, ActionStatus> getArtifactRes = null;
- ArtifactDefinition foundArtifact = null;
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> getContainerRes = null;
- org.openecomp.sdc.be.model.Component fetchedContainerComponent = null;
+ log.debug("Going to find the artifact {} on the component {}", artifactId, parent.getUniqueId());
+ Either<ImmutablePair<ArtifactDefinition, ComponentInstance>, ActionStatus> getArtifactRes = findArtifact(artifactId, parent, parentId, componentType);
+ if (getArtifactRes.isRight()) {
+ log.debug("Failed to find the artifact {} belonging to {} on the component {}", artifactId, parentId, parent.getUniqueId());
+ throw new ByActionStatusComponentException(getArtifactRes.right().value(), artifactId);
+ }
+ ArtifactDefinition foundArtifact = getArtifactRes.left().value().getLeft();
+ ComponentInstance foundInstance = getArtifactRes.left().value().getRight();
+ String esId = foundArtifact.getEsId();
+ boolean needToClone = false;
+ if (StringUtils.isNotEmpty(esId)) {
+ Either<Boolean, StorageOperationStatus> needCloneRes = null;
+ needCloneRes = artifactToscaOperation.isCloneNeeded(parent.getUniqueId(), foundArtifact, parentType);
+ if (needCloneRes.isRight()) {
+ throw new StorageException(needCloneRes.right().value(), foundArtifact.getArtifactDisplayName());
+ } else if (log.isDebugEnabled()) {
+ needToClone = needCloneRes.left().value();
+ log.debug("handleDelete: clone is needed for deleting {} held by {} in component {} ? {}",
+ foundArtifact.getArtifactName(), parentType, parent.getUniqueId(), parent.getName(), needCloneRes.left().value());
+ }
+ }
+ boolean isNeedToDeleteArtifactFromDB = true;
boolean isDuplicated = false;
- String esId = null;
- Either<Boolean, StorageOperationStatus> needCloneRes = null;
- try {
- if (shouldLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, "Delete Artifact - lock resource: ");
- if (lockComponent.isRight()) {
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, lockComponent.right()
- .value(), componentType, null);
- resultOp = Either.right(lockComponent.right().value());
- }
- }
- if (resultOp == null) {
- log.debug("Going to fetch the container component {}. ", parent.getUniqueId());
- getContainerRes = toscaOperationFacade.getToscaElement(parent.getUniqueId());
- if (getContainerRes.isRight()) {
- log.debug("Failed to fetch the container component {}. ", parentId);
- responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(getContainerRes
- .right()
- .value()), artifactId);
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
- }
- if (resultOp == null) {
- fetchedContainerComponent = getContainerRes.left().value();
- log.debug("Going to find the artifact {} on the component {}", artifactId, fetchedContainerComponent.getUniqueId());
- getArtifactRes = findArtifact(artifactId, fetchedContainerComponent, parentId, componentType);
- if (getArtifactRes.isRight()) {
- log.debug("Failed to find the artifact {} belonging to {} on the component {}", artifactId, parentId, fetchedContainerComponent
- .getUniqueId());
- responseFormat = componentsUtils.getResponseFormatByArtifactId(getArtifactRes.right()
- .value(), artifactId);
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
- else {
- foundArtifact = getArtifactRes.left().value().getLeft();
- esId = foundArtifact.getEsId();
- }
- }
- if (resultOp == null && StringUtils.isNotEmpty(esId)) {
- needCloneRes = artifactToscaOperation.isCloneNeeded(parent.getUniqueId(), foundArtifact, convertParentType(parent
- .getComponentType()));
- if (needCloneRes.isRight()) {
- log.debug(FAILED_UPDATE_ARTIFACT, artifactId, parentId);
- responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(needCloneRes
- .right()
- .value()), foundArtifact.getArtifactDisplayName());
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
- }
- boolean isNeedToDeleteArtifactFromDB = true;
- if (resultOp == null) {
-
- if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
- String instanceId = parentId;
- Either<Boolean, ActionStatus> isOnlyResourceInstanceArtifact = isArtifactOnlyResourceInstanceArtifact(foundArtifact, fetchedContainerComponent, instanceId);
-
- if (isOnlyResourceInstanceArtifact.isRight()) {
- log.debug(FAILED_UPDATE_ARTIFACT, artifactId, parentId);
- responseFormat = componentsUtils.getResponseFormatByArtifactId(isOnlyResourceInstanceArtifact.right()
- .value(), foundArtifact
- .getArtifactDisplayName());
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
- }
- isNeedToDeleteArtifactFromDB = isOnlyResourceInstanceArtifact.left().value();
- }
-
- Either<ArtifactDataDefinition, StorageOperationStatus> updatedArtifactRes = deleteOrUpdateArtifactOnGraph(parent, parentId, artifactId, parentType, foundArtifact, needCloneRes
- .left()
- .value());
- if (updatedArtifactRes.isRight()) {
- log.debug(FAILED_UPDATE_ARTIFACT, artifactId, parentId);
- responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(updatedArtifactRes
- .right()
- .value()), foundArtifact.getArtifactDisplayName());
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
- else {
- isDuplicated = updatedArtifactRes.left().value().getDuplicated();
- }
- }
+ if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
+ isNeedToDeleteArtifactFromDB = isArtifactOnlyResourceInstanceArtifact(foundArtifact, parent, parentId);
+ }
+ ArtifactDataDefinition updatedArtifact = deleteOrUpdateArtifactOnGraph(parent, parentId, artifactId, parentType, foundArtifact, needToClone);
+ isDuplicated = updatedArtifact.getDuplicated();
- if (resultOp == null && (!needCloneRes.left().value() && !isDuplicated) && isNeedToDeleteArtifactFromDB) {
- log.debug("Going to delete the artifact {} from the database. ", artifactId);
- CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(esId);
- if (cassandraStatus != CassandraOperationStatus.OK) {
- log.debug("Failed to delete the artifact {} from the database. ", artifactId);
- responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(componentsUtils.convertToStorageOperationStatus(cassandraStatus)), foundArtifact
- .getArtifactDisplayName());
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
+ if (!needToClone && !isDuplicated && isNeedToDeleteArtifactFromDB) {
+ log.debug("Going to delete the artifact {} from the database. ", artifactId);
+ CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(esId);
+ if (cassandraStatus != CassandraOperationStatus.OK) {
+ log.debug("Failed to delete the artifact {} from the database. ", artifactId);
+ throw new StorageException(convertToStorageOperationStatus(cassandraStatus), foundArtifact.getArtifactDisplayName());
}
- if (resultOp == null && componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
-
- List<GroupInstance> updatedGroupInstances = getUpdatedGroupInstances(artifactId, foundArtifact, getArtifactRes
- .left()
- .value()
- .getRight()
- .getGroupInstances());
- if (CollectionUtils.isNotEmpty(updatedGroupInstances)) {
- Either<List<GroupInstance>, StorageOperationStatus> status = toscaOperationFacade.updateGroupInstancesOnComponent(fetchedContainerComponent, parentId, updatedGroupInstances);
- if (status.isRight()) {
- log.debug(FAILED_UPDATE_GROUPS, fetchedContainerComponent.getUniqueId());
- responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(status
- .right()
- .value()), foundArtifact.getArtifactDisplayName());
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
+ }
+ if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
+ List<GroupInstance> updatedGroupInstances = getUpdatedGroupInstances(artifactId, foundArtifact, foundInstance.getGroupInstances());
+ if (CollectionUtils.isNotEmpty(updatedGroupInstances)) {
+ Either<List<GroupInstance>, StorageOperationStatus> status = toscaOperationFacade.updateGroupInstancesOnComponent(parent, parentId, updatedGroupInstances);
+ if (status.isRight()) {
+ log.debug(FAILED_UPDATE_GROUPS, parent.getUniqueId());
+ throw new StorageException(status.right().value(), foundArtifact.getArtifactDisplayName());
}
}
- if (resultOp == null && componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
- StorageOperationStatus status = generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentType);
- if (status != StorageOperationStatus.OK) {
- log.debug("Failed to generate new customization UUID for the component instance {}. ", parentId);
- responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(status), foundArtifact
- .getArtifactDisplayName());
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
+ StorageOperationStatus status = generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentType);
+ if (status != StorageOperationStatus.OK) {
+ log.debug("Failed to generate new customization UUID for the component instance {}. ", parentId);
+ throw new StorageException(status, foundArtifact.getArtifactDisplayName());
}
- if (resultOp == null && componentType != ComponentTypeEnum.RESOURCE_INSTANCE) {
- List<GroupDataDefinition> updatedGroups = getUpdatedGroups(artifactId, foundArtifact, fetchedContainerComponent
- .getGroups());
- if (CollectionUtils.isNotEmpty(updatedGroups)) {
- Either<List<GroupDefinition>, StorageOperationStatus> status = toscaOperationFacade.updateGroupsOnComponent(fetchedContainerComponent, updatedGroups);
- if (status.isRight()) {
- log.debug(FAILED_UPDATE_GROUPS, fetchedContainerComponent.getUniqueId());
- responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(status
- .right()
- .value()), foundArtifact.getArtifactDisplayName());
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
+ } else {
+ List<GroupDataDefinition> updatedGroups = getUpdatedGroups(artifactId, foundArtifact, parent.getGroups());
+ if (CollectionUtils.isNotEmpty(updatedGroups)) {
+ Either<List<GroupDefinition>, StorageOperationStatus> status = toscaOperationFacade.updateGroupsOnComponent(parent, updatedGroups);
+ if (status.isRight()) {
+ log.debug(FAILED_UPDATE_GROUPS, parent.getUniqueId());
+ throw new StorageException(status.right().value(), foundArtifact.getArtifactDisplayName());
}
}
- if (resultOp == null) {
- resultOp = Either.left(Either.left(foundArtifact));
- handleAuditing(auditingAction, parent, parentId, user, foundArtifact, null, artifactId, responseFormat, componentType, null);
- }
- return resultOp;
- }
- finally {
- if (shouldLock) {
- unlockComponent(resultOp, parent, inTransaction);
- }
}
+ return foundArtifact;
}
- private Either<Boolean, ActionStatus> isArtifactOnlyResourceInstanceArtifact(ArtifactDefinition foundArtifact, Component parent, String instanceId) {
- Either<Boolean, ActionStatus> result = Either.left(true);
- ComponentInstance foundInstance = null;
- Optional<ComponentInstance> componentInstanceOpt = parent.getComponentInstances()
- .stream()
- .filter(i -> i.getUniqueId().equals(instanceId))
- .findFirst();
+ private boolean isArtifactOnlyResourceInstanceArtifact(ArtifactDefinition foundArtifact, Component parent, String instanceId) {
+ Optional<ComponentInstance> componentInstanceOpt = parent.getComponentInstanceById(instanceId);
if (!componentInstanceOpt.isPresent()) {
- result = Either.right(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER);
- }
- else {
- foundInstance = componentInstanceOpt.get();
- String componentUid = foundInstance.getComponentUid();
- Either<Component, StorageOperationStatus> getContainerRes = toscaOperationFacade.getToscaElement(componentUid);
- if (getContainerRes.isRight()) {
- log.debug("Failed to fetch the container component {}. ", componentUid);
- return Either.right(componentsUtils.convertFromStorageResponse(getContainerRes.right().value()));
- }
- Component origComponent = getContainerRes.left().value();
- Map<String, ArtifactDefinition> deploymentArtifacts = origComponent.getDeploymentArtifacts();
- if (deploymentArtifacts != null && !deploymentArtifacts.isEmpty()) {
- Optional<String> op = deploymentArtifacts.keySet()
- .stream()
- .filter(a -> a.equals(foundArtifact.getArtifactLabel()))
- .findAny();
- if (op.isPresent()) {
- return Either.left(false);
- }
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, instanceId, "", "", parent.getName());
+ }
+ ComponentInstance foundInstance = componentInstanceOpt.get();
+ String componentUid = foundInstance.getComponentUid();
+ Either<Component, StorageOperationStatus> getContainerRes = toscaOperationFacade.getToscaElement(componentUid);
+ if (getContainerRes.isRight()) {
+ log.debug("Failed to fetch the container component {}. ", componentUid);
+ throw new StorageException(getContainerRes.right().value());
+ }
+ Component origComponent = getContainerRes.left().value();
+ Map<String, ArtifactDefinition> deploymentArtifacts = origComponent.getDeploymentArtifacts();
+ if (MapUtils.isNotEmpty(deploymentArtifacts)) {
+ Optional<String> op = deploymentArtifacts.keySet()
+ .stream()
+ .filter(a -> a.equals(foundArtifact.getArtifactLabel()))
+ .findAny();
+ if (op.isPresent()) {
+ return false;
}
- Map<String, ArtifactDefinition> artifacts = origComponent.getArtifacts();
- if (artifacts != null && !artifacts.isEmpty()) {
- Optional<String> op = artifacts.keySet()
- .stream()
- .filter(a -> a.equals(foundArtifact.getArtifactLabel()))
- .findAny();
- if (op.isPresent()) {
- return Either.left(false);
- }
+ }
+ Map<String, ArtifactDefinition> artifacts = origComponent.getArtifacts();
+ if (MapUtils.isNotEmpty(artifacts)) {
+ Optional<String> op = artifacts.keySet()
+ .stream()
+ .filter(a -> a.equals(foundArtifact.getArtifactLabel()))
+ .findAny();
+ if (op.isPresent()) {
+ return false;
}
-
}
- return result;
+ return true;
}
private List<GroupDataDefinition> getUpdatedGroups(String artifactId, ArtifactDefinition foundArtifact, List<GroupDefinition> groups) {
@@ -1558,7 +1329,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
isUpdated = true;
}
if (CollectionUtils.isNotEmpty(group.getArtifactsUuid()) && group.getArtifactsUuid()
- .contains(foundArtifact.getArtifactUUID())) {
+ .contains(foundArtifact.getArtifactUUID())) {
group.getArtifactsUuid().remove(foundArtifact.getArtifactUUID());
isUpdated = true;
}
@@ -1576,14 +1347,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
boolean isUpdated = false;
for (GroupInstance groupInstance : groupInstances) {
isUpdated = false;
- if (CollectionUtils.isNotEmpty(groupInstance.getGroupInstanceArtifacts()) && groupInstance.getGroupInstanceArtifacts()
- .contains(artifactId)) {
+ if (CollectionUtils.isNotEmpty(groupInstance.getGroupInstanceArtifacts()) && groupInstance.getGroupInstanceArtifacts().contains(artifactId)) {
groupInstance.getGroupInstanceArtifacts().remove(artifactId);
isUpdated = true;
}
if (CollectionUtils.isNotEmpty(groupInstance.getGroupInstanceArtifactsUuid()) && groupInstance.getGroupInstanceArtifactsUuid()
- .contains(foundArtifact
- .getArtifactUUID())) {
+ .contains(foundArtifact.getArtifactUUID())) {
groupInstance.getGroupInstanceArtifactsUuid().remove(foundArtifact.getArtifactUUID());
isUpdated = true;
}
@@ -1595,7 +1364,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return updatedGroupInstances;
}
- private Either<ArtifactDataDefinition, StorageOperationStatus> deleteOrUpdateArtifactOnGraph(Component component, String parentId, String artifactId, NodeTypeEnum parentType, ArtifactDefinition foundArtifact, Boolean cloneIsNeeded) {
+ private ArtifactDataDefinition deleteOrUpdateArtifactOnGraph(Component component, String parentId, String artifactId, NodeTypeEnum parentType, ArtifactDefinition foundArtifact, Boolean cloneIsNeeded) {
Either<ArtifactDataDefinition, StorageOperationStatus> result;
boolean isMandatory = foundArtifact.getMandatory() || foundArtifact.getServiceApi();
@@ -1604,7 +1373,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (isMandatory) {
log.debug("Going to update mandatory artifact {} from the component {}", artifactId, parentId);
resetMandatoryArtifactFields(foundArtifact);
- result = artifactToscaOperation.updateArtifactOnGraph(componentId, foundArtifact, parentType, artifactId, instanceId, true, true);
+ result = artifactToscaOperation.updateArtifactOnGraph(component, foundArtifact, parentType, artifactId, instanceId, true, true);
}
else if (cloneIsNeeded) {
log.debug("Going to clone artifacts and to delete the artifact {} from the component {}", artifactId, parentId);
@@ -1614,7 +1383,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
log.debug("Going to delete the artifact {} from the component {}", artifactId, parentId);
result = artifactToscaOperation.removeArtifactOnGraph(foundArtifact, componentId, instanceId, parentType, false);
}
- return result;
+ if (result.isRight()) {
+ throw new StorageException(result.right().value(), foundArtifact.getArtifactDisplayName());
+ }
+ return result.left().value();
}
private Either<ImmutablePair<ArtifactDefinition, ComponentInstance>, ActionStatus> findArtifact(String artifactId, Component fetchedContainerComponent, String parentId, ComponentTypeEnum componentType) {
@@ -1624,10 +1396,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
ComponentInstance foundInstance = null;
if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE && StringUtils.isNotEmpty(parentId)) {
Optional<ComponentInstance> componentInstanceOpt = fetchedContainerComponent.getComponentInstances()
- .stream()
- .filter(i -> i.getUniqueId()
- .equals(parentId))
- .findFirst();
+ .stream()
+ .filter(i -> i.getUniqueId()
+ .equals(parentId))
+ .findFirst();
if (!componentInstanceOpt.isPresent()) {
result = Either.right(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER);
}
@@ -1654,27 +1426,27 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Map<String, ArtifactDefinition> currArtifacts;
if (!artifacts.containsKey(artifactId) && MapUtils.isNotEmpty(component.getDeploymentArtifacts())) {
currArtifacts = component.getDeploymentArtifacts()
- .values()
- .stream()
- .collect(Collectors.toMap(i -> i.getUniqueId(), i -> i));
+ .values()
+ .stream()
+ .collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId, i -> i));
if (MapUtils.isNotEmpty(currArtifacts)) {
artifacts.putAll(currArtifacts);
}
}
if (!artifacts.containsKey(artifactId) && MapUtils.isNotEmpty(component.getArtifacts())) {
currArtifacts = component.getArtifacts()
- .values()
- .stream()
- .collect(Collectors.toMap(i -> i.getUniqueId(), i -> i));
+ .values()
+ .stream()
+ .collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId, Function.identity()));
if (MapUtils.isNotEmpty(currArtifacts)) {
artifacts.putAll(currArtifacts);
}
}
if (!artifacts.containsKey(artifactId) && MapUtils.isNotEmpty(component.getArtifacts())) {
currArtifacts = component.getToscaArtifacts()
- .values()
- .stream()
- .collect(Collectors.toMap(i -> i.getUniqueId(), i -> i));
+ .values()
+ .stream()
+ .collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId, Function.identity()));
if (MapUtils.isNotEmpty(currArtifacts)) {
artifacts.putAll(currArtifacts);
}
@@ -1685,24 +1457,44 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Map<String, ArtifactDefinition> currArtifacts;
if (MapUtils.isNotEmpty(instance.getDeploymentArtifacts())) {
currArtifacts = instance.getDeploymentArtifacts()
- .values()
- .stream()
- .collect(Collectors.toMap(i -> i.getUniqueId(), i -> i));
+ .values()
+ .stream()
+ .collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId, Function.identity()));
if (MapUtils.isNotEmpty(currArtifacts)) {
artifacts.putAll(currArtifacts);
}
}
if (!artifacts.containsKey(artifactId) && MapUtils.isNotEmpty(instance.getArtifacts())) {
currArtifacts = instance.getArtifacts()
- .values()
- .stream()
- .collect(Collectors.toMap(i -> i.getUniqueId(), i -> i));
+ .values()
+ .stream()
+ .collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId, Function.identity()));
if (MapUtils.isNotEmpty(currArtifacts)) {
artifacts.putAll(currArtifacts);
}
}
}
+ private StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
+ StorageOperationStatus result;
+ switch (cassandraStatus) {
+ case OK:
+ result = StorageOperationStatus.OK;
+ break;
+ case NOT_FOUND:
+ result = StorageOperationStatus.NOT_FOUND;
+ break;
+ case CLUSTER_NOT_CONNECTED:
+ case KEYSPACE_NOT_CONNECTED:
+ result = StorageOperationStatus.CONNECTION_FAILURE;
+ break;
+ default:
+ result = StorageOperationStatus.GENERAL_ERROR;
+ break;
+ }
+ return result;
+ }
+
private void resetMandatoryArtifactFields(ArtifactDefinition fetchedArtifact) {
if (fetchedArtifact != null) {
log.debug("Going to reset mandatory artifact {} fields. ", fetchedArtifact.getUniqueId());
@@ -1729,29 +1521,18 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return error;
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDownload(String componentId, String artifactId, User user, AuditingActionEnum auditingAction, ComponentTypeEnum componentType,
- Component parent) {
- Either<ArtifactDefinition, StorageOperationStatus> artifactById = artifactToscaOperation.getArtifactById(componentId, artifactId, componentType, parent
- .getUniqueId());
+ private ArtifactDefinition handleDownload(String componentId, String artifactId, ComponentTypeEnum componentType,
+ Component parent) {
+ Either<ArtifactDefinition, StorageOperationStatus> artifactById = artifactToscaOperation.getArtifactById(componentId, artifactId, componentType,
+ parent.getUniqueId());
if (artifactById.isRight()) {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(artifactById.right().value());
- log.debug("Error when getting artifact info by id{}, error: {}", artifactId, actionStatus);
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(actionStatus, "");
- handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
+ throw new StorageException(artifactById.right().value());
}
ArtifactDefinition artifactDefinition = artifactById.left().value();
if (artifactDefinition == null) {
- log.debug("Empty artifact definition returned from DB by artifact id {}", artifactId);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, "");
- handleAuditing(auditingAction, parent, componentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, artifactId);
}
-
- Either<ArtifactDefinition, Operation> insideEither = Either.left(artifactDefinition);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleAuditing(auditingAction, parent, componentId, user, artifactDefinition, null, artifactId, responseFormat, componentType, null);
- return Either.left(insideEither);
+ return artifactDefinition;
}
private Either<ActionStatus, ResponseFormat> handleArtifactLabel(String componentId, Component parentComponent, ArtifactOperationInfo operation, ArtifactDefinition artifactInfo, String operationName,
@@ -1759,9 +1540,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String artifactLabel = artifactInfo.getArtifactLabel();
if (operationName == null && (artifactInfo.getArtifactLabel() == null || artifactInfo.getArtifactLabel()
- .isEmpty())) {
+ .isEmpty())) {
BeEcompErrorManager.getInstance()
- .logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
+ .logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
log.debug("missing artifact logical name for component {}", componentId);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_LABEL));
}
@@ -1812,7 +1593,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private boolean validateLabelUniqueness(String componentId, Component parentComponent, String artifactLabel, ComponentTypeEnum componentType) {
boolean isUnique = true;
Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifacts;
- if (componentType.equals(ComponentTypeEnum.RESOURCE_INSTANCE)) {
+ if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
artifacts = artifactToscaOperation.getAllInstanceArtifacts(parentComponent.getUniqueId(), componentId);
}
else {
@@ -1827,21 +1608,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
}
- if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
- Either<Map<String, InterfaceDefinition>, StorageOperationStatus> allInterfacesOfResource = interfaceLifecycleOperation
- .getAllInterfacesOfResource(componentId, true, true);
- if (allInterfacesOfResource.isLeft()) {
- for (InterfaceDefinition interace : allInterfacesOfResource.left().value().values()) {
- for (Operation operation : interace.getOperationsMap().values()) {
- if (operation.getImplementation() != null && operation.getImplementation()
- .getArtifactLabel()
- .equals(artifactLabel)) {
- isUnique = false;
- break;
- }
- }
- }
- }
+ if (componentType == ComponentTypeEnum.RESOURCE && isUnique) {
+ isUnique = isUniqueLabelInResourceInterfaces(componentId, artifactLabel);
}
return isUnique;
}
@@ -1859,7 +1627,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return false;
}
}
- if (ComponentTypeEnum.RESOURCE.equals(componentType)) {
+ if (ComponentTypeEnum.RESOURCE == componentType) {
return isUniqueArtifactNameInResourceInterfaces(componentId, artifactName, artifactInfo.getArtifactLabel());
}
return true;
@@ -1869,14 +1637,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<Map<String, InterfaceDefinition>, StorageOperationStatus> allInterfacesOfResource = interfaceLifecycleOperation
.getAllInterfacesOfResource(componentId, true, true);
- if (allInterfacesOfResource.isLeft() && Objects.nonNull(allInterfacesOfResource)){
- return !allInterfacesOfResource.left().value()
+ if (allInterfacesOfResource.isLeft()){
+ return allInterfacesOfResource.left().value()
.values()
.stream().map(InterfaceDefinition :: getOperationsMap)
.flatMap(map -> map.values().stream())
.map(OperationDataDefinition::getImplementation)
.filter(Objects::nonNull)
- .anyMatch(add -> artifactName.equals(add.getArtifactName())
+ .noneMatch(add -> artifactName.equals(add.getArtifactName())
&& !artifactLabel.equals(add.getArtifactLabel()));
}
return true;
@@ -1887,13 +1655,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
.getAllInterfacesOfResource(componentId, true, true);
if (allInterfacesOfResource.isLeft()){
- return !allInterfacesOfResource.left().value()
+ return allInterfacesOfResource.left().value()
.values()
.stream().map(InterfaceDefinition :: getOperationsMap)
.flatMap(map -> map.values().stream())
.map(OperationDataDefinition::getImplementation)
.filter(Objects::nonNull)
- .anyMatch(add -> artifactLabel.equals(add.getArtifactLabel()));
+ .noneMatch(add -> artifactLabel.equals(add.getArtifactLabel()));
}
return true;
}
@@ -1901,349 +1669,196 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getArtifacts(ComponentTypeEnum componentType, Component parentComponent,
String componentId, ArtifactGroupTypeEnum artifactGroupType) {
Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifactsResponse;
- if (componentType.equals(ComponentTypeEnum.RESOURCE_INSTANCE)) {
+ if (componentType == ComponentTypeEnum.RESOURCE_INSTANCE) {
artifactsResponse = artifactToscaOperation.getAllInstanceArtifacts(parentComponent.getUniqueId(), componentId);
}
else {
artifactsResponse = artifactToscaOperation.getArtifacts(componentId);
}
- if (artifactsResponse.isRight() && artifactsResponse.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ if (artifactsResponse.isRight() && artifactsResponse.right().value() == StorageOperationStatus.NOT_FOUND) {
log.debug("failed to retrieve artifacts for {} ", componentId);
return Either.right(artifactsResponse.right().value());
}
return Either.left(artifactsResponse.left().value().entrySet()
.stream()
- .filter(x -> artifactGroupType.equals(x.getValue().getArtifactGroupType()))
+ .filter(x -> artifactGroupType == x.getValue().getArtifactGroupType())
.collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
}
- private List<String> getListOfArtifactName(Map<String, ArtifactDefinition> artifacts) {
- return artifacts.entrySet()
- .stream()
- .map(x -> x.getValue().getArtifactName())
- .collect(Collectors.toList());
- }
-
// ***************************************************************
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> createAndLinkArtifact(org.openecomp.sdc.be.model.Component parent, String parentId, ArtifactDefinition artifactInfo, User user,
- ComponentTypeEnum componentTypeEnum, AuditingActionEnum auditingActionEnum) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
- Either<ArtifactDefinition, Operation> insideEither = null;
- ComponentInstance foundInstance = findComponentInstance(parentId, parent);
- String instanceId = null;
- String instanceName = null;
- if (foundInstance != null) {
- instanceId = foundInstance.getUniqueId();
- instanceName = foundInstance.getName();
- }
- boolean isLeft = false;
- String artifactUniqueId = null;
- StorageOperationStatus error = null;
- // information/deployment/api aritfacts
- log.trace("Try to create entry on graph");
- NodeTypeEnum nodeType = convertParentType(componentTypeEnum);
- Either<ArtifactDefinition, StorageOperationStatus> result = artifactToscaOperation.addArifactToComponent(artifactInfo, parent
- .getUniqueId(), nodeType, true, instanceId);
-
- isLeft = result.isLeft();
- if (isLeft) {
- artifactUniqueId = result.left().value().getUniqueId();
- result.left().value();
-
- insideEither = Either.left(result.left().value());
- resultOp = Either.left(insideEither);
-
- error = generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentTypeEnum);
- if (error != StorageOperationStatus.OK) {
- isLeft = false;
- }
-
- }
- if (isLeft) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, artifactUniqueId, artifactUniqueId, responseFormat, componentTypeEnum, instanceName);
- return resultOp;
- }
- else {
- log.debug("Failed to create entry on graph for artifact {}", artifactInfo.getArtifactName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(error), artifactInfo
- .getArtifactDisplayName());
- handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, null, null, responseFormat, componentTypeEnum, instanceName);
- resultOp = Either.right(responseFormat);
- return resultOp;
+ private Either<ArtifactDefinition, Operation> createArtifact(Component parent, String parentId, ArtifactDefinition artifactInfo, byte[] decodedPayload,
+ ComponentTypeEnum componentTypeEnum, AuditingActionEnum auditingActionEnum, String interfaceType, String operationName) {
+ DAOArtifactData artifactData = createEsArtifactData(artifactInfo, decodedPayload);
+ if (artifactData == null) {
+ BeEcompErrorManager.getInstance().logBeDaoSystemError("Upload Artifact");
+ log.debug("Failed to create artifact object for ES.");
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
- }
-
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> createArtifact(org.openecomp.sdc.be.model.Component parent, String parentId, ArtifactDefinition artifactInfo, byte[] decodedPayload, User user,
- ComponentTypeEnum componentTypeEnum, AuditingActionEnum auditingActionEnum, String interfaceType, String operationName) {
-
- ESArtifactData artifactData = createEsArtifactData(artifactInfo, decodedPayload);
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
- Either<ArtifactDefinition, Operation> insideEither = null;
ComponentInstance foundInstance = findComponentInstance(parentId, parent);
String instanceId = null;
- String instanceName = null;
if (foundInstance != null) {
if (foundInstance.isArtifactExists(artifactInfo.getArtifactGroupType(), artifactInfo.getArtifactLabel())) {
log.debug("Failed to create artifact, already exists");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_EXIST, artifactInfo
- .getArtifactLabel());
- handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, null, artifactInfo.getUniqueId(), responseFormat, componentTypeEnum, foundInstance
- .getName());
- resultOp = Either.right(responseFormat);
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_EXIST, artifactInfo.getArtifactLabel());
}
-
instanceId = foundInstance.getUniqueId();
- instanceName = foundInstance.getName();
- }
- if (artifactData == null) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Upload Artifact");
- log.debug("Failed to create artifact object for ES.");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, null, null, responseFormat, componentTypeEnum, null);
- resultOp = Either.right(responseFormat);
- return resultOp;
-
}
// set on graph object id of artifact in ES!
artifactInfo.setEsId(artifactData.getId());
- boolean isLeft = false;
- String artifactUniqueId = null;
- StorageOperationStatus error = null;
+ Either<ArtifactDefinition, Operation> operationResult;
if (interfaceType != null && operationName != null) {
// lifecycle artifact
Operation operation = convertToOperation(artifactInfo, operationName);
-
Either<Operation, StorageOperationStatus> result = interfaceLifecycleOperation.updateInterfaceOperation(parentId, interfaceType, operationName, operation);
-
- isLeft = result.isLeft();
- if (isLeft) {
- artifactUniqueId = result.left().value().getImplementation().getUniqueId();
- result.left().value().getImplementation();
-
- insideEither = Either.right(result.left().value());
- resultOp = Either.left(insideEither);
- }
- else {
- error = result.right().value();
+ if (result.isRight()) {
+ throw new StorageException(result.right().value());
}
+ operationResult = Either.right(result.left().value());
}
else {
- // information/deployment/api aritfacts
- log.trace("Try to create entry on graph");
+ // information/deployment/api artifacts
NodeTypeEnum nodeType = convertParentType(componentTypeEnum);
- Either<ArtifactDefinition, StorageOperationStatus> result = artifactToscaOperation.addArifactToComponent(artifactInfo, parent
- .getUniqueId(), nodeType, true, instanceId);
-
- isLeft = result.isLeft();
- if (isLeft) {
- artifactUniqueId = result.left().value().getUniqueId();
- artifactData.setId(result.left().value().getEsId());
- insideEither = Either.left(result.left().value());
- resultOp = Either.left(insideEither);
-
- error = generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentTypeEnum);
- if (error != StorageOperationStatus.OK) {
- isLeft = false;
- }
-
- }
- else {
- error = result.right().value();
- }
- }
- if (isLeft) {
- boolean res = saveArtifacts(artifactData, parentId);
-
- if (res) {
- log.debug(ARTIFACT_SAVED, artifactUniqueId);
-
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, artifactUniqueId, artifactUniqueId, responseFormat, componentTypeEnum, instanceName);
- return resultOp;
+ Either<ArtifactDefinition, StorageOperationStatus> result = artifactToscaOperation.addArtifactToComponent(
+ artifactInfo, parent, nodeType, true, instanceId);
+ if (result.isRight()) {
+ throw new StorageException(result.right().value());
}
- else {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Upload Artifact");
- log.debug(FAILED_SAVE_ARTIFACT);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, null, artifactUniqueId, responseFormat, componentTypeEnum, instanceName);
+ ArtifactDefinition artifactDefinition = result.left().value();
+ artifactData.setId(artifactDefinition.getEsId());
+ operationResult = Either.left(artifactDefinition);
- resultOp = Either.right(responseFormat);
- return resultOp;
+ if (generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentTypeEnum) != StorageOperationStatus.OK) {
+ throw new StorageException(generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentTypeEnum));
}
}
- else {
- log.debug("Failed to create entry on graph for artifact {}", artifactInfo.getArtifactName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils.convertFromStorageResponse(error), artifactInfo
- .getArtifactDisplayName());
- handleAuditing(auditingActionEnum, parent, parentId, user, artifactInfo, null, null, responseFormat, componentTypeEnum, instanceName);
- resultOp = Either.right(responseFormat);
- return resultOp;
- }
-
+ saveArtifactInCassandra(artifactData, parent, artifactInfo, "", "", auditingActionEnum, componentTypeEnum);
+ return operationResult;
}
private ComponentInstance findComponentInstance(String componentInstanceId, Component containerComponent) {
ComponentInstance foundInstance = null;
if (CollectionUtils.isNotEmpty(containerComponent.getComponentInstances())) {
foundInstance = containerComponent.getComponentInstances()
- .stream()
- .filter(i -> i.getUniqueId().equals(componentInstanceId))
- .findFirst()
- .orElse(null);
+ .stream()
+ .filter(i -> i.getUniqueId().equals(componentInstanceId))
+ .findFirst()
+ .orElse(null);
}
return foundInstance;
}
- private Either<Boolean, ResponseFormat> validateDeploymentArtifact(Component parentComponent, String parentId, boolean isCreate, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact, NodeTypeEnum parentType) {
-
- Either<Boolean, ResponseFormat> result = Either.left(true);
- Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
-
- validateArtifactTypeExists(responseWrapper, artifactInfo);
-
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
+ private void validateDeploymentArtifact(Component parentComponent, String parentId, boolean isCreate, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact, NodeTypeEnum parentType) {
+ ArtifactTypeEnum artifactType = getValidArtifactType(artifactInfo);
Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts = fillDeploymentArtifactTypeConf(parentType);
-
- if (responseWrapper.isEmpty()) {
- validateDeploymentArtifactConf(artifactInfo, responseWrapper, artifactType, resourceDeploymentArtifacts);
+ validateDeploymentArtifactTypeIsLegalForParent(artifactInfo, artifactType, resourceDeploymentArtifacts);
+ if (!isCreate) {
+ validateArtifactTypeNotChanged(artifactInfo, currentArtifact);
}
-
- // Common code for all types
- // not allowed to change artifactType
- if (responseWrapper.isEmpty() && !isCreate) {
- Either<Boolean, ResponseFormat> validateServiceApiType = validateArtifactTypeNotChanged(artifactInfo, currentArtifact);
- if (validateServiceApiType.isRight()) {
- responseWrapper.setInnerElement(validateServiceApiType.right().value());
- }
- }
- if (responseWrapper.isEmpty()) {
- if (parentType.equals(NodeTypeEnum.Resource)) {
- Resource resource = (Resource) parentComponent;
- ResourceTypeEnum resourceType = resource.getResourceType();
- ArtifactTypeConfig config = resourceDeploymentArtifacts.get(artifactType.getType());
- if (config == null) {
- responseWrapper.setInnerElement(ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo
- .getArtifactType()));
- }
- else {
- List<String> myList = config.getValidForResourceTypes();
- Either<Boolean, ResponseFormat> either = validateResourceType(resourceType, artifactInfo, myList);
- if (either.isRight()) {
- responseWrapper.setInnerElement(either.right().value());
- }
- }
+ if (parentType == NodeTypeEnum.Resource) {
+ Resource resource = (Resource) parentComponent;
+ ResourceTypeEnum resourceType = resource.getResourceType();
+ ArtifactTypeConfig config = resourceDeploymentArtifacts.get(artifactType.getType());
+ if (config == null) {
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
}
-
- validateFileExtension(responseWrapper, () -> getDeploymentArtifactTypeConfig(parentType, artifactType), artifactInfo, parentType, artifactType);
+ List<String> myList = config.getValidForResourceTypes();
+ validateResourceType(resourceType, artifactInfo, myList);
}
- if (responseWrapper.isEmpty() && !NodeTypeEnum.ResourceInstance.equals(parentType)) {
+ validateFileExtension(() -> getDeploymentArtifactTypeConfig(parentType, artifactType), artifactInfo, parentType, artifactType);
+
+ if (NodeTypeEnum.ResourceInstance != parentType) {
String artifactName = artifactInfo.getArtifactName();
if (isCreate || !artifactName.equalsIgnoreCase(currentArtifact.getArtifactName())) {
- validateSingleDeploymentArtifactName(responseWrapper, artifactName, parentComponent, parentType);
+ validateSingleDeploymentArtifactName(artifactName, parentComponent, parentType);
}
}
- if (responseWrapper.isEmpty()) {
- switch (artifactType) {
- case HEAT:
- case HEAT_VOL:
- case HEAT_NET:
- result = validateHeatDeploymentArtifact(isCreate, artifactInfo, currentArtifact);
- break;
- case HEAT_ENV:
- result = validateHeatEnvDeploymentArtifact(parentComponent, parentId, artifactInfo, parentType);
- artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
- break;
- case DCAE_INVENTORY_TOSCA:
- case DCAE_INVENTORY_JSON:
- case DCAE_INVENTORY_POLICY:
- // Validation is done in handle payload.
- case DCAE_INVENTORY_DOC:
- case DCAE_INVENTORY_BLUEPRINT:
- case DCAE_INVENTORY_EVENT:
- // No specific validation
- default:
- artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
- break;
- }
-
- }
-
- if (!responseWrapper.isEmpty()) {
- result = Either.right(responseWrapper.getInnerElement());
+ switch (artifactType) {
+ case HEAT:
+ case HEAT_VOL:
+ case HEAT_NET:
+ validateHeatTimeoutValue(isCreate, artifactInfo, currentArtifact);
+ break;
+ case HEAT_ENV:
+ validateHeatEnvDeploymentArtifact(parentComponent, parentId, artifactInfo, parentType);
+ artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
+ break;
+ case DCAE_INVENTORY_TOSCA:
+ case DCAE_INVENTORY_JSON:
+ case DCAE_INVENTORY_POLICY:
+ // Validation is done in handle payload.
+ case DCAE_INVENTORY_DOC:
+ case DCAE_INVENTORY_BLUEPRINT:
+ case DCAE_INVENTORY_EVENT:
+ // No specific validation
+ default:
+ artifactInfo.setTimeout(NodeTemplateOperation.NON_HEAT_TIMEOUT);
+ break;
}
- return result;
}
- private void validateDeploymentArtifactConf(ArtifactDefinition artifactInfo, Wrapper<ResponseFormat> responseWrapper, ArtifactTypeEnum artifactType, Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts) {
+ @VisibleForTesting
+ void validateDeploymentArtifactTypeIsLegalForParent(ArtifactDefinition artifactInfo, ArtifactTypeEnum artifactType, Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts) {
if ((resourceDeploymentArtifacts == null) || !resourceDeploymentArtifacts.containsKey(artifactType.name())) {
- ResponseFormat responseFormat = ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo
- .getArtifactType());
- responseWrapper.setInnerElement(responseFormat);
log.debug("Artifact Type: {} Not found !", artifactInfo.getArtifactType());
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
}
}
private Map<String, ArtifactTypeConfig> fillDeploymentArtifactTypeConf(NodeTypeEnum parentType) {
- Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts = null;
- if (parentType.equals(NodeTypeEnum.Resource)) {
+ Map<String, ArtifactTypeConfig> resourceDeploymentArtifacts;
+ if (parentType == NodeTypeEnum.Resource) {
resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceDeploymentArtifacts();
+ .getConfiguration()
+ .getResourceDeploymentArtifacts();
}
- else if (parentType.equals(NodeTypeEnum.ResourceInstance)) {
+ else if (parentType == NodeTypeEnum.ResourceInstance) {
resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceInstanceDeploymentArtifacts();
+ .getConfiguration()
+ .getResourceInstanceDeploymentArtifacts();
}
else {
resourceDeploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getServiceDeploymentArtifacts();
+ .getConfiguration()
+ .getServiceDeploymentArtifacts();
}
return resourceDeploymentArtifacts;
}
- public void validateArtifactTypeExists(Wrapper<ResponseFormat> responseWrapper, ArtifactDefinition artifactInfo) {
+ public ArtifactTypeEnum getValidArtifactType(ArtifactDefinition artifactInfo) {
ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifactInfo.getArtifactType());
if (artifactType == null) {
- ResponseFormat responseFormat = ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo
- .getArtifactType());
- responseWrapper.setInnerElement(responseFormat);
log.debug("Artifact Type: {} Not found !", artifactInfo.getArtifactType());
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo.getArtifactType());
}
+ return artifactType;
}
private ArtifactTypeConfig getDeploymentArtifactTypeConfig(NodeTypeEnum parentType, ArtifactTypeEnum artifactType) {
ArtifactTypeConfig retConfig = null;
String fileType = artifactType.getType();
- if (parentType.equals(NodeTypeEnum.Resource)) {
+ if (parentType == NodeTypeEnum.Resource) {
retConfig = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceDeploymentArtifacts()
- .get(fileType);
+ .getConfiguration()
+ .getResourceDeploymentArtifacts()
+ .get(fileType);
}
- else if (parentType.equals(NodeTypeEnum.Service)) {
+ else if (parentType == NodeTypeEnum.Service) {
retConfig = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getServiceDeploymentArtifacts()
- .get(fileType);
+ .getConfiguration()
+ .getServiceDeploymentArtifacts()
+ .get(fileType);
}
- else if (parentType.equals(NodeTypeEnum.ResourceInstance)) {
+ else if (parentType == NodeTypeEnum.ResourceInstance) {
retConfig = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceInstanceDeploymentArtifacts()
- .get(fileType);
+ .getConfiguration()
+ .getResourceInstanceDeploymentArtifacts()
+ .get(fileType);
}
return retConfig;
}
@@ -2254,9 +1869,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String heatDecodedPayload = new String(Base64.decodeBase64(artifactInfo.getPayloadData()));
Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParamsWithoutImplicitTypes(heatDecodedPayload, artifactInfo
.getArtifactType());
- if (heatParameters.isRight() && (!heatParameters.right()
- .value()
- .equals(ResultStatusEnum.ELEMENT_NOT_FOUND))) {
+ if (heatParameters.isRight() && (heatParameters.right().value() != ResultStatusEnum.ELEMENT_NOT_FOUND)) {
log.info("failed to parse heat parameters ");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEPLOYMENT_ARTIFACT_HEAT, artifactInfo
.getArtifactType());
@@ -2270,82 +1883,63 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
- // Valid extension
- public void validateFileExtension(Wrapper<ResponseFormat> responseWrapper, IDeploymentArtifactTypeConfigGetter deploymentConfigGetter, ArtifactDefinition artifactInfo, NodeTypeEnum parentType, ArtifactTypeEnum artifactType) {
- String fileType = artifactType.getType();
- List<String> acceptedTypes = null;
- ArtifactTypeConfig deploymentAcceptedTypes = deploymentConfigGetter.getDeploymentArtifactConfig();
- if (!parentType.equals(NodeTypeEnum.Resource) && !parentType.equals(NodeTypeEnum.Service) && !parentType.equals(NodeTypeEnum.ResourceInstance)) {
+ @VisibleForTesting
+ public void validateFileExtension(IDeploymentArtifactTypeConfigGetter deploymentConfigGetter, ArtifactDefinition artifactInfo, NodeTypeEnum parentType, ArtifactTypeEnum artifactType) {
+ if (parentType != NodeTypeEnum.Resource && parentType != NodeTypeEnum.Service && parentType != NodeTypeEnum.ResourceInstance) {
log.debug("parent type of artifact can be either resource or service");
- responseWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- return;
+ throw new ByActionStatusComponentException(MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE, artifactType.name(), "Service, Resource or ResourceInstance", parentType.getName());
}
+ String fileType = artifactType.getType();
+ ArtifactTypeConfig deploymentAcceptedTypes = deploymentConfigGetter.getDeploymentArtifactConfig();
if (deploymentAcceptedTypes == null) {
- log.debug("parent type of artifact can be either resource or service");
- responseWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo
- .getArtifactType()));
- return;
- }
- else {
- acceptedTypes = deploymentAcceptedTypes.getAcceptedTypes();
+ log.debug("invalid artifact type {}", fileType);
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, fileType);
}
/*
* No need to check specific types. In case there are no acceptedTypes in configuration, then any type is accepted.
*/
+ List<String> acceptedTypes = deploymentAcceptedTypes.getAcceptedTypes();
String artifactName = artifactInfo.getArtifactName();
String fileExtension = GeneralUtility.getFilenameExtension(artifactName);
// Pavel - File extension validation is case-insensitive - Ella,
// 21/02/2016
- if (acceptedTypes != null && !acceptedTypes.isEmpty() && !acceptedTypes.contains(fileExtension.toLowerCase())) {
+ if (CollectionUtils.isNotEmpty(acceptedTypes) && !acceptedTypes.contains(fileExtension.toLowerCase())) {
log.debug("File extension \"{}\" is not allowed for {} which is of type:{}", fileExtension, artifactName, fileType);
- responseWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.WRONG_ARTIFACT_FILE_EXTENSION, fileType));
- return;
+ throw new ByActionStatusComponentException(ActionStatus.WRONG_ARTIFACT_FILE_EXTENSION, fileType);
}
}
- private Either<Boolean, ResponseFormat> validateHeatEnvDeploymentArtifact(Component parentComponent, String parentId, ArtifactDefinition artifactInfo, NodeTypeEnum parentType) {
+ @VisibleForTesting
+ void validateHeatEnvDeploymentArtifact(Component parentComponent, String parentId, ArtifactDefinition artifactInfo, NodeTypeEnum parentType) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
Wrapper<ArtifactDefinition> heatMDWrapper = new Wrapper<>();
Wrapper<byte[]> payloadWrapper = new Wrapper<>();
- if (errorWrapper.isEmpty()) {
- validateValidYaml(errorWrapper, artifactInfo);
- }
-
- if (errorWrapper.isEmpty()) {
- // Validate Heat Exist
- validateHeatExist(parentComponent.getUniqueId(), parentId, errorWrapper, heatMDWrapper, artifactInfo, parentType, parentComponent
- .getComponentType());
- }
+ validateYaml(artifactInfo);
+ validateHeatExist(parentComponent.getUniqueId(), parentId, heatMDWrapper, artifactInfo,
+ parentType, parentComponent.getComponentType());
- if (errorWrapper.isEmpty() && !heatMDWrapper.isEmpty()) {
- fillArtifactPayloadValidation(errorWrapper, payloadWrapper, heatMDWrapper.getInnerElement());
+ if (!heatMDWrapper.isEmpty()) {
+ fillArtifactPayload(payloadWrapper, heatMDWrapper.getInnerElement());
}
- if (errorWrapper.isEmpty() && !heatMDWrapper.isEmpty()) {
- validateEnvVsHeat(errorWrapper, artifactInfo, heatMDWrapper.getInnerElement(), payloadWrapper.getInnerElement());
+ if (!heatMDWrapper.isEmpty()) {
+ validateEnvVsHeat(artifactInfo, heatMDWrapper.getInnerElement(), payloadWrapper.getInnerElement());
}
-
- // init Response
- Either<Boolean, ResponseFormat> eitherResponse;
- if (errorWrapper.isEmpty()) {
- eitherResponse = Either.left(true);
- }
- else {
- eitherResponse = Either.right(errorWrapper.getInnerElement());
- }
- return eitherResponse;
}
- public void fillArtifactPayloadValidation(Wrapper<ResponseFormat> errorWrapper, Wrapper<byte[]> payloadWrapper, ArtifactDefinition artifactDefinition) {
- if (artifactDefinition.getPayloadData() == null || artifactDefinition.getPayloadData().length == 0) {
- Either<Boolean, ResponseFormat> fillArtifactPayload = fillArtifactPayload(payloadWrapper, artifactDefinition);
- if (fillArtifactPayload.isRight()) {
- errorWrapper.setInnerElement(fillArtifactPayload.right().value());
+ public void fillArtifactPayload(Wrapper<byte[]> payloadWrapper, ArtifactDefinition artifactDefinition) {
+ if (ArrayUtils.isEmpty(artifactDefinition.getPayloadData())) {
+ Either<DAOArtifactData, CassandraOperationStatus> eitherArtifactData = artifactCassandraDao.getArtifact(artifactDefinition.getEsId());
+ if (eitherArtifactData.isLeft()) {
+ byte[] data = eitherArtifactData.left().value().getDataAsArray();
+ payloadWrapper.setInnerElement(Base64.encodeBase64(data));
+ }
+ else {
log.debug("Error getting payload for artifact:{}", artifactDefinition.getArtifactName());
+ throw new StorageException(DaoStatusConverter.convertCassandraStatusToStorageStatus(eitherArtifactData.right().value()));
}
}
else {
@@ -2353,71 +1947,37 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
- public Either<Boolean, ResponseFormat> fillArtifactPayload(Wrapper<byte[]> payloadWrapper, ArtifactDefinition artifactMD) {
- Either<Boolean, ResponseFormat> result = Either.left(true);
- Either<ESArtifactData, CassandraOperationStatus> eitherArtifactData = artifactCassandraDao.getArtifact(artifactMD
- .getEsId());
- if (eitherArtifactData.isLeft()) {
- byte[] data = eitherArtifactData.left().value().getDataAsArray();
- data = Base64.encodeBase64(data);
- payloadWrapper.setInnerElement(data);
- }
- else {
- StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(eitherArtifactData
- .right()
- .value());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus));
- result = Either.right(responseFormat);
- }
- return result;
-
- }
-
- @SuppressWarnings("unchecked")
- private void validateEnvVsHeat(Wrapper<ResponseFormat> errorWrapper, ArtifactDefinition envArtifact, ArtifactDefinition heatArtifact, byte[] heatPayloadData) {
+ private void validateEnvVsHeat(ArtifactDefinition envArtifact, ArtifactDefinition heatArtifact, byte[] heatPayloadData) {
String envPayload = new String(Base64.decodeBase64(envArtifact.getPayloadData()));
Map<String, Object> heatEnvToscaJson = (Map<String, Object>) new Yaml().load(envPayload);
String heatDecodedPayload = new String(Base64.decodeBase64(heatPayloadData));
Map<String, Object> heatToscaJson = (Map<String, Object>) new Yaml().load(heatDecodedPayload);
Either<Map<String, Object>, ResultStatusEnum> eitherHeatEnvProperties = ImportUtils.findFirstToscaMapElement(heatEnvToscaJson, TypeUtils.ToscaTagNamesEnum.PARAMETERS);
- Either<Map<String, Object>, ResultStatusEnum> eitherHeatProperties = ImportUtils.findFirstToscaMapElement(heatToscaJson, TypeUtils.ToscaTagNamesEnum.PARAMETERS);
if (eitherHeatEnvProperties.isRight()) {
- ResponseFormat responseFormat = ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.CORRUPTED_FORMAT, "Heat Env");
- errorWrapper.setInnerElement(responseFormat);
log.debug("Invalid heat env format for file:{}", envArtifact.getArtifactName());
+ throw new ByActionStatusComponentException(ActionStatus.CORRUPTED_FORMAT, "Heat Env");
}
- else if (eitherHeatProperties.isRight()) {
- ResponseFormat responseFormat = ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.MISMATCH_HEAT_VS_HEAT_ENV, envArtifact
- .getArtifactName(), heatArtifact.getArtifactName());
- errorWrapper.setInnerElement(responseFormat);
- log.debug("Validation of heat_env for artifact:{} vs heat artifact for artifact :{} failed", envArtifact.getArtifactName(), heatArtifact
- .getArtifactName());
+ Either<Map<String, Object>, ResultStatusEnum> eitherHeatProperties = ImportUtils.findFirstToscaMapElement(heatToscaJson, TypeUtils.ToscaTagNamesEnum.PARAMETERS);
+ if (eitherHeatProperties.isRight()) {
+ log.debug("Invalid heat format for file:{}", heatArtifact.getArtifactName());
+ throw new ByActionStatusComponentException(ActionStatus.CORRUPTED_FORMAT, "Heat");
}
- else {
- Set<String> heatPropertiesKeys = eitherHeatProperties.left().value().keySet();
- Set<String> heatEnvPropertiesKeys = eitherHeatEnvProperties.left().value().keySet();
- heatEnvPropertiesKeys.removeAll(heatPropertiesKeys);
- if (!heatEnvPropertiesKeys.isEmpty()) {
- ResponseFormat responseFormat = ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.MISMATCH_HEAT_VS_HEAT_ENV, envArtifact
- .getArtifactName(), heatArtifact.getArtifactName());
- errorWrapper.setInnerElement(responseFormat);
- }
+ Set<String> heatPropertiesKeys = eitherHeatProperties.left().value().keySet();
+ Set<String> heatEnvPropertiesKeys = eitherHeatEnvProperties.left().value().keySet();
+ heatEnvPropertiesKeys.removeAll(heatPropertiesKeys);
+ if (!heatEnvPropertiesKeys.isEmpty()) {
+ log.debug("Validation of heat_env for artifact:{} vs heat artifact for artifact :{} failed", envArtifact.getArtifactName(), heatArtifact.getArtifactName());
+ throw new ByActionStatusComponentException(ActionStatus.MISMATCH_HEAT_VS_HEAT_ENV, envArtifact.getArtifactName(), heatArtifact.getArtifactName());
}
}
- private void validateValidYaml(Wrapper<ResponseFormat> errorWrapper, ArtifactDefinition artifactInfo) {
- YamlToObjectConverter yamlConvertor = new YamlToObjectConverter();
- boolean isYamlValid = yamlConvertor.isValidYamlEncoded64(artifactInfo.getPayloadData());
+ private void validateYaml(ArtifactDefinition artifactInfo) {
+ YamlToObjectConverter yamlConverter = new YamlToObjectConverter();
+ boolean isYamlValid = yamlConverter.isValidYamlEncoded64(artifactInfo.getPayloadData());
if (!isYamlValid) {
- ResponseFormat responseFormat = ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.INVALID_YAML, artifactInfo
- .getArtifactType());
- errorWrapper.setInnerElement(responseFormat);
log.debug("Yaml is not valid for artifact : {}", artifactInfo.getArtifactName());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML, artifactInfo.getArtifactType());
}
}
@@ -2445,7 +2005,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
- private void validateSingleDeploymentArtifactName(Wrapper<ResponseFormat> errorWrapper, String artifactName, Component parentComponent, NodeTypeEnum parentType) {
+ private void validateSingleDeploymentArtifactName(String artifactName, Component parentComponent, NodeTypeEnum parentType) {
boolean artifactNameFound = false;
Iterator<ArtifactDefinition> parentDeploymentArtifactsItr = getDeploymentArtifacts(parentComponent, parentType, null)
.iterator();
@@ -2454,36 +2014,24 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
artifactNameFound = artifactName.equalsIgnoreCase(parentDeploymentArtifactsItr.next().getArtifactName());
}
if (artifactNameFound) {
- String parentName = parentComponent.getName();
- ResponseFormat responseFormat = ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS, parentType
- .name(), parentName, artifactName);
-
- errorWrapper.setInnerElement(responseFormat);
log.debug("Can't upload artifact: {}, because another artifact with this name already exist.", artifactName);
-
+ throw new ByActionStatusComponentException(ActionStatus.DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS, parentType.name(),
+ parentComponent.getName(), artifactName);
}
}
- private void validateHeatExist(String componentId, String parentRiId, Wrapper<ResponseFormat> errorWrapper, Wrapper<ArtifactDefinition> heatArtifactMDWrapper, ArtifactDefinition heatEnvArtifact, NodeTypeEnum parentType,
+ private void validateHeatExist(String componentId, String parentRiId, Wrapper<ArtifactDefinition> heatArtifactMDWrapper, ArtifactDefinition heatEnvArtifact, NodeTypeEnum parentType,
ComponentTypeEnum componentType) {
Either<ArtifactDefinition, StorageOperationStatus> res = artifactToscaOperation.getHeatArtifactByHeatEnvId(parentRiId, heatEnvArtifact, parentType, componentId, componentType);
if (res.isRight()) {
- ResponseFormat responseFormat;
- if (res.right().value() == StorageOperationStatus.NOT_FOUND) {
- responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.MISSING_HEAT);
- }
- else {
- responseFormat = ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.MISSING_HEAT);
- }
- errorWrapper.setInnerElement(responseFormat);
- return;
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_HEAT);
+ } else {
+ heatArtifactMDWrapper.setInnerElement(res.left().value());
}
- ArtifactDefinition heatArtifact = res.left().value();
- heatArtifactMDWrapper.setInnerElement(heatArtifact);
}
- private Either<Boolean, ResponseFormat> validateHeatDeploymentArtifact(boolean isCreate, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
+ @VisibleForTesting
+ void validateHeatTimeoutValue(boolean isCreate, ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
log.trace("Started HEAT pre-payload validation for artifact {}", artifactInfo.getArtifactLabel());
// timeout > 0 for HEAT artifacts
Integer timeout = artifactInfo.getTimeout();
@@ -2493,28 +2041,23 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
// HEAT artifact but timeout is invalid
}
else if (timeout < 1) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_INVALID_TIMEOUT));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_INVALID_TIMEOUT);
}
-
// US649856 - Allow several HEAT files on Resource
log.trace("Ended HEAT validation for artifact {}", artifactInfo.getArtifactLabel());
- return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validateResourceType(ResourceTypeEnum resourceType, ArtifactDefinition artifactInfo, List<String> typeList) {
- String listToString = (typeList != null) ? typeList.toString() : "";
- ResponseFormat responseFormat = ResponseFormatManager.getInstance()
- .getResponseFormat(ActionStatus.MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE, artifactInfo
- .getArtifactName(), listToString, resourceType.getValue());
- Either<Boolean, ResponseFormat> either = Either.right(responseFormat);
- String resourceTypeName = resourceType.name();
- if (typeList != null && typeList.contains(resourceTypeName)) {
- either = Either.left(true);
+ @VisibleForTesting
+ void validateResourceType(ResourceTypeEnum resourceType, ArtifactDefinition artifactInfo, List<String> typeList) {
+ if (typeList == null || !typeList.contains(resourceType.name())) {
+ String listToString = (typeList != null) ? typeList.toString() : "";
+ throw new ByActionStatusComponentException(MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE, artifactInfo.getArtifactName(),
+ listToString, resourceType.getValue());
}
- return either;
}
- private Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParamers(ArtifactDefinition artifactInfo, String artifactType) {
+ @VisibleForTesting
+ Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParameters(ArtifactDefinition artifactInfo, String artifactType) {
if (artifactInfo.getHeatParameters() != null) {
for (HeatParameterDefinition heatParam : artifactInfo.getListHeatParameters()) {
String parameterType = heatParam.getType();
@@ -2642,9 +2185,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
private Either<ActionStatus, ResponseFormat> validateArtifactType(String userId, ArtifactDefinition artifactInfo, NodeTypeEnum parentType) {
- if (Strings.isNullOrEmpty(artifactInfo.getArtifactType())) {
+ if (artifactInfo.getArtifactType() == null || artifactInfo.getArtifactType().isEmpty()) {
BeEcompErrorManager.getInstance()
- .logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
+ .logBeMissingArtifactInformationError("Artifact Update / Upload", "artifactLabel");
log.debug("Missing artifact type for artifact {}", artifactInfo.getArtifactName());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_TYPE));
}
@@ -2653,7 +2196,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<List<ArtifactType>, ActionStatus> allArtifactTypes = null;
ArtifactGroupTypeEnum artifactGroupType = artifactInfo.getArtifactGroupType();
- if ((artifactGroupType != null) && artifactGroupType.equals(ArtifactGroupTypeEnum.DEPLOYMENT)) {
+ if ((artifactGroupType != null) && artifactGroupType == ArtifactGroupTypeEnum.DEPLOYMENT) {
allArtifactTypes = getDeploymentArtifactTypes(parentType);
}
else {
@@ -2662,12 +2205,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
if (allArtifactTypes.isRight()) {
BeEcompErrorManager.getInstance()
- .logBeInvalidConfigurationError("Artifact Upload / Update", "artifactTypes", allArtifactTypes
- .right()
- .value()
- .name());
+ .logBeInvalidConfigurationError("Artifact Upload / Update", "artifactTypes", allArtifactTypes
+ .right()
+ .value()
+ .name());
log.debug("Failed to retrieve list of suported artifact types. error: {}", allArtifactTypes.right()
- .value());
+ .value());
return Either.right(componentsUtils.getResponseFormatByUserId(allArtifactTypes.right().value(), userId));
}
@@ -2681,8 +2224,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (!artifactTypeExist) {
BeEcompErrorManager.getInstance()
- .logBeInvalidTypeError("Artifact Upload / Delete / Update - Not supported artifact type", artifactInfo
- .getArtifactType(), "Artifact " + artifactInfo.getArtifactName());
+ .logBeInvalidTypeError("Artifact Upload / Delete / Update - Not supported artifact type", artifactInfo
+ .getArtifactType(), "Artifact " + artifactInfo.getArtifactName());
log.debug("Not supported artifact type = {}", artifactInfo.getArtifactType());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_TYPE_NOT_SUPPORTED, artifactInfo
.getArtifactType()));
@@ -2696,20 +2239,20 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Map<String, ArtifactTypeConfig> deploymentArtifacts ;
List<ArtifactType> artifactTypes = new ArrayList<>();
- if (parentType.equals(NodeTypeEnum.Service)) {
+ if (parentType == NodeTypeEnum.Service) {
deploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getServiceDeploymentArtifacts();
+ .getConfiguration()
+ .getServiceDeploymentArtifacts();
}
- else if (parentType.equals(NodeTypeEnum.ResourceInstance)) {
+ else if (parentType == NodeTypeEnum.ResourceInstance) {
deploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceInstanceDeploymentArtifacts();
+ .getConfiguration()
+ .getResourceInstanceDeploymentArtifacts();
}
else {
deploymentArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getResourceDeploymentArtifacts();
+ .getConfiguration()
+ .getResourceDeploymentArtifacts();
}
if (deploymentArtifacts != null) {
for (String artifactType : deploymentArtifacts.keySet()) {
@@ -2733,11 +2276,11 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
- private Either<Boolean, ResponseFormat> validateAndSetArtifactname(ArtifactDefinition artifactInfo) {
+ @VisibleForTesting
+ Either<Boolean, ResponseFormat> validateAndSetArtifactName(ArtifactDefinition artifactInfo) {
if (artifactInfo.getArtifactName() == null || artifactInfo.getArtifactName().isEmpty()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_NAME));
}
-
String normalizeFileName = ValidationUtils.normalizeFileName(artifactInfo.getArtifactName());
if (normalizeFileName == null || normalizeFileName.isEmpty()) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_NAME));
@@ -2751,29 +2294,29 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validateArtifactTypeNotChanged(ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
- if (artifactInfo.getArtifactType() == null || artifactInfo.getArtifactType().isEmpty()) {
+ private void validateArtifactTypeNotChanged(ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
+ if (StringUtils.isEmpty(artifactInfo.getArtifactType())) {
log.info("artifact type is missing operation ignored");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_ARTIFACT_TYPE));
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_ARTIFACT_TYPE);
}
if (!currentArtifact.getArtifactType().equalsIgnoreCase(artifactInfo.getArtifactType())) {
log.info("artifact type cannot be changed operation ignored");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
- return Either.left(true);
}
private Either<ArtifactDefinition, ResponseFormat> validateOrSetArtifactGroupType(ArtifactDefinition artifactInfo, ArtifactDefinition currentArtifact) {
- if (artifactInfo.getArtifactGroupType() == null) {
- artifactInfo.setArtifactGroupType(currentArtifact.getArtifactGroupType());
- }
- else if (!currentArtifact.getArtifactGroupType()
- .getType()
- .equalsIgnoreCase(artifactInfo.getArtifactGroupType().getType())) {
- log.info("artifact group type cannot be changed. operation failed");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ if (Objects.nonNull(artifactInfo) && Objects.nonNull(currentArtifact)) {
+ if (artifactInfo.getArtifactGroupType() == null) {
+ artifactInfo.setArtifactGroupType(currentArtifact.getArtifactGroupType());
+ } else if (!currentArtifact.getArtifactGroupType()
+ .getType()
+ .equalsIgnoreCase(artifactInfo.getArtifactGroupType().getType())) {
+ log.info("artifact group type cannot be changed. operation failed");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
}
return Either.left(artifactInfo);
}
@@ -2791,56 +2334,56 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
artifactInfo.setUniqueId(currentArtifact.getUniqueId());
if (artifactInfo.getArtifactRef() != null && !currentArtifact.getArtifactRef()
- .equals(artifactInfo.getArtifactRef())) {
+ .equals(artifactInfo.getArtifactRef())) {
log.error("artifact ref cannot be set ignoring");
}
artifactInfo.setArtifactRef(currentArtifact.getArtifactRef());
if (artifactInfo.getArtifactRepository() != null && !currentArtifact.getArtifactRepository()
- .equals(artifactInfo.getArtifactRepository())) {
+ .equals(artifactInfo.getArtifactRepository())) {
log.error("artifact repository cannot be set ignoring");
}
artifactInfo.setArtifactRepository(currentArtifact.getArtifactRepository());
if (artifactInfo.getUserIdCreator() != null && !currentArtifact.getUserIdCreator()
- .equals(artifactInfo.getUserIdCreator())) {
+ .equals(artifactInfo.getUserIdCreator())) {
log.error("creator uuid cannot be set ignoring");
}
artifactInfo.setUserIdCreator(currentArtifact.getUserIdCreator());
if (artifactInfo.getArtifactCreator() != null && !currentArtifact.getArtifactCreator()
- .equals(artifactInfo.getArtifactCreator())) {
+ .equals(artifactInfo.getArtifactCreator())) {
log.error("artifact creator cannot be set ignoring");
}
artifactInfo.setArtifactCreator(currentArtifact.getArtifactCreator());
if (artifactInfo.getUserIdLastUpdater() != null && !currentArtifact.getUserIdLastUpdater()
- .equals(artifactInfo.getUserIdLastUpdater())) {
+ .equals(artifactInfo.getUserIdLastUpdater())) {
log.error("userId of last updater cannot be set ignoring");
}
artifactInfo.setUserIdLastUpdater(user.getUserId());
if (artifactInfo.getCreatorFullName() != null && !currentArtifact.getCreatorFullName()
- .equals(artifactInfo.getCreatorFullName())) {
+ .equals(artifactInfo.getCreatorFullName())) {
log.error("creator Full name cannot be set ignoring");
}
artifactInfo.setCreatorFullName(currentArtifact.getCreatorFullName());
if (artifactInfo.getUpdaterFullName() != null && !currentArtifact.getUpdaterFullName()
- .equals(artifactInfo.getUpdaterFullName())) {
+ .equals(artifactInfo.getUpdaterFullName())) {
log.error("updater Full name cannot be set ignoring");
}
String fullName = user.getFirstName() + " " + user.getLastName();
artifactInfo.setUpdaterFullName(fullName);
if (artifactInfo.getCreationDate() != null && !currentArtifact.getCreationDate()
- .equals(artifactInfo.getCreationDate())) {
+ .equals(artifactInfo.getCreationDate())) {
log.error("Creation Date cannot be set ignoring");
}
artifactInfo.setCreationDate(currentArtifact.getCreationDate());
if (artifactInfo.getLastUpdateDate() != null && !currentArtifact.getLastUpdateDate()
- .equals(artifactInfo.getLastUpdateDate())) {
+ .equals(artifactInfo.getLastUpdateDate())) {
log.error("Last Update Date cannot be set ignoring");
}
long time = System.currentTimeMillis();
@@ -2852,19 +2395,18 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
artifactInfo.setEsId(currentArtifact.getUniqueId());
if (artifactInfo.getArtifactDisplayName() != null && !currentArtifact.getArtifactDisplayName()
- .equals(artifactInfo.getArtifactDisplayName())) {
+ .equals(artifactInfo.getArtifactDisplayName())) {
log.error(" Artifact Display Name cannot be set ignoring");
}
artifactInfo.setArtifactDisplayName(currentArtifact.getArtifactDisplayName());
if (artifactInfo.getServiceApi() != null && !currentArtifact.getServiceApi()
- .equals(artifactInfo.getServiceApi())) {
+ .equals(artifactInfo.getServiceApi())) {
log.debug("serviceApi cannot be set. ignoring.");
}
artifactInfo.setServiceApi(currentArtifact.getServiceApi());
- if (artifactInfo.getArtifactGroupType() != null && !currentArtifact.getArtifactGroupType()
- .equals(artifactInfo.getArtifactGroupType())) {
+ if (artifactInfo.getArtifactGroupType() != null && currentArtifact.getArtifactGroupType() != artifactInfo.getArtifactGroupType()) {
log.debug("artifact group cannot be set. ignoring.");
}
artifactInfo.setArtifactGroupType(currentArtifact.getArtifactGroupType());
@@ -2872,8 +2414,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
artifactInfo.setArtifactVersion(currentArtifact.getArtifactVersion());
if (artifactInfo.getArtifactUUID() != null && !artifactInfo.getArtifactUUID()
- .isEmpty() && !currentArtifact.getArtifactUUID()
- .equals(artifactInfo.getArtifactUUID())) {
+ .isEmpty() && !currentArtifact.getArtifactUUID()
+ .equals(artifactInfo.getArtifactUUID())) {
log.debug("artifact UUID cannot be set. ignoring.");
}
artifactInfo.setArtifactUUID(currentArtifact.getArtifactUUID());
@@ -2898,7 +2440,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
parameter.setName(currentParam.getName());
}
if (parameter.getDefaultValue() != null && !parameter.getDefaultValue()
- .equalsIgnoreCase(currentParam.getDefaultValue())) {
+ .equalsIgnoreCase(currentParam.getDefaultValue())) {
log.debug("heat parameter defaultValue cannot be updated ({}). ignoring.", parameter.getDefaultValue());
parameter.setDefaultValue(currentParam.getDefaultValue());
}
@@ -2907,7 +2449,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
parameter.setType(currentParam.getType());
}
if (parameter.getDescription() != null && !parameter.getDescription()
- .equalsIgnoreCase(currentParam.getDescription())) {
+ .equalsIgnoreCase(currentParam.getDescription())) {
log.debug("heat parameter description cannot be updated ({}). ignoring.", parameter.getDescription());
parameter.setDescription(currentParam.getDescription());
}
@@ -2923,7 +2465,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
private Map<String, HeatParameterDefinition> getMapOfParameters(List<HeatParameterDefinition> currentParameters) {
- Map<String, HeatParameterDefinition> currentParamsMap = new HashMap<String, HeatParameterDefinition>();
+ Map<String, HeatParameterDefinition> currentParamsMap = new HashMap<>();
for (HeatParameterDefinition param : currentParameters) {
currentParamsMap.put(param.getUniqueId(), param);
}
@@ -2968,136 +2510,75 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(true);
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> updateArtifactFlow(org.openecomp.sdc.be.model.Component parent, String parentId, String artifactId, ArtifactDefinition artifactInfo, User user, byte[] decodedPayload,
- ComponentTypeEnum componentType, AuditingActionEnum auditingAction, String interfaceType, String operationUuid) {
- ESArtifactData artifactData = createEsArtifactData(artifactInfo, decodedPayload);
- String prevArtifactId = null;
+ private Either<ArtifactDefinition, Operation> updateArtifactFlow(Component parent, String parentId, String artifactId, ArtifactDefinition artifactInfo, byte[] decodedPayload,
+ ComponentTypeEnum componentType, AuditingActionEnum auditingAction, String interfaceType, String operationName) {
+ DAOArtifactData artifactData = createEsArtifactData(artifactInfo, decodedPayload);
+ if (artifactData == null) {
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(UPDATE_ARTIFACT);
+ log.debug("Failed to create artifact object for ES.");
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ String prevArtifactId;
String currArtifactId = artifactId;
-
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
- Either<ArtifactDefinition, Operation> insideEither = null;
-
- log.trace("Try to update entry on graph");
- String artifactUniqueId = null;
ArtifactDefinition artifactDefinition = artifactInfo;
- StorageOperationStatus error;
-
- boolean isLeft;
- if (interfaceType == null || operationUuid == null) {
- log.debug("Entity on graph is updated. Update artifact in ES");
- boolean res = true;
- // Changing previous and current artifactId for auditing
- prevArtifactId = currArtifactId;
- currArtifactId = artifactDefinition.getUniqueId();
-
-
- if (decodedPayload == null) {
- if (!artifactDefinition.getMandatory() || artifactDefinition.getEsId() != null) {
- Either<ESArtifactData, CassandraOperationStatus> artifactFromCassandra = artifactCassandraDao.getArtifact(artifactDefinition
- .getEsId());
- if (artifactFromCassandra.isRight()) {
- log.debug("Failed to get artifact data from ES for artifact id {}", artifactId);
- error = DaoStatusConverter.convertCassandraStatusToStorageStatus(artifactFromCassandra.right()
- .value());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(error));
- handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- return resultOp;
- }
- // clone data to new artifact
- artifactData.setData(artifactFromCassandra.left().value().getData());
- artifactData.setId(artifactFromCassandra.left().value().getId());
- }
- } else {
- if (artifactDefinition.getEsId() == null) {
- artifactDefinition.setEsId(artifactDefinition.getUniqueId());
- artifactData.setId(artifactDefinition.getUniqueId());
- }
- }
+ if (interfaceType != null && operationName != null) {
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(UPDATE_ARTIFACT);
+ log.debug("Received both interface and operation for update artifact - something is wrong");
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ log.debug("Entry on graph is updated. Update artifact in ES");
+ // Changing previous and current artifactId for auditing
+ prevArtifactId = currArtifactId;
+ currArtifactId = artifactDefinition.getUniqueId();
- NodeTypeEnum convertParentType = convertParentType(componentType);
- Either<ArtifactDefinition, StorageOperationStatus> result = artifactToscaOperation.updateArtifactOnResource(artifactInfo, parent
- .getUniqueId(), artifactId, convertParentType, parentId);
- isLeft = result.isLeft();
- if (isLeft) {
- artifactUniqueId = result.left().value().getUniqueId();
- artifactDefinition = result.left().value();
- String artifactType = artifactInfo.getArtifactType();
- if (NodeTypeEnum.Resource == convertParentType
- && (ArtifactTypeEnum.HEAT.getType().equalsIgnoreCase(artifactType)
- || ArtifactTypeEnum.HEAT_VOL.getType().equalsIgnoreCase(artifactType)
- || ArtifactTypeEnum.HEAT_NET.getType().equalsIgnoreCase(artifactType))
- && !artifactUniqueId.equals(artifactId)) {
- // need to update the generated id in heat env
- Map<String, ArtifactDefinition> deploymentArtifacts = parent.getDeploymentArtifacts();
- Optional<Entry<String, ArtifactDefinition>> findFirst = deploymentArtifacts.entrySet()
- .stream()
- .filter(a -> a.getValue()
- .getGeneratedFromId() != null && a
- .getValue()
- .getGeneratedFromId()
- .equals(artifactId))
- .findFirst();
- if (findFirst.isPresent()) {
- ArtifactDefinition artifactEnvInfo = findFirst.get().getValue();
- artifactEnvInfo.setArtifactChecksum(null);
- artifactToscaOperation.updateHeatEnvArtifact(parent.getUniqueId(), artifactEnvInfo, artifactId, artifactUniqueId, convertParentType, parentId);
- }
- }
- error = generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentType);
+ NodeTypeEnum parentType = convertParentType(componentType);
- insideEither = Either.left(result.left().value());
- resultOp = Either.left(insideEither);
- if (error != StorageOperationStatus.OK) {
- isLeft = false;
+ if (decodedPayload == null) {
+ if (!artifactDefinition.getMandatory() || artifactDefinition.getEsId() != null) {
+ Either<DAOArtifactData, CassandraOperationStatus> artifactFromCassandra = artifactCassandraDao.getArtifact(artifactDefinition.getEsId());
+ if (artifactFromCassandra.isRight()) {
+ throw new StorageException(artifactFromCassandra.right().value());
}
-
- } else {
- error = result.right().value();
+ // clone data to new artifact
+ artifactData.setData(artifactFromCassandra.left().value().getData());
+ artifactData.setId(artifactFromCassandra.left().value().getId());
}
- if (isLeft) {
-
- // create new entry in ES
- res = true;
- if (artifactData.getData() != null) {
- if (!artifactDefinition.getDuplicated() || artifactData.getId() == null) {
- artifactData.setId(artifactDefinition.getEsId());
- }
- res = saveArtifacts(artifactData, parentId);
+ } else if (artifactDefinition.getEsId() == null) {
+ artifactDefinition.setEsId(artifactDefinition.getUniqueId());
+ artifactData.setId(artifactDefinition.getUniqueId());
+ }
- }
- }
+ Either<ArtifactDefinition, StorageOperationStatus> result = artifactToscaOperation.updateArtifactOnResource(artifactInfo,
+ parent, artifactId, parentType, parentId, true);
+ if (result.isRight()) {
+ throw new StorageException(result.right().value());
+ }
+ artifactDefinition = result.left().value();
+ updateGeneratedIdInHeatEnv(parent, parentId, artifactId, artifactInfo, artifactDefinition, parentType);
- if (res) {
- log.debug(ARTIFACT_SAVED, artifactUniqueId);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
- } else {
- BeEcompErrorManager.getInstance().logBeDaoSystemError(UPDATE_ARTIFACT);
- log.debug(FAILED_SAVE_ARTIFACT);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
+ StorageOperationStatus storageOperationStatus = generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentType);
+ if (storageOperationStatus != StorageOperationStatus.OK) {
+ throw new StorageException(storageOperationStatus);
+ }
+ if (artifactData.getData() != null) {
+ if (!artifactDefinition.getDuplicated() || artifactData.getId() == null) {
+ artifactData.setId(artifactDefinition.getEsId());
}
- } else {
- return updateArtifactsFlowForInterfaceOperations(parent, parentId, artifactId, artifactInfo, user,
- decodedPayload, componentType, auditingAction, interfaceType, operationUuid, artifactData, prevArtifactId,
- currArtifactId, artifactDefinition);
+ saveArtifactInCassandra(artifactData, parent, artifactInfo, currArtifactId, prevArtifactId, auditingAction, componentType);
}
-
- return resultOp;
+ return Either.left(artifactDefinition);
}
private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> updateArtifactsFlowForInterfaceOperations(
Component parent, String parentId, String artifactId, ArtifactDefinition artifactInfo, User user,
byte[] decodedPayload, ComponentTypeEnum componentType, AuditingActionEnum auditingAction, String interfaceType,
- String operationUuid, ESArtifactData artifactData, String prevArtifactId, String currArtifactId,
+ String operationUuid, DAOArtifactData artifactData, String prevArtifactId, String currArtifactId,
ArtifactDefinition artifactDefinition) {
StorageOperationStatus error;
Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp;
if (decodedPayload == null) {
if (!artifactDefinition.getMandatory() || artifactDefinition.getEsId() != null) {
- Either<ESArtifactData, CassandraOperationStatus> artifactFromCassandra = artifactCassandraDao.getArtifact(artifactDefinition
+ Either<DAOArtifactData, CassandraOperationStatus> artifactFromCassandra = artifactCassandraDao.getArtifact(artifactDefinition
.getEsId());
if (artifactFromCassandra.isRight()) {
log.debug("Failed to get artifact data from ES for artifact id {}", artifactId);
@@ -3127,7 +2608,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
artifactInfo.setArtifactDisplayName(artifactInfo.getArtifactName());
Either<ArtifactDefinition, StorageOperationStatus> updateArtifactOnResourceEither =
- artifactToscaOperation.updateArtifactOnResource(artifactInfo, parent.getUniqueId(), artifactId, convertParentType, parentId);
+ artifactToscaOperation.updateArtifactOnResource(artifactInfo, parent, artifactId, convertParentType, parentId, true);
if(updateArtifactOnResourceEither.isRight()){
log.debug("Failed to persist operation artifact {} in resource, error is {}",artifactInfo.getArtifactName(), updateArtifactOnResourceEither.right().value());
ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(updateArtifactOnResourceEither.right().value());
@@ -3151,6 +2632,45 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(Either.left(updateOprEither.left().value()));
}
+ private String updateGeneratedIdInHeatEnv(Component parent, String parentId, String artifactId, ArtifactDefinition artifactInfo, ArtifactDefinition artifactDefinition, NodeTypeEnum parentType) {
+ if (NodeTypeEnum.Resource == parentType) {
+ return updateGeneratedIdInHeatEnv(parent.getDeploymentArtifacts(), parent, parentId, artifactId, artifactInfo, artifactDefinition, parentType, false);
+ }
+ return artifactDefinition.getUniqueId();
+ }
+
+ private String updateGeneratedIdInHeatEnv(Map<String, ArtifactDefinition> deploymentArtifacts, Component parentComponent, String parentId, String artifactId, ArtifactDefinition artifactInfo, ArtifactDefinition artifactDefinition, NodeTypeEnum parentType, boolean isInstanceArtifact) {
+ String artifactUniqueId;
+ artifactUniqueId = artifactDefinition.getUniqueId();
+ String artifactType = artifactInfo.getArtifactType();
+ if ((ArtifactTypeEnum.HEAT.getType().equalsIgnoreCase(artifactType) ||
+ ArtifactTypeEnum.HEAT_VOL.getType().equalsIgnoreCase(artifactType) ||
+ ArtifactTypeEnum.HEAT_NET.getType().equalsIgnoreCase(artifactType))
+ && !artifactUniqueId.equals(artifactId)) {
+ // need to update the generated id in heat env
+ Optional<Entry<String, ArtifactDefinition>> findFirst = deploymentArtifacts.entrySet()
+ .stream()
+ .filter(a -> artifactId.equals(a.getValue().getGeneratedFromId()))
+ .findFirst();
+ if (findFirst.isPresent()) {
+ ArtifactDefinition artifactEnvInfo = findFirst.get().getValue();
+ artifactEnvInfo.setIsFromCsar(artifactDefinition.getIsFromCsar());
+ artifactEnvInfo.setArtifactChecksum(null);
+ if (isInstanceArtifact) {
+ artifactToscaOperation.updateHeatEnvArtifactOnInstance(parentComponent, artifactEnvInfo, artifactId, artifactUniqueId, parentType, parentId);
+ } else {
+ artifactToscaOperation.updateHeatEnvArtifact(parentComponent, artifactEnvInfo, artifactId, artifactUniqueId, parentType, parentId);
+ }
+ }
+ }
+ return artifactUniqueId;
+ }
+
+ private String updateGeneratedIdInHeatEnvOnInstance(ComponentInstance parent, Component parentComponent, String artifactId, ArtifactDefinition artifactInfo, ArtifactDefinition artifactDefinition, NodeTypeEnum parentType) {
+ return updateGeneratedIdInHeatEnv(parent.getDeploymentArtifacts(), parentComponent, parent.getUniqueId(),artifactId, artifactInfo, artifactDefinition, parentType, true);
+ }
+
+ @VisibleForTesting
private Either<byte[], ResponseFormat> handlePayload(ArtifactDefinition artifactInfo, boolean isArtifactMetadataUpdate) {
log.trace("Starting payload handling");
byte[] payload = artifactInfo.getPayloadData();
@@ -3205,6 +2725,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(decodedPayload);
}
+
public Either<Operation, ResponseFormat> deleteArtifactByInterface(String resourceId, String userUserId, String artifactId,
boolean inTransaction) {
User user = new User();
@@ -3248,43 +2769,35 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
// download by MSO
- public Either<byte[], ResponseFormat> downloadRsrcArtifactByNames(String serviceName, String serviceVersion, String resourceName, String resourceVersion, String artifactName) {
+ public byte[] downloadRsrcArtifactByNames(String serviceName, String serviceVersion, String resourceName, String resourceVersion, String artifactName) {
// General validation
if (serviceName == null || serviceVersion == null || resourceName == null || resourceVersion == null || artifactName == null) {
log.debug(NULL_PARAMETER);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
// Normalizing artifact name
artifactName = ValidationUtils.normalizeFileName(artifactName);
// Resource validation
- Either<Resource, ResponseFormat> validateResourceNameAndVersion = validateResourceNameAndVersion(resourceName, resourceVersion);
- if (validateResourceNameAndVersion.isRight()) {
- return Either.right(validateResourceNameAndVersion.right().value());
- }
-
- Resource resource = validateResourceNameAndVersion.left().value();
+ Resource resource = validateResourceNameAndVersion(resourceName, resourceVersion);
String resourceId = resource.getUniqueId();
// Service validation
- Either<Service, ResponseFormat> validateServiceNameAndVersion = validateServiceNameAndVersion(serviceName, serviceVersion);
- if (validateServiceNameAndVersion.isRight()) {
- return Either.right(validateServiceNameAndVersion.right().value());
- }
+ Service validateServiceNameAndVersion = validateServiceNameAndVersion(serviceName, serviceVersion);
Map<String, ArtifactDefinition> artifacts = resource.getDeploymentArtifacts();
if (artifacts == null || artifacts.isEmpty()) {
log.debug("Deployment artifacts of resource {} are not found", resourceId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, artifactName);
}
ArtifactDefinition deploymentArtifact = null;
for (ArtifactDefinition artifactDefinition : artifacts.values()) {
if (artifactDefinition.getArtifactName() != null && artifactDefinition.getArtifactName()
- .equals(artifactName)) {
+ .equals(artifactName)) {
log.debug(FOUND_DEPLOYMENT_ARTIFACT, artifactName);
deploymentArtifact = artifactDefinition;
break;
@@ -3293,100 +2806,91 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (deploymentArtifact == null) {
log.debug("No deployment artifact {} was found for resource {}", artifactName, resourceId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, artifactName);
}
// Downloading the artifact
- Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = downloadArtifact(deploymentArtifact);
- if (downloadArtifactEither.isRight()) {
- log.debug(FAILED_DOWNLOAD_ARTIFACT, artifactName);
- return Either.right(downloadArtifactEither.right().value());
- }
+ ImmutablePair<String, byte[]> downloadArtifactEither = downloadArtifact(deploymentArtifact);
log.trace("Download of resource artifact succeeded, uniqueId {}", deploymentArtifact.getUniqueId());
- return Either.left(downloadArtifactEither.left().value().getRight());
+ return downloadArtifactEither.getRight();
}
// download by MSO
- public Either<byte[], ResponseFormat> downloadRsrcInstArtifactByNames(String serviceName, String serviceVersion, String resourceInstanceName, String artifactName) {
+ public byte[] downloadRsrcInstArtifactByNames(String serviceName, String serviceVersion, String resourceInstanceName, String artifactName) {
// General validation
if (serviceName == null || serviceVersion == null || resourceInstanceName == null || artifactName == null) {
log.debug(NULL_PARAMETER);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
// Normalizing artifact name
artifactName = ValidationUtils.normalizeFileName(artifactName);
// Service validation
- Either<Service, ResponseFormat> validateServiceNameAndVersion = validateServiceNameAndVersion(serviceName, serviceVersion);
- if (validateServiceNameAndVersion.isRight()) {
- return Either.right(validateServiceNameAndVersion.right().value());
- }
-
- Service service = validateServiceNameAndVersion.left().value();
+ Service service = validateServiceNameAndVersion(serviceName, serviceVersion);
// ResourceInstance validation
- Either<ComponentInstance, ResponseFormat> validateResourceInstance = validateResourceInstance(service, resourceInstanceName);
- if (validateResourceInstance.isRight()) {
- return Either.right(validateResourceInstance.right().value());
- }
-
- ComponentInstance resourceInstance = validateResourceInstance.left().value();
+ ComponentInstance resourceInstance = validateResourceInstance(service, resourceInstanceName);
Map<String, ArtifactDefinition> artifacts = resourceInstance.getDeploymentArtifacts();
final String finalArtifactName = artifactName;
Predicate<ArtifactDefinition> filterArtifactByName = p -> p.getArtifactName().equals(finalArtifactName);
- boolean hasDeploymentArtifacts = artifacts != null && artifacts.values()
- .stream()
- .anyMatch(filterArtifactByName);
- ArtifactDefinition deployableArtifact;
+ ArtifactDefinition deployableArtifact = artifacts==null ? null :
+ artifacts.values().stream()
+ .filter(filterArtifactByName)
+ .findFirst()
+ .orElse(null);
- if (!hasDeploymentArtifacts) {
+ if (deployableArtifact == null) {
log.debug("Deployment artifact with name {} not found", artifactName);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactName));
}
log.debug(FOUND_DEPLOYMENT_ARTIFACT, artifactName);
- deployableArtifact = artifacts.values().stream().filter(filterArtifactByName).findFirst().get();
- // Downloading the artifact
- Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = downloadArtifact(deployableArtifact);
+ ImmutablePair<String, byte[]> downloadArtifactEither = downloadArtifact(deployableArtifact);
- if (downloadArtifactEither.isRight()) {
- log.debug(FAILED_DOWNLOAD_ARTIFACT, artifactName);
- return Either.right(downloadArtifactEither.right().value());
- }
log.trace("Download of resource artifact succeeded, uniqueId {}", deployableArtifact.getUniqueId());
- return Either.left(downloadArtifactEither.left().value().getRight());
+ return downloadArtifactEither.getRight();
}
- private Either<ComponentInstance, ResponseFormat> validateResourceInstance(Service service, String resourceInstanceName) {
+ private ComponentInstance validateResourceInstance(Service service, String resourceInstanceName) {
List<ComponentInstance> riList = service.getComponentInstances();
for (ComponentInstance ri : riList) {
if (ri.getNormalizedName().equals(resourceInstanceName)) {
- return Either.left(ri);
+ return ri;
}
}
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND, resourceInstanceName);
+ }
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND, resourceInstanceName));
+ private ComponentInstance validateResourceInstanceById(Component component, String resourceInstanceId) {
+
+ List<ComponentInstance> riList = component.getComponentInstances();
+ for (ComponentInstance ri : riList) {
+ if (ri.getUniqueId().equals(resourceInstanceId)) {
+ return ri;
+ }
+ }
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NOT_FOUND, resourceInstanceId);
}
- private Either<Service, ResponseFormat> validateServiceNameAndVersion(String serviceName, String serviceVersion) {
+ private Service validateServiceNameAndVersion(String serviceName, String serviceVersion) {
Either<List<Service>, StorageOperationStatus> serviceListBySystemName = toscaOperationFacade.getBySystemName(ComponentTypeEnum.SERVICE, serviceName);
if (serviceListBySystemName.isRight()) {
log.debug("Couldn't fetch any service with name {}", serviceName);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceListBySystemName
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(serviceListBySystemName
.right()
- .value(), ComponentTypeEnum.SERVICE), serviceName));
+ .value(), ComponentTypeEnum.SERVICE), serviceName);
}
List<Service> serviceList = serviceListBySystemName.left().value();
if (serviceList == null || serviceList.isEmpty()) {
log.debug("Couldn't fetch any service with name {}", serviceName);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_FOUND, serviceName));
+ throw new ByActionStatusComponentException(ActionStatus.SERVICE_NOT_FOUND, serviceName);
}
Service foundService = null;
@@ -3400,13 +2904,25 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (foundService == null) {
log.debug("Couldn't find version {} for service {}", serviceVersion, serviceName);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_VERSION_NOT_FOUND, ComponentTypeEnum.SERVICE
- .getValue(), serviceVersion));
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_VERSION_NOT_FOUND, ComponentTypeEnum.SERVICE
+ .getValue(), serviceVersion);
+ }
+ return foundService;
+ }
+
+ private Resource validateResourceNameAndVersion(String resourceName, String resourceVersion) {
+
+ Either<Resource, StorageOperationStatus> resourceListBySystemName = toscaOperationFacade.getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName, resourceVersion, JsonParseFlagEnum.ParseMetadata);
+ if (resourceListBySystemName.isRight()) {
+ log.debug("Couldn't fetch any resource with name {} and version {}. ", resourceName, resourceVersion);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(resourceListBySystemName
+ .right()
+ .value()), resourceName);
}
- return Either.left(foundService);
+ return resourceListBySystemName.left().value();
}
- private Either<Resource, ResponseFormat> validateResourceNameAndVersion(String resourceName, String resourceVersion) {
+ /*private Either<Resource, ResponseFormat> validateResourceNameAndVersion(String resourceName, String resourceVersion) {
Either<Resource, StorageOperationStatus> resourceListBySystemName = toscaOperationFacade.getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName, resourceVersion, JsonParseFlagEnum.ParseMetadata);
if (resourceListBySystemName.isRight()) {
@@ -3416,81 +2932,71 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
.value()), resourceName));
}
return Either.left(resourceListBySystemName.left().value());
- }
+ }*/
- public Either<byte[], ResponseFormat> downloadServiceArtifactByNames(String serviceName, String serviceVersion, String artifactName) {
+ public byte[] downloadServiceArtifactByNames(String serviceName, String serviceVersion, String artifactName) {
// Validation
log.trace("Starting download of service interface artifact, serviceName {}, serviceVersion {}, artifact name {}", serviceName, serviceVersion, artifactName);
if (serviceName == null || serviceVersion == null || artifactName == null) {
log.debug(NULL_PARAMETER);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
// Normalizing artifact name
final String normalizedArtifactName = ValidationUtils.normalizeFileName(artifactName);
// Service validation
- Either<Service, ResponseFormat> validateServiceNameAndVersion = validateServiceNameAndVersion(serviceName, serviceVersion);
- if (validateServiceNameAndVersion.isRight()) {
- return Either.right(validateServiceNameAndVersion.right().value());
- }
-
- String serviceId = validateServiceNameAndVersion.left().value().getUniqueId();
-
+ Service service = validateServiceNameAndVersion(serviceName, serviceVersion);
// Looking for deployment or tosca artifacts
- Service service = validateServiceNameAndVersion.left().value();
+ String serviceId = service.getUniqueId();
if (MapUtils.isEmpty(service.getDeploymentArtifacts()) && MapUtils.isEmpty(service.getToscaArtifacts())) {
log.debug("Neither Deployment nor Tosca artifacts of service {} are found", serviceId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, normalizedArtifactName));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, normalizedArtifactName);
}
- Optional<ArtifactDefinition> foundArtifactOptl = null;
+ Optional<ArtifactDefinition> foundArtifactOptl = Optional.empty();
if (!MapUtils.isEmpty(service.getDeploymentArtifacts())) {
foundArtifactOptl = service.getDeploymentArtifacts().values().stream()
- // filters artifact by name
- .filter(a -> a.getArtifactName().equals(normalizedArtifactName)).findAny();
+ // filters artifact by name
+ .filter(a -> a.getArtifactName().equals(normalizedArtifactName)).findAny();
}
- if ((foundArtifactOptl == null || !foundArtifactOptl.isPresent()) && !MapUtils.isEmpty(service.getToscaArtifacts())) {
+ if ((!foundArtifactOptl.isPresent()) && !MapUtils.isEmpty(service.getToscaArtifacts())) {
foundArtifactOptl = service.getToscaArtifacts().values().stream()
- // filters TOSCA artifact by name
- .filter(a -> a.getArtifactName().equals(normalizedArtifactName)).findAny();
+ // filters TOSCA artifact by name
+ .filter(a -> a.getArtifactName().equals(normalizedArtifactName)).findAny();
}
if (!foundArtifactOptl.isPresent()) {
log.debug("The artifact {} was not found for service {}", normalizedArtifactName, serviceId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, normalizedArtifactName));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, normalizedArtifactName);
}
log.debug(FOUND_DEPLOYMENT_ARTIFACT, normalizedArtifactName);
// Downloading the artifact
- Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = downloadArtifact(foundArtifactOptl
+ ImmutablePair<String, byte[]> downloadArtifactEither = downloadArtifact(foundArtifactOptl
.get());
- if (downloadArtifactEither.isRight()) {
- log.debug(FAILED_DOWNLOAD_ARTIFACT, normalizedArtifactName);
- return Either.right(downloadArtifactEither.right().value());
- }
log.trace("Download of service artifact succeeded, uniqueId {}", foundArtifactOptl.get().getUniqueId());
- return Either.left(downloadArtifactEither.left().value().getRight());
+ return downloadArtifactEither.getRight();
}
- public Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifact(String parentId, String artifactUniqueId) {
+ public ImmutablePair<String, byte[]> downloadArtifact(String parentId, String artifactUniqueId) {
log.trace("Starting download of artifact, uniqueId {}", artifactUniqueId);
Either<ArtifactDefinition, StorageOperationStatus> artifactById = artifactToscaOperation.getArtifactById(parentId, artifactUniqueId);
if (artifactById.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(artifactById.right().value());
log.debug("Error when getting artifact info by id{}, error: {}", artifactUniqueId, actionStatus);
- return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, ""));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByArtifactId(actionStatus, ""));
}
ArtifactDefinition artifactDefinition = artifactById.left().value();
if (artifactDefinition == null) {
log.debug("Empty artifact definition returned from DB by artifact id {}", artifactUniqueId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ""));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ""));
}
return downloadArtifact(artifactDefinition);
}
- private boolean checkArtifactInComponent(org.openecomp.sdc.be.model.Component component, String artifactId) {
+ private boolean checkArtifactInComponent(Component component, String artifactId) {
boolean found = false;
Map<String, ArtifactDefinition> artifactsS = component.getArtifacts();
if (artifactsS != null) {
@@ -3535,7 +3041,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
}
-
switch (component.getComponentType()) {
case RESOURCE:
break;
@@ -3593,41 +3098,41 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return found;
}
- private Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists(String componentId, AuditingActionEnum auditingAction, User user, String artifactId, ComponentTypeEnum componentType,
- String containerComponentType) {
+ private Component validateComponentExists(String componentId, AuditingActionEnum auditingAction, User user, String artifactId, ComponentTypeEnum componentType,
+ String containerComponentType) {
ComponentTypeEnum componentForAudit = null == containerComponentType ? componentType : ComponentTypeEnum.findByParamName(containerComponentType);
componentForAudit.getNodeType();
- Either<? extends org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentResult = toscaOperationFacade
+ Either<? extends Component, StorageOperationStatus> componentResult = toscaOperationFacade
.getToscaFullElement(componentId);
if (componentResult.isRight()) {
- ActionStatus status = componentForAudit == ComponentTypeEnum.RESOURCE ? ActionStatus.RESOURCE_NOT_FOUND : componentType == ComponentTypeEnum.SERVICE ? ActionStatus.SERVICE_NOT_FOUND : ActionStatus.PRODUCT_NOT_FOUND;
+ ActionStatus status = componentForAudit == ComponentTypeEnum.RESOURCE ? ActionStatus.RESOURCE_NOT_FOUND : componentForAudit == ComponentTypeEnum.SERVICE ? ActionStatus.SERVICE_NOT_FOUND : ActionStatus.PRODUCT_NOT_FOUND;
ResponseFormat responseFormat = componentsUtils.getResponseFormat(status, componentId);
log.debug("Service not found, serviceId {}", componentId);
handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentForAudit, null);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(status, componentId);
}
- return Either.left(componentResult.left().value());
+ return componentResult.left().value();
}
- private Either<Boolean, ResponseFormat> validateWorkOnComponent(Component component, String userId, AuditingActionEnum auditingAction, User user, String artifactId, ArtifactOperationInfo operation) {
+ private Boolean validateWorkOnComponent(Component component, String userId, AuditingActionEnum auditingAction, User user, String artifactId, ArtifactOperationInfo operation) {
if (operation.getArtifactOperationEnum() != ArtifactOperationEnum.DOWNLOAD && !operation.ignoreLifecycleState()) {
- Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
- if (canWork.isRight()) {
+ try {
+ validateCanWorkOnComponent(component, userId);
+ }catch (ComponentException e) {
String uniqueId = component.getUniqueId();
log.debug("Service status isn't CHECKOUT or user isn't owner, serviceId {}", uniqueId);
- handleAuditing(auditingAction, component, uniqueId, user, null, null, artifactId, canWork.right()
- .value(), component
- .getComponentType(), null);
- return Either.right(canWork.right().value());
+ handleAuditing(auditingAction, component, uniqueId, user, null, null, artifactId, e.getResponseFormat(),
+ component.getComponentType(), null);
+ throw e;
}
}
- return Either.left(true);
+ return true;
}
- private Either<Boolean, ResponseFormat> validateUserRole(User user, AuditingActionEnum auditingAction, String componentId, String artifactId, ComponentTypeEnum componentType, ArtifactOperationInfo operation) {
+ private void validateUserRole(User user, AuditingActionEnum auditingAction, String componentId, String artifactId, ComponentTypeEnum componentType, ArtifactOperationInfo operation) {
if (operation.getArtifactOperationEnum() != ArtifactOperationEnum.DOWNLOAD) {
String role = user.getRole();
@@ -3635,16 +3140,15 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
log.debug("addArtifact - user isn't permitted to perform operation, userId {}, role {}", user.getUserId(), role);
handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
}
}
- return Either.left(true);
}
- private Either<User, ResponseFormat> validateUserExists(String userId, AuditingActionEnum auditingAction, String componentId, String artifactId, ComponentTypeEnum componentType, boolean inTransaction) {
+ private User validateUserExists(String userId, AuditingActionEnum auditingAction, String componentId, String artifactId, ComponentTypeEnum componentType, boolean inTransaction) {
User user;
try{
- user = validateUserExists(userId, auditingAction.getName(), inTransaction);
+ user = validateUserExists(userId);
} catch(ByResponseFormatComponentException e){
ResponseFormat responseFormat = e.getResponseFormat();
handleComponentException(auditingAction, componentId, artifactId, responseFormat, componentType, userId);
@@ -3654,7 +3158,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
handleComponentException(auditingAction, componentId, artifactId, responseFormat, componentType, userId);
throw e;
}
- return Either.left(user);
+ return user;
}
private void handleComponentException(AuditingActionEnum auditingAction, String componentId, String artifactId,
@@ -3685,75 +3189,62 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return auditingAction;
}
- private Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifact(ArtifactDefinition artifactDefinition) {
+ private ImmutablePair<String, byte[]> downloadArtifact(ArtifactDefinition artifactDefinition) {
String esArtifactId = artifactDefinition.getEsId();
- Either<ESArtifactData, CassandraOperationStatus> artifactfromES = artifactCassandraDao.getArtifact(esArtifactId);
+ Either<DAOArtifactData, CassandraOperationStatus> artifactfromES = artifactCassandraDao.getArtifact(esArtifactId);
if (artifactfromES.isRight()) {
CassandraOperationStatus resourceUploadStatus = artifactfromES.right().value();
StorageOperationStatus storageResponse = DaoStatusConverter.convertCassandraStatusToStorageStatus(resourceUploadStatus);
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageResponse);
log.debug("Error when getting artifact from ES, error: {}", actionStatus);
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(actionStatus, artifactDefinition
- .getArtifactDisplayName());
-
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(actionStatus, artifactDefinition.getArtifactDisplayName());
}
- ESArtifactData esArtifactData = artifactfromES.left().value();
- byte[] data = esArtifactData.getDataAsArray();
+ DAOArtifactData DAOArtifactData = artifactfromES.left().value();
+ byte[] data = DAOArtifactData.getDataAsArray();
if (data == null) {
- log.debug("Artifact data from ES is null");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactDefinition.getArtifactDisplayName()));
+ log.debug("Artifact data from cassandra is null");
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, artifactDefinition.getArtifactDisplayName());
}
String artifactName = artifactDefinition.getArtifactName();
log.trace("Download of artifact succeeded, uniqueId {}, artifact file name {}", artifactDefinition.getUniqueId(), artifactName);
- return Either.left(new ImmutablePair<String, byte[]>(artifactName, data));
+ return new ImmutablePair<>(artifactName, data);
}
- public ESArtifactData createEsArtifactData(ArtifactDataDefinition artifactInfo, byte[] artifactPayload) {
- return new ESArtifactData(artifactInfo.getEsId(), artifactPayload);
+ public DAOArtifactData createEsArtifactData(ArtifactDataDefinition artifactInfo, byte[] artifactPayload) {
+ return new DAOArtifactData(artifactInfo.getEsId(), artifactPayload);
}
- private boolean saveArtifacts(ESArtifactData artifactData, String resourceId) {
+ private void saveArtifactInCassandra(DAOArtifactData artifactData, Component parent, ArtifactDefinition artifactInfo,
+ String currArtifactId, String prevArtifactId, AuditingActionEnum auditingAction, ComponentTypeEnum componentType) {
CassandraOperationStatus resourceUploadStatus = artifactCassandraDao.saveArtifact(artifactData);
- if (resourceUploadStatus.equals(CassandraOperationStatus.OK)) {
- log.debug("Artifact {} was saved in component .", artifactData.getId(), resourceId);
+ if (resourceUploadStatus == CassandraOperationStatus.OK) {
+ log.debug("Artifact {} was saved in component {}.", artifactData.getId(), parent.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), null, artifactInfo, prevArtifactId,
+ currArtifactId, responseFormat, componentType, null);
}
else {
- log.info("Failed to save artifact {}.", artifactData.getId());
- return false;
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(UPDATE_ARTIFACT);
+ log.info(FAILED_SAVE_ARTIFACT);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ handleAuditing(auditingAction, parent, parent.getUniqueId(), null, artifactInfo, prevArtifactId, currArtifactId, responseFormat, componentType, null);
+ throw new StorageException(resourceUploadStatus);
}
- return true;
}
private boolean isArtifactMetadataUpdate(AuditingActionEnum auditingActionEnum) {
- return auditingActionEnum.equals(AuditingActionEnum.ARTIFACT_METADATA_UPDATE);
+ return auditingActionEnum == AuditingActionEnum.ARTIFACT_METADATA_UPDATE;
}
private boolean isDeploymentArtifact(ArtifactDefinition artifactInfo) {
- return ArtifactGroupTypeEnum.DEPLOYMENT.equals(artifactInfo.getArtifactGroupType());
+ return ArtifactGroupTypeEnum.DEPLOYMENT == artifactInfo.getArtifactGroupType();
}
- public Either<ArtifactDefinition, ResponseFormat> createArtifactPlaceHolderInfo(String resourceId, String logicalName, Map<String, Object> artifactInfoMap, String userUserId, ArtifactGroupTypeEnum groupType, boolean inTransaction) {
- Either<User, ActionStatus> user = userAdminManager.getUser(userUserId, inTransaction);
- if (user.isRight()) {
- ResponseFormat responseFormat;
- if (user.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
- log.debug("create artifact placeholder - not authorized user, userId {}", userUserId);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- }
- else {
- log.debug("create artifact placeholder - failed to authorize user, userId {}", userUserId);
- responseFormat = componentsUtils.getResponseFormat(user.right().value());
- }
- return Either.right(responseFormat);
- }
-
- ArtifactDefinition artifactDefinition = createArtifactPlaceHolderInfo(resourceId, logicalName, artifactInfoMap, user
- .left()
- .value(), groupType);
- return Either.left(artifactDefinition);
+ public ArtifactDefinition createArtifactPlaceHolderInfo(String resourceId, String logicalName, Map<String, Object> artifactInfoMap, String userUserId, ArtifactGroupTypeEnum groupType, boolean inTransaction) {
+ User user = userBusinessLogic.getUser(userUserId, inTransaction);
+ return createArtifactPlaceHolderInfo(resourceId, logicalName, artifactInfoMap, user, groupType);
}
public ArtifactDefinition createArtifactPlaceHolderInfo(String resourceId, String logicalName, Map<String, Object> artifactInfoMap, User user, ArtifactGroupTypeEnum groupType) {
@@ -3780,7 +3271,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
if (resourceId != null) {
uniqueId = UniqueIdBuilder.buildPropertyUniqueId(resourceId.toLowerCase(), artifactInfo.getArtifactLabel()
- .toLowerCase());
+ .toLowerCase());
artifactInfo.setUniqueId(uniqueId);
}
artifactInfo.setUserIdCreator(user.getUserId());
@@ -3802,15 +3293,15 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return artifactToscaOperation.getArtifacts(parentId, parentType, groupType, instanceId);
}
- public Either<ArtifactDefinition, StorageOperationStatus> addHeatEnvArtifact(ArtifactDefinition artifactHeatEnv, ArtifactDefinition artifact, String componentId, NodeTypeEnum parentType, String instanceId) {
- return artifactToscaOperation.addHeatEnvArtifact(artifactHeatEnv, artifact, componentId, parentType, true, instanceId);
+ public Either<ArtifactDefinition, StorageOperationStatus> addHeatEnvArtifact(ArtifactDefinition artifactHeatEnv, ArtifactDefinition artifact, Component component, NodeTypeEnum parentType, String instanceId) {
+ return artifactToscaOperation.addHeatEnvArtifact(artifactHeatEnv, artifact, component, parentType, true, instanceId);
}
- private Either<ESArtifactData, ResponseFormat> createEsHeatEnvArtifactDataFromString(ArtifactDefinition artifactDefinition, String payloadStr) {
+ private Either<DAOArtifactData, ResponseFormat> createEsHeatEnvArtifactDataFromString(ArtifactDefinition artifactDefinition, String payloadStr) {
byte[] payload = payloadStr.getBytes();
- ESArtifactData artifactData = createEsArtifactData(artifactDefinition, payload);
+ DAOArtifactData artifactData = createEsArtifactData(artifactDefinition, payload);
return Either.left(artifactData);
}
@@ -3818,34 +3309,35 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param artifactDefinition
* @return
*/
- public Either<ArtifactDefinition, ResponseFormat> generateHeatEnvArtifact(ArtifactDefinition artifactDefinition, ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component component, String resourceInstanceName, User modifier,
+ public Either<ArtifactDefinition, ResponseFormat> generateHeatEnvArtifact(ArtifactDefinition artifactDefinition, ComponentTypeEnum componentType, Component component, String resourceInstanceName, User modifier,
String instanceId, boolean shouldLock, boolean inTransaction) {
String payload = generateHeatEnvPayload(artifactDefinition);
String prevUUID = artifactDefinition.getArtifactUUID();
ArtifactDefinition clonedBeforeGenerate = new ArtifactDefinition(artifactDefinition);
return generateAndSaveHeatEnvArtifact(artifactDefinition, payload, componentType, component, resourceInstanceName, modifier, instanceId, shouldLock, inTransaction)
.left()
- .bind(artifactDef -> updateArtifactOnGroupInstance(componentType, component, instanceId, prevUUID, clonedBeforeGenerate, artifactDef));
+ .bind(artifactDef -> updateArtifactOnGroupInstance(component, instanceId, prevUUID, clonedBeforeGenerate, artifactDef));
}
- public Either<ArtifactDefinition, ResponseFormat> forceGenerateHeatEnvArtifact(ArtifactDefinition artifactDefinition, ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component component, String resourceInstanceName, User modifier,
+ public Either<ArtifactDefinition, ResponseFormat> forceGenerateHeatEnvArtifact(ArtifactDefinition artifactDefinition, ComponentTypeEnum componentType, Component component, String resourceInstanceName, User modifier,
boolean shouldLock, boolean inTransaction, String instanceId) {
String payload = generateHeatEnvPayload(artifactDefinition);
String prevUUID = artifactDefinition.getArtifactUUID();
ArtifactDefinition clonedBeforeGenerate = new ArtifactDefinition(artifactDefinition);
return forceGenerateAndSaveHeatEnvArtifact(artifactDefinition, payload, componentType, component, resourceInstanceName, modifier, instanceId, shouldLock, inTransaction)
.left()
- .bind(artifactDef -> updateArtifactOnGroupInstance(componentType, component, instanceId, prevUUID, clonedBeforeGenerate, artifactDef));
+ .bind(artifactDef -> updateArtifactOnGroupInstance(component, instanceId, prevUUID, clonedBeforeGenerate, artifactDef));
}
- private Either<ArtifactDefinition, ResponseFormat> updateArtifactOnGroupInstance(ComponentTypeEnum componentType, Component component, String instanceId, String prevUUID, ArtifactDefinition clonedBeforeGenerate, ArtifactDefinition updatedArtDef) {
+ @VisibleForTesting
+ Either<ArtifactDefinition, ResponseFormat> updateArtifactOnGroupInstance(Component component, String instanceId, String prevUUID, ArtifactDefinition clonedBeforeGenerate, ArtifactDefinition updatedArtDef) {
if (prevUUID == null || !prevUUID.equals(updatedArtDef.getArtifactUUID())) {
List<ComponentInstance> componentInstances = component.getComponentInstances();
if (componentInstances != null) {
Optional<ComponentInstance> findFirst = componentInstances.stream()
- .filter(ci -> ci.getUniqueId()
- .equals(instanceId))
- .findFirst();
+ .filter(ci -> ci.getUniqueId()
+ .equals(instanceId))
+ .findFirst();
if (findFirst.isPresent()) {
ComponentInstance relevantInst = findFirst.get();
List<GroupInstance> updatedGroupInstances = getUpdatedGroupInstances(updatedArtDef.getUniqueId(), clonedBeforeGenerate, relevantInst
@@ -3861,7 +3353,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
log.debug(FAILED_UPDATE_GROUPS, component.getUniqueId());
ResponseFormat responseFormat = componentsUtils.getResponseFormatByArtifactId(componentsUtils
.convertFromStorageResponse(status.right()
- .value()), clonedBeforeGenerate.getArtifactDisplayName());
+ .value()), clonedBeforeGenerate.getArtifactDisplayName());
return Either.right(responseFormat);
}
}
@@ -3877,7 +3369,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
sb.append(ConfigurationManager.getConfigurationManager().getConfiguration().getHeatEnvArtifactHeader());
sb.append("parameters:\n");
if (heatParameters != null) {
- heatParameters.sort(Comparator.comparing(e -> e.getName()));
+ heatParameters.sort(Comparator.comparing(HeatParameterDataDefinition::getName));
List<HeatParameterDefinition> empltyHeatValues = new ArrayList<>();
@@ -3896,28 +3388,28 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
switch (type) {
case BOOLEAN:
sb.append(" ")
- .append(heatParameterDefinition.getName())
- .append(":")
- .append(" ")
- .append(Boolean.parseBoolean(heatValue))
- .append("\n");
+ .append(heatParameterDefinition.getName())
+ .append(":")
+ .append(" ")
+ .append(Boolean.parseBoolean(heatValue))
+ .append("\n");
break;
case NUMBER:
sb.append(" ")
- .append(heatParameterDefinition.getName())
- .append(":")
- .append(" ")
- .append(new BigDecimal(heatValue).toPlainString())
- .append("\n");
+ .append(heatParameterDefinition.getName())
+ .append(":")
+ .append(" ")
+ .append(new BigDecimal(heatValue).toPlainString())
+ .append("\n");
break;
case COMMA_DELIMITED_LIST:
case JSON:
sb.append(" ")
- .append(heatParameterDefinition.getName())
- .append(":")
- .append(" ")
- .append(heatValue)
- .append("\n");
+ .append(heatParameterDefinition.getName())
+ .append(":")
+ .append(" ")
+ .append(heatValue)
+ .append("\n");
break;
default:
String value = heatValue;
@@ -3931,10 +3423,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
sb.append(" ")
- .append(heatParameterDefinition.getName())
- .append(":")
- .append(" ")
- .append(value);
+ .append(heatParameterDefinition.getName())
+ .append(":")
+ .append(" ")
+ .append(value);
sb.append("\n");
break;
@@ -3942,7 +3434,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
if (!empltyHeatValues.isEmpty()) {
- empltyHeatValues.sort(Comparator.comparing(e -> e.getName()));
+ empltyHeatValues.sort(Comparator.comparing(HeatParameterDataDefinition::getName));
empltyHeatValues.forEach(hv -> {
sb.append(" ").append(hv.getName()).append(":");
HeatParameterType type = HeatParameterType.isValidType(hv.getType());
@@ -3967,23 +3459,22 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param payload
* @return
*/
- public Either<ArtifactDefinition, ResponseFormat> generateAndSaveHeatEnvArtifact(ArtifactDefinition artifactDefinition, String payload, ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component component, String resourceInstanceName,
+ public Either<ArtifactDefinition, ResponseFormat> generateAndSaveHeatEnvArtifact(ArtifactDefinition artifactDefinition, String payload, ComponentTypeEnum componentType, Component component, String resourceInstanceName,
User modifier, String instanceId, boolean shouldLock, boolean inTransaction) {
- return generateArtifactPayload(artifactDefinition, componentType, component, resourceInstanceName, modifier, shouldLock, inTransaction, () -> artifactDefinition
- .getHeatParamsUpdateDate(),
+ return generateArtifactPayload(artifactDefinition, componentType, component, resourceInstanceName, modifier, shouldLock, inTransaction, artifactDefinition::getHeatParamsUpdateDate,
() -> createEsHeatEnvArtifactDataFromString(artifactDefinition, payload), instanceId);
}
- public Either<ArtifactDefinition, ResponseFormat> forceGenerateAndSaveHeatEnvArtifact(ArtifactDefinition artifactDefinition, String payload, ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component component, String resourceInstanceName,
+ public Either<ArtifactDefinition, ResponseFormat> forceGenerateAndSaveHeatEnvArtifact(ArtifactDefinition artifactDefinition, String payload, ComponentTypeEnum componentType, Component component, String resourceInstanceName,
User modifier, String instanceId, boolean shouldLock, boolean inTransaction) {
return generateArtifactPayload(artifactDefinition, componentType, component, resourceInstanceName, modifier, shouldLock, inTransaction, System::currentTimeMillis,
() -> createEsHeatEnvArtifactDataFromString(artifactDefinition, payload), instanceId);
}
- protected Either<ArtifactDefinition, ResponseFormat> generateArtifactPayload(ArtifactDefinition artifactDefinition, ComponentTypeEnum componentType, org.openecomp.sdc.be.model.Component component, String resourceInstanceName, User modifier,
- boolean shouldLock, boolean inTransaction, Supplier<Long> payloadUpdateDateGen, Supplier<Either<ESArtifactData, ResponseFormat>> esDataCreator, String instanceId) {
+ protected Either<ArtifactDefinition, ResponseFormat> generateArtifactPayload(ArtifactDefinition artifactDefinition, ComponentTypeEnum componentType, Component component, String resourceInstanceName, User modifier,
+ boolean shouldLock, boolean inTransaction, Supplier<Long> payloadUpdateDateGen, Supplier<Either<DAOArtifactData, ResponseFormat>> esDataCreator, String instanceId) {
log.trace("Start generating payload for {} artifact {}", artifactDefinition.getArtifactType(), artifactDefinition
.getEsId());
@@ -3991,8 +3482,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
.getPayloadUpdateDate() <= payloadUpdateDateGen.get()) {
log.trace("Generating payload for {} artifact {}", artifactDefinition.getArtifactType(), artifactDefinition.getEsId());
- Either<ESArtifactData, ResponseFormat> artifactDataRes = esDataCreator.get();
- ESArtifactData artifactData = null;
+ Either<DAOArtifactData, ResponseFormat> artifactDataRes = esDataCreator.get();
+ DAOArtifactData artifactData = null;
if (artifactDataRes.isLeft()) {
artifactData = artifactDataRes.left().value();
@@ -4008,8 +3499,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
String newCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(artifactData.getDataAsArray());
String oldCheckSum;
String esArtifactId = artifactDefinition.getEsId();
- Either<ESArtifactData, CassandraOperationStatus> artifactfromES;
- ESArtifactData esArtifactData;
+ Either<DAOArtifactData, CassandraOperationStatus> artifactfromES;
+ DAOArtifactData DAOArtifactData;
if (esArtifactId != null && !esArtifactId.isEmpty() && artifactDefinition.getPayloadData() == null) {
log.debug("Try to fetch artifact from cassandra with id : {}", esArtifactId);
artifactfromES = artifactCassandraDao.getArtifact(esArtifactId);
@@ -4020,8 +3511,8 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
log.debug("Error when getting artifact from ES, error: {} esid : {}", actionStatus, esArtifactId);
return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, artifactDefinition.getArtifactDisplayName()));
}
- esArtifactData = artifactfromES.left().value();
- oldCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(esArtifactData.getDataAsArray());
+ DAOArtifactData = artifactfromES.left().value();
+ oldCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(DAOArtifactData.getDataAsArray());
}
else {
oldCheckSum = artifactDefinition.getArtifactChecksum();
@@ -4030,11 +3521,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<ArtifactDefinition, StorageOperationStatus> updateArifactDefinitionStatus = null;
if (shouldLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, "Update Artifact - lock resource: ");
- if (lockComponent.isRight()) {
+ try {
+ lockComponent(component, "Update Artifact - lock resource: ");
+ }catch (ComponentException e){
handleAuditing(AuditingActionEnum.ARTIFACT_METADATA_UPDATE, component, component.getUniqueId(), modifier, null, null, artifactDefinition
- .getUniqueId(), lockComponent.right().value(), component.getComponentType(), null);
- return Either.right(lockComponent.right().value());
+ .getUniqueId(), e.getResponseFormat(), component.getComponentType(), null);
+ throw e;
}
}
try {
@@ -4042,7 +3534,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
artifactDefinition.setPayloadUpdateDate(payloadUpdateDateGen.get());
updateArifactDefinitionStatus = artifactToscaOperation.updateArtifactOnResource(artifactDefinition, component
- .getUniqueId(), artifactDefinition.getUniqueId(), componentType.getNodeType(), instanceId);
+ ,artifactDefinition.getUniqueId(), componentType.getNodeType(), instanceId, true);
log.trace("No real update done in payload for {} artifact, updating payloadUpdateDate {}", artifactDefinition
.getArtifactType(), artifactDefinition.getEsId());
if (updateArifactDefinitionStatus.isRight()) {
@@ -4058,28 +3550,27 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
else {
-
- oldCheckSum = artifactDefinition.getArtifactChecksum();
+ artifactDefinition.getArtifactChecksum();
artifactDefinition.setArtifactChecksum(newCheckSum);
artifactDefinition.setEsId(artifactDefinition.getUniqueId());
log.trace("No real update done in payload for {} artifact, updating payloadUpdateDate {}", artifactDefinition
.getArtifactType(), artifactDefinition.getEsId());
- updateArifactDefinitionStatus = artifactToscaOperation.updateArtifactOnResource(artifactDefinition, component
- .getUniqueId(), artifactDefinition.getUniqueId(), componentType.getNodeType(), instanceId);
+ updateArifactDefinitionStatus = artifactToscaOperation.updateArtifactOnResource(artifactDefinition, component,
+ artifactDefinition.getUniqueId(), componentType.getNodeType(), instanceId, true);
- log.trace("Update Payload ", artifactDefinition.getEsId());
+ log.trace("Update Payload {}", artifactDefinition.getEsId());
}
- if (updateArifactDefinitionStatus != null && updateArifactDefinitionStatus.isLeft()) {
+ if (updateArifactDefinitionStatus.isLeft()) {
artifactDefinition = updateArifactDefinitionStatus.left().value();
artifactData.setId(artifactDefinition.getUniqueId());
CassandraOperationStatus saveArtifactStatus = artifactCassandraDao.saveArtifact(artifactData);
- if (saveArtifactStatus.equals(CassandraOperationStatus.OK)) {
+ if (saveArtifactStatus == CassandraOperationStatus.OK) {
if (!inTransaction) {
janusGraphDao.commit();
}
- log.debug("Artifact Saved In ES {}", artifactData.getId());
+ log.debug("Artifact Saved In cassandra {}", artifactData.getId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
handleAuditing(AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, component, component.getUniqueId(), modifier, artifactDefinition, artifactDefinition
.getUniqueId(), artifactDefinition.getUniqueId(), responseFormat,
@@ -4115,7 +3606,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
finally {
if (shouldLock) {
graphLockOperation.unlockComponent(component.getUniqueId(), component.getComponentType()
- .getNodeType());
+ .getNodeType());
}
}
}
@@ -4153,259 +3644,208 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
json.put(Constants.ARTIFACT_GROUP_TYPE, artifactGroupType.getType());
json.put(Constants.REQUIRED_ARTIFACTS, (updatedRequiredArtifacts == null || updatedRequiredArtifacts.isEmpty()) ? new ArrayList<>()
: updatedRequiredArtifacts.stream()
- .filter(e -> e.getType().equals(ArtifactTypeEnum.HEAT_ARTIFACT.getType()) || e
- .getType()
- .equals(ArtifactTypeEnum.HEAT_NESTED.getType()))
- .map(e -> e.getFileName())
- .collect(Collectors.toList()));
+ .filter(e -> e.getType().equals(ArtifactTypeEnum.HEAT_ARTIFACT.getType()) || e
+ .getType()
+ .equals(ArtifactTypeEnum.HEAT_NESTED.getType()))
+ .map(ArtifactTemplateInfo::getFileName)
+ .collect(Collectors.toList()));
json.put(Constants.ARTIFACT_HEAT_PARAMS, (heatParameters == null || heatParameters.isEmpty()) ? new ArrayList<>()
: heatParameters);
return json;
}
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> updateResourceInstanceArtifactNoContent(String resourceId, Component containerComponent, User user, Map<String, Object> json, ArtifactOperationInfo operation, ArtifactDefinition artifactInfo) {
+ public Either<ArtifactDefinition, Operation> updateResourceInstanceArtifactNoContent(String resourceId, Component containerComponent, User user, Map<String, Object> json, ArtifactOperationInfo operation, ArtifactDefinition artifactInfo) {
String jsonStr = gson.toJson(json);
- ArtifactDefinition artifactDefinitionFromJson = artifactInfo == null ? RepresentationUtils.convertJsonToArtifactDefinition(jsonStr, ArtifactDefinition.class) : artifactInfo;
+ ArtifactDefinition artifactDefinitionFromJson = artifactInfo == null ? RepresentationUtils.convertJsonToArtifactDefinition(jsonStr, ArtifactDefinition.class, false) : artifactInfo;
String artifactUniqueId = artifactDefinitionFromJson == null ? null : artifactDefinitionFromJson.getUniqueId();
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = validateAndHandleArtifact(resourceId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, artifactUniqueId,
+ Either<ArtifactDefinition, Operation> uploadArtifactToService = validateAndHandleArtifact(resourceId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, artifactUniqueId,
artifactDefinitionFromJson, null, jsonStr, null, null, user, containerComponent, false, false, true);
- if (uploadArtifactToService.isRight()) {
- return Either.right(uploadArtifactToService.right().value());
- }
return Either.left(uploadArtifactToService.left().value());
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleUpdateHeatEnv(String componentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, String artifactId, User user, ComponentTypeEnum componentType,
- org.openecomp.sdc.be.model.Component parent, String originData, String origMd5, ArtifactOperationInfo operation, boolean shouldLock, boolean inTransaction) {
- convertParentType(componentType);
- String parentId = parent.getUniqueId();
- ArtifactDefinition currArtifact = artifactInfo;
-
+ private Either<ArtifactDefinition, Operation> handleUpdateHeatEnvAndHeatMeta(String componentId, ArtifactDefinition artifactInfo, AuditingActionEnum auditingAction, String artifactId, User user, ComponentTypeEnum componentType,
+ Component parent, String originData, String origMd5, ArtifactOperationInfo operation) {
if (origMd5 != null) {
- Either<Boolean, ResponseFormat> validateMd5 = validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
- if (validateMd5.isRight()) {
- ResponseFormat responseFormat = validateMd5.right().value();
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
- }
-
- if (artifactInfo.getPayloadData() != null && artifactInfo.getPayloadData().length != 0) {
- Either<Boolean, ResponseFormat> deploymentValidationResult = validateDeploymentArtifact(parent, componentId, false, artifactInfo, currArtifact, NodeTypeEnum.ResourceInstance);
- if (deploymentValidationResult.isRight()) {
- ResponseFormat responseFormat = deploymentValidationResult.right().value();
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
- }
-
- Either<byte[], ResponseFormat> payloadEither = handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
- if (payloadEither.isRight()) {
- ResponseFormat responseFormat = payloadEither.right().value();
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
- }
- }
- else { // duplicate
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD);
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
+ validateMd5(origMd5, originData, artifactInfo.getPayloadData(), operation);
+ if (ArrayUtils.isNotEmpty(artifactInfo.getPayloadData())) {
+ validateDeploymentArtifact(parent, componentId, false, artifactInfo, artifactInfo, NodeTypeEnum.ResourceInstance);
+ handlePayload(artifactInfo, isArtifactMetadataUpdate(auditingAction));
+ } else { // duplicate
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_DATA, ARTIFACT_PAYLOAD);
}
}
-
- // lock resource
- if (shouldLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(parent, UPDATE_ARTIFACT_LOCK);
- if (lockComponent.isRight()) {
- handleAuditing(auditingAction, parent, parentId, user, null, null, artifactId, lockComponent.right()
- .value(), componentType, null);
- return Either.right(lockComponent.right().value());
- }
- }
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
- try {
- resultOp = updateHeatEnvParams(componentId, artifactId, artifactInfo, user, auditingAction, parent, componentType, origMd5);
- return resultOp;
-
- }
- finally {
- // unlock resource
- if (resultOp == null || resultOp.isRight()) {
- log.debug(ROLLBACK);
- if (!inTransaction) {
- janusGraphDao.rollback();
- }
- }
- else {
- log.debug(COMMIT);
- if (!inTransaction) {
- janusGraphDao.commit();
- }
- }
- if (shouldLock) {
- componentType = parent.getComponentType();
- }
- NodeTypeEnum nodeType = componentType.getNodeType();
- graphLockOperation.unlockComponent(parent.getUniqueId(), nodeType);
- }
+ return updateHeatEnvParamsAndMetadata(componentId, artifactId, artifactInfo, user, auditingAction, parent, componentType, origMd5);
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> updateHeatEnvParams(String componentId, String artifactId, ArtifactDefinition artifactInfo, User user, AuditingActionEnum auditingAction, Component parent,
- ComponentTypeEnum componentType, String origMd5) {
-
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp = null;
- Either<ArtifactDefinition, Operation> insideEither = null;
+ private Either<ArtifactDefinition, Operation> updateHeatEnvParamsAndMetadata(String componentId, String artifactId, ArtifactDefinition artifactInfo, User user, AuditingActionEnum auditingAction, Component parent,
+ ComponentTypeEnum componentType, String origMd5) {
Either<ComponentInstance, ResponseFormat> getRI = getRIFromComponent(parent, componentId, artifactId, auditingAction, user);
if (getRI.isRight()) {
- return Either.right(getRI.right().value());
+ throw new ByResponseFormatComponentException(getRI.right().value());
}
ComponentInstance ri = getRI.left().value();
Either<ArtifactDefinition, ResponseFormat> getArtifactRes = getArtifactFromRI(parent, ri, componentId, artifactId, auditingAction, user);
if (getArtifactRes.isRight()) {
- return Either.right(getArtifactRes.right().value());
+ throw new ByResponseFormatComponentException(getArtifactRes.right().value());
}
ArtifactDefinition currArtifact = getArtifactRes.left().value();
- if (currArtifact.getArtifactType().equals(ArtifactTypeEnum.HEAT.getType()) || currArtifact.getArtifactType()
- .equals(ArtifactTypeEnum.HEAT_VOL
- .getType()) || currArtifact
- .getArtifactType()
- .equals(ArtifactTypeEnum.HEAT_NET.getType())) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri
- .getName());
- return Either.right(responseFormat);
+ if (currArtifact.getArtifactType().equals(ArtifactTypeEnum.HEAT.getType()) ||
+ currArtifact.getArtifactType().equals(ArtifactTypeEnum.HEAT_VOL.getType()) ||
+ currArtifact.getArtifactType().equals(ArtifactTypeEnum.HEAT_NET.getType())) {
+ throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
}
List<HeatParameterDefinition> currentHeatEnvParams = currArtifact.getListHeatParameters();
List<HeatParameterDefinition> updatedHeatEnvParams = artifactInfo.getListHeatParameters();
- new ArrayList<HeatParameterDefinition>();
// upload
if (origMd5 != null) {
- Either<List<HeatParameterDefinition>, ResponseFormat> uploadParamsValidationResult = validateUploadParamsFromEnvFile(auditingAction, parent, user, artifactInfo, artifactId, componentType, ri
- .getName(), currentHeatEnvParams,
- updatedHeatEnvParams, currArtifact.getArtifactName());
+ Either<List<HeatParameterDefinition>, ResponseFormat> uploadParamsValidationResult = validateUploadParamsFromEnvFile(auditingAction, parent, user, artifactInfo,
+ artifactId, componentType, ri.getName(), currentHeatEnvParams, updatedHeatEnvParams, currArtifact.getArtifactName());
if (uploadParamsValidationResult.isRight()) {
- ResponseFormat responseFormat = uploadParamsValidationResult.right().value();
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri
- .getName());
- return Either.right(responseFormat);
+ throw new ByResponseFormatComponentException(uploadParamsValidationResult.right().value());
}
artifactInfo.setListHeatParameters(updatedHeatEnvParams);
}
- Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParamers = validateAndConvertHeatParamers(artifactInfo, ArtifactTypeEnum.HEAT_ENV
- .getType());
+ Either<ArtifactDefinition, ResponseFormat> validateAndConvertHeatParamers = validateAndConvertHeatParameters(artifactInfo, ArtifactTypeEnum.HEAT_ENV.getType());
if (validateAndConvertHeatParamers.isRight()) {
- ResponseFormat responseFormat = validateAndConvertHeatParamers.right().value();
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri
- .getName());
- return Either.right(responseFormat);
+ throw new ByResponseFormatComponentException(validateAndConvertHeatParamers.right().value());
}
if (updatedHeatEnvParams != null && !updatedHeatEnvParams.isEmpty()) {
// fill reduced heat env parameters List for updating
- replaceCurrHeatValueWithUpdatedValue(currentHeatEnvParams, updatedHeatEnvParams);
- currArtifact.setHeatParamsUpdateDate(System.currentTimeMillis());
- currArtifact.setListHeatParameters(currentHeatEnvParams);
-
- Either<ArtifactDefinition, StorageOperationStatus> updateArifactRes = artifactToscaOperation.updateArtifactOnResource(currArtifact, parent
- .getUniqueId(), currArtifact.getUniqueId(), componentType.getNodeType(), componentId);
- if (updateArifactRes.isRight()) {
- log.debug("Failed to update artifact on graph - {}", artifactId);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateArifactRes
- .right()
- .value()));
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri
- .getName());
- return Either.right(responseFormat);
- }
- StorageOperationStatus error = generateCustomizationUUIDOnInstance(parent.getUniqueId(), ri.getUniqueId(), componentType);
- if (error != StorageOperationStatus.OK) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(error));
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri
- .getName());
- return Either.right(responseFormat);
+ boolean updateRequired = replaceCurrHeatValueWithUpdatedValue(currentHeatEnvParams, updatedHeatEnvParams);
+ if (updateRequired) {
+ currArtifact.setHeatParamsUpdateDate(System.currentTimeMillis());
+ currArtifact.setListHeatParameters(currentHeatEnvParams);
+ Either<ArtifactDefinition, StorageOperationStatus> updateArtifactRes = artifactToscaOperation.updateArtifactOnResource(
+ currArtifact, parent, currArtifact.getUniqueId(), componentType.getNodeType(), componentId, true);
+ if (updateArtifactRes.isRight()) {
+ log.debug("Failed to update artifact on graph - {}", artifactId);
+ throw new StorageException(updateArtifactRes.right().value());
+ }
+ StorageOperationStatus error = generateCustomizationUUIDOnGroupInstance(ri, updateArtifactRes.left().value().getUniqueId(), parent.getUniqueId());
+ if (error != StorageOperationStatus.OK) {
+ throw new StorageException(error);
+ }
}
+ }
+ updateHeatMetaDataIfNeeded(componentId,user,auditingAction,componentType, parent,ri,artifactInfo);
+ StorageOperationStatus error = generateCustomizationUUIDOnInstance(parent.getUniqueId(), ri.getUniqueId(), componentType);
+ if (error != StorageOperationStatus.OK) {
+ throw new StorageException(error);
+ }
- error = generateCustomizationUUIDOnGroupInstance(ri, updateArifactRes.left()
- .value()
- .getUniqueId(), parent.getUniqueId());
+ return Either.left(currArtifact);
+ }
+
+ private void
+ updateHeatMetaDataIfNeeded(String componentId, User user, AuditingActionEnum auditingAction, ComponentTypeEnum componentType, Component parent, ComponentInstance resourceInstance, ArtifactDefinition updatedHeatEnvArtifact) {
+ String heatArtifactId = updatedHeatEnvArtifact.getGeneratedFromId();
+ Either<ArtifactDefinition, ResponseFormat> getArtifactRes = getArtifactFromRI(parent, resourceInstance, componentId, heatArtifactId, auditingAction, user);
+ if (getArtifactRes.isRight()) {
+ throw new ByResponseFormatComponentException(getArtifactRes.right().value());
+ }
+ ArtifactDefinition heatArtifactToUpdate = getArtifactRes.left().value();
+ if (isUpdateHeatMetaDataNeeded(updatedHeatEnvArtifact, heatArtifactToUpdate)) {
+ validateHeatMetaData(updatedHeatEnvArtifact);
+ updateHeatMetadataFromHeatEnv(updatedHeatEnvArtifact, heatArtifactToUpdate);
+ Either<ArtifactDefinition, StorageOperationStatus> updateArtifactRes = artifactToscaOperation.updateArtifactOnResource(heatArtifactToUpdate, parent,
+ heatArtifactToUpdate.getUniqueId(), componentType.getNodeType(), componentId, false);
+
+ if (updateArtifactRes.isRight()) {
+ log.debug("Failed to update artifact on graph - {}", heatArtifactId);
+ throw new StorageException(updateArtifactRes.right().value());
+ }
+ ArtifactDefinition artifactDefinition = updateArtifactRes.left().value();
+ updateGeneratedIdInHeatEnvOnInstance(resourceInstance, parent, heatArtifactId, heatArtifactToUpdate, artifactDefinition, componentType.getNodeType());
+ StorageOperationStatus error = generateCustomizationUUIDOnGroupInstance(resourceInstance, artifactDefinition.getUniqueId(), parent.getUniqueId());
if (error != StorageOperationStatus.OK) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(error));
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactInfo, null, artifactId, responseFormat, componentType, ri
- .getName());
- return Either.right(responseFormat);
+ throw new StorageException(error);
}
+ }
+ }
+ private void validateHeatMetaData(ArtifactDefinition updatedHeatEnv) {
+ Integer maxMinutes = ConfigurationManager.getConfigurationManager().getConfiguration().getHeatArtifactDeploymentTimeout().getMaxMinutes();
+ Integer minMinutes = ConfigurationManager.getConfigurationManager().getConfiguration().getHeatArtifactDeploymentTimeout().getMinMinutes();
+ Integer updateTimeout = updatedHeatEnv.getTimeout();
+ if (updateTimeout > maxMinutes || updateTimeout < minMinutes) {
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_INVALID_TIMEOUT);
}
- insideEither = Either.left(currArtifact);
- resultOp = Either.left(insideEither);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, currArtifact, null, artifactId, responseFormat, componentType, ri
- .getName());
- return resultOp;
}
- private void replaceCurrHeatValueWithUpdatedValue(List<HeatParameterDefinition> currentHeatEnvParams, List<HeatParameterDefinition> updatedHeatEnvParams) {
+ private boolean isUpdateHeatMetaDataNeeded(ArtifactDefinition updatedHeatEnv, ArtifactDefinition origHeat) {
+ // currently only timeout metadata can be updated
+ return !origHeat.getTimeout().equals(updatedHeatEnv.getTimeout());
+ }
+
+ private void updateHeatMetadataFromHeatEnv(ArtifactDefinition updatedHeatEnv, ArtifactDefinition origHeat) {
+ // currently only timeout metadata can be updated
+ origHeat.setTimeout(updatedHeatEnv.getTimeout());
+ }
+
+ private boolean replaceCurrHeatValueWithUpdatedValue(List<HeatParameterDefinition> currentHeatEnvParams, List<HeatParameterDefinition> updatedHeatEnvParams) {
+ boolean isUpdate = false;
+ List<String> currentParamsNames = currentHeatEnvParams.stream().map(x -> x.getName()).collect(Collectors.toList());
for (HeatParameterDefinition heatEnvParam : updatedHeatEnvParams) {
String paramName = heatEnvParam.getName();
+ validateParamName(paramName, currentParamsNames);
for (HeatParameterDefinition currHeatParam : currentHeatEnvParams) {
if (paramName.equalsIgnoreCase(currHeatParam.getName())) {
String updatedParamValue = heatEnvParam.getCurrentValue();
- currHeatParam.setCurrentValue(updatedParamValue);
+ if (!Objects.equals(updatedParamValue, currHeatParam.getCurrentValue())) {
+ currHeatParam.setCurrentValue(updatedParamValue);
+ isUpdate = true;
+ }
}
}
}
+ return isUpdate;
}
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> updateHeatParams(String componentId, String artifactId, ArtifactDefinition artifactEnvInfo, User user, AuditingActionEnum auditingAction, Component parent,
- ComponentTypeEnum componentType, ArtifactDefinition currHeatArtifact, boolean needToUpdateGroup) {
+ private void validateParamName(String paramName, List<String> heatParamsNames) {
+ if (!heatParamsNames.contains(paramName)) {
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, paramName);
+ }
+ }
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> resultOp;
+ private Either<ArtifactDefinition, Operation> updateHeatParams(String componentId, ArtifactDefinition artifactEnvInfo, AuditingActionEnum auditingAction, Component parent,
+ ComponentTypeEnum componentType, ArtifactDefinition currHeatArtifact, boolean needToUpdateGroup) {
Either<ArtifactDefinition, Operation> insideEither = null;
String currentHeatId = currHeatArtifact.getUniqueId();
String esArtifactId = currHeatArtifact.getEsId();
- Either<ESArtifactData, CassandraOperationStatus> artifactFromES = artifactCassandraDao.getArtifact(esArtifactId);
+ Either<DAOArtifactData, CassandraOperationStatus> artifactFromES = artifactCassandraDao.getArtifact(esArtifactId);
if (artifactFromES.isRight()) {
- CassandraOperationStatus resourceUploadStatus = artifactFromES.right().value();
- StorageOperationStatus storageResponse = DaoStatusConverter.convertCassandraStatusToStorageStatus(resourceUploadStatus);
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageResponse);
- log.debug("Error when getting artifact from ES, error: {}", actionStatus);
- return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, currHeatArtifact.getArtifactDisplayName()));
+ StorageOperationStatus storageResponse = DaoStatusConverter.convertCassandraStatusToStorageStatus(artifactFromES.right().value());
+ throw new StorageException(storageResponse, currHeatArtifact.getArtifactDisplayName());
}
- ESArtifactData esArtifactData = artifactFromES.left().value();
-
+ DAOArtifactData DAOArtifactData = artifactFromES.left().value();
ArtifactDefinition updatedHeatArt = currHeatArtifact;
-
List<HeatParameterDefinition> updatedHeatEnvParams = artifactEnvInfo.getListHeatParameters();
List<HeatParameterDefinition> currentHeatEnvParams = currHeatArtifact.getListHeatParameters();
- List<HeatParameterDefinition> newHeatEnvParams = new ArrayList<HeatParameterDefinition>();
-
- if (updatedHeatEnvParams != null && !updatedHeatEnvParams.isEmpty() && currentHeatEnvParams != null && !currentHeatEnvParams
- .isEmpty()) {
+ List<HeatParameterDefinition> newHeatEnvParams = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(updatedHeatEnvParams) && CollectionUtils.isNotEmpty(currentHeatEnvParams)) {
+ //TODO: improve complexity - currently N^2
String paramName;
for (HeatParameterDefinition heatEnvParam : updatedHeatEnvParams) {
-
paramName = heatEnvParam.getName();
for (HeatParameterDefinition currHeatParam : currentHeatEnvParams) {
if (paramName.equalsIgnoreCase(currHeatParam.getName())) {
-
String updatedParamValue = heatEnvParam.getCurrentValue();
if (updatedParamValue == null) {
updatedParamValue = heatEnvParam.getDefaultValue();
}
HeatParameterType paramType = HeatParameterType.isValidType(currHeatParam.getType());
if (!paramType.getValidator().isValid(updatedParamValue, null)) {
- ActionStatus status = ActionStatus.INVALID_HEAT_PARAMETER_VALUE;
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(status, ArtifactTypeEnum.HEAT_ENV
- .getType(), paramType.getType(), paramName);
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, artifactEnvInfo, null, artifactId, responseFormat, componentType, "");
- return Either.right(responseFormat);
-
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_HEAT_PARAMETER_VALUE,
+ ArtifactTypeEnum.HEAT_ENV.getType(), paramType.getType(), paramName);
}
currHeatParam.setCurrentValue(paramType.getConverter().convert(updatedParamValue, null, null));
newHeatEnvParams.add(currHeatParam);
@@ -4415,78 +3855,45 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
if (!newHeatEnvParams.isEmpty()) {
currHeatArtifact.setListHeatParameters(currentHeatEnvParams);
- Either<ArtifactDefinition, StorageOperationStatus> operationStatus = artifactToscaOperation.updateArtifactOnResource(currHeatArtifact, parent
- .getUniqueId(), currHeatArtifact.getUniqueId(), componentType.getNodeType(), componentId);
+ Either<ArtifactDefinition, StorageOperationStatus> operationStatus = artifactToscaOperation.updateArtifactOnResource(
+ currHeatArtifact, parent, currHeatArtifact.getUniqueId(), componentType.getNodeType(), componentId, true);
if (operationStatus.isRight()) {
log.debug("Failed to update artifact on graph - {}", currHeatArtifact.getUniqueId());
-
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(operationStatus
- .right()
- .value()));
- return Either.right(responseFormat);
-
+ throw new StorageException(operationStatus.right().value());
}
updatedHeatArt = operationStatus.left().value();
- boolean res = true;
- if (!updatedHeatArt.getDuplicated() || esArtifactData.getId() == null) {
- esArtifactData.setId(updatedHeatArt.getEsId());
+ if (!updatedHeatArt.getDuplicated() || DAOArtifactData.getId() == null) {
+ DAOArtifactData.setId(updatedHeatArt.getEsId());
}
- res = saveArtifacts(esArtifactData, parent.getUniqueId());
-
- if (res) {
- log.debug(ARTIFACT_SAVED, updatedHeatArt.getUniqueId());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, updatedHeatArt, currentHeatId, updatedHeatArt
- .getUniqueId(), responseFormat, componentType, null);
- }
- else {
- BeEcompErrorManager.getInstance().logBeDaoSystemError(UPDATE_ARTIFACT);
- log.debug(FAILED_SAVE_ARTIFACT);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, updatedHeatArt, currentHeatId, updatedHeatArt
- .getUniqueId(), responseFormat, componentType, null);
- resultOp = Either.right(responseFormat);
- }
-
+ saveArtifactInCassandra(DAOArtifactData, parent, artifactEnvInfo, currentHeatId, updatedHeatArt
+ .getUniqueId(), auditingAction, componentType);
insideEither = Either.left(updatedHeatArt);
}
}
Either<ArtifactDefinition, StorageOperationStatus> updateHeatEnvArtifact;
if (!currentHeatId.equals(updatedHeatArt.getUniqueId())) {
artifactEnvInfo.setArtifactChecksum(null);
- updateHeatEnvArtifact = artifactToscaOperation.updateHeatEnvArtifact(parent.getUniqueId(), artifactEnvInfo, currentHeatId, updatedHeatArt
+ updateHeatEnvArtifact = artifactToscaOperation.updateHeatEnvArtifact(parent, artifactEnvInfo, currentHeatId, updatedHeatArt
.getUniqueId(), componentType.getNodeType(), componentId);
}
else {
- updateHeatEnvArtifact = artifactToscaOperation.updateHeatEnvPlaceholder(artifactEnvInfo, componentId, componentType
+ //TODO Andrey check if componentId = parent.getUniqeId
+ updateHeatEnvArtifact = artifactToscaOperation.updateHeatEnvPlaceholder(artifactEnvInfo, parent, componentType
.getNodeType());
}
if (needToUpdateGroup && updateHeatEnvArtifact.isLeft()) {
- ActionStatus result = updateGroupForHeat(currHeatArtifact, updatedHeatArt, artifactEnvInfo, updateHeatEnvArtifact
- .left()
- .value(), parent, componentType);
+ ActionStatus result = updateGroupForHeat(currHeatArtifact, updatedHeatArt, artifactEnvInfo,
+ updateHeatEnvArtifact.left().value(), parent);
if (result != ActionStatus.OK) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(result);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(result);
}
}
-
if (updatedHeatEnvParams.isEmpty()) {
- return getResponseAndAuditInvalidEmptyHeatEnvFile(auditingAction, parent, user, currHeatArtifact, artifactId, componentType);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML, currHeatArtifact.getArtifactName());
}
- resultOp = Either.left(insideEither);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, currHeatArtifact, null, artifactId, responseFormat, componentType, "");
- return resultOp;
-
- }
-
- private Either<Either<ArtifactDefinition, Operation>, ResponseFormat> getResponseAndAuditInvalidEmptyHeatEnvFile(AuditingActionEnum auditingAction, Component parent, User user, ArtifactDefinition currHeatArtifact, String artifactId, ComponentTypeEnum componentType) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML, currHeatArtifact.getArtifactName());
- handleAuditing(auditingAction, parent, parent.getUniqueId(), user, currHeatArtifact, null, artifactId, responseFormat, componentType, "");
- return Either.right(responseFormat);
+ return insideEither;
}
@@ -4497,10 +3904,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
List<String> groupInstancesId = null;
if (groupsInstances != null && !groupsInstances.isEmpty()) {
groupInstancesId = groupsInstances.stream()
- .filter(p -> p.getGroupInstanceArtifacts() != null && p.getGroupInstanceArtifacts()
- .contains(artifactId))
- .map(GroupInstanceDataDefinition::getUniqueId)
- .collect(Collectors.toList());
+ .filter(p -> p.getGroupInstanceArtifacts() != null && p.getGroupInstanceArtifacts()
+ .contains(artifactId))
+ .map(GroupInstanceDataDefinition::getUniqueId)
+ .collect(Collectors.toList());
}
if (groupInstancesId != null && !groupInstancesId.isEmpty()) {
toscaOperationFacade.generateCustomizationUUIDOnInstanceGroup(componentId, ri.getUniqueId(), groupInstancesId);
@@ -4581,31 +3988,10 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return ret;
}
- /**
- * downloads artifact of component by UUIDs
- *
- * @param componentType
- * @param componentUuid
- * @param artifactUUID
- * @param resourceCommonInfo
- * @return
- */
- public Either<byte[], ResponseFormat> downloadComponentArtifactByUUIDs(ComponentTypeEnum componentType, String componentUuid, String artifactUUID, ResourceCommonInfo resourceCommonInfo) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<byte[], ResponseFormat> result;
- byte[] downloadedArtifact = null;
- Component component = getComponentByUuid(componentType, componentUuid, errorWrapper);
- if (errorWrapper.isEmpty() && component != null) {
- resourceCommonInfo.setResourceName(component.getName());
- downloadedArtifact = downloadArtifact(component.getAllArtifacts(), artifactUUID, errorWrapper, component.getName());
- }
- if (errorWrapper.isEmpty()) {
- result = Either.left(downloadedArtifact);
- }
- else {
- result = Either.right(errorWrapper.getInnerElement());
- }
- return result;
+ public byte[] downloadComponentArtifactByUUIDs(ComponentTypeEnum componentType, String componentUuid, String artifactUUID, ResourceCommonInfo resourceCommonInfo) {
+ Component component = getComponentByUuid(componentType, componentUuid);
+ resourceCommonInfo.setResourceName(component.getName());
+ return downloadArtifact(component.getAllArtifacts(), artifactUUID, component.getName());
}
/**
@@ -4617,22 +4003,11 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param artifactUUID
* @return
*/
- public Either<byte[], ResponseFormat> downloadResourceInstanceArtifactByUUIDs(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<byte[], ResponseFormat> result;
- byte[] downloadedArtifact = null;
- ComponentInstance resourceInstance = getRelatedComponentInstance(componentType, componentUuid, resourceInstanceName, errorWrapper);
- if (errorWrapper.isEmpty()) {
- downloadedArtifact = downloadArtifact(resourceInstance.getDeploymentArtifacts(), artifactUUID, errorWrapper, resourceInstance
- .getName());
- }
- if (errorWrapper.isEmpty()) {
- result = Either.left(downloadedArtifact);
- }
- else {
- result = Either.right(errorWrapper.getInnerElement());
- }
- return result;
+ public byte[] downloadResourceInstanceArtifactByUUIDs(ComponentTypeEnum componentType, String componentUuid,
+ String resourceInstanceName, String artifactUUID) {
+ ComponentInstance resourceInstance = getRelatedComponentInstance(componentType, componentUuid, resourceInstanceName);
+ return downloadArtifact(resourceInstance == null ? null : resourceInstance.getDeploymentArtifacts(),
+ artifactUUID, resourceInstance.getName());
}
/**
@@ -4646,50 +4021,43 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param operation
* @return
*/
- public Either<ArtifactDefinition, ResponseFormat> uploadArtifactToComponentByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, ResourceCommonInfo resourceCommonInfo,ArtifactOperationInfo operation) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
- Component component = null;
- String componentId = null;
- ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
+ public ArtifactDefinition uploadArtifactToComponentByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType,
+ String componentUuid, ResourceCommonInfo resourceCommonInfo, ArtifactOperationInfo operation) {
+ Either<ArtifactDefinition, Operation> actionResult;
+ Component component;
+ String componentId;
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class, false);
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
+ Either<ComponentMetadataData, StorageOperationStatus> getComponentRes =
+ toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
if (getComponentRes.isRight()) {
StorageOperationStatus status = getComponentRes.right().value();
log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status, componentType), componentUuid));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), componentUuid);
}
- if (errorWrapper.isEmpty()) {
- componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
- String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
- if (!getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getState()
- .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
- component = checkoutParentComponent(componentType, componentId, userId, errorWrapper);
- if (component != null) {
- componentId = component.getUniqueId();
- componentName = component.getName();
- }
- }
- resourceCommonInfo.setResourceName(componentName);
- }
- if (errorWrapper.isEmpty()) {
- actionResult = handleArtifactRequest(componentId, userId, componentType, operation, null, artifactInfo, origMd5, data, null, null, null, null);
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
- .right()
- .value());
- return Either.right(actionResult.right().value());
+ ComponentMetadataDataDefinition componentMetadataDataDefinition = getComponentRes.left().value().getMetadataDataDefinition();
+ componentId = componentMetadataDataDefinition.getUniqueId();
+ String componentName = componentMetadataDataDefinition.getName();
+
+ if (!componentMetadataDataDefinition
+ .getState()
+ .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, componentId, userId);
+ if (component != null) {
+ componentId = component.getUniqueId();
+ componentName = component.getName();
}
- return Either.left(actionResult.left().value().left().value());
}
- return Either.right(errorWrapper.getInnerElement());
+ resourceCommonInfo.setResourceName(componentName);
+
+ actionResult = handleArtifactRequest(componentId, userId, componentType, operation, null, artifactInfo,
+ origMd5, data, null, null, null, null);
+ return actionResult.left().value();
}
+
/**
* upload an artifact to a resource instance by UUID
*
@@ -4701,12 +4069,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param operation
* @return
*/
- public Either<ArtifactDefinition, ResponseFormat> uploadArtifactToRiByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName,
- ArtifactOperationInfo operation) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactResult;
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
- ArtifactDefinition uploadArtifact = null;
+ public ArtifactDefinition uploadArtifactToRiByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName,
+ ArtifactOperationInfo operation) {
+ Either<ArtifactDefinition, Operation> actionResult;
Component component = null;
String componentInstanceId;
String componentId;
@@ -4717,49 +4082,34 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
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, componentType), resourceInstanceName));
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), resourceInstanceName);
}
- if (errorWrapper.isEmpty() && !getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getState()
- .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ if (!getComponentRes.left()
+ .value()
+ .getMetadataDataDefinition()
+ .getState()
+ .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
component = checkoutParentComponent(componentType, getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getUniqueId(), userId, errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- if (component == null) {
- componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName, errorWrapper);
- }
- else {
- componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName, errorWrapper);
- }
- }
- if (errorWrapper.isEmpty()) {
- componentInstanceId = componentRiPair.getRight().getUniqueId();
- componentId = componentRiPair.getLeft().getUniqueId();
- ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
-
- actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, null, artifactInfo, origMd5, data, null, null, componentId, ComponentTypeEnum
- .findParamByType(componentType));
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_INSTANCE, resourceInstanceName, componentType, componentUuid, actionResult
- .right()
- .value());
- errorWrapper.setInnerElement(actionResult.right().value());
- }
+ .value()
+ .getMetadataDataDefinition()
+ .getUniqueId(), userId);
}
- if (errorWrapper.isEmpty()) {
- uploadArtifact = actionResult.left().value().left().value();
- uploadArtifactResult = Either.left(uploadArtifact);
+ if (component == null) {
+ componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName);
}
else {
- uploadArtifactResult = Either.right(errorWrapper.getInnerElement());
+ componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName);
}
- return uploadArtifactResult;
+ componentInstanceId = componentRiPair.getRight().getUniqueId();
+ componentId = componentRiPair.getLeft().getUniqueId();
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class, false);
+
+ actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE,
+ operation, null, artifactInfo, origMd5, data, null, null,
+ componentId, ComponentTypeEnum.findParamByType(componentType));
+
+ return actionResult.left().value();
}
/**
@@ -4770,18 +4120,16 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param componentType
* @param componentUuid
* @param artifactUUID
- * @param operation
+ * @param resourceCommonInfo
+ * @param operation TODO
* @return
*/
- public Either<ArtifactDefinition, ResponseFormat> updateArtifactOnComponentByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String artifactUUID,
- ResourceCommonInfo resourceCommonInfo, ArtifactOperationInfo operation) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<ArtifactDefinition, ResponseFormat> updateArtifactResult;
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
- ArtifactDefinition updateArtifact = null;
- Component component = null;
- String componentId = null;
- String artifactId = null;
+ public ArtifactDefinition updateArtifactOnComponentByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String artifactUUID,
+ ResourceCommonInfo resourceCommonInfo, ArtifactOperationInfo operation) {
+ Either<ArtifactDefinition, Operation> actionResult;
+ Component component;
+ String componentId;
+ String artifactId ;
ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinitionForUpdate(data, ArtifactDefinition.class);
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
@@ -4789,47 +4137,34 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
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)));
- }
- if (errorWrapper.isEmpty()) {
- componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
- String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
-
- if (!getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getState()
- .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
- component = checkoutParentComponent(componentType, componentId, userId, errorWrapper);
- if (component != null) {
- componentId = component.getUniqueId();
- componentName = component.getName();
- }
- }
- resourceCommonInfo.setResourceName(componentName);
- }
- if (errorWrapper.isEmpty()) {
- artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, errorWrapper, componentId, componentType);
- }
- if (errorWrapper.isEmpty()) {
- actionResult = handleArtifactRequest(componentId, userId, componentType, operation, artifactId, artifactInfo, origMd5, data, null, null, null, null);
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
- .right()
- .value());
- errorWrapper.setInnerElement(actionResult.right().value());
- }
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
+ }
+ componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
+ String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
+
+ if (!getComponentRes.left()
+ .value()
+ .getMetadataDataDefinition()
+ .getState()
+ .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, componentId, userId);
+ if (component != null) {
+ componentId = component.getUniqueId();
+ componentName = component.getName();
+ }
+ }
+ resourceCommonInfo.setResourceName(componentName);
+ artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, componentId, componentType);
+ actionResult = handleArtifactRequest(componentId, userId, componentType, operation, artifactId, artifactInfo,
+ origMd5, data, null, null, null, null);
+ if (actionResult.isRight()) {
+ log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
+ .right()
+ .value());
}
- if (errorWrapper.isEmpty()) {
- updateArtifact = actionResult.left().value().left().value();
- updateArtifactResult = Either.left(updateArtifact);
- }
- else {
- updateArtifactResult = Either.right(errorWrapper.getInnerElement());
- }
- return updateArtifactResult;
+ return actionResult.left().value();
}
/**
@@ -4844,17 +4179,14 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param operation TODO
* @return
*/
- public Either<ArtifactDefinition, ResponseFormat> updateArtifactOnRiByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID,
- ArtifactOperationInfo operation) {
+ public ArtifactDefinition updateArtifactOnRiByUUID(String data, HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID,
+ ArtifactOperationInfo operation) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<ArtifactDefinition, ResponseFormat> updateArtifactResult;
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
- ArtifactDefinition updateArtifact = null;
+ Either<ArtifactDefinition, Operation> actionResult;
Component component = null;
- String componentInstanceId = null;
- String componentId = null;
- String artifactId = null;
+ String componentInstanceId;
+ String componentId;
+ String artifactId;
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
@@ -4862,52 +4194,33 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
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)));
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
}
- if (errorWrapper.isEmpty() && !getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getState()
- .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ if (!getComponentRes.left()
+ .value()
+ .getMetadataDataDefinition()
+ .getState()
+ .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
component = checkoutParentComponent(componentType, getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getUniqueId(), userId, errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- if (component == null) {
- componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName, errorWrapper);
- }
- else {
- componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName, errorWrapper);
- }
- }
- if (errorWrapper.isEmpty()) {
- componentInstanceId = componentRiPair.getRight().getUniqueId();
- componentId = componentRiPair.getLeft().getUniqueId();
- artifactId = findArtifactId(componentRiPair.getRight(), artifactUUID, errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
-
- actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, artifactId, artifactInfo, origMd5, data, null, null, componentId, ComponentTypeEnum
- .findParamByType(componentType));
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_INSTANCE, resourceInstanceName, componentType, componentUuid, actionResult
- .right()
- .value());
- errorWrapper.setInnerElement(actionResult.right().value());
- }
+ .value()
+ .getMetadataDataDefinition()
+ .getUniqueId(), userId);
}
- if (errorWrapper.isEmpty()) {
- updateArtifact = actionResult.left().value().left().value();
- updateArtifactResult = Either.left(updateArtifact);
+ if (component == null) {
+ componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName);
}
else {
- updateArtifactResult = Either.right(errorWrapper.getInnerElement());
+ componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName);
}
- return updateArtifactResult;
+ componentInstanceId = componentRiPair.getRight().getUniqueId();
+ componentId = componentRiPair.getLeft().getUniqueId();
+ artifactId = findArtifactId(componentRiPair.getRight(), artifactUUID);
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class, false);
+
+ actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, artifactId, artifactInfo, origMd5, data, null, null, componentId, ComponentTypeEnum
+ .findParamByType(componentType));
+ return actionResult.left().value();
}
private Either<ArtifactDefinition, ResponseFormat> updateOperationArtifact(String componentId, String interfaceType, String operationUuid, ArtifactDefinition artifactInfo){
@@ -4929,9 +4242,9 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
InterfaceDefinition gotInterface = optionalInterface.get();
Map<String, Operation> operationsMap = gotInterface.getOperationsMap();
Optional<Operation> optionalOperation = operationsMap.values()
- .stream()
- .filter(o -> o.getUniqueId().equals(operationUuid))
- .findFirst();
+ .stream()
+ .filter(o -> o.getUniqueId().equals(operationUuid))
+ .findFirst();
if (!optionalOperation.isPresent()) {
log.debug("Failed to get resource interface operation for resource Id {} and operationId {}", componentId, operationUuid);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId);
@@ -4962,6 +4275,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(artifactInfo);
}
+
/**
* updates an artifact on a component by UUID
*
@@ -5003,7 +4317,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
.getMetadataDataDefinition()
.getState()
.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
- Component component = checkoutParentComponent(componentType, componentId, userId, errorWrapper);
+ Component component = checkoutParentComponent(componentType, componentId, userId);
if (component != null) {
componentId = component.getUniqueId();
componentName = component.getName();
@@ -5047,14 +4361,12 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
if (errorWrapper.isEmpty()) {
- actionResult = handleArtifactRequest(componentId, userId, componentType, operation,
- artifactUUID, artifactInfo, origMd5, data, interfaceName,
- operationUUID, null, null);
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
- .right()
- .value());
- errorWrapper.setInnerElement(actionResult.right().value());
+ try {
+ actionResult = Either.left(handleArtifactRequest(componentId, userId, componentType, operation,
+ artifactUUID, artifactInfo, origMd5, data, interfaceName,
+ operationUUID, null, null));
+ }catch (ComponentException e){
+ errorWrapper.setInnerElement(e.getResponseFormat());
}
}
@@ -5086,7 +4398,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return Either.left(optionalInterface.get().getType());
}
-
/**
* deletes an artifact on a component by UUID
*
@@ -5098,61 +4409,39 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param operation TODO
* @return
*/
- public Either<ArtifactDefinition, ResponseFormat> deleteArtifactOnComponentByUUID(HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String artifactUUID, ResourceCommonInfo resourceCommonInfo,
- ArtifactOperationInfo operation) {
+ public ArtifactDefinition deleteArtifactOnComponentByUUID(HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String artifactUUID, ResourceCommonInfo resourceCommonInfo,
+ ArtifactOperationInfo operation) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<ArtifactDefinition, ResponseFormat> deleteArtifactResult;
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
- ArtifactDefinition deleteArtifact = null;
- Component component = null;
- String componentId = null;
- String artifactId = null;
+ Either<ArtifactDefinition, Operation> actionResult;
+ Component component;
+ String componentId ;
+ String artifactId;
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
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, componentType), componentUuid));
- }
- if (errorWrapper.isEmpty()) {
- componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
- String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
- if (!getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getState()
- .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
- component = checkoutParentComponent(componentType, componentId, userId, errorWrapper);
- if (component != null) {
- componentId = component.getUniqueId();
- componentName = component.getName();
- }
- }
- resourceCommonInfo.setResourceName(componentName);
- }
- if (errorWrapper.isEmpty()) {
- artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, errorWrapper, componentId, componentType);
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status, componentType), componentUuid);
}
- if (errorWrapper.isEmpty()) {
- actionResult = handleArtifactRequest(componentId, userId, componentType, operation, artifactId, null, origMd5, null, null, null, null, null);
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
- .right()
- .value());
- errorWrapper.setInnerElement(actionResult.right().value());
+ componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
+ String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
+ if (!getComponentRes.left()
+ .value()
+ .getMetadataDataDefinition()
+ .getState()
+ .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ component = checkoutParentComponent(componentType, componentId, userId);
+ if (component != null) {
+ componentId = component.getUniqueId();
+ componentName = component.getName();
}
}
- if (errorWrapper.isEmpty()) {
- deleteArtifact = actionResult.left().value().left().value();
- deleteArtifactResult = Either.left(deleteArtifact);
- }
- else {
- deleteArtifactResult = Either.right(errorWrapper.getInnerElement());
- }
- return deleteArtifactResult;
+ resourceCommonInfo.setResourceName(componentName);
+ artifactId = getLatestParentArtifactDataIdByArtifactUUID(artifactUUID, componentId, componentType);
+ actionResult = handleArtifactRequest(componentId, userId, componentType, operation, artifactId, null, origMd5, null, null, null, null, null);
+ return actionResult.left().value();
}
/**
@@ -5166,95 +4455,74 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
* @param operation TODO
* @return
*/
- public Either<ArtifactDefinition, ResponseFormat> deleteArtifactOnRiByUUID(HttpServletRequest request, ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, String artifactUUID,
- ArtifactOperationInfo operation) {
+ public ArtifactDefinition deleteArtifactOnRiByUUID(HttpServletRequest request, ComponentTypeEnum componentType,
+ String componentUuid, String resourceInstanceName,
+ String artifactUUID, ArtifactOperationInfo operation) {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<ArtifactDefinition, ResponseFormat> deleteArtifactResult;
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = null;
- ArtifactDefinition deleteArtifact = null;
+ Either<ArtifactDefinition, Operation> actionResult;
Component component = null;
- String componentInstanceId = null;
- String componentId = null;
- String artifactId = null;
+ String componentInstanceId;
+ String componentId;
+ String artifactId;
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
ImmutablePair<Component, ComponentInstance> componentRiPair = null;
- Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
+ Either<ComponentMetadataData, StorageOperationStatus> getComponentRes =
+ toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
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)));
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
}
- if (errorWrapper.isEmpty() && !getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getState()
- .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ if (!getComponentRes.left()
+ .value()
+ .getMetadataDataDefinition()
+ .getState()
+ .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
component = checkoutParentComponent(componentType, getComponentRes.left()
- .value()
- .getMetadataDataDefinition()
- .getUniqueId(), userId, errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
- if (component == null) {
- componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName, errorWrapper);
- }
- else {
- componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName, errorWrapper);
- }
- }
- if (errorWrapper.isEmpty()) {
- componentInstanceId = componentRiPair.getRight().getUniqueId();
- componentId = componentRiPair.getLeft().getUniqueId();
- artifactId = findArtifactId(componentRiPair.getRight(), artifactUUID, errorWrapper);
- }
- if (errorWrapper.isEmpty()) {
-
- actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, artifactId, null, origMd5, null, null, null, componentId, ComponentTypeEnum
- .findParamByType(componentType));
-
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_INSTANCE, resourceInstanceName, componentType, componentUuid, actionResult
- .right()
- .value());
- errorWrapper.setInnerElement(actionResult.right().value());
- }
+ .value()
+ .getMetadataDataDefinition()
+ .getUniqueId(), userId);
}
- if (errorWrapper.isEmpty()) {
- deleteArtifact = actionResult.left().value().left().value();
- deleteArtifactResult = Either.left(deleteArtifact);
+ if (component == null) {
+ componentRiPair = getRelatedComponentComponentInstance(componentType, componentUuid, resourceInstanceName);
}
else {
- deleteArtifactResult = Either.right(errorWrapper.getInnerElement());
+ componentRiPair = getRelatedComponentComponentInstance(component, resourceInstanceName);
}
- return deleteArtifactResult;
+ componentInstanceId = componentRiPair.getRight().getUniqueId();
+ componentId = componentRiPair.getLeft().getUniqueId();
+ artifactId = findArtifactId(componentRiPair.getRight(), artifactUUID);
+
+ actionResult = handleArtifactRequest(componentInstanceId, userId, ComponentTypeEnum.RESOURCE_INSTANCE, operation, artifactId, null, origMd5, null, null, null, componentId, ComponentTypeEnum
+ .findParamByType(componentType));
+ return actionResult.left().value();
}
- private String findArtifactId(ComponentInstance instance, String artifactUUID, Wrapper<ResponseFormat> errorWrapper) {
+ private String findArtifactId(ComponentInstance instance, String artifactUUID) {
String artifactId = null;
ArtifactDefinition foundArtifact = null;
if (instance.getDeploymentArtifacts() != null) {
foundArtifact = instance.getDeploymentArtifacts()
- .values()
- .stream()
- .filter(e -> e.getArtifactUUID() != null && e.getArtifactUUID()
- .equals(artifactUUID))
- .findFirst()
- .orElse(null);
+ .values()
+ .stream()
+ .filter(e -> e.getArtifactUUID() != null && e.getArtifactUUID()
+ .equals(artifactUUID))
+ .findFirst()
+ .orElse(null);
}
if (foundArtifact == null && instance.getArtifacts() != null) {
foundArtifact = instance.getArtifacts()
- .values()
- .stream()
- .filter(e -> e.getArtifactUUID() != null && e.getArtifactUUID()
- .equals(artifactUUID))
- .findFirst()
- .orElse(null);
+ .values()
+ .stream()
+ .filter(e -> e.getArtifactUUID() != null && e.getArtifactUUID()
+ .equals(artifactUUID))
+ .findFirst()
+ .orElse(null);
}
if (foundArtifact == null) {
log.debug("The artifact {} was not found on instance {}. ", artifactUUID, instance.getUniqueId());
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactUUID));
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, artifactUUID);
}
else {
artifactId = foundArtifact.getUniqueId();
@@ -5263,63 +4531,64 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
@SuppressWarnings("unchecked")
- public Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder(ArtifactDefinition heatArtifact, String envType, String parentId, NodeTypeEnum parentType, String parentName, User user, Component component,
- Map<String, String> existingEnvVersions) {
+ public ArtifactDefinition createHeatEnvPlaceHolder(List<ArtifactDefinition> createdArtifacts, ArtifactDefinition heatArtifact,
+ String envType, String parentId, NodeTypeEnum parentType,
+ String parentName, User user, Component component,
+ Map<String, String> existingEnvVersions) {
Map<String, Object> deploymentResourceArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration()
- .getDeploymentResourceInstanceArtifacts();
+ .getConfiguration()
+ .getDeploymentResourceInstanceArtifacts();
if (deploymentResourceArtifacts == null) {
log.debug("no deployment artifacts are configured for generated artifacts");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
Map<String, Object> placeHolderData = (Map<String, Object>) deploymentResourceArtifacts.get(envType);
if (placeHolderData == null) {
log.debug("no env type {} are configured for generated artifacts", envType);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
String envLabel = (heatArtifact.getArtifactLabel() + HEAT_ENV_SUFFIX).toLowerCase();
- Either<ArtifactDefinition, ResponseFormat> createArtifactPlaceHolder = createArtifactPlaceHolderInfo(parentId, envLabel, placeHolderData, user
+ ArtifactDefinition createArtifactPlaceHolder = createArtifactPlaceHolderInfo(parentId, envLabel, placeHolderData, user
.getUserId(), ArtifactGroupTypeEnum.DEPLOYMENT, true);
- if (createArtifactPlaceHolder.isRight()) {
- return Either.right(createArtifactPlaceHolder.right().value());
- }
- ArtifactDefinition artifactHeatEnv = createArtifactPlaceHolder.left().value();
+ ArtifactDefinition artifactHeatEnv = createArtifactPlaceHolder;
artifactHeatEnv.setGeneratedFromId(heatArtifact.getUniqueId());
artifactHeatEnv.setHeatParamsUpdateDate(System.currentTimeMillis());
artifactHeatEnv.setTimeout(0);
+ artifactHeatEnv.setIsFromCsar(heatArtifact.getIsFromCsar());
buildHeatEnvFileName(heatArtifact, artifactHeatEnv, placeHolderData);
// rbetzer - keep env artifactVersion - changeComponentInstanceVersion flow
handleEnvArtifactVersion(artifactHeatEnv, existingEnvVersions);
ArtifactDefinition heatEnvPlaceholder;
// Evg : for resource instance artifact will be added later as block with other env artifacts from BL
if (parentType != NodeTypeEnum.ResourceInstance) {
- Either<ArtifactDefinition, StorageOperationStatus> addHeatEnvArtifact = addHeatEnvArtifact(artifactHeatEnv, heatArtifact, component
- .getUniqueId(), parentType, parentId);
+ String checkSum = artifactToscaOperation.sortAndCalculateChecksumForHeatParameters(heatArtifact.getHeatParameters());
+ artifactHeatEnv.setArtifactChecksum(checkSum);
+ Either<ArtifactDefinition, StorageOperationStatus> addHeatEnvArtifact = addHeatEnvArtifact(artifactHeatEnv, heatArtifact, component, parentType, parentId);
if (addHeatEnvArtifact.isRight()) {
log.debug("failed to create heat env artifact on resource instance");
- return Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(addHeatEnvArtifact
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(addHeatEnvArtifact
.right()
.value(), false), "", null));
}
- heatEnvPlaceholder = createArtifactPlaceHolder.left().value();
+ heatEnvPlaceholder = createArtifactPlaceHolder;
}
else {
heatEnvPlaceholder = artifactHeatEnv;
artifactToscaOperation.generateUUID(heatEnvPlaceholder, heatEnvPlaceholder.getArtifactVersion());
setHeatCurrentValuesOnHeatEnvDefaultValues(heatArtifact, heatEnvPlaceholder);
}
-
ComponentTypeEnum componentType = component.getComponentType();
if (parentType == NodeTypeEnum.ResourceInstance) {
componentType = ComponentTypeEnum.RESOURCE_INSTANCE;
}
+ createdArtifacts.add(heatEnvPlaceholder);
componentsUtils.auditComponent(componentsUtils.getResponseFormat(ActionStatus.OK), user, component, AuditingActionEnum.ARTIFACT_UPLOAD,
new ResourceCommonInfo(parentName, componentType.getValue()),
ResourceVersionInfo.newBuilder().build(),
ResourceVersionInfo.newBuilder().artifactUuid(heatEnvPlaceholder.getUniqueId()).build(),
null, heatEnvPlaceholder, null);
- return Either.left(heatEnvPlaceholder);
+ return heatEnvPlaceholder;
}
private void setHeatCurrentValuesOnHeatEnvDefaultValues(ArtifactDefinition artifact, ArtifactDefinition artifactDefinition) {
@@ -5360,26 +4629,75 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
}
}
- /**
- * Handles Artifacts Request For Inner Component
- *
- * @param artifactsToHandle
- * @param component
- * @param user
- * @param vfcsNewCreatedArtifacts
- * @param operation
- * @param shouldLock
- * @param inTransaction
- * @return
- */
- public Either<List<ArtifactDefinition>, ResponseFormat> handleArtifactsRequestForInnerVfcComponent(List<ArtifactDefinition> artifactsToHandle, Resource component, User user, List<ArtifactDefinition> vfcsNewCreatedArtifacts,
- ArtifactOperationInfo operation, boolean shouldLock, boolean inTransaction) {
-
- Either<List<ArtifactDefinition>, ResponseFormat> handleArtifactsResult = null;
+ public List<ArtifactDefinition> handleArtifactsForInnerVfcComponent(List<ArtifactDefinition> artifactsToHandle, Resource component, User user, List<ArtifactDefinition> vfcsNewCreatedArtifacts,
+ ArtifactOperationInfo operation, boolean shouldLock, boolean inTransaction) {
ComponentTypeEnum componentType = component.getComponentType();
List<ArtifactDefinition> uploadedArtifacts = new ArrayList<>();
+ Either<ArtifactDefinition, Operation> result;
+ try {
+ for (ArtifactDefinition artifactDefinition : artifactsToHandle) {
+ result = handleLoadedArtifact(component, user, operation, shouldLock, inTransaction, componentType, artifactDefinition);
+ uploadedArtifacts.add(result.left().value());
+ }
+ } catch (ComponentException e) {
+ log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, component
+ .getName(), e.getResponseFormat());
+ if (ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum())) {
+ vfcsNewCreatedArtifacts.addAll(uploadedArtifacts);
+ }
+ throw e;
+ }
+ return uploadedArtifacts;
+ }
+
+ public Either<ArtifactDefinition, Operation> handleLoadedArtifact(Resource component, User user, ArtifactOperationInfo operation, boolean shouldLock, boolean inTransaction,
+ ComponentTypeEnum componentType, ArtifactDefinition artifactDefinition) {
+ AuditingActionEnum auditingAction = detectAuditingType(operation, "");
+ String componentId = component.getUniqueId();
+ String artifactId = artifactDefinition.getUniqueId();
+ Either<ArtifactDefinition, Operation> result;
Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult;
+ //artifact validation
+ artifactDefinition = validateArtifact(componentId, componentType, operation,
+ artifactId, artifactDefinition, auditingAction, user,
+ component, shouldLock, inTransaction);
+ switch (operation.getArtifactOperationEnum()) {
+ case CREATE:
+ byte[] validPayload = getValidPayload(componentId, artifactDefinition, operation, auditingAction, artifactId, user, componentType, component, null, null);
+ result = createArtifact(component, componentId, artifactDefinition, validPayload,
+ componentType, auditingAction, null, null);
+ break;
+ case UPDATE:
+ validPayload = getValidPayload(componentId, artifactDefinition, operation, auditingAction, artifactId, user, componentType, component, null, null);
+ result = handleUpdate(componentId, componentType, operation, artifactId, artifactDefinition, validPayload, null, null, null, null,
+ auditingAction, user, component, true);
+ break;
+ case DELETE:
+ result = Either.left(handleDeleteInternal(componentId, artifactId, componentType, component));
+ break;
+ case DOWNLOAD:
+ if (artifactGenerationRequired(component, artifactDefinition)) {
+ result = Either.left(generateNotSavedArtifact(component, artifactDefinition));
+ } else {
+ result = Either.left(handleDownload(componentId, artifactId, componentType, component));
+ }
+ break;
+ case LINK:
+ result = Either.left(handleLink(componentId, artifactDefinition, componentType, component));
+ break;
+ default:
+ throw new UnsupportedOperationException("In ArtifactsBusinessLogic received illegal operation: " + operation.getArtifactOperationEnum());
+ }
+ return result;
+ }
+
+ public List<ArtifactDefinition> handleArtifactsRequestForInnerVfcComponent(List<ArtifactDefinition> artifactsToHandle, Resource component, User user, List<ArtifactDefinition> vfcsNewCreatedArtifacts,
+ ArtifactOperationInfo operation, boolean shouldLock, boolean inTransaction) {
+
+ List<ArtifactDefinition> handleArtifactsResult;
+ ComponentTypeEnum componentType = component.getComponentType();
+ List<ArtifactDefinition> uploadedArtifacts = new ArrayList<>();
+ Either<ArtifactDefinition, Operation> actionResult;
String originData;
String origMd5;
try {
@@ -5388,68 +4706,50 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
origMd5 = GeneralUtility.calculateMD5Base64EncodedByString(originData);
actionResult = handleArtifactRequest(component.getUniqueId(), user.getUserId(), componentType, operation, artifact
.getUniqueId(), artifact, origMd5, originData, null, null, null, null, shouldLock, inTransaction);
- if (actionResult.isRight()) {
- log.debug("Failed to upload artifact to component with type {} and name {}. Status is {}. ", componentType, component
- .getName(), actionResult.right().value());
- errorWrapper.setInnerElement(actionResult.right().value());
- if (ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum())) {
- vfcsNewCreatedArtifacts.addAll(uploadedArtifacts);
- }
- break;
- }
- uploadedArtifacts.add(actionResult.left().value().left().value());
+ uploadedArtifacts.add(actionResult.left().value());
}
- if (errorWrapper.isEmpty()) {
- handleArtifactsResult = Either.left(uploadedArtifacts);
- }
- else {
- handleArtifactsResult = Either.right(errorWrapper.getInnerElement());
+ handleArtifactsResult = uploadedArtifacts;
+ }catch (ComponentException e){
+ if (ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum())) {
+ vfcsNewCreatedArtifacts.addAll(uploadedArtifacts);
}
- }
- catch (Exception e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- handleArtifactsResult = Either.right(responseFormat);
- log.debug("Exception occured when handleArtifactsRequestForInnerVfcComponent, error is:{}", e.getMessage(), e);
+ throw e;
}
return handleArtifactsResult;
}
- private ComponentInstance getRelatedComponentInstance(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, Wrapper<ResponseFormat> errorWrapper) {
- ComponentInstance componentInstance = null;
+ private ComponentInstance getRelatedComponentInstance(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName) {
+ ComponentInstance componentInstance;
String normalizedName = ValidationUtils.normalizeComponentInstanceName(resourceInstanceName);
- 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) {
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, resourceInstanceName, RESOURCE_INSTANCE, component
- .getComponentType()
- .getValue(), component.getName()));
- log.debug(COMPONENT_INSTANCE_NOT_FOUND, resourceInstanceName, component.getName());
- }
+ Component component = getComponentByUuid(componentType, componentUuid);
+ componentInstance = (component == null) ? null : component.getComponentInstances()
+ .stream()
+ .filter(ci -> ValidationUtils.normalizeComponentInstanceName(ci.getName())
+ .equals(normalizedName))
+ .findFirst()
+ .orElse(null);
+ if (componentInstance == null) {
+ log.debug(COMPONENT_INSTANCE_NOT_FOUND, resourceInstanceName, component.getName());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, resourceInstanceName,
+ RESOURCE_INSTANCE, component.getComponentType().getValue(), component.getName());
}
return componentInstance;
}
- private ImmutablePair<Component, ComponentInstance> getRelatedComponentComponentInstance(Component component, String resourceInstanceName, Wrapper<ResponseFormat> errorWrapper) {
+ private ImmutablePair<Component, ComponentInstance> getRelatedComponentComponentInstance(Component component, String resourceInstanceName) {
ImmutablePair<Component, ComponentInstance> relatedComponentComponentInstancePair = null;
String normalizedName = ValidationUtils.normalizeComponentInstanceName(resourceInstanceName);
ComponentInstance componentInstance = component.getComponentInstances()
- .stream()
- .filter(ci -> ValidationUtils.normalizeComponentInstanceName(ci.getName())
- .equals(normalizedName))
- .findFirst()
- .orElse(null);
+ .stream()
+ .filter(ci -> ValidationUtils.normalizeComponentInstanceName(ci.getName())
+ .equals(normalizedName))
+ .findFirst()
+ .orElse(null);
if (componentInstance == null) {
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, resourceInstanceName, RESOURCE_INSTANCE, component
- .getComponentType()
- .getValue(), component.getName()));
log.debug(COMPONENT_INSTANCE_NOT_FOUND, resourceInstanceName, component.getName());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, resourceInstanceName,
+ RESOURCE_INSTANCE, component.getComponentType().getValue(), component.getName());
}
else {
relatedComponentComponentInstancePair = new ImmutablePair<>(component, componentInstance);
@@ -5457,68 +4757,57 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return relatedComponentComponentInstancePair;
}
- private ImmutablePair<Component, ComponentInstance> getRelatedComponentComponentInstance(ComponentTypeEnum componentType, String componentUuid, String resourceInstanceName, Wrapper<ResponseFormat> errorWrapper) {
+ private ImmutablePair<Component, ComponentInstance> getRelatedComponentComponentInstance(ComponentTypeEnum componentType,
+ String componentUuid, String resourceInstanceName) {
ComponentInstance componentInstance;
- ImmutablePair<Component, ComponentInstance> relatedComponentComponentInstancePair = null;
- Component component = getLatestComponentByUuid(componentType, componentUuid, errorWrapper);
- if (errorWrapper.isEmpty()) {
- componentInstance = component.getComponentInstances()
- .stream()
- .filter(ci -> ci.getNormalizedName().equals(resourceInstanceName))
- .findFirst()
- .orElse(null);
- if (componentInstance == null) {
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, resourceInstanceName, RESOURCE_INSTANCE, component
- .getComponentType()
- .getValue(), component.getName()));
- log.debug(COMPONENT_INSTANCE_NOT_FOUND, resourceInstanceName, component.getName());
- }
- else {
- relatedComponentComponentInstancePair = new ImmutablePair<>(component, componentInstance);
- }
+ ImmutablePair<Component, ComponentInstance> relatedComponentComponentInstancePair;
+ Component component = getLatestComponentByUuid(componentType, componentUuid);
+ componentInstance = component.getComponentInstances()
+ .stream()
+ .filter(ci -> ci.getNormalizedName().equals(resourceInstanceName))
+ .findFirst()
+ .orElse(null);
+ if (componentInstance == null) {
+ log.debug(COMPONENT_INSTANCE_NOT_FOUND, resourceInstanceName, component.getName());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER,
+ resourceInstanceName, RESOURCE_INSTANCE, component
+ .getComponentType().getValue(), component.getName());
+ }
+ else {
+ relatedComponentComponentInstancePair = new ImmutablePair<>(component, componentInstance);
}
return relatedComponentComponentInstancePair;
}
- private byte[] downloadArtifact(Map<String, ArtifactDefinition> artifacts, String artifactUUID, Wrapper<ResponseFormat> errorWrapper, String componentName) {
+ private byte[] downloadArtifact(Map<String, ArtifactDefinition> artifacts, String artifactUUID, String componentName) {
- byte[] downloadedArtifact = null;
- Either<ImmutablePair<String, byte[]>, ResponseFormat> downloadArtifactEither = null;
+ ImmutablePair<String, byte[]> downloadArtifact;
List<ArtifactDefinition> artifactsList = null;
- ArtifactDefinition deploymentArtifact = null;
+ ArtifactDefinition deploymentArtifact;
if (artifacts != null && !artifacts.isEmpty()) {
artifactsList = artifacts.values()
- .stream()
- .filter(art -> art.getArtifactUUID() != null && art.getArtifactUUID()
- .equals(artifactUUID))
- .collect(Collectors.toList());
+ .stream()
+ .filter(art -> art.getArtifactUUID() != null && art.getArtifactUUID()
+ .equals(artifactUUID))
+ .collect(Collectors.toList());
}
if (artifactsList == null || artifactsList.isEmpty()) {
log.debug("Deployment artifact with uuid {} was not found for component {}", artifactUUID, componentName);
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactUUID));
- }
- if (errorWrapper.isEmpty()) {
- deploymentArtifact = artifactsList.get(0);
- downloadArtifactEither = downloadArtifact(deploymentArtifact);
- if (downloadArtifactEither.isRight()) {
- log.debug("Failed to download artifact {}. ", deploymentArtifact.getArtifactName());
- errorWrapper.setInnerElement(downloadArtifactEither.right().value());
- }
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_NOT_FOUND, artifactUUID);
}
- if (errorWrapper.isEmpty()) {
- log.trace("Succeeded to download artifact with uniqueId {}", deploymentArtifact.getUniqueId());
- downloadedArtifact = downloadArtifactEither.left().value().getRight();
- }
- return downloadedArtifact;
+ deploymentArtifact = artifactsList.get(0);
+ downloadArtifact = downloadArtifact(deploymentArtifact);
+ log.trace("Succeeded to download artifact with uniqueId {}", deploymentArtifact.getUniqueId());
+ return downloadArtifact.getRight();
}
- private Component getLatestComponentByUuid(ComponentTypeEnum componentType, String componentUuid, Wrapper<ResponseFormat> errorWrapper) {
- Component component = null;
+ private Component getLatestComponentByUuid(ComponentTypeEnum componentType, String componentUuid) {
+ Component component;
Either<Component, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentByUuid(componentUuid);
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)));
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
}
else {
component = getComponentRes.left().value();
@@ -5526,20 +4815,20 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return component;
}
- private Component getComponentByUuid(ComponentTypeEnum componentType, String componentUuid, Wrapper<ResponseFormat> errorWrapper) {
- Component component = null;
+ private Component getComponentByUuid(ComponentTypeEnum componentType, String componentUuid) {
+ Component component;
Either<List<Component>, 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)));
+ log.debug(FAILED_FETCH_COMPONENT, componentType, componentUuid, status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
}
else {
List<Component> 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));
+ throw new ByActionStatusComponentException(status);
}
else {
component = value.get(0);
@@ -5548,78 +4837,58 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return component;
}
- private String getLatestParentArtifactDataIdByArtifactUUID(String artifactUUID, Wrapper<ResponseFormat> errorWrapper, String parentId, ComponentTypeEnum componentType) {
- String artifactId = null;
+ private String getLatestParentArtifactDataIdByArtifactUUID(String artifactUUID, String parentId, ComponentTypeEnum componentType) {
ActionStatus actionStatus = ActionStatus.ARTIFACT_NOT_FOUND;
StorageOperationStatus storageStatus;
- ArtifactDefinition latestArtifact = null;
- List<ArtifactDefinition> artifacts = null;
+ ArtifactDefinition latestArtifact;
+ List<ArtifactDefinition> artifacts;
Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getArtifactsRes = artifactToscaOperation.getArtifacts(parentId);
if (getArtifactsRes.isRight()) {
storageStatus = getArtifactsRes.right().value();
log.debug("Couldn't fetch artifacts data for parent component {} with uid {}, error: {}", componentType, parentId, storageStatus);
- if (!storageStatus.equals(StorageOperationStatus.NOT_FOUND)) {
+ if (storageStatus != StorageOperationStatus.NOT_FOUND) {
actionStatus = componentsUtils.convertFromStorageResponse(storageStatus);
}
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID));
+ throw new ByActionStatusComponentException(actionStatus, artifactUUID);
}
- if (errorWrapper.isEmpty()) {
- artifacts = getArtifactsRes.left()
- .value()
- .values()
- .stream()
- .filter(a -> a.getArtifactUUID() != null && a.getArtifactUUID()
- .equals(artifactUUID))
- .collect(Collectors.toList());
- if (artifacts == null || artifacts.isEmpty()) {
- log.debug("Couldn't fetch artifact with UUID {} data for parent component {} with uid {}, error: {}", artifactUUID, componentType, parentId, actionStatus);
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID));
- }
+ artifacts = getArtifactsRes.left()
+ .value()
+ .values()
+ .stream()
+ .filter(a -> a.getArtifactUUID() != null && a.getArtifactUUID()
+ .equals(artifactUUID))
+ .collect(Collectors.toList());
+ if (artifacts == null || artifacts.isEmpty()) {
+ log.debug("Couldn't fetch artifact with UUID {} data for parent component {} with uid {}, error: {}", artifactUUID, componentType, parentId, actionStatus);
+ throw new ByActionStatusComponentException(actionStatus, artifactUUID);
}
- if (errorWrapper.isEmpty()) {
- latestArtifact = artifacts.stream().max((a1, a2) -> {
- int compareRes = Double.compare(Double.parseDouble(a1.getArtifactVersion()), Double.parseDouble(a2.getArtifactVersion()));
- if (compareRes == 0) {
- compareRes = Long.compare(a1.getLastUpdateDate() == null ? 0 : a1.getLastUpdateDate(), a2.getLastUpdateDate() == null ? 0 : a2
- .getLastUpdateDate());
- }
- return compareRes;
- }).get();
- if (latestArtifact == null) {
- log.debug("Couldn't fetch latest artifact with UUID {} data for parent component {} with uid {}, error: {}", artifactUUID, componentType, parentId, actionStatus);
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(actionStatus, artifactUUID));
+ latestArtifact = artifacts.stream().max((a1, a2) -> {
+ int compareRes = Double.compare(Double.parseDouble(a1.getArtifactVersion()), Double.parseDouble(a2.getArtifactVersion()));
+ if (compareRes == 0) {
+ compareRes = Long.compare(a1.getLastUpdateDate() == null ? 0 : a1.getLastUpdateDate(), a2.getLastUpdateDate() == null ? 0 : a2
+ .getLastUpdateDate());
}
+ return compareRes;
+ }).get();
+ if (latestArtifact == null) {
+ log.debug("Couldn't fetch latest artifact with UUID {} data for parent component {} with uid {}, error: {}", artifactUUID, componentType, parentId, actionStatus);
+ throw new ByActionStatusComponentException(actionStatus, artifactUUID);
}
- if (errorWrapper.isEmpty()) {
- artifactId = latestArtifact.getUniqueId();
- }
- return artifactId;
+ return latestArtifact.getUniqueId();
}
- private Component checkoutParentComponent(ComponentTypeEnum componentType, String parentId, String userId, Wrapper<ResponseFormat> errorWrapper) {
+ private Component checkoutParentComponent(ComponentTypeEnum componentType, String parentId, String userId) {
Component component = null;
- Either<User, ActionStatus> getUserRes = userBusinessLogic.getUser(userId, false);
- if (getUserRes.isRight()) {
- log.debug("Could not fetch User of component {} with uid {} to checked out. Status is {}. ", componentType.getNodeType(), parentId, getUserRes
- .right()
- .value());
- errorWrapper.setInnerElement(componentsUtils.getResponseFormat(getUserRes.right().value()));
+ User modifier = userBusinessLogic.getUser(userId, false);
+ LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction("External API checkout", LifecycleChanceActionEnum.UPDATE_FROM_EXTERNAL_API);
+ Either<? extends Component, ResponseFormat> checkoutRes = lifecycleBusinessLogic.changeComponentState(componentType, parentId, modifier, LifeCycleTransitionEnum.CHECKOUT, changeInfo, false, true);
+ if (checkoutRes.isRight()) {
+ log.debug("Could not change state of component {} with uid {} to checked out. Status is {}. ", componentType
+ .getNodeType(), parentId, checkoutRes.right().value().getStatus());
+ throw new ByResponseFormatComponentException(checkoutRes.right().value());
}
- if (errorWrapper.isEmpty()) {
- User modifier = getUserRes.left().value();
- LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction("External API checkout", LifecycleChanceActionEnum.UPDATE_FROM_EXTERNAL_API);
- Either<? extends Component, ResponseFormat> checkoutRes = lifecycleBusinessLogic.changeComponentState(componentType, parentId, modifier, LifeCycleTransitionEnum.CHECKOUT, changeInfo, false, true);
- if (checkoutRes.isRight()) {
- log.debug("Could not change state of component {} with uid {} to checked out. Status is {}. ", componentType
- .getNodeType(), parentId, checkoutRes.right().value().getStatus());
- errorWrapper.setInnerElement(checkoutRes.right().value());
- }
- else {
- component = checkoutRes.left().value();
- }
- }
- return component;
+ return checkoutRes.left().value();
}
private String buildJsonStringForCsarVfcArtifact(ArtifactDefinition artifact) {
@@ -5639,4 +4908,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
void setNodeTemplateOperation(NodeTemplateOperation nodeTemplateOperation) {
this.nodeTemplateOperation = nodeTemplateOperation;
}
+
}
+
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
index c20a2b3b28..c0f08b0bb3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
@@ -84,7 +84,7 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
*/
public Either<PropertyDefinition, ResponseFormat> createAttribute(String resourceId, PropertyDefinition newAttributeDef, String userId) {
Either<PropertyDefinition, ResponseFormat> result = null;
- validateUserExists(userId, "create Attribute", false);
+ validateUserExists(userId);
StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, NodeTypeEnum.Resource);
if (lockResult != StorageOperationStatus.OK) {
@@ -110,17 +110,14 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
if (isAttributeExist(resource.getAttributes(), resourceId, newAttributeDef.getName())) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.ATTRIBUTE_ALREADY_EXIST, newAttributeDef.getName()));
}
- Either<Map<String, DataTypeDefinition>, ResponseFormat> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
- if (eitherAllDataTypes.isRight()) {
- return Either.right(eitherAllDataTypes.right().value());
- }
+ Map<String, DataTypeDefinition> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
// validate property default values
- Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newAttributeDef, eitherAllDataTypes.left().value());
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newAttributeDef, eitherAllDataTypes);
if (defaultValuesValidation.isRight()) {
return Either.right(defaultValuesValidation.right().value());
}
- handleDefaultValue(newAttributeDef, eitherAllDataTypes.left().value());
+ handleDefaultValue(newAttributeDef, eitherAllDataTypes);
// add the new attribute to resource on graph
// need to get StorageOpaerationStatus and convert to ActionStatus from
@@ -157,7 +154,7 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
*/
public Either<PropertyDefinition, ResponseFormat> getAttribute(String resourceId, String attributeId, String userId) {
- validateUserExists(userId, "get Attribute", false);
+ validateUserExists(userId);
// Get the resource from DB
Either<Resource, StorageOperationStatus> status = toscaOperationFacade.getToscaElement(resourceId);
@@ -213,19 +210,16 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
if (eitherAttribute.isRight()) {
return Either.right(eitherAttribute.right().value());
}
- Either<Map<String, DataTypeDefinition>, ResponseFormat> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
- if (eitherAllDataTypes.isRight()) {
- return Either.right(eitherAllDataTypes.right().value());
- }
+ Map<String, DataTypeDefinition> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
// validate attribute default values
- Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newAttDef, eitherAllDataTypes.left().value());
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newAttDef, eitherAllDataTypes);
if (defaultValuesValidation.isRight()) {
return Either.right(defaultValuesValidation.right().value());
}
// add the new property to resource on graph
- StorageOperationStatus validateAndUpdateAttribute = propertyOperation.validateAndUpdateProperty(newAttDef, eitherAllDataTypes.left().value());
+ StorageOperationStatus validateAndUpdateAttribute = propertyOperation.validateAndUpdateProperty(newAttDef, eitherAllDataTypes);
if (validateAndUpdateAttribute != StorageOperationStatus.OK) {
log.debug("Problem while updating attribute with id {}. Reason - {}", attributeId, validateAndUpdateAttribute);
result = Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(validateAndUpdateAttribute), resource.getName()));
@@ -261,7 +255,7 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
Either<PropertyDefinition, ResponseFormat> result = null;
- validateUserExists(userId, "delete Attribute", false);
+ validateUserExists(userId);
StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceId, NodeTypeEnum.Resource);
if (lockResult != StorageOperationStatus.OK) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index b1356fc11b..42e8d9bad1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -26,21 +26,18 @@ import com.google.gson.JsonElement;
import fj.data.Either;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
@@ -48,13 +45,17 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.IComplexDefaultValue;
import org.openecomp.sdc.be.model.IPropertyInputCommon;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.User;
@@ -79,30 +80,36 @@ import org.openecomp.sdc.be.model.tosca.ToscaType;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
import org.openecomp.sdc.be.model.tosca.validators.DataTypeValidatorConverter;
import org.openecomp.sdc.be.model.tosca.validators.PropertyTypeValidator;
-import org.openecomp.sdc.be.user.IUserBusinessLogic;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
public abstract class BaseBusinessLogic {
private static final String FAILED_TO_LOCK_COMPONENT_ERROR = "Failed to lock component {} error - {}";
- private static final Logger log = Logger.getLogger(BaseBusinessLogic.class.getName());
-
+ private static final Logger log = Logger.getLogger(BaseBusinessLogic.class.getName());
private static final String EMPTY_VALUE = null;
private static final String SCHEMA_DOESN_T_EXISTS_FOR_PROPERTY_OF_TYPE = "Schema doesn't exists for property of type {}";
private static final String PROPERTY_IN_SCHEMA_DEFINITION_INSIDE_PROPERTY_OF_TYPE_DOESN_T_EXIST = "Property in Schema Definition inside property of type {} doesn't exist";
private static final String ADD_PROPERTY_VALUE = "Add property value";
private static final String THE_VALUE_OF_PROPERTY_FROM_TYPE_IS_INVALID = "The value {} of property from type {} is invalid";
- protected final IGroupTypeOperation groupTypeOperation;
- protected final InterfaceOperation interfaceOperation;
- protected final IElementOperation elementDao;
+ protected IGroupTypeOperation groupTypeOperation;
+ protected InterfaceOperation interfaceOperation;
+ protected IElementOperation elementDao;
protected ComponentsUtils componentsUtils;
- protected IUserBusinessLogic userAdmin;
+ protected UserBusinessLogic userAdmin;
protected IGraphLockOperation graphLockOperation;
protected JanusGraphDao janusGraphDao;
protected JanusGraphGenericDao janusGraphGenericDao;
@@ -110,12 +117,12 @@ public abstract class BaseBusinessLogic {
protected ApplicationDataTypeCache applicationDataTypeCache;
protected ToscaOperationFacade toscaOperationFacade;
protected ApplicationDataTypeCache dataTypeCache;
- final IGroupOperation groupOperation;
- final IGroupInstanceOperation groupInstanceOperation;
- final InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
- PolicyTypeOperation policyTypeOperation;
- protected final ArtifactsOperations artifactToscaOperation;
- private UserValidations userValidations;
+ protected IGroupOperation groupOperation;
+ protected IGroupInstanceOperation groupInstanceOperation;
+ protected InterfaceLifecycleOperation interfaceLifecycleTypeOperation;
+ protected PolicyTypeOperation policyTypeOperation;
+ protected ArtifactsOperations artifactToscaOperation;
+ protected UserValidations userValidations;
DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
@@ -190,154 +197,157 @@ public abstract class BaseBusinessLogic {
return userValidations.validateUserNotEmpty(user, ecompErrorContext);
}
- protected User validateUserExists(User user, String ecompErrorContext, boolean inTransaction) {
- return userValidations.validateUserExists(user.getUserId(), ecompErrorContext, inTransaction);
- }
-
- protected void validateUserExist(String userId, String ecompErrorContext) {
- userValidations.validateUserExist(userId, ecompErrorContext);
+ protected User validateUserExists(String userId) {
+ return userValidations.validateUserExists(userId);
}
- Either<User, ActionStatus> validateUserExistsActionStatus(String userId, String ecompErrorContext) {
- return userValidations.validateUserExistsActionStatus(userId, ecompErrorContext);
+ public User validateUserExists(User user) {
+ return userValidations.validateUserExists(user);
}
- public User validateUserExists(String userId, String ecompErrorContext, boolean inTransaction) {
- return userValidations.validateUserExists(userId, ecompErrorContext, inTransaction);
+ ActionStatus validateUserExistsActionStatus(String userId) {
+ return userValidations.validateUserExistsActionStatus(userId);
}
protected void validateUserRole(User user, List<Role> roles) {
userValidations.validateUserRole(user, roles);
}
- protected Either<Boolean, ResponseFormat> lockComponent(Component component, String ecompErrorContext) {
- return lockComponent(component.getUniqueId(), component, ecompErrorContext);
+ protected void lockComponent(Component component, String ecompErrorContext) {
+ lockComponent(component.getUniqueId(), component, ecompErrorContext);
}
- protected Either<Component, ResponseFormat> lockComponent(Component component, boolean shoulLock, String ecompErrorContext) {
- return shoulLock ? lockComponent(component.getUniqueId(), component, ecompErrorContext)
- .either(l -> Either.left(component), Either::right) : Either.left(component);
+ protected boolean isVolumeGroup(List<String> artifactsInGroup,List <ArtifactDefinition> deploymentArtifacts) {
+ for (String artifactId : artifactsInGroup) {
+ ArtifactDefinition artifactDef = ArtifactUtils.findArtifactInList(deploymentArtifacts, artifactId);
+ if (artifactDef != null
+ && artifactDef.getArtifactType().equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType())) {
+ return true;
+ }
+ }
+ return false;
}
- protected Either<Boolean, ResponseFormat> lockComponent(String componentId, Component component, String ecompErrorContext) {
- return lockElement( componentId, component, ecompErrorContext)
- .right()
- .map(r -> logAndConvertError(r, component.getUniqueId(), component.getName()) );
+ protected void lockComponent(Component component, boolean shouldLock, String ecompErrorContext) {
+ if(shouldLock){
+ lockComponent(component.getUniqueId(), component, ecompErrorContext);
+ }
}
- protected void lockComponent(String componentId, Component component, boolean needLock, String ecompErrorContext) {
- if (needLock){
- lockElement( componentId, component, ecompErrorContext)
- .left()
- .on(r -> logAndThrowException(r, component.getUniqueId(), component.getName()) );
+ protected void lockComponent(String componentId, Component component, String ecompErrorContext) {
+ ActionStatus lock = lockElement(componentId, component, ecompErrorContext);
+ if ( lock!= ActionStatus.OK ) {
+ logAndThrowComponentException(lock, component.getUniqueId(), component.getName());
}
}
- private Boolean logAndThrowException(ActionStatus status, String componentId, String name){
- log.debug(FAILED_TO_LOCK_COMPONENT_ERROR, componentId, status);
- throw new ByActionStatusComponentException(status, name);
+ protected void lockComponent(String componentId, Component component, boolean needLock, String ecompErrorContext) {
+ if (needLock) {
+ lockComponent(componentId, component, ecompErrorContext);
+ }
}
- private ResponseFormat logAndConvertError(ActionStatus status, String componentId, String name){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(status, name);
+ private ResponseFormat logAndThrowComponentException(ActionStatus status, String componentId, String name){
log.debug(FAILED_TO_LOCK_COMPONENT_ERROR, componentId, status);
- return responseFormat;
+ throw new ByActionStatusComponentException(status, name);
}
- private Either<Boolean, ActionStatus> lockElement(String componentId, Component component, String ecompErrorContext) {
+ private ActionStatus lockElement(String componentId, Component component, String ecompErrorContext) {
ComponentTypeEnum componentType = component.getComponentType();
NodeTypeEnum nodeType = componentType.getNodeType();
StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponent(componentId, nodeType);
- if (lockResourceStatus.equals(StorageOperationStatus.OK)) {
- return Either.left(true);
+ if (lockResourceStatus == StorageOperationStatus.OK) {
+ return ActionStatus.OK;
} else {
BeEcompErrorManager.getInstance().logBeFailedLockObjectError(ecompErrorContext, nodeType.getName(), componentId);
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(lockResourceStatus, componentType);
- return Either.right(actionStatus);
+ return componentsUtils.convertFromStorageResponse(lockResourceStatus, componentType);
}
}
- protected void unlockComponent(Either<?, ?> either, Component component, boolean inTransaction) {
- ComponentTypeEnum componentType = component.getComponentType();
- NodeTypeEnum nodeType = componentType.getNodeType();
- if (!inTransaction) {
- if (either == null || either.isRight()) {
- janusGraphDao.rollback();
- } else {
- janusGraphDao.commit();
+ protected void unlockComponent(boolean failed, Component component, boolean inTransaction) {
+ if (component != null) {
+ ComponentTypeEnum componentType = component.getComponentType();
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ if (!inTransaction) {
+ if (failed) {
+ janusGraphDao.rollback();
+ } else {
+ janusGraphDao.commit();
+ }
}
+ // unlock resource
+ graphLockOperation.unlockComponent(component.getUniqueId(), nodeType);
}
- // unlock resource
- graphLockOperation.unlockComponent(component.getUniqueId(), nodeType);
+ else log.debug("component is NULL");
}
- protected void unlockComponent(Either<?, ?> either, Component component) {
- unlockComponent(either, component, false);
+ protected void unlockComponent(boolean failed, Component component) {
+ unlockComponent(failed, component, false);
}
- void unlockComponentById(Either<?, ?> either, String componentId) {
+ void unlockComponentById(boolean failed, String componentId) {
Either<Component, StorageOperationStatus> component = toscaOperationFacade.getToscaElement(componentId);
if(component.isLeft()) {
- unlockComponent(either, component.left().value(), false);
+ unlockComponent(failed, component.left().value(), false);
}
}
- <T> Either<Boolean, ResponseFormat> validateJsonBody(T bodyObject, Class<T> clazz) {
+ <T> Boolean validateJsonBody(T bodyObject, Class<T> clazz) {
if (bodyObject == null) {
log.debug("Invalid JSON received for object of type {}", clazz.getSimpleName());
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
} else {
- return Either.left(true);
+ return true;
}
}
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType(String componentType) {
+
+ ComponentTypeEnum validateComponentType(String componentType) {
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
if (componentTypeEnum == null) {
log.debug("Invalid component type {}", componentType);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, componentType));
+ throw new ByActionStatusComponentException(ActionStatus.UNSUPPORTED_ERROR, componentType);
} else {
- return Either.left(componentTypeEnum);
+ return componentTypeEnum;
}
}
- protected Either<Component, ResponseFormat> validateComponentExists(String componentId, ComponentTypeEnum componentType, ComponentParametersView filter) {
- return toscaOperationFacade.getToscaElement(componentId, filter == null ? new ComponentParametersView() : filter)
- .right()
- .map(err -> handleGetComponentError(componentId, componentType, err))
- .left()
- .bind(cmpt -> validateComponentType(cmpt, componentType));
+ Component validateComponentExists(String componentId, ComponentTypeEnum componentType, ComponentParametersView filter) {
+
+ Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(componentId, filter == null ? new ComponentParametersView() : filter);
+ if(toscaElement.isRight()){
+ handleGetComponentError(componentId, componentType, toscaElement.right().value());
+ }
+ return validateComponentType(toscaElement.left().value(), componentType);
}
- private Either<Component, ResponseFormat> validateComponentType(Component cmpt, ComponentTypeEnum componentType) {
+ private Component validateComponentType(Component cmpt, ComponentTypeEnum componentType) {
if (componentType != cmpt.getComponentType()) {
log.debug("component {} is not of requested type {}", cmpt.getUniqueId(), componentType);
- ActionStatus cmptNotFoundError = componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, componentType);
- return Either.right(componentsUtils.getResponseFormat(cmptNotFoundError));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, componentType));
}
- return Either.left(cmpt);
+ return cmpt;
}
- <T extends PropertyDataDefinition> Either<String, ResponseFormat> updateInputPropertyObjectValue(T property) {
+ <T extends PropertyDataDefinition> String updateInputPropertyObjectValue(T property) {
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypesEither = dataTypeCache.getAll();
if (allDataTypesEither.isRight()) {
JanusGraphOperationStatus status = allDataTypesEither.right().value();
BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status))));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)));
}
Map<String, DataTypeDefinition> allDataTypes = allDataTypesEither.left().value();
String propertyType = property.getType();
String innerType = getInnerType(property);
// Specific Update Logic
Either<Object, Boolean> isValid =
- propertyOperation.validateAndUpdatePropertyValue(propertyType, (String) property.getValue(), true,
- innerType, allDataTypes);
+ propertyOperation.validateAndUpdatePropertyValue(propertyType, (String) property.getValue(), true,
+ innerType, allDataTypes);
String newValue = property.getValue();
if (isValid.isRight()) {
Boolean res = isValid.right().value();
if (Boolean.FALSE.equals(res)) {
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(
- JanusGraphOperationStatus.ILLEGAL_ARGUMENT))));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT)));
}
} else {
Object object = isValid.left().value();
@@ -345,10 +355,10 @@ public abstract class BaseBusinessLogic {
newValue = object.toString();
}
}
- return Either.left(newValue);
+ return newValue;
}
- private <T extends PropertyDataDefinition> String getInnerType(T property){
+ <T extends PropertyDataDefinition> String getInnerType(T property){
ToscaPropertyType type = ToscaPropertyType.isValidType(property.getType());
log.debug("#getInnerType - The type of the property {} is {}", property.getUniqueId(), property.getType());
String innerType = null;
@@ -367,35 +377,41 @@ public abstract class BaseBusinessLogic {
return innerType;
}
- public Either<Boolean, ResponseFormat> validateCanWorkOnComponent(Component component, String userId) {
- Either<Boolean, ResponseFormat> canWork = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ public void validateCanWorkOnComponent(Component component, String userId) {
+ ActionStatus actionStatus = ActionStatus.RESTRICTED_OPERATION;
+ // verify resource is not archived
+ if (component.isArchived() == true){
+ actionStatus = ActionStatus.COMPONENT_IS_ARCHIVED;
+ throw new ByActionStatusComponentException(actionStatus, component.getName());
+ }
+
if (component.getLifecycleState() != LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
log.debug("Component {} is not checked-out", component.getName());
- return canWork;
+ throw new ByActionStatusComponentException(actionStatus);
}
// verify userId is not null
if (userId == null) {
log.debug("Current user userId is null");
- return canWork;
+ throw new ByActionStatusComponentException(actionStatus);
}
// verify component last update user is the current user
String lastUpdaterUserId = component.getLastUpdaterUserId();
if (!userId.equals(lastUpdaterUserId)) {
log.debug("Current user is not last updater, last updater userId: {}, current user userId: {}", lastUpdaterUserId, userId);
- return canWork;
+ throw new ByActionStatusComponentException(actionStatus);
}
// verify resource is not deleted
if (Boolean.TRUE.equals(component.getIsDeleted())) {
log.debug("Component {} is marked as deleted", component.getUniqueId());
- return canWork;
+ throw new ByActionStatusComponentException(actionStatus);
}
- return Either.left(true);
}
+
ComponentTypeEnum getComponentTypeByParentComponentType(ComponentTypeEnum parentComponentType) {
switch (parentComponentType) {
case SERVICE:
@@ -410,19 +426,20 @@ public abstract class BaseBusinessLogic {
}
- protected Either<Map<String, DataTypeDefinition>, ResponseFormat> getAllDataTypes(ApplicationDataTypeCache applicationDataTypeCache) {
+
+ protected Map<String, DataTypeDefinition> getAllDataTypes(ApplicationDataTypeCache applicationDataTypeCache) {
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll();
if (allDataTypes.isRight()) {
JanusGraphOperationStatus operationStatus = allDataTypes.right().value();
if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) {
BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY));
+ throw new ByActionStatusComponentException(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY);
} else {
BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
}
- return Either.left(allDataTypes.left().value());
+ return allDataTypes.left().value();
}
Either<Boolean, ResponseFormat> validatePropertyDefaultValue(IComplexDefaultValue property, Map<String, DataTypeDefinition> dataTypes) {
@@ -448,10 +465,10 @@ public abstract class BaseBusinessLogic {
ResponseFormat responseFormat;
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType,
- property.getDefaultValue());
+ property.getDefaultValue());
} else {
responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type,
- property.getDefaultValue());
+ property.getDefaultValue());
}
return Either.right(responseFormat);
@@ -525,7 +542,7 @@ public abstract class BaseBusinessLogic {
NodeTypeEnum nodeType = componentType.getNodeType();
StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponentByName(name, nodeType);
- if (lockResourceStatus.equals(StorageOperationStatus.OK)) {
+ if (lockResourceStatus == StorageOperationStatus.OK) {
return Either.left(true);
} else {
BeEcompErrorManager.getInstance().logBeFailedLockObjectError(ecompErrorContext, nodeType.getName(), name);
@@ -536,18 +553,17 @@ public abstract class BaseBusinessLogic {
}
}
- protected Either<Component, ResponseFormat> validateComponentExistsByFilter(String componentId, ComponentTypeEnum componentType, ComponentParametersView componentParametersView) {
+ protected Component validateComponentExistsByFilter(String componentId, ComponentTypeEnum componentType, ComponentParametersView componentParametersView) {
return toscaOperationFacade.getToscaElement(componentId, componentParametersView)
- .right()
- .map(err -> handleGetComponentError(componentId, componentType, err));
+ .left()
+ .on(err -> handleGetComponentError(componentId, componentType, err));
}
- private ResponseFormat handleGetComponentError(String componentId, ComponentTypeEnum componentType, StorageOperationStatus getComponentError) {
+ private Component handleGetComponentError(String componentId, ComponentTypeEnum componentType, StorageOperationStatus getComponentError) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentError, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, componentId);
log.debug("error fetching component with id {}. error status: {}", componentId, getComponentError);
- return responseFormat;
+ throw new ByActionStatusComponentException(actionStatus, componentId);
}
@SafeVarargs
@@ -566,7 +582,7 @@ public abstract class BaseBusinessLogic {
Boolean res = isValid.right().value();
if (Boolean.FALSE.equals(res)) {
throw new StorageException(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(
- JanusGraphOperationStatus.ILLEGAL_ARGUMENT));
+ JanusGraphOperationStatus.ILLEGAL_ARGUMENT));
}
} else {
Object object = isValid.left().value();
@@ -579,7 +595,7 @@ public abstract class BaseBusinessLogic {
if (Boolean.FALSE.equals(pair.getRight())) {
BeEcompErrorManager.getInstance().logBeInvalidValueError(ADD_PROPERTY_VALUE, pair.getLeft(), property.getName(), propertyType);
throw new StorageException(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(
- JanusGraphOperationStatus.ILLEGAL_ARGUMENT));
+ JanusGraphOperationStatus.ILLEGAL_ARGUMENT));
}
return newValue;
}
@@ -697,7 +713,7 @@ public abstract class BaseBusinessLogic {
}
public <T extends ToscaDataDefinition> Either<List<T>, ResponseFormat> declareProperties(String userId, String componentId,
- ComponentTypeEnum componentTypeEnum, ComponentInstInputsMap componentInstInputsMap) {
+ ComponentTypeEnum componentTypeEnum, ComponentInstInputsMap componentInstInputsMap) {
return Either.left(new ArrayList<>());
}
@@ -705,7 +721,7 @@ public abstract class BaseBusinessLogic {
public <T extends PropertyDataDefinition> List<PropertyConstraint> setInputConstraint(T inputDefinition) {
if (StringUtils.isNotBlank(inputDefinition.getParentPropertyType())
&& StringUtils.isNotBlank(inputDefinition.getSubPropertyInputPath())) {
- return setConstraint(inputDefinition);
+ return setConstraint(inputDefinition);
}
return Collections.emptyList();
@@ -756,4 +772,53 @@ public abstract class BaseBusinessLogic {
return type;
}
+
+
+ protected void rollbackWithException(StorageException e) {
+ janusGraphDao.rollback();
+ throw e;
+ }
+
+ protected void rollbackWithException(ComponentException e) {
+ janusGraphDao.rollback();
+ throw e;
+ }
+
+ protected void unlockRollbackWithException(Component component, RuntimeException e) {
+ janusGraphDao.rollback();
+ graphLockOperation.unlockComponent(component.getUniqueId(), component.getComponentType().getNodeType());
+ throw e;
+ }
+
+ protected void unlockWithCommit(Component component){
+ ComponentTypeEnum componentType = component.getComponentType();
+ NodeTypeEnum nodeType = componentType.getNodeType();
+ janusGraphDao.commit();
+ graphLockOperation.unlockComponent(component.getUniqueId(), nodeType);
+ }
+
+ protected ComponentInstance componentInstanceException(StorageOperationStatus storageOperationStatus) {
+ throw new StorageException(storageOperationStatus);
+ }
+
+ protected Component componentException(StorageOperationStatus storageOperationStatus) {
+ throw new StorageException(storageOperationStatus);
+ }
+
+ protected PolicyDefinition storageExceptionPolicyDefinition(StorageOperationStatus storageOperationStatus) {
+ throw new StorageException(storageOperationStatus);
+ }
+
+ protected PolicyDefinition componentExceptionPolicyDefinition(ResponseFormat responseFormat) {
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+
+ protected Component componentException(ResponseFormat responseFormat) {
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+
+ protected List<ComponentInstanceProperty> componentInstancePropertyListException(StorageOperationStatus storageOperationStatus) {
+ throw new StorageException(storageOperationStatus);
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CADIHealthCheck.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CADIHealthCheck.java
new file mode 100644
index 0000000000..f94528c64a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CADIHealthCheck.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl;
+
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Component;
+
+import static org.openecomp.sdc.common.api.Constants.HC_COMPONENT_CADI;
+import static org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus.DOWN;
+
+@Component
+public class CADIHealthCheck {
+
+ private static CADIHealthCheck cadiHealthCheckInstance = new CADIHealthCheck();;
+
+ private static HealthCheckInfo.HealthCheckStatus isCADIUpOrDown = DOWN;
+
+ private static final Logger log = Logger.getLogger(CADIHealthCheck.class.getName());
+
+ public static CADIHealthCheck getCADIHealthCheckInstance() {
+ return cadiHealthCheckInstance;
+ }
+
+ public void setIsCADIUp(HealthCheckInfo.HealthCheckStatus cadiStatus) {
+ log.debug("Setting cadiHealthCheckInstance status to: {}", cadiStatus.toString());
+ isCADIUpOrDown = cadiStatus;
+ }
+
+ public static HealthCheckInfo getCADIStatus() {
+ log.debug("getCADIStatus: Checking whether CADI was up or down while its init.");
+ String description = "OK";
+ if (isCADIUpOrDown == DOWN){
+ description = "CADI filter failed initialization";
+ }
+ return new HealthCheckInfo(HC_COMPONENT_CADI, isCADIUpOrDown, null,
+ description);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogic.java
index 63aa08063a..4bfc6509c6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CapabilitiesBusinessLogic.java
@@ -20,6 +20,7 @@ import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.CapabilitiesValidation;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -131,7 +132,7 @@ public class CapabilitiesBusinessLogic extends BaseBusinessLogic {
private Either<Component, ResponseFormat> validateUserAndCapabilities(User user, String componentId,
String errorContext,
List<CapabilityDefinition> capabilityDefinitions ) {
- validateUserExists(user.getUserId(), errorContext, true);
+ validateUserExists(user.getUserId());
Either<Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()) {
return Either.right(componentEither.right().value());
@@ -194,7 +195,7 @@ public class CapabilitiesBusinessLogic extends BaseBusinessLogic {
public Either<List<CapabilityDefinition>, ResponseFormat> updateCapabilities(String componentId,
List<CapabilityDefinition> capabilityDefinitions,
User user, String errorContext, boolean lock) {
- validateUserExists(user.getUserId(), errorContext, true);
+ validateUserExists(user.getUserId());
Either<Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()) {
return Either.right(componentEither.right().value());
@@ -371,7 +372,7 @@ public class CapabilitiesBusinessLogic extends BaseBusinessLogic {
public Either<CapabilityDefinition, ResponseFormat> getCapability(String componentId, String capabilityToGet,
User user, boolean lock) {
- validateUserExists(user.getUserId(), GET_CAPABILITIES, true);
+ validateUserExists(user.getUserId());
Either<Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()) {
return Either.right(componentEither.right().value());
@@ -423,7 +424,7 @@ public class CapabilitiesBusinessLogic extends BaseBusinessLogic {
public Either<CapabilityDefinition, ResponseFormat> deleteCapability(String componentId, String capabilityIdToDelete,
User user, boolean lock) {
- validateUserExists(user.getUserId(), DELETE_CAPABILITIES, true);
+ validateUserExists(user.getUserId());
Either<Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()) {
return Either.right(componentEither.right().value());
@@ -546,12 +547,12 @@ public class CapabilitiesBusinessLogic extends BaseBusinessLogic {
private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock, Component component, String action) {
if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action);
- if (lockResult.isRight()) {
- LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, component.getName(),
- lockResult.right().value().getFormattedMessage());
+ try {
+ lockComponent(component.getUniqueId(), component, action);
+ } catch (ComponentException e){
+ LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, component.getName(), e.getMessage());
janusGraphDao.rollback();
- return Either.right(lockResult.right().value());
+ throw e;
}
}
return Either.left(true);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java
index 56cad89569..d5fe938bca 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CassandraHealthCheck.java
@@ -33,10 +33,16 @@ import org.openecomp.sdc.common.util.GeneralUtility;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
-
+import javax.annotation.PreDestroy;
import java.io.FileInputStream;
import java.io.InputStream;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
@Component("cassandra-health-check")
public class CassandraHealthCheck {
@@ -50,6 +56,7 @@ public class CassandraHealthCheck {
private int HC_FormulaNumber;
private SdcSchemaUtils sdcSchemaUtils;
+
@PostConstruct
private void init() {
@@ -92,13 +99,8 @@ public class CassandraHealthCheck {
log.info("creating cluster for Cassandra Health Check.");
//Create cluster from nodes in cassandra configuration
- cluster = sdcSchemaUtils.createCluster();
- if (cluster == null) {
- log.error("Failure create cassandra cluster.");
- return;
- }
-
- Metadata metadata = cluster.getMetadata();
+
+ Metadata metadata = sdcSchemaUtils.getMetadata();
if (metadata == null) {
log.error("Failure get cassandra metadata.");
@@ -153,7 +155,8 @@ public class CassandraHealthCheck {
}
}
-
+
+
public boolean getCassandraStatus() {
if (GeneralUtility.isEmptyString(localDataCenterName)) {
@@ -161,17 +164,19 @@ public class CassandraHealthCheck {
return false;
}
- Cluster cluster = null;
+
Session session = null;
try {
- log.info("creating cluster for Cassandra for monitoring.");
- cluster = sdcSchemaUtils.createCluster();
- if (cluster == null) {
- log.error("Failure create cassandra cluster.");
+ log.info("creating cluster for Cassandra for monitoring.");
+
+ session = sdcSchemaUtils.connect();
+ log.info("The cassandra session is {}", session);
+ if(session == null){
+ log.error("Failed to connect to cassandra ");
return false;
}
- session = cluster.connect();
- Metadata metadata = cluster.getMetadata();
+
+ Metadata metadata = sdcSchemaUtils.getMetadata();
if (metadata == null) {
log.error("Failure get cassandra metadata.");
@@ -192,11 +197,18 @@ public class CassandraHealthCheck {
return false;
} finally {
if (session != null) {
+ log.info("close session for Cassandra for monitoring.");
session.close();
}
- if (cluster != null) {
- cluster.close();
- }
+
+ }
+ }
+
+ @PreDestroy
+ public void closeClient() {
+ if (sdcSchemaUtils!= null) {
+ sdcSchemaUtils.closeCluster();
}
+ log.info("** sdcSchemaUtils cluster closed");
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java
index 0df7c7066d..0eeb1a7086 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java
@@ -38,7 +38,11 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
@Component("categoriesImportManager")
@@ -80,25 +84,9 @@ public class CategoriesImportManager {
List<SubCategoryDefinition> newsubcategories = new ArrayList<>();
List<SubCategoryDefinition> subcategories = category.getSubcategories();
if (subcategories != null) {
- for (SubCategoryDefinition subcategory : subcategories) {
- Either<SubCategoryDefinition, ResponseFormat> createdSubCategory = createSubCategorieDeo(entry, newcategory, subcategory, nodeTypeSubCategory);
- if (createdSubCategory.isRight()) {
- return Either.right(createdCategoryRes.right().value());
- }
- SubCategoryDefinition newsubcategory = createdSubCategory.left().value();
- List<GroupingDefinition> groupings = subcategory.getGroupings();
- if (groupings != null) {
- List<GroupingDefinition> newgroupings = new ArrayList<>();
- for (GroupingDefinition grouping : groupings) {
- Either<GroupingDefinition, ResponseFormat> createdGrouping = createGroupingDeo(entry, grouping, subcategory, category, nodeTypeGroup);
- if (createdGrouping.isRight()) {
- return Either.right(createdCategoryRes.right().value());
- }
- newgroupings.add(createdGrouping.left().value());
- }
- newsubcategory.setGroupings(newgroupings);
- }
- newsubcategories.add(newsubcategory);
+ boolean createdNewSubCategory = isCreatedNewSubCategory(entry, nodeTypeSubCategory, nodeTypeGroup, category, newcategory, newsubcategories, subcategories);
+ if (!createdNewSubCategory) {
+ return Either.right(createdCategoryRes.right().value());
}
newcategory.setSubcategories(newsubcategories);
}
@@ -109,12 +97,36 @@ public class CategoriesImportManager {
return Either.left(result);
}
+ private boolean isCreatedNewSubCategory(Entry<String, List<CategoryDefinition>> entry, NodeTypeEnum nodeTypeSubCategory, NodeTypeEnum nodeTypeGroup, CategoryDefinition category, CategoryDefinition newcategory, List<SubCategoryDefinition> newsubcategories, List<SubCategoryDefinition> subcategories) {
+ for (SubCategoryDefinition subcategory : subcategories) {
+ Either<SubCategoryDefinition, ResponseFormat> createdSubCategory = createSubCategorieDeo(entry, newcategory, subcategory, nodeTypeSubCategory);
+ if (createdSubCategory.isRight()) {
+ return false;
+ }
+ SubCategoryDefinition newsubcategory = createdSubCategory.left().value();
+ List<GroupingDefinition> groupings = subcategory.getGroupings();
+ if (groupings != null) {
+ List<GroupingDefinition> newgroupings = new ArrayList<>();
+ for (GroupingDefinition grouping : groupings) {
+ Either<GroupingDefinition, ResponseFormat> createdGrouping = createGroupingDeo(entry, grouping, subcategory, category, nodeTypeGroup);
+ if (createdGrouping.isRight()) {
+ return false;
+ }
+ newgroupings.add(createdGrouping.left().value());
+ }
+ newsubcategory.setGroupings(newgroupings);
+ }
+ newsubcategories.add(newsubcategory);
+ }
+ return true;
+ }
+
private Either<GroupingDefinition, ResponseFormat> createGroupingDeo(Map.Entry<String, List<CategoryDefinition>> entry, GroupingDefinition grouping, SubCategoryDefinition subcategory, CategoryDefinition category, NodeTypeEnum nodeTypeGroup) {
log.debug("createGroupingDeo: creating grouping {}", grouping);
Either<GroupingDefinition, ActionStatus> createdGrouping = elementOperation.createGrouping(subcategory.getUniqueId(), grouping, nodeTypeGroup);
if (createdGrouping.isRight()) {
- if (ActionStatus.COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY.equals(createdGrouping.right().value())) {
+ if (ActionStatus.COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY == createdGrouping.right().value()) {
log.debug(" create grouping for {} group {} already exists ", entry.getKey(), grouping.getName());
String groupingId = UniqueIdBuilder.buildGroupingUid(grouping.getUniqueId(), grouping.getNormalizedName());
createdGrouping = elementOperation.getGroupingUniqueForType(nodeTypeGroup, groupingId);
@@ -139,7 +151,7 @@ public class CategoriesImportManager {
log.debug("createSubCategorieDeo: creating subcategory {}", subcategory);
Either<SubCategoryDefinition, ActionStatus> createdSubCategory = elementOperation.createSubCategory(newcategory.getUniqueId(), subcategory, nodeTypeSubCategory);
if (createdSubCategory.isRight()) {
- if (ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY.equals(createdSubCategory.right().value())) {
+ if (ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY == createdSubCategory.right().value()) {
log.debug(" create subcategory for {} category {} subcategory {} already exists retrieving", entry.getKey(), newcategory.getName(), subcategory.getName());
String subCategoryId = UniqueIdBuilder.buildSubCategoryUid(newcategory.getUniqueId(), subcategory.getNormalizedName());
createdSubCategory = elementOperation.getSubCategory(nodeTypeSubCategory, subCategoryId);
@@ -162,7 +174,7 @@ public class CategoriesImportManager {
Either<CategoryDefinition, ActionStatus> createdCategory = elementOperation.createCategory(category, nodeTypeCategory);
if (createdCategory.isRight()) {
log.debug("Failed to create category for {} {} error {}", entry.getKey(), category.getName(), createdCategory.right().value());
- if (!ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS.equals(createdCategory.right().value())) {
+ if (ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS != createdCategory.right().value()) {
return Either.right(componentsUtils.getResponseFormat(createdCategory.right().value()));
} else {
log.debug("createCategorieDeo: category exists {} retriving.", category);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
index 4dd012fcf7..c3ecda3e03 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
@@ -32,7 +32,11 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.ToscaTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.api.TypeOperations;
@@ -43,7 +47,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiFunction;
import java.util.function.Consumer;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
index 785b545d7e..83e4cf4c65 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
@@ -22,20 +22,22 @@
package org.openecomp.sdc.be.components.impl;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
+import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentIconValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentNameValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentProjectCodeValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentTagsValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -48,8 +50,8 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+import org.openecomp.sdc.be.facade.operations.CatalogOperation;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapReqDef;
import org.openecomp.sdc.be.model.Component;
@@ -89,13 +91,31 @@ import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
- protected final ArtifactsBusinessLogic artifactsBusinessLogic;
+ protected ArtifactsBusinessLogic artifactsBusinessLogic;
protected final GroupBusinessLogic groupBusinessLogic;
- private GenericTypeBusinessLogic genericTypeBusinessLogic;
+ protected GenericTypeBusinessLogic genericTypeBusinessLogic;
+
+ protected ComponentDescriptionValidator componentDescriptionValidator;
+ protected ComponentProjectCodeValidator componentProjectCodeValidator;
+
+ protected CatalogOperation catalogOperations;
+ protected ComponentIconValidator componentIconValidator;
+
+ protected ComponentValidator componentValidator;
+ protected ComponentTagsValidator componentTagsValidator;
+ protected ComponentNameValidator componentNameValidator;
+ protected ComponentContactIdValidator componentContactIdValidator;
public ComponentBusinessLogic(IElementOperation elementDao,
IGroupOperation groupOperation,
@@ -105,13 +125,53 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
InterfaceOperation interfaceOperation,
InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
ArtifactsBusinessLogic artifactsBusinessLogic,
- ArtifactsOperations artifactToscaOperation) {
+ ArtifactsOperations artifactToscaOperation,
+ ComponentContactIdValidator componentContactIdValidator,
+ ComponentNameValidator componentNameValidator,
+ ComponentTagsValidator componentTagsValidator,
+ ComponentValidator componentValidator,
+ ComponentIconValidator componentIconValidator,
+ ComponentProjectCodeValidator componentProjectCodeValidator,
+ ComponentDescriptionValidator componentDescriptionValidator){
+
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
this.artifactsBusinessLogic = artifactsBusinessLogic;
this.groupBusinessLogic = groupBusinessLogic;
+ this.componentContactIdValidator = componentContactIdValidator;
+ this.componentNameValidator = componentNameValidator;
+ this.componentTagsValidator = componentTagsValidator;
+ this.componentValidator = componentValidator;
+ this.componentIconValidator = componentIconValidator;
+ this.componentProjectCodeValidator = componentProjectCodeValidator;
+ this.componentDescriptionValidator = componentDescriptionValidator;
+ }
+
+ public void setComponentDescriptionValidator(ComponentDescriptionValidator componentDescriptionValidator) {
+ this.componentDescriptionValidator = componentDescriptionValidator;
+ }
+
+ public void setComponentProjectCodeValidator(ComponentProjectCodeValidator componentProjectCodeValidator) {
+ this.componentProjectCodeValidator = componentProjectCodeValidator;
+ }
+
+ public void setComponentIconValidator(ComponentIconValidator componentIconValidator) {
+ this.componentIconValidator = componentIconValidator;
}
+ public void setComponentContactIdValidator(ComponentContactIdValidator componentContactIdValidator) {
+ this.componentContactIdValidator = componentContactIdValidator;
+ }
+
+ public void setComponentTagsValidator(ComponentTagsValidator componentTagsValidator) {
+ this.componentTagsValidator = componentTagsValidator;
+ }
+
+ public void setComponentNameValidator(ComponentNameValidator componentNameValidator) {
+ this.componentNameValidator = componentNameValidator;
+ }
+
+
@Autowired
public void setGenericTypeBusinessLogic(GenericTypeBusinessLogic genericTypeBusinessLogic) {
this.genericTypeBusinessLogic = genericTypeBusinessLogic;
@@ -135,12 +195,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
*/
public abstract Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String componentId, List<String> dataParamsToReturn);
- protected User validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) {
+ User validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) {
User validatedUser;
ResponseFormat responseFormat;
try {
validateUserNotEmpty(user, ecompErrorContext);
- validatedUser = validateUserExists(user, ecompErrorContext, inTransaction);
+ validatedUser = validateUserExists(user);
} catch(ByActionStatusComponentException e){
if(e.getActionStatus() == ActionStatus.MISSING_INFORMATION){
user.setUserId("UNKNOWN");
@@ -179,7 +239,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
String commentStr = null;
String distrStatus = null;
ComponentTypeEnum componentType = component.getComponentType();
- if (componentType.equals(ComponentTypeEnum.SERVICE)) {
+ if (componentType == ComponentTypeEnum.SERVICE) {
distrStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getDistributionStatus();
commentStr = comment;
}
@@ -189,119 +249,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
commentStr, null, null);
}
- protected void validateComponentName(User user, Component component, AuditingActionEnum actionEnum) {
- ComponentTypeEnum type = component.getComponentType();
- String componentName = component.getName();
- if (!ValidationUtils.validateStringNotEmpty(componentName)) {
- log.debug("component name is empty");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_COMPONENT_NAME, type.getValue());
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ByActionStatusComponentException(ActionStatus.MISSING_COMPONENT_NAME, type.getValue());
- }
-
- if (!ValidationUtils.validateComponentNameLength(componentName)) {
- log.debug("Component name exceeds max length {} ", ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
- }
-
- if (!validateTagPattern(componentName)) {
- log.debug("Component name {} has invalid format", componentName);
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPONENT_NAME, type.getValue());
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPONENT_NAME, type.getValue());
- }
- component.setNormalizedName(ValidationUtils.normaliseComponentName(componentName));
- component.setSystemName(ValidationUtils.convertToSystemName(componentName));
- }
-
- protected void validateDescriptionAndCleanup(User user, Component component, AuditingActionEnum actionEnum) {
- ComponentTypeEnum type = component.getComponentType();
- String description = component.getDescription();
- if (!ValidationUtils.validateStringNotEmpty(description)) {
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue());
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue());
- }
-
- description = cleanUpText(description);
- try {
- validateComponentDescription(description, type);
- } catch(ByActionStatusComponentException e){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
- throw e;
- } catch(ByResponseFormatComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat();
- componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
- throw e;
- }
- component.setDescription(description);
- }
-
- private void validateComponentDescription(String description, ComponentTypeEnum type) {
- if (description != null) {
- if (!ValidationUtils.validateDescriptionLength(description)) {
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
- }
-
- if (!ValidationUtils.validateIsEnglish(description)) {
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, type.getValue());
- }
- }
- }
-
- protected Either<Boolean, ResponseFormat> validateComponentNameUnique(User user, Component component, AuditingActionEnum actionEnum) {
- log.debug("validate component name uniqueness for: {}", component.getName());
- ComponentTypeEnum type = component.getComponentType();
- ResourceTypeEnum resourceType = null;
- if(component instanceof Resource){
- resourceType = ((Resource)component).getResourceType();
- }
- Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade.validateComponentNameExists(component.getName(), resourceType, type);
-
- if (dataModelResponse.isLeft()) {
- if ( !dataModelResponse.left().value()) {
- return Either.left(true);
- } else {
- log.info("Component with name {} already exists", component.getName());
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getName());
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- return Either.right(errorResponse);
- }
- }
- BeEcompErrorManager.getInstance().logBeSystemError("validateComponentNameUnique");
- log.debug("Error while validateComponentNameUnique for component: {}", component.getName());
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- return Either.right(errorResponse);
- }
-
- protected void validateContactId(User user, Component component, AuditingActionEnum actionEnum) {
- log.debug("validate component contactId");
- ComponentTypeEnum type = component.getComponentType();
- String contactId = component.getContactId();
-
- if (!ValidationUtils.validateStringNotEmpty(contactId)) {
- log.info("contact is missing.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
- }
- validateContactId(contactId, user, component, actionEnum, type);
- }
-
- private void validateContactId(String contactId, User user, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum type) {
- if (contactId != null && !ValidationUtils.validateContactId(contactId)) {
- log.info("contact is invalid.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
- }
- }
-
-
public Either<Boolean, ResponseFormat> validateConformanceLevel(String componentUuid, ComponentTypeEnum componentTypeEnum, String userId) {
log.trace("validate conformance level");
@@ -311,7 +258,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return Either.right(errorResponse);
}
- validateUserExists(userId, "validateConformanceLevel", false);
+ validateUserExists(userId);
Either<ComponentMetadataData, StorageOperationStatus> eitherComponent = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, null);
if (eitherComponent.isRight()) {
@@ -342,149 +289,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return Either.left(result);
}
- protected void validateIcon(User user, Component component, AuditingActionEnum actionEnum) {
- log.debug("validate Icon");
- ComponentTypeEnum type = component.getComponentType();
- String icon = component.getIcon();
- if (!ValidationUtils.validateStringNotEmpty(icon)) {
- log.info("icon is missing.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
- }
- try {
- validateIcon(icon, type);
- } catch(ByActionStatusComponentException e){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
- throw e;
- } catch(ByResponseFormatComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat();
- componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
- throw e;
- }
- }
-
- private void validateIcon(String icon, ComponentTypeEnum type) {
- if (icon != null) {
- if (!ValidationUtils.validateIconLength(icon)) {
- log.debug("icon exceeds max length");
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
- }
-
- if (!ValidationUtils.validateIcon(icon)) {
- log.info("icon is invalid.");
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue());
- }
- }
- }
-
- protected void validateTagsListAndRemoveDuplicates(User user, Component component, AuditingActionEnum actionEnum) {
- List<String> tagsList = component.getTags();
- try {
- validateComponentTags(tagsList, component.getName(), component.getComponentType(), user, component, actionEnum);
- } catch(ByActionStatusComponentException e){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType());
- throw e;
- } catch(ByResponseFormatComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat();
- componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType());
- throw e;
- }
- ValidationUtils.removeDuplicateFromList(tagsList);
- }
-
- protected void validateComponentTags(List<String> tags, String name, ComponentTypeEnum componentType, User user, Component component, AuditingActionEnum action) {
- log.debug("validate component tags");
- boolean includesComponentName = false;
- int tagListSize = 0;
- ResponseFormat responseFormat;
- if (tags != null && !tags.isEmpty()) {
- for (String tag : tags) {
- if (!ValidationUtils.validateTagLength(tag)) {
- log.debug("tag length exceeds limit {}", ValidationUtils.TAG_MAX_LENGTH);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
- componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
- }
- if (validateTagPattern(tag)) {
- if (!includesComponentName) {
- includesComponentName = name.equals(tag);
- }
- } else {
- log.debug("invalid tag {}", tag);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL);
- componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ByActionStatusComponentException(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL);
- }
- tagListSize += tag.length() + 1;
- }
- if (tagListSize > 0) {
- tagListSize--;
- }
-
- if (!includesComponentName) {
- log.debug("tags must include component name");
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
- componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
- }
- if (!ValidationUtils.validateTagListLength(tagListSize)) {
- log.debug("overall tags length exceeds limit {}", ValidationUtils.TAG_LIST_MAX_LENGTH);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
- componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
- }
- } else {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_TAGS);
- componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_TAGS);
- }
- }
-
- protected boolean validateTagPattern(String tag) {
- return ValidationUtils.validateComponentNamePattern(tag);
- }
-
- protected Either<Boolean, ResponseFormat> validateProjectCode(User user, Component component, AuditingActionEnum actionEnum) {
- if (ComponentTypeEnum.RESOURCE.equals(component.getComponentType())) {
- return Either.left(true);
- }
- log.debug("validate ProjectCode name ");
- String projectCode = component.getProjectCode();
-
- if (!ValidationUtils.validateStringNotEmpty(projectCode)) {
- log.info("projectCode is missing.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_PROJECT_CODE);
- componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, component.getComponentType(),
- ResourceVersionInfo.newBuilder()
- .build());
- return Either.right(errorResponse);
- }
-
- Either<Boolean, ResponseFormat> validateProjectCodeResponse = validateProjectCode(projectCode);
- if (validateProjectCodeResponse.isRight()) {
- ResponseFormat responseFormat = validateProjectCodeResponse.right().value();
- componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType(),
- ResourceVersionInfo.newBuilder()
- .build());
- }
- return validateProjectCodeResponse;
-
- }
-
- private Either<Boolean, ResponseFormat> validateProjectCode(String projectCode) {
- if (projectCode != null) {
- if (!ValidationUtils.validateProjectCode(projectCode)) {
- log.info("projectCode is not valid.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROJECT_CODE);
- return Either.right(errorResponse);
- }
- return Either.left(true);
- }
- return Either.left(false);
- }
protected void checkComponentFieldsForOverrideAttempt(Component component) {
if (component.getLifecycleState() != null) {
@@ -520,46 +324,28 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
}
- protected void validateComponentFieldsBeforeCreate(User user, Component component, AuditingActionEnum actionEnum) {
- // validate component name uniqueness
- log.debug("validate component name ");
- validateComponentName(user, component, actionEnum);
- // validate description
- log.debug("validate description");
- validateDescriptionAndCleanup(user, component, actionEnum);
- // validate tags
- log.debug("validate tags");
- validateTagsListAndRemoveDuplicates(user, component, actionEnum);
- // validate contact info
- log.debug("validate contact info");
- validateContactId(user, component, actionEnum);
- // validate icon
- log.debug("validate icon");
- validateIcon(user, component, actionEnum);
- }
-
- public Either<CapReqDef, ResponseFormat> getRequirementsAndCapabilities(String componentId, ComponentTypeEnum componentTypeEnum, String userId) {
+ public CapReqDef getRequirementsAndCapabilities(String componentId, ComponentTypeEnum componentTypeEnum, String userId) {
- validateUserExists(userId, "create Component Instance", false);
- Either<CapReqDef, ResponseFormat> eitherRet = null;
+ validateUserExists(userId);
ComponentParametersView filter = new ComponentParametersView(true);
filter.setIgnoreCapabilities(false);
filter.setIgnoreRequirements(false);
filter.setIgnoreComponentInstances(false);
- Either<Component, ResponseFormat> eitherComponent = validateComponentExists(componentId, componentTypeEnum, filter);
- if (eitherComponent.isLeft()) {
- eitherRet = Either.left(new CapReqDef(eitherComponent.left().value().getRequirements(), eitherComponent.left().value().getCapabilities()));
- } else {
+
+ try {
+ Component component = validateComponentExists(componentId, componentTypeEnum, filter);
+ return new CapReqDef(component.getRequirements(), component.getCapabilities());
+ }catch (ComponentException e){
BeEcompErrorManager.getInstance().logBeComponentMissingError("getRequirementsAndCapabilities", componentTypeEnum.getValue(), componentId);
- eitherRet = Either.right(eitherComponent.right().value());
+ throwComponentException(e.getResponseFormat());
}
- return eitherRet;
+ return null;
}
public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponents(boolean isAbstractAbstract, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids,
String userId) {
try{
- validateUserExists(userId, "get Latest Version Not Abstract Components", false);
+ validateUserExists(userId);
List<Component> result = new ArrayList<>();
List<String> componentsUidToFetch = new ArrayList<>();
componentsUidToFetch.addAll(componentUids);
@@ -602,12 +388,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
ResponseFormat responseFormat = null;
try{
- validateUserExists(userId, "get Latest Version Not Abstract Components", false);
+ validateUserExists(userId);
Boolean isHighest = isHighest(highestFilter);
Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade.getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType);
if (nonCheckoutCompResponse.isLeft()) {
- log.debug("Retrived Resource successfully.");
+ log.debug("Retrieved Resource successfully.");
return Either.left(nonCheckoutCompResponse.left().value());
}
responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value()));
@@ -643,27 +429,30 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
component.setToscaArtifacts(artifactMap);
}
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock) {
- return populateToscaArtifacts(component, user, isInCertificationRequest, inTransaction, shouldLock, true);
+ public Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock) {
+ return populateToscaArtifacts(component, user, isInCertificationRequest, inTransaction, shouldLock, true, true);
+ }
+
+ public Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock, boolean retrieveResource) {
+ return populateToscaArtifacts(component, user, isInCertificationRequest, inTransaction, shouldLock, true, retrieveResource);
}
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock, boolean fetchTemplatesFromDB) {
- Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaFullElement(component.getUniqueId());
- if ( toscaElement.isRight() ){
- ResponseFormat response = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(toscaElement.right().value(), component.getComponentType()));
- return Either.right(response);
+ private Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock, boolean fetchTemplatesFromDB, boolean retrieveResource) {
+ if (retrieveResource) {
+ Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaFullElement(component.getUniqueId());
+ if ( toscaElement.isRight() ){
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(toscaElement.right().value(), component.getComponentType()));
+ }
+ component = toscaElement.left().value();
}
- component = toscaElement.left().value();
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> generateToscaRes = null;
+
+ Either<ArtifactDefinition, Operation> generateToscaRes = null;
if (component.getToscaArtifacts() != null && !component.getToscaArtifacts().isEmpty()) {
ArtifactDefinition toscaArtifact = component.getToscaArtifacts().values().stream()
.filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_TEMPLATE.getType()))
.findAny().get();
generateToscaRes = saveToscaArtifactPayload(toscaArtifact, component, user, isInCertificationRequest, shouldLock, inTransaction, fetchTemplatesFromDB);
- if (generateToscaRes.isRight()) {
- return generateToscaRes;
- }
- toscaArtifact = generateToscaRes.left().value().left().value();
+ toscaArtifact = generateToscaRes.left().value();
component.getToscaArtifacts().put(toscaArtifact.getArtifactLabel(), toscaArtifact);
if(!isAbstractResource(component)){
toscaArtifact = component.getToscaArtifacts().values().stream()
@@ -673,7 +462,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
if (generateToscaRes.isRight()) {
return generateToscaRes;
}
- toscaArtifact = generateToscaRes.left().value().left().value();
+ toscaArtifact = generateToscaRes.left().value();
component.getToscaArtifacts().put(toscaArtifact.getArtifactLabel(), toscaArtifact);
}
}
@@ -684,18 +473,17 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return component.getComponentType() == ComponentTypeEnum.RESOURCE && ((Resource)component).isAbstract();
}
- public Either<Either<ArtifactDefinition, Operation>, ResponseFormat> saveToscaArtifactPayload(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, User user, boolean isInCertificationRequest, boolean shouldLock,
- boolean inTransaction, boolean fetchTemplatesFromDB) {
+ private Either<ArtifactDefinition, Operation> saveToscaArtifactPayload(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, User user, boolean isInCertificationRequest, boolean shouldLock,
+ boolean inTransaction, boolean fetchTemplatesFromDB) {
return artifactsBusinessLogic.generateAndSaveToscaArtifact(artifactDefinition, component, user, isInCertificationRequest, shouldLock, inTransaction, fetchTemplatesFromDB);
}
- public Either<ImmutablePair<String, byte[]>, ResponseFormat> getToscaModelByComponentUuid(ComponentTypeEnum componentType, String uuid, ResourceCommonInfo resourceCommonInfo) {
+ public ImmutablePair<String, byte[]> getToscaModelByComponentUuid(ComponentTypeEnum componentType, String uuid, ResourceCommonInfo resourceCommonInfo) {
Either<List<Component>, StorageOperationStatus> latestVersionEither = toscaOperationFacade.getComponentListByUuid(uuid, null);
if (latestVersionEither.isRight()) {
- ResponseFormat response = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(latestVersionEither.right().value(), componentType));
- return Either.right(response);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(latestVersionEither.right().value(), componentType));
}
List<Component> components = latestVersionEither.left().value();
@@ -706,14 +494,13 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
if(component == null){
- ResponseFormat response = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, componentType));
- return Either.right(response);
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, componentType)));
}
resourceCommonInfo.setResourceName(component.getName());
// TODO remove after migration - handle artifact not found(no
// placeholder)
if (null == component.getToscaArtifacts() || component.getToscaArtifacts().isEmpty()) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
}
ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream()
.filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType()))
@@ -736,6 +523,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return markResourceToDelete;
} else {
log.debug("Component {} of type {} was marked as deleted", uniqueId, componentType);
+ updateCatalog(component, ChangeTypeEnum.DELETE);
return StorageOperationStatus.OK;
}
}
@@ -744,7 +532,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
String descriptionUpdated = updatedComponent.getDescription();
String descriptionCurrent = currentComponent.getDescription();
if (descriptionUpdated != null && !descriptionCurrent.equals(descriptionUpdated)) {
- validateDescriptionAndCleanup(user, updatedComponent, auditingAction);
+ componentDescriptionValidator.validateAndCorrectField(user, updatedComponent, auditingAction);
currentComponent.setDescription(updatedComponent.getDescription());
}
return Either.left(true);
@@ -754,9 +542,10 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
String projectCodeUpdated = updatedComponent.getProjectCode();
String projectCodeCurrent = currentComponent.getProjectCode();
if (projectCodeUpdated != null && !projectCodeCurrent.equals(projectCodeUpdated)) {
- Either<Boolean, ResponseFormat> validatProjectCodeResponse = validateProjectCode(user, updatedComponent, null);
- if (validatProjectCodeResponse.isRight()) {
- ResponseFormat errorRespons = validatProjectCodeResponse.right().value();
+ try {
+ componentProjectCodeValidator.validateAndCorrectField(user, updatedComponent, null);
+ } catch (ComponentException exp) {
+ ResponseFormat errorRespons = exp.getResponseFormat();
return Either.right(errorRespons);
}
currentComponent.setProjectCode(updatedComponent.getProjectCode());
@@ -769,7 +558,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
String iconCurrent = currentComponent.getIcon();
if (iconUpdated != null && !iconCurrent.equals(iconUpdated)) {
if (!hasBeenCertified) {
- validateIcon(user, updatedComponent, null);
+ componentIconValidator.validateAndCorrectField(user, updatedComponent, null);
currentComponent.setIcon(updatedComponent.getIcon());
} else {
log.info("icon {} cannot be updated once the component has been certified once.", iconUpdated);
@@ -800,7 +589,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
List<ArtifactDefinition> artifacts = new ArrayList<>();
Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifactsResponse = artifactToscaOperation.getArtifacts(parentId);
if (artifactsResponse.isRight()) {
- if (!artifactsResponse.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ if (artifactsResponse.right().value() != StorageOperationStatus.NOT_FOUND) {
log.debug("failed to retrieve artifacts for {} {}", parentType, parentId);
return Either.right(artifactsResponse.right().value());
}
@@ -821,7 +610,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
public Either<UiComponentDataTransfer, ResponseFormat> getComponentDataFilteredByParams(String componentId, User user, List<String> dataParamsToReturn) {
if (user != null) {
- validateUserExists(user, "Get Component by filtered by ui params", false);
+ validateUserExists(user);
}
UiComponentDataTransfer result = new UiComponentDataTransfer();
@@ -885,7 +674,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
response = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
if (userId != null && response == null) {
- validateUserExists(userId, "Get filtered component instance properties", false);
+ validateUserExists(userId);
}
if(response == null){
getResourceRes = toscaOperationFacade.getToscaElement(componentId);
@@ -920,18 +709,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
for(ComponentInstance instance : filteredInstances){
if(component.getComponentInstancesProperties()!=null &&component.getComponentInstancesProperties().containsKey(instance.getUniqueId())){
List<IComponentInstanceConnectedElement> currProperties = getFilteredComponentInstanceProperties(component.getComponentInstancesProperties().get(instance.getUniqueId()), propertyNameFragment, searchByFragment);
- if(CollectionUtils.isNotEmpty(currProperties)){
- filteredProperties.put(instance.getUniqueId(), currProperties);
- }
+ setFilteredProperties(filteredProperties, instance, currProperties);
}
if(component.getComponentInstancesInputs()!=null && component.getComponentInstancesInputs().containsKey(instance.getUniqueId())){
List<IComponentInstanceConnectedElement> currInputs = getFilteredComponentInstanceInputs(component.getComponentInstancesInputs().get(instance.getUniqueId()), propertyNameFragment, searchByFragment);
if(CollectionUtils.isNotEmpty(currInputs)){
- if(filteredProperties.get(instance.getUniqueId())!=null){
- filteredProperties.get(instance.getUniqueId()).addAll(currInputs);
- } else {
- filteredProperties.put(instance.getUniqueId(), currInputs);
- }
+ checkFilteredProperties(filteredProperties, instance, currInputs);
}
}
}
@@ -939,6 +722,20 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return result;
}
+ private void setFilteredProperties(Map<String, List<IComponentInstanceConnectedElement>> filteredProperties, ComponentInstance instance, List<IComponentInstanceConnectedElement> currProperties) {
+ if(CollectionUtils.isNotEmpty(currProperties)){
+ filteredProperties.put(instance.getUniqueId(), currProperties);
+ }
+ }
+
+ private void checkFilteredProperties(Map<String, List<IComponentInstanceConnectedElement>> filteredProperties, ComponentInstance instance, List<IComponentInstanceConnectedElement> currInputs) {
+ if(filteredProperties.get(instance.getUniqueId())!=null){
+ filteredProperties.get(instance.getUniqueId()).addAll(currInputs);
+ } else {
+ filteredProperties.put(instance.getUniqueId(), currInputs);
+ }
+ }
+
private List<IComponentInstanceConnectedElement> getFilteredComponentInstanceInputs(List<ComponentInstanceInput> inputs, String propertyNameFragment, boolean searchByFragment) {
return inputs.stream().filter(i -> isMatchingInput(i, propertyNameFragment, searchByFragment)).collect(Collectors.toList());
}
@@ -996,18 +793,23 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
dataTypeProperties = currentProperty.getProperties();
if(CollectionUtils.isNotEmpty(dataTypeProperties)){
- for(PropertyDefinition prop : dataTypeProperties){
- if(isMatchingComplexPropertyByRecursively(prop, propertyNameFragment, searchByFragment)){
- return true;
- }
+ if (isMatchingComplexProperty(propertyNameFragment, searchByFragment, dataTypeProperties)){
+ return true;
}
}
dataTypeProperties = currentProperty.getDerivedFrom().getProperties();
if(CollectionUtils.isNotEmpty(dataTypeProperties)){
- for(PropertyDefinition prop : dataTypeProperties){
- if(isMatchingComplexPropertyByRecursively(prop, propertyNameFragment, searchByFragment)){
- return true;
- }
+ if (isMatchingComplexProperty(propertyNameFragment, searchByFragment, dataTypeProperties)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isMatchingComplexProperty(String propertyNameFragment, boolean searchByFragment, List<PropertyDefinition> dataTypeProperties) {
+ for(PropertyDefinition prop : dataTypeProperties){
+ if(isMatchingComplexPropertyByRecursively(prop, propertyNameFragment, searchByFragment)){
+ return true;
}
}
return false;
@@ -1120,22 +922,34 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return isMatchingType;
}
- String cleanUpText(String text){
- text = ValidationUtils.removeNoneUtf8Chars(text);
- text = ValidationUtils.normaliseWhitespace(text);
- text = ValidationUtils.stripOctets(text);
- text = ValidationUtils.removeHtmlTagsOnly(text);
- return text;
- }
-
public Either<Component, ActionStatus> shouldUpgradeToLatestDerived(Component clonedComponent) {
//general implementation. Must be error for service, VF . In ResourceBuisnessLogic exist override
return Either.right(ActionStatus.GENERAL_ERROR);
}
+ protected Either<Component, ResponseFormat> updateCatalog(Component component, ChangeTypeEnum changeStatus){
+ log.debug("update Catalog start with Component Type {} And Componet Name {} with change status {}", component.getComponentType().name(), component.getName(), changeStatus.name());
+ ActionStatus status = catalogOperations.updateCatalog(changeStatus,component);
+ if(status != ActionStatus.OK){
+ return Either.right( componentsUtils.getResponseFormat(status));
+ }
+
+ return Either.left(component);
+ }
+
+ public CatalogOperation getCatalogOperations() {
+ return catalogOperations;
+ }
+
+ @Autowired
+ public void setCatalogOperations(CatalogOperation catalogOperations) {
+ this.catalogOperations = catalogOperations;
+ }
+
public List<GroupDefinition> throwComponentException(ResponseFormat responseFormat) {
throw new ByResponseFormatComponentException(responseFormat);
}
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java
index 2c516cce57..5f1e6a100f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java
@@ -27,8 +27,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.springframework.stereotype.Component;
-import javax.inject.Inject;
-
@Component
public class ComponentBusinessLogicProvider {
@@ -36,7 +34,6 @@ public class ComponentBusinessLogicProvider {
private final ServiceBusinessLogic serviceBusinessLogic;
private final ProductBusinessLogic productBusinessLogic;
- @Inject
public ComponentBusinessLogicProvider(ResourceBusinessLogic resourceBusinessLogic, ServiceBusinessLogic serviceBusinessLogic, ProductBusinessLogic productBusinessLogic) {
this.resourceBusinessLogic = resourceBusinessLogic;
this.serviceBusinessLogic = serviceBusinessLogic;
@@ -54,7 +51,7 @@ public class ComponentBusinessLogicProvider {
return resourceBusinessLogic;
default:
BeEcompErrorManager.getInstance().logBeSystemError("getComponentBL");
- throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT_PARAM, componentTypeEnum.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT, componentTypeEnum.getValue());
}
}
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 040c460ffc..51eb22d527 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
@@ -26,6 +26,9 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.instance.ComponentInstanceChangeOperationOrchestrator;
import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceMergeDataBusinessLogic;
@@ -34,23 +37,24 @@ import org.openecomp.sdc.be.components.utils.PropertiesUtils;
import org.openecomp.sdc.be.components.validation.ComponentValidations;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.datamodel.utils.PropertyValueConstraintValidationUtil;
+import org.openecomp.sdc.be.datamodel.utils.ContainerInstanceTypesData;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ForwardingPathUtils;
import org.openecomp.sdc.be.impl.ServiceFilterUtils;
import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
@@ -69,7 +73,6 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames;
import org.openecomp.sdc.be.model.RelationshipInfo;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.RequirementDefinition;
@@ -82,12 +85,13 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeFilterOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
-import org.openecomp.sdc.be.model.operations.api.IComponentInstanceOperation;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.ComponentInstanceOperation;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
@@ -142,12 +146,12 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
private static final String FAILED_TO_COPY_COMP_INSTANCE_TO_CANVAS = "Failed to copy the component instance to the canvas";
private static final String COPY_COMPONENT_INSTANCE_OK = "Copy component instance OK";
- private final IComponentInstanceOperation componentInstanceOperation;
- private final ArtifactsBusinessLogic artifactBusinessLogic;
- private final ComponentInstanceMergeDataBusinessLogic compInstMergeDataBL;
- private final ComponentInstanceChangeOperationOrchestrator onChangeInstanceOperationOrchestrator;
- private final ForwardingPathOperation forwardingPathOperation;
- private final NodeFilterOperation serviceFilterOperation;
+ private ComponentInstanceOperation componentInstanceOperation;
+ private ArtifactsBusinessLogic artifactBusinessLogic;
+ private ComponentInstanceMergeDataBusinessLogic compInstMergeDataBL;
+ private ComponentInstanceChangeOperationOrchestrator onChangeInstanceOperationOrchestrator;
+ private ForwardingPathOperation forwardingPathOperation;
+ private NodeFilterOperation serviceFilterOperation;
@Autowired
public ComponentInstanceBusinessLogic(IElementOperation elementDao,
@@ -156,7 +160,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
IGroupTypeOperation groupTypeOperation,
InterfaceOperation interfaceOperation,
InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
- IComponentInstanceOperation componentInstanceOperation, ArtifactsBusinessLogic artifactBusinessLogic,
+ ComponentInstanceOperation componentInstanceOperation, ArtifactsBusinessLogic artifactBusinessLogic,
ComponentInstanceMergeDataBusinessLogic compInstMergeDataBL,
ComponentInstanceChangeOperationOrchestrator onChangeInstanceOperationOrchestrator,
ForwardingPathOperation forwardingPathOperation, NodeFilterOperation serviceFilterOperation,
@@ -171,10 +175,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
this.serviceFilterOperation = serviceFilterOperation;
}
- public Either<ComponentInstance, ResponseFormat> createComponentInstance(String containerComponentParam,
- String containerComponentId, String userId, ComponentInstance resourceInstance) {
- return createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, false,
- true);
+ @Autowired
+ private CompositionBusinessLogic compositionBusinessLogic;
+
+ @Autowired
+ private ContainerInstanceTypesData containerInstanceTypesData;
+
+ public ComponentInstance createComponentInstance(String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance) {
+ return createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, false, true);
}
public List<ComponentInstanceProperty> getComponentInstancePropertiesByInputId(org.openecomp.sdc.be.model.Component component, String inputId){
@@ -191,23 +199,27 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (ciPropList != null && !ciPropList.isEmpty()) {
for(ComponentInstanceProperty prop: ciPropList){
List<GetInputValueDataDefinition> inputsValues = prop.getGetInputValues();
- if(inputsValues != null && !inputsValues.isEmpty()){
- for(GetInputValueDataDefinition inputData: inputsValues){
- if(isGetInputValueForInput(inputData, inputId)){
- prop.setComponentInstanceId(s);
- prop.setComponentInstanceName(ciName);
- resList.add(prop);
- break;
- }
- }
- }
-
+ addCompInstanceProperty(s, ciName, prop, inputsValues, inputId, resList);
}
}
}
});
}
return resList;
+
+ }
+
+ private void addCompInstanceProperty(String s, String ciName, ComponentInstanceProperty prop, List<GetInputValueDataDefinition> inputsValues, String inputId, List<ComponentInstanceProperty> resList) {
+ if(inputsValues != null && !inputsValues.isEmpty()){
+ for(GetInputValueDataDefinition inputData: inputsValues){
+ if(isGetInputValueForInput(inputData, inputId)){
+ prop.setComponentInstanceId(s);
+ prop.setComponentInstanceName(ciName);
+ resList.add(prop);
+ break;
+ }
+ }
+ }
}
public Optional<ComponentInstanceProperty> getComponentInstancePropertyByPolicyId(Component component,
@@ -286,16 +298,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (ciPropList != null && !ciPropList.isEmpty()) {
for(ComponentInstanceInput prop: ciPropList){
List<GetInputValueDataDefinition> inputsValues = prop.getGetInputValues();
- if(inputsValues != null && !inputsValues.isEmpty()){
- for(GetInputValueDataDefinition inputData: inputsValues){
- if(isGetInputValueForInput(inputData, inputId)){
- prop.setComponentInstanceId(s);
- prop.setComponentInstanceName(ciName);
- resList.add(prop);
- break;
- }
- }
- }
+ addCompInstanceInput(s, ciName, prop, inputsValues, inputId, resList);
}
}
@@ -303,90 +306,190 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
});
}
return resList;
+
}
- public Either<ComponentInstance, ResponseFormat> createComponentInstance(
- String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance, boolean inTransaction, boolean needLock) {
+ private void addCompInstanceInput(String s, String ciName, ComponentInstanceInput prop, List<GetInputValueDataDefinition> inputsValues, String inputId, List<ComponentInstanceInput> resList) {
+ if(inputsValues != null && !inputsValues.isEmpty()){
+ for(GetInputValueDataDefinition inputData: inputsValues){
+ if(isGetInputValueForInput(inputData, inputId)){
+ prop.setComponentInstanceId(s);
+ prop.setComponentInstanceName(ciName);
+ resList.add(prop);
+ break;
+ }
+ }
+ }
+ }
+
+ public ComponentInstance createComponentInstance(String containerComponentParam, String containerComponentId, String userId, ComponentInstance resourceInstance, boolean inTransaction, boolean needLock) {
Component origComponent = null;
- Either<ComponentInstance, ResponseFormat> resultOp = null;
- User user = null;
+ User user;
org.openecomp.sdc.be.model.Component containerComponent = null;
ComponentTypeEnum containerComponentType;
-
try {
- user = validateUserExists(userId, "create Component Instance", inTransaction);
-
- Either<Boolean, ResponseFormat> validateValidJson = validateJsonBody(resourceInstance, ComponentInstance.class);
- if (validateValidJson.isRight()) {
- return Either.right(validateValidJson.right().value());
- }
-
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
- if (validateComponentType.isRight()) {
- return Either.right(validateComponentType.right().value());
- } else {
- containerComponentType = validateComponentType.left().value();
- }
-
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, null);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- } else {
- containerComponent = validateComponentExists.left().value();
- }
+ user = validateUserExists(userId);
+ validateUserNotEmpty(user, "Create component instance");
+ validateJsonBody(resourceInstance, ComponentInstance.class);
+ containerComponentType = validateComponentType(containerComponentParam);
+ containerComponent = validateComponentExists(containerComponentId, containerComponentType, null);
if (ModelConverter.isAtomicComponent(containerComponent)) {
log.debug("Cannot attach resource instances to container resource of type {}", containerComponent.assetType());
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType()));
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType());
}
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
- }
+ validateCanWorkOnComponent(containerComponent, userId);
if (resourceInstance != null && containerComponentType != null) {
OriginTypeEnum originType = resourceInstance.getOriginType();
+ validateInstanceName(resourceInstance);
if (originType == OriginTypeEnum.ServiceProxy) {
+
Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName("serviceProxy");
- if (serviceProxyOrigin.isRight()) {
- log.debug("Failed to fetch normative service proxy resource by tosca name, error {}", serviceProxyOrigin.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value())));
+ if (isServiceProxyOrigin(serviceProxyOrigin)) {
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value()));
}
origComponent = serviceProxyOrigin.left().value();
StorageOperationStatus fillProxyRes = fillProxyInstanceData(resourceInstance, origComponent);
- if (fillProxyRes != StorageOperationStatus.OK) {
- log.debug("Failed to fill service proxy resource data with data from service, error {}", fillProxyRes);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(fillProxyRes)));
-
- }
-
- } else {
- Either<Component, ResponseFormat> getOriginComponentRes = getAndValidateOriginComponentOfComponentInstance(containerComponentType, resourceInstance);
-
- if (getOriginComponentRes.isRight()) {
- return Either.right(getOriginComponentRes.right().value());
- } else {
- origComponent = getOriginComponentRes.left().value();
+ if (isFillProxyRes(fillProxyRes)) {
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(fillProxyRes));
}
}
- }
- if (needLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "createComponentInstance");
- if (lockComponent.isRight()) {
- return Either.right(lockComponent.right().value());
+ else {
+ origComponent = getAndValidateOriginComponentOfComponentInstance(containerComponent, resourceInstance);
}
+ validateOriginAndResourceInstanceTypes(containerComponent, origComponent, originType);
+ validateResourceInstanceState(containerComponent, origComponent);
+ overrideFields(origComponent, resourceInstance);
+ compositionBusinessLogic.validateAndSetDefaultCoordinates(resourceInstance);
}
- log.debug(TRY_TO_CREATE_ENTRY_ON_GRAPH);
- resultOp = createComponentInstanceOnGraph(containerComponent, origComponent, resourceInstance, user);
- return resultOp;
+ return createComponent(needLock, containerComponent,origComponent, resourceInstance, user);
- } finally {
+ }catch (ComponentException e){
+ throw e;
+ }
+ }
+
+ private ComponentInstance createComponent(boolean needLock, Component containerComponent, Component origComponent, ComponentInstance resourceInstance, User user) {
+
+ boolean failed = false;
+ try {
+
+ ComponentInstance lockComponent = isNeedLock(needLock, containerComponent);
+ if (lockComponent != null) {
+ return lockComponent;
+ }
+ log.debug(TRY_TO_CREATE_ENTRY_ON_GRAPH);
+ return createComponentInstanceOnGraph(containerComponent, origComponent, resourceInstance, user);
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
if (needLock)
- unlockComponent(resultOp, containerComponent);
+ unlockComponent(failed, containerComponent);
+ }
+ }
+
+ private void overrideFields(Component origComponent, ComponentInstance resourceInstance) {
+ resourceInstance.setComponentVersion(origComponent.getVersion());
+ resourceInstance.setIcon(origComponent.getIcon());
+ }
+
+ private void validateInstanceName(ComponentInstance resourceInstance) {
+
+ String resourceInstanceName = resourceInstance.getName();
+ if (StringUtils.isEmpty(resourceInstanceName)) {
+ log.debug("ComponentInstance name is empty");
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPONENT_NAME, resourceInstance.getName());
+ }
+
+ if (!ValidationUtils.validateComponentNameLength(resourceInstanceName)) {
+ log.debug("ComponentInstance name exceeds max length {} ", ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPONENT_NAME, resourceInstance.getName());
+ }
+
+ if (!ValidationUtils.validateComponentNamePattern(resourceInstanceName)) {
+ log.debug("ComponentInstance name {} has invalid format", resourceInstanceName);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPONENT_NAME, resourceInstance.getName());
+ }
+ }
+
+ private void validateResourceInstanceState(Component containerComponent, Component origComponent) {
+ if (origComponent.getLifecycleState() == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT){
+ throw new ByActionStatusComponentException(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE,
+ containerComponent.getComponentType().getValue(), origComponent.getLifecycleState().toString());
+ }
+ }
+
+ private void validateOriginAndResourceInstanceTypes(Component containerComponent, Component origComponent, OriginTypeEnum originType) {
+ ResourceTypeEnum resourceType = null;
+ ResourceTypeEnum convertedOriginType;
+ resourceType = getResourceTypeEnumFromOriginComponent(origComponent, resourceType);
+ validateOriginType(originType, resourceType);
+ validateOriginComponentIsValidForContainer(containerComponent, resourceType);
+ }
+
+ private void validateOriginComponentIsValidForContainer(Component containerComponent, ResourceTypeEnum resourceType) {
+ switch (containerComponent.getComponentType()) {
+ case SERVICE:
+ if (!containerInstanceTypesData.getServiceContainerList().contains((resourceType))) {
+ throw new ByActionStatusComponentException(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE,
+ containerComponent.getComponentType().toString(), resourceType.name());
+ }
+ break;
+ case RESOURCE:
+ if (!containerInstanceTypesData.getValidInstanceTypesInResourceContainer().get(((Resource) containerComponent).getResourceType()).contains(resourceType)) {
+ throw new ByActionStatusComponentException(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE,
+ containerComponent.getComponentType().toString(), resourceType.name());
+ }
+ break;
+ default:
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
+ }
+ }
+
+ private void validateOriginType(OriginTypeEnum originType, ResourceTypeEnum resourceType) {
+ ResourceTypeEnum convertedOriginType;
+ try {
+ convertedOriginType = ResourceTypeEnum.getTypeIgnoreCase(originType.name());
+ }
+ catch (Exception e){
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
+ }
+
+ if (resourceType != convertedOriginType) throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
+ }
+
+ private ResourceTypeEnum getResourceTypeEnumFromOriginComponent(Component origComponent, ResourceTypeEnum resourceType) {
+ switch (origComponent.getComponentType()) {
+ case SERVICE:
+ resourceType = ResourceTypeEnum.ServiceProxy;
+ break;
+ case RESOURCE:
+ resourceType = ((Resource) origComponent).getResourceType();
+ break;
+ default:
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
+ return resourceType;
+ }
+
+ private ComponentInstance isNeedLock(boolean needLock, Component containerComponent) {
+ if (needLock) {
+ lockComponent(containerComponent, "createComponentInstance");
+ }
+ return null;
+ }
+
+ private boolean isServiceProxyOrigin(Either<Component, StorageOperationStatus> serviceProxyOrigin) {
+ if (serviceProxyOrigin.isRight()) {
+ log.debug("Failed to fetch normative service proxy resource by tosca name, error {}", serviceProxyOrigin.right().value());
+ return true;
+ }
+ return false;
}
private StorageOperationStatus fillProxyInstanceData(ComponentInstance resourceInstance, Component proxyTemplate) {
@@ -409,7 +512,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
resourceInstance.setCapabilities(capabilities);
Map<String, List<RequirementDefinition>> req = service.getRequirements();
resourceInstance.setRequirements(req);
-
Map<String, InterfaceDefinition> serviceInterfaces = service.getInterfaces();
if(MapUtils.isNotEmpty(serviceInterfaces)) {
serviceInterfaces.forEach(resourceInstance::addInterface);
@@ -421,7 +523,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
List<InputDefinition> serviceInputs = service.getInputs();
resourceInstance.setInputs(serviceInputs);
- String name = service.getNormalizedName() + ToscaOperationFacade.PROXY_SUFFIX;
+ String name = ValidationUtils.normalizeComponentInstanceName(service.getName()) + ToscaOperationFacade.PROXY_SUFFIX;
String toscaResourceName = ((Resource) proxyTemplate).getToscaResourceName();
int lastIndexOf = toscaResourceName.lastIndexOf('.');
if (lastIndexOf != -1) {
@@ -447,64 +549,34 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
ComponentInstance resourceInstance = createAndAssotiateInfo.getNode();
RequirementCapabilityRelDef associationInfo = createAndAssotiateInfo.getAssociate();
- User user = validateUserExists(userId, "create And Associate RI To RI", false);
+ User user = validateUserExists(userId);
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
- if (validateComponentType.isRight()) {
- return Either.right(validateComponentType.right().value());
- }
-
- final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ final ComponentTypeEnum containerComponentType = validateComponentType(containerComponentParam);
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, null);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- }
- org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists(containerComponentId, containerComponentType, null);
if (ModelConverter.isAtomicComponent(containerComponent)) {
log.debug("Cannot attach resource instances to container resource of type {}", containerComponent.assetType());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, containerComponent.assetType()));
}
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
- }
-
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "createAndAssociateRIToRI");
- if (lockComponent.isRight()) {
- return Either.right(lockComponent.right().value());
- }
+ validateCanWorkOnComponent(containerComponent, userId);
+ boolean failed = false;
try {
+ lockComponent(containerComponent, "createAndAssociateRIToRI");
log.debug(TRY_TO_CREATE_ENTRY_ON_GRAPH);
- Either<Component, ResponseFormat> eitherResourceName = getOriginComponentFromComponentInstance(resourceInstance);
-
- if (eitherResourceName.isRight()) {
- resultOp = Either.right(eitherResourceName.right().value());
- return resultOp;
- }
- Component origComponent = eitherResourceName.left().value();
-
- Either<ComponentInstance, ResponseFormat> result = createComponentInstanceOnGraph(containerComponent, origComponent, resourceInstance, user);
- if (result.isRight()) {
- log.debug("Failed to create resource instance {}", containerComponentId);
- resultOp = Either.right(result.right().value());
- return resultOp;
-
- }
+ Component origComponent = getOriginComponentFromComponentInstance(resourceInstance);
log.debug(ENTITY_ON_GRAPH_IS_CREATED);
- ComponentInstance resResourceInfo = result.left().value();
+ ComponentInstance resResourceInfo = createComponentInstanceOnGraph(containerComponent, origComponent, resourceInstance, user);
if (associationInfo.getFromNode() == null || associationInfo.getFromNode().isEmpty()) {
associationInfo.setFromNode(resResourceInfo.getUniqueId());
} else {
associationInfo.setToNode(resResourceInfo.getUniqueId());
}
- RequirementCapabilityRelDef requirementCapabilityRelDef = associationInfo;
- Either<RequirementCapabilityRelDef, StorageOperationStatus> resultReqCapDef = toscaOperationFacade.associateResourceInstances(containerComponentId, requirementCapabilityRelDef);
+ Either<RequirementCapabilityRelDef, StorageOperationStatus> resultReqCapDef = toscaOperationFacade.associateResourceInstances(containerComponent, containerComponentId, associationInfo);
if (resultReqCapDef.isLeft()) {
log.debug(ENTITY_ON_GRAPH_IS_CREATED);
RequirementCapabilityRelDef resReqCapabilityRelDef = resultReqCapDef.left().value();
@@ -518,61 +590,53 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return resultOp;
}
- } finally {
- unlockComponent(resultOp, containerComponent);
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponent(failed, containerComponent);
}
}
- private Either<Component, ResponseFormat> getOriginComponentFromComponentInstance(ComponentInstance componentInstance) {
+ private Component getOriginComponentFromComponentInstance(ComponentInstance componentInstance) {
return getOriginComponentFromComponentInstance(componentInstance.getName(), componentInstance.getComponentUid());
}
- private Either<Component, ResponseFormat> getInstanceOriginNode(ComponentInstance componentInstance) {
+ private Component getInstanceOriginNode(ComponentInstance componentInstance) {
return getOriginComponentFromComponentInstance(componentInstance.getName(), componentInstance.getActualComponentUid());
}
- private Either<Component, ResponseFormat> getOriginComponentFromComponentInstance(String componentInstanceName, String origComponetId) {
- Either<Component, ResponseFormat> eitherResponse;
+ private Component getOriginComponentFromComponentInstance(String componentInstanceName, String origComponetId) {
Either<Component, StorageOperationStatus> eitherComponent = toscaOperationFacade.getToscaFullElement(origComponetId);
if (eitherComponent.isRight()) {
log.debug("Failed to get origin component with id {} for component instance {} ", origComponetId, componentInstanceName);
- eitherResponse = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponse(eitherComponent.right().value(), ComponentTypeEnum.RESOURCE), "", null));
- } else {
- eitherResponse = Either.left(eitherComponent.left().value());
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(eitherComponent.right().value(), ComponentTypeEnum.RESOURCE), "", null);
}
- return eitherResponse;
+ return eitherComponent.left().value();
}
- private Either<ComponentInstance, ResponseFormat> createComponentInstanceOnGraph(org.openecomp.sdc.be.model.Component containerComponent, Component originComponent, ComponentInstance componentInstance, User user) {
+ private ComponentInstance createComponentInstanceOnGraph(org.openecomp.sdc.be.model.Component containerComponent, Component originComponent, ComponentInstance componentInstance, User user) {
Either<ComponentInstance, ResponseFormat> resultOp;
Either<ImmutablePair<Component, String>, StorageOperationStatus> result = toscaOperationFacade.addComponentInstanceToTopologyTemplate(containerComponent, originComponent, componentInstance, false, user);
if (result.isRight()) {
log.debug(FAILED_TO_CREATE_ENTRY_ON_GRAPH_FOR_COMPONENT_INSTANCE, componentInstance.getName());
- resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), "", null));
- return resultOp;
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), "", null));
}
log.debug(ENTITY_ON_GRAPH_IS_CREATED);
Component updatedComponent = result.left().value().getLeft();
Map<String, String> existingEnvVersions = new HashMap<>();
// TODO existingEnvVersions ??
- Either<ActionStatus, ResponseFormat> addComponentInstanceArtifacts = addComponentInstanceArtifacts(updatedComponent, componentInstance, originComponent, user, existingEnvVersions);
- if (addComponentInstanceArtifacts.isRight()) {
- log.debug("Failed to create component instance {}", componentInstance.getName());
- resultOp = Either.right(addComponentInstanceArtifacts.right().value());
- return resultOp;
- }
+ addComponentInstanceArtifacts(updatedComponent, componentInstance, originComponent, user, existingEnvVersions);
Optional<ComponentInstance> updatedInstanceOptional = updatedComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(result.left().value().getRight())).findFirst();
if (!updatedInstanceOptional.isPresent()) {
log.debug("Failed to fetch new added component instance {} from component {}", componentInstance.getName(), containerComponent.getName());
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName()));
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName());
}
- resultOp = Either.left(updatedInstanceOptional.get());
- return resultOp;
+ return updatedInstanceOptional.get();
}
public boolean isCloudSpecificArtifact(String artifact) {
@@ -598,14 +662,13 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
* @param existingEnvVersions
* @return
*/
- protected Either<ActionStatus, ResponseFormat> addComponentInstanceArtifacts(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance componentInstance, org.openecomp.sdc.be.model.Component originComponent, User user, Map<String, String> existingEnvVersions) {
+ protected ActionStatus addComponentInstanceArtifacts(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance componentInstance, org.openecomp.sdc.be.model.Component originComponent, User user, Map<String, String> existingEnvVersions) {
log.debug("add artifacts to resource instance");
List<GroupDefinition> filteredGroups = null;
ActionStatus status = setResourceArtifactsOnResourceInstance(componentInstance);
- if (!ActionStatus.OK.equals(status)) {
- ResponseFormat resultOp = componentsUtils.getResponseFormatForResourceInstance(status, "", null);
- return Either.right(resultOp);
+ if (ActionStatus.OK != status) {
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatForResourceInstance(status, "", null));
}
StorageOperationStatus artStatus;
// generate heat_env if necessary
@@ -614,22 +677,23 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Map<String, ArtifactDefinition> finalDeploymentArtifacts = new HashMap<>();
Map<String, List<ArtifactDefinition>> groupInstancesArtifacts = new HashMap<>();
-
+ Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration()
+ .getHeatArtifactDeploymentTimeout().getDefaultMinutes();
for (ArtifactDefinition artifact : componentDeploymentArtifacts.values()) {
String type = artifact.getArtifactType();
if (!type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_ENV.getType())) {
finalDeploymentArtifacts.put(artifact.getArtifactLabel(), artifact);
}
- if (!(type.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT.getType()))) {
+ if (type.equalsIgnoreCase(ArtifactTypeEnum.HEAT.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_NET.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.HEAT_VOL.getType()) || type.equalsIgnoreCase(ArtifactTypeEnum.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT.getType())) {
+ artifact.setTimeout(defaultHeatTimeout);
+ } else {
continue;
}
if (artifact.checkEsIdExist()) {
- Either<ArtifactDefinition, ResponseFormat> createHeatEnvPlaceHolder = artifactBusinessLogic.createHeatEnvPlaceHolder(artifact, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(), NodeTypeEnum.ResourceInstance,
- componentInstance.getName(), user, containerComponent, existingEnvVersions);
- if (createHeatEnvPlaceHolder.isRight()) {
- return Either.right(createHeatEnvPlaceHolder.right().value());
- }
- ArtifactDefinition artifactDefinition = createHeatEnvPlaceHolder.left().value();
+ ArtifactDefinition artifactDefinition = artifactBusinessLogic.createHeatEnvPlaceHolder(new ArrayList<>(),
+ artifact, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
+ NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
+ existingEnvVersions);
// put env
finalDeploymentArtifacts.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
@@ -637,37 +701,25 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
filteredGroups = originComponent.getGroups().stream().filter(g -> g.getType().equals(VF_MODULE)).collect(Collectors.toList());
}
if (CollectionUtils.isNotEmpty(filteredGroups)) {
- for (GroupDefinition groupInstance : filteredGroups) {
- Optional<String> op = groupInstance.getArtifacts().stream().filter(p -> p.equals(artifactDefinition.getGeneratedFromId())).findAny();
- if (op.isPresent()) {
- List<ArtifactDefinition> artifactsUid;
- if (groupInstancesArtifacts.containsKey(groupInstance.getUniqueId())) {
- artifactsUid = groupInstancesArtifacts.get(groupInstance.getUniqueId());
- } else {
- artifactsUid = new ArrayList<>();
- }
- artifactsUid.add(artifactDefinition);
- groupInstancesArtifacts.put(groupInstance.getUniqueId(), artifactsUid);
- break;
- }
-
- if (isCloudSpecificArtifact(artifactDefinition.getArtifactName())) {
- groupInstance.getArtifacts().add(artifactDefinition.getGeneratedFromId());
- }
- }
+ filteredGroups.stream().filter(g ->
+ g.getArtifacts()
+ .stream()
+ .anyMatch(p -> p.equals(artifactDefinition.getGeneratedFromId())))
+ .findFirst()
+ .ifPresent(g -> fillInstanceArtifactMap(groupInstancesArtifacts, artifactDefinition, g));
}
}
}
artStatus = toscaOperationFacade.addDeploymentArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, finalDeploymentArtifacts);
if (artStatus != StorageOperationStatus.OK) {
log.debug("Failed to add instance deployment artifacts for instance {} in conatiner {} error {}", componentInstance.getUniqueId(), containerComponent.getUniqueId(), artStatus);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false)));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false)));
}
StorageOperationStatus result = toscaOperationFacade.addGroupInstancesToComponentInstance(containerComponent, componentInstance, filteredGroups, groupInstancesArtifacts);
if (result != StorageOperationStatus.OK) {
log.debug("failed to update group instance for component instance {}", componentInstance.getUniqueId());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result)));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result)));
}
componentInstance.setDeploymentArtifacts(finalDeploymentArtifacts);
}
@@ -675,20 +727,35 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
artStatus = toscaOperationFacade.addInformationalArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, originComponent.getArtifacts());
if (artStatus != StorageOperationStatus.OK) {
log.debug("Failed to add informational artifacts to the instance {} belonging to the conatiner {}. Status is {}", componentInstance.getUniqueId(), containerComponent.getUniqueId(), artStatus);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false)));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(artStatus, false)));
}
componentInstance.setArtifacts(originComponent.getArtifacts());
- return Either.left(ActionStatus.OK);
+ return ActionStatus.OK;
+ }
+
+ private void fillInstanceArtifactMap(Map<String, List<ArtifactDefinition>> groupInstancesArtifacts, ArtifactDefinition artifactDefinition, GroupDefinition groupInstance) {
+ List<ArtifactDefinition> artifactsUid;
+ if (groupInstancesArtifacts.containsKey(groupInstance.getUniqueId())) {
+ artifactsUid = groupInstancesArtifacts.get(groupInstance.getUniqueId());
+ } else {
+ artifactsUid = new ArrayList<>();
+ }
+ artifactsUid.add(artifactDefinition);
+ groupInstancesArtifacts.put(groupInstance.getUniqueId(), artifactsUid);
+ if (isCloudSpecificArtifact(artifactDefinition.getArtifactName())) {
+ groupInstance.getArtifacts().add(artifactDefinition.getGeneratedFromId());
+ }
}
private ActionStatus setResourceArtifactsOnResourceInstance(ComponentInstance resourceInstance) {
- Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = artifactBusinessLogic.getArtifacts(resourceInstance.getComponentUid(), NodeTypeEnum.Resource, ArtifactGroupTypeEnum.DEPLOYMENT, null);
+ Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts =
+ artifactBusinessLogic.getArtifacts(resourceInstance.getComponentUid(), NodeTypeEnum.Resource, ArtifactGroupTypeEnum.DEPLOYMENT, null);
Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
if (getResourceDeploymentArtifacts.isRight()) {
StorageOperationStatus status = getResourceDeploymentArtifacts.right().value();
- if (!status.equals(StorageOperationStatus.NOT_FOUND)) {
+ if (status != StorageOperationStatus.NOT_FOUND) {
log.debug("Failed to fetch resource: {} artifacts. status is {}", resourceInstance.getComponentUid(), status);
return componentsUtils.convertFromStorageResponseForResourceInstance(status, true);
}
@@ -711,119 +778,78 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
public Either<ComponentInstance, ResponseFormat> updateComponentInstanceMetadata(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance componentInstance) {
- return updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, componentInstance, false, true, true);
+ return updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, componentInstance, false, true);
}
public Either<ComponentInstance, ResponseFormat> updateComponentInstanceMetadata(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance componentInstance, boolean inTransaction,
- boolean needLock, boolean createNewTransaction) {
+ boolean needLock) {
- validateUserExists(userId, "update Component Instance", inTransaction);
+ validateUserExists(userId);
- Either<ComponentInstance, ResponseFormat> resultOp = null;
+ final ComponentTypeEnum containerComponentType = validateComponentType(containerComponentParam);
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
- if (validateComponentType.isRight()) {
- return Either.right(validateComponentType.right().value());
- }
-
- final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
-
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, null);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- }
- org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists(containerComponentId, containerComponentType, null);
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
- }
+ validateCanWorkOnComponent(containerComponent, userId);
ComponentTypeEnum instanceType = getComponentType(containerComponentType);
Either<Boolean, StorageOperationStatus> validateParentStatus = toscaOperationFacade.validateComponentExists(componentInstance.getComponentUid());
if (validateParentStatus.isRight()) {
log.debug("Failed to get component instance {} on service {}", componentInstanceId, containerComponentId);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, componentInstance.getName(), instanceType.getValue().toLowerCase()));
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, componentInstance.getName(), instanceType.getValue().toLowerCase());
}
if (!validateParentStatus.left().value()) {
- resultOp = Either.right(
- componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName(), instanceType.getValue().toLowerCase(), containerComponentType.getValue().toLowerCase(), containerComponentId));
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName(), instanceType.getValue().toLowerCase(), containerComponentType.getValue().toLowerCase(), containerComponentId);
}
if (needLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "updateComponentInstance");
- if (lockComponent.isRight()) {
- return Either.right(lockComponent.right().value());
- }
+ lockComponent(containerComponent, "updateComponentInstance");
}
+ Component origComponent;
+ boolean failed = false;
try {
-
- Either<Component, ResponseFormat> eitherResourceName = getOriginComponentFromComponentInstance(componentInstance);
-
- if (eitherResourceName.isRight()) {
- resultOp = Either.right(eitherResourceName.right().value());
- return resultOp;
+ origComponent = getOriginComponentFromComponentInstance(componentInstance);
+ componentInstance = updateComponentInstanceMetadata(containerComponent, containerComponentType, origComponent, componentInstanceId, componentInstance);
+ }catch (ComponentException e) {
+ failed = true;
+ throw e;
+ }finally {
+ if (needLock) {
+ unlockComponent(failed, containerComponent);
}
- Component origComponent = eitherResourceName.left().value();
-
- resultOp = updateComponentInstanceMetadata(containerComponent, containerComponentType, origComponent, componentInstanceId, componentInstance);
- return resultOp;
-
- } finally {
- if (needLock)
- unlockComponent(resultOp, containerComponent);
}
+ return Either.left(componentInstance);
}
// New Multiple Instance Update API
- public Either<List<ComponentInstance>, ResponseFormat> updateComponentInstance(String containerComponentParam, String containerComponentId, String userId, List<ComponentInstance> componentInstanceList, boolean needLock) {
+ public List<ComponentInstance> updateComponentInstance(String containerComponentParam, Component containerComponent, String containerComponentId, String userId, List<ComponentInstance> componentInstanceList, boolean needLock) {
- Either<List<ComponentInstance>, ResponseFormat> resultOp = null;
- org.openecomp.sdc.be.model.Component containerComponent = null;
+ boolean failed = false;
try {
- validateUserExists(userId, "update Component Instance", true);
-
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
- if (validateComponentType.isRight()) {
- return Either.right(validateComponentType.right().value());
- }
-
- final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ validateUserExists(userId);
+ final ComponentTypeEnum containerComponentType = validateComponentType(containerComponentParam);
ComponentParametersView componentFilter = new ComponentParametersView();
componentFilter.disableAll();
componentFilter.setIgnoreUsers(false);
componentFilter.setIgnoreComponentInstances(false);
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExistsByFilter(containerComponentId, containerComponentType, componentFilter);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- }
-
- containerComponent = validateComponentExists.left().value();
-
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
+ if (containerComponent == null) {
+ containerComponent = validateComponentExistsByFilter(containerComponentId, containerComponentType, componentFilter);
}
+ validateCanWorkOnComponent(containerComponent, userId);
ComponentTypeEnum instanceType = getComponentType(containerComponentType);
for (ComponentInstance componentInstance : componentInstanceList) {
boolean validateParent = validateParent(containerComponent, componentInstance.getUniqueId());
if (!validateParent) {
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName(), instanceType.getValue().toLowerCase(), containerComponentType.getValue().toLowerCase(),
- containerComponentId));
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName(),
+ instanceType.getValue().toLowerCase(), containerComponentType.getValue().toLowerCase(),
+ containerComponentId);
}
}
if (needLock) {
-
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "updateComponentInstance");
- if (lockComponent.isRight()) {
- return Either.right(lockComponent.right().value());
- }
+ lockComponent(containerComponent, "updateComponentInstance");
}
List<ComponentInstance> updatedList = new ArrayList<>();
@@ -843,8 +869,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Boolean isUniqueName = validateInstanceNameUniquenessUponUpdate(containerComponent, origInst, updatedCi.getName());
if (!isUniqueName) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the name of the component instance {} to {}. A component instance with the same name already exists. ", origInst.getName(), updatedCi.getName());
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), origInst.getName()));
- return resultOp;
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), origInst.getName()));
}
listForUpdate.add(updatedCi);
} else
@@ -852,28 +877,26 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
containerComponent.setComponentInstances(listForUpdate);
- if (resultOp == null) {
- Either<Component, StorageOperationStatus> updateStatus = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, componentFilter);
- if (updateStatus.isRight()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update metadata belonging to container component {}. Status is {}. ", containerComponent.getName(), updateStatus.right().value());
- resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(updateStatus.right().value(), true), "", null));
- return resultOp;
- }
- for (ComponentInstance updatedInstance : updateStatus.left().value().getComponentInstances()) {
- Optional<ComponentInstance> op = componentInstanceList.stream().filter(ci -> ci.getName().equals(updatedInstance.getName())).findAny();
- if (op.isPresent()) {
- updatedList.add(updatedInstance);
- }
+ Either<Component, StorageOperationStatus> updateStatus = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent, componentFilter);
+ if (updateStatus.isRight()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update metadata belonging to container component {}. Status is {}. ", containerComponent.getName(), updateStatus.right().value());
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(updateStatus.right().value(), true), "", null));
+ }
+
+ for (ComponentInstance updatedInstance : updateStatus.left().value().getComponentInstances()) {
+ Optional<ComponentInstance> op = componentInstanceList.stream().filter(ci -> ci.getName().equals(updatedInstance.getName())).findAny();
+ if (op.isPresent()) {
+ updatedList.add(updatedInstance);
}
}
}
-
- resultOp = Either.left(updatedList);
- return resultOp;
-
- } finally {
+ return updatedList;
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
if (needLock) {
- unlockComponent(resultOp, containerComponent);
+ unlockComponent(failed, containerComponent);
}
}
}
@@ -883,94 +906,94 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
private ComponentTypeEnum getComponentType(ComponentTypeEnum containerComponentType) {
- if (ComponentTypeEnum.PRODUCT.equals(containerComponentType)) {
+ if (ComponentTypeEnum.PRODUCT == containerComponentType) {
return ComponentTypeEnum.SERVICE_INSTANCE;
} else {
return ComponentTypeEnum.RESOURCE_INSTANCE;
}
}
- private Either<ComponentInstance, ResponseFormat> updateComponentInstanceMetadata(Component containerComponent, ComponentTypeEnum containerComponentType, org.openecomp.sdc.be.model.Component origComponent, String componentInstanceId,
- ComponentInstance componentInstance) {
+ private ComponentInstance updateComponentInstanceMetadata(Component containerComponent, ComponentTypeEnum containerComponentType, org.openecomp.sdc.be.model.Component origComponent, String componentInstanceId,
+ ComponentInstance componentInstance) {
- Either<ComponentInstance, ResponseFormat> resultOp = null;
- Optional<ComponentInstance> componentInstanceOptional = null;
+ Optional<ComponentInstance> componentInstanceOptional;
Either<ImmutablePair<Component, String>, StorageOperationStatus> updateRes = null;
ComponentInstance oldComponentInstance = null;
boolean isNameChanged = false;
- if (resultOp == null) {
- componentInstanceOptional = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(componentInstance.getUniqueId())).findFirst();
- if (!componentInstanceOptional.isPresent()) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find the component instance {} in container component {}. ", componentInstance.getName(), containerComponent.getName());
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName()));
- }
- }
- if (resultOp == null) {
- oldComponentInstance = componentInstanceOptional.get();
- String newInstanceName = componentInstance.getName();
- if (oldComponentInstance != null && oldComponentInstance.getName() != null && !oldComponentInstance.getName().equals(newInstanceName))
- isNameChanged = true;
- Boolean isUniqueName = validateInstanceNameUniquenessUponUpdate(containerComponent, oldComponentInstance, newInstanceName);
- if (!isUniqueName) {
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the name of the component instance {} to {}. A component instance with the same name already exists. ", oldComponentInstance.getName(), newInstanceName);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), componentInstance.getName()));
- }
- if(!DirectivesUtils.isValid(componentInstance.getDirectives())) {
- final String directivesStr =
- componentInstance.getDirectives().stream().collect(Collectors.joining(" , ", " [ ", " ] "));
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
- "Failed to update the directives of the component instance {} to {}. Directives data {} is invalid. ",
- oldComponentInstance.getName(), newInstanceName ,
- directivesStr);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.DIRECTIVES_INVALID_VALUE,
- directivesStr));
- }
+ componentInstanceOptional = containerComponent.getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(componentInstance.getUniqueId())).findFirst();
+ if (!componentInstanceOptional.isPresent()) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to find the component instance {} in container component {}. ", componentInstance.getName(), containerComponent.getName());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName());
}
+ String oldComponentName;
+ oldComponentInstance = componentInstanceOptional.get();
+ oldComponentName = oldComponentInstance.getName();
String newInstanceName = componentInstance.getName();
- String oldInstanceName = null;
- if (resultOp == null) {
- oldComponentInstance = componentInstanceOptional.get();
- newInstanceName = componentInstance.getName();
- 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());
- resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(updateRes.right().value(), true), "", null));
- } else {
- // region - Update instance Groups
- if (isNameChanged) {
- Either result = toscaOperationFacade.cleanAndAddGroupInstancesToComponentInstance(containerComponent, oldComponentInstance, componentInstanceId);
- if (result.isRight())
- CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to rename group instances for container {}. error {} ", componentInstanceId, result.right().value());
- if (containerComponent instanceof Service) {
- Either<ComponentInstance, ResponseFormat> renameEither =
- renameServiceFilter((Service) containerComponent, newInstanceName,
- oldInstanceName);
- if (renameEither.isRight()) {
- return renameEither;
- }
+ if (oldComponentName != null && !oldComponentInstance.getName().equals(newInstanceName))
+ isNameChanged = true;
+ Boolean isUniqueName = validateInstanceNameUniquenessUponUpdate(containerComponent, oldComponentInstance, newInstanceName);
+ if (!isUniqueName) {
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to update the name of the component instance {} to {}. A component instance with the same name already exists. ", oldComponentInstance.getName(), newInstanceName);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, containerComponentType.getValue(), componentInstance.getName());
+ }
+ if(!DirectivesUtils.isValid(componentInstance.getDirectives())) {
+ final String directivesStr =
+ componentInstance.getDirectives().stream().collect(Collectors.joining(" , ", " [ ", " ] "));
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG,
+ "Failed to update the directives of the component instance {} to {}. Directives data {} is invalid. ",
+ oldComponentInstance.getName(), newInstanceName ,
+ directivesStr);
+ throw new ByActionStatusComponentException(ActionStatus.DIRECTIVES_INVALID_VALUE, containerComponentType.getValue(), componentInstance.getName()); }
+ 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());
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatForResourceInstance(componentsUtils.convertFromStorageResponseForResourceInstance(updateRes.right().value(), true), "", null));
+ } else {
+ // region - Update instance Groups
+ if (isNameChanged) {
+ Either<StorageOperationStatus, StorageOperationStatus> result =
+ toscaOperationFacade.cleanAndAddGroupInstancesToComponentInstance(containerComponent, oldComponentInstance, componentInstanceId);
+ if (result.isRight())
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to rename group instances for container {}. error {} ", componentInstanceId, result.right().value());
+
+ if (containerComponent instanceof Service){
+ Either<ComponentInstance, ResponseFormat> renameEither =
+ renameServiceFilter((Service) containerComponent, newInstanceName,
+ oldComponentInstance.getName());
+ if (renameEither.isRight()) {
+ throw new ByResponseFormatComponentException(renameEither.right().value());
}
+
+ updateForwardingPathDefinition(containerComponent, componentInstance, oldComponentName);
}
- // endregion
}
+ // endregion
}
- if (resultOp == null) {
- String newInstanceId = updateRes.left().value().getRight();
- Optional<ComponentInstance> updatedInstanceOptional = updateRes.left().value().getLeft().getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(newInstanceId)).findFirst();
+ String newInstanceId = updateRes.left().value().getRight();
+ Optional<ComponentInstance> updatedInstanceOptional = updateRes.left().value().getLeft().getComponentInstances().stream().filter(ci -> ci.getUniqueId().equals(newInstanceId)).findFirst();
- if (!updatedInstanceOptional.isPresent()) {
- log.debug("Failed to update metadata of component instance {} of container component {}", componentInstance.getName(), containerComponent.getName());
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName()));
- } else {
- resultOp = Either.left(updatedInstanceOptional.get());
- }
-
- }
- if (resultOp == null) {
- resultOp = Either.left(componentInstanceOptional.get());
+ if (!updatedInstanceOptional.isPresent()) {
+ log.debug("Failed to update metadata of component instance {} of container component {}", componentInstance.getName(), containerComponent.getName());
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, componentInstance.getName()));
}
- return resultOp;
+
+ return componentInstanceOptional.get();
+ }
+
+ private void updateForwardingPathDefinition(Component containerComponent, ComponentInstance componentInstance, String oldComponentName) {
+ Collection<ForwardingPathDataDefinition> forwardingPathDataDefinitions = getForwardingPathDataDefinitions(containerComponent.getUniqueId());
+ Set<ForwardingPathDataDefinition> updated = new ForwardingPathUtils()
+ .updateComponentInstanceName(forwardingPathDataDefinitions, oldComponentName,
+ componentInstance.getName());
+ updated.forEach(fp -> {
+ Either<ForwardingPathDataDefinition, StorageOperationStatus> resultEither = forwardingPathOperation
+ .updateForwardingPath(containerComponent.getUniqueId(), fp);
+ if (resultEither.isRight()){
+ CommonUtility.addRecordToLog(log, LogLevelEnum.ERROR, "Failed to rename forwarding path for container {}. error {} ",containerComponent.getName(), resultEither.right().value());
+ }
+ });
}
@@ -1023,32 +1046,17 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return oldComponentInstance;
}
- public Either<ComponentInstance, ResponseFormat> deleteComponentInstance(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId) {
+ public ComponentInstance deleteComponentInstance(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId) {
- validateUserExists(userId, "delete Component Instance", false);
+ validateUserExists(userId);
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
- if (validateComponentType.isRight()) {
- return Either.right(validateComponentType.right().value());
- }
+ final ComponentTypeEnum containerComponentType = validateComponentType(containerComponentParam);
- final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, null);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- }
- org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
- }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists(containerComponentId, containerComponentType, null);
+ validateCanWorkOnComponent(containerComponent, userId);
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "deleteComponentInstance");
- if (lockComponent.isRight()) {
- return Either.right(lockComponent.right().value());
- }
-
- Either<ComponentInstance, ResponseFormat> resultOp = null;
+ boolean failed = false;
+ ComponentInstance deletedRelatedInst;
try {
if (containerComponent instanceof Service) {
ComponentInstance componentInstance = containerComponent.getComponentInstanceById(componentInstanceId).get();
@@ -1058,29 +1066,32 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
ActionStatus status = componentsUtils.convertFromStorageResponse(deleteServiceFilterEither.right().value(),
containerComponentType);
janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(status, componentInstanceId));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(status, componentInstanceId));
}
- resultOp = deleteServiceFiltersRelatedTobeDeletedComponentInstance((Service) containerComponent,
+ Either<ComponentInstance, ResponseFormat> resultOp = deleteServiceFiltersRelatedTobeDeletedComponentInstance((Service) containerComponent,
componentInstance, ComponentTypeEnum.SERVICE, userId);
if (resultOp.isRight()) {
janusGraphDao.rollback();
- return resultOp;
+ throw new ByResponseFormatComponentException(resultOp.right().value());
}
}
- resultOp = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);
- if (resultOp.isRight()){
- return resultOp;
- }
- Either<ComponentInstance, ResponseFormat> deleteEither = deleteForwardingPathsRelatedTobeDeletedComponentInstance(containerComponentId,
- containerComponentType, resultOp);
- if (deleteEither.isRight()){
- return deleteEither;
- }
- return deleteEither;
+ lockComponent(containerComponent, "deleteComponentInstance");
+ ComponentInstance deletedCompInstance = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);
- } finally {
- unlockComponent(resultOp, containerComponent);
+ deletedRelatedInst = deleteForwardingPathsRelatedTobeDeletedComponentInstance(containerComponentId,
+ containerComponentType, deletedCompInstance);
+ ActionStatus onDeleteOperationsStatus = onChangeInstanceOperationOrchestrator.doOnDeleteInstanceOperations(containerComponent, componentInstanceId);
+ if (ActionStatus.OK != onDeleteOperationsStatus) {
+ throw new ByActionStatusComponentException(onDeleteOperationsStatus);
+ }
+ } catch (ComponentException e) {
+ failed = true;
+ throw e;
}
+ finally {
+ unlockComponent(failed, containerComponent);
+ }
+ return deletedRelatedInst;
}
public Either<ComponentInstance, ResponseFormat> deleteServiceFiltersRelatedTobeDeletedComponentInstance(
@@ -1112,7 +1123,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
ci.setDirectives(directives);
final Either<ComponentInstance, ResponseFormat> componentInstanceResponseFormatEither =
updateComponentInstanceMetadata(ComponentTypeEnum.SERVICE_PARAM_NAME, service.getUniqueId(),
- ci.getUniqueId(), userId, ci, true, false, false);
+ ci.getUniqueId(), userId, ci, true, false);
if (componentInstanceResponseFormatEither.isRight()) {
return componentInstanceResponseFormatEither;
}
@@ -1137,45 +1148,37 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
- public Either<ComponentInstance, ResponseFormat> deleteForwardingPathsRelatedTobeDeletedComponentInstance(String containerComponentId, ComponentTypeEnum containerComponentType,
- Either<ComponentInstance, ResponseFormat> resultOp) {
- if(containerComponentType.equals(ComponentTypeEnum.SERVICE) && resultOp.isLeft() ){
- final ComponentInstance componentInstance = resultOp.left().value();
+ ComponentInstance deleteForwardingPathsRelatedTobeDeletedComponentInstance(String containerComponentId,
+ ComponentTypeEnum containerComponentType, ComponentInstance componentInstance) {
+ if(containerComponentType == ComponentTypeEnum.SERVICE){
List<String> pathIDsToBeDeleted = getForwardingPathsRelatedToComponentInstance(containerComponentId, componentInstance.getName());
if (!pathIDsToBeDeleted.isEmpty()) {
- Either<Set<String>, ResponseFormat> deleteForwardingPathsEither = deleteForwardingPaths(containerComponentId,
- pathIDsToBeDeleted);
- if(deleteForwardingPathsEither.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
+ deleteForwardingPaths(containerComponentId, pathIDsToBeDeleted);
}
}
- return resultOp;
+ return componentInstance;
}
- private Either<Set<String>, ResponseFormat> deleteForwardingPaths(String serviceId, List<String> pathIdsToDelete){
+
+
+
+ private void deleteForwardingPaths(String serviceId, List<String> pathIdsToDelete){
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
if(storageStatus.isRight()) {
- return Either.right(componentsUtils.getResponseFormat(storageStatus.right().value()));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageStatus.right().value()));
}
Either<Set<String>, StorageOperationStatus> result = forwardingPathOperation.deleteForwardingPath(storageStatus.left().value(),
Sets.newHashSet(pathIdsToDelete));
if(result.isRight()) {
- return Either.right(componentsUtils.getResponseFormat(result.right().value()));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(result.right().value()));
}
- return Either.left(result.left().value());
}
private List<String> getForwardingPathsRelatedToComponentInstance(String containerComponentId, String componentInstanceId){
- ComponentParametersView filter = new ComponentParametersView(true);
- filter.setIgnoreForwardingPath(false);
- Either<Service, StorageOperationStatus> forwardingPathOrigin = toscaOperationFacade
- .getToscaElement(containerComponentId, filter);
- Collection<ForwardingPathDataDefinition> allPaths = forwardingPathOrigin.left().value().getForwardingPaths().values();
+ Collection<ForwardingPathDataDefinition> allPaths = getForwardingPathDataDefinitions(containerComponentId);
List<String> pathIDsToBeDeleted = new ArrayList<>();
allPaths.stream().filter(path -> isPathRelatedToComponent(path,componentInstanceId ))
@@ -1184,6 +1187,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return pathIDsToBeDeleted;
}
+ private Collection<ForwardingPathDataDefinition> getForwardingPathDataDefinitions(String containerComponentId) {
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreForwardingPath(false);
+ Either<Service, StorageOperationStatus> forwardingPathOrigin = toscaOperationFacade
+ .getToscaElement(containerComponentId, filter);
+ return forwardingPathOrigin.left().value().getForwardingPaths().values();
+ }
+
private boolean isPathRelatedToComponent(ForwardingPathDataDefinition pathDataDefinition,
String componentInstanceId){
return pathDataDefinition.getPathElements().getListToscaDataDefinition()
@@ -1193,49 +1204,28 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
- private Either<ComponentInstance, ResponseFormat> deleteComponentInstance(Component containerComponent, String componentInstanceId, ComponentTypeEnum containerComponentType) {
-
- Either<ComponentInstance, ResponseFormat> resultOp = null;
- ComponentInstance deletedInstance = null;
+ private ComponentInstance deleteComponentInstance(Component containerComponent, String componentInstanceId, ComponentTypeEnum containerComponentType) {
Either<ImmutablePair<Component, String>, StorageOperationStatus> deleteRes = toscaOperationFacade.deleteComponentInstanceFromTopologyTemplate(containerComponent, componentInstanceId);
-
if (deleteRes.isRight()) {
log.debug("Failed to delete entry on graph for resourceInstance {}", componentInstanceId);
ActionStatus status = componentsUtils.convertFromStorageResponse(deleteRes.right().value(), containerComponentType);
- resultOp = Either.right(componentsUtils.getResponseFormat(status, componentInstanceId));
- }
- if (resultOp == null) {
- log.debug("The component instance {} has been removed from container component {}. ", componentInstanceId, containerComponent);
- deletedInstance = findAndRemoveComponentInstanceFromContainerComponent(componentInstanceId, containerComponent);
- resultOp = Either.left(deletedInstance);
- }
- if (resultOp.isLeft() && CollectionUtils.isNotEmpty(containerComponent.getGroups())) {
- List<GroupDataDefinition> groupsToUpdate = new ArrayList<>();
- for (GroupDataDefinition currGroup : containerComponent.getGroups()) {
- Map<String, String> members = currGroup.getMembers();
- if (members != null && members.containsKey(deletedInstance.getName())) {
- members.remove(deletedInstance.getName());
- groupsToUpdate.add(currGroup);
- }
- }
- Either<List<GroupDefinition>, StorageOperationStatus> updateGroupsRes = toscaOperationFacade.updateGroupsOnComponent(containerComponent, groupsToUpdate);
- if (updateGroupsRes.isRight()) {
- log.debug("Failed to delete component instance {} from group members. ", componentInstanceId);
- ActionStatus status = componentsUtils.convertFromStorageResponse(updateGroupsRes.right().value(), containerComponentType);
- resultOp = Either.right(componentsUtils.getResponseFormat(status, componentInstanceId));
- }
+ throw new ByActionStatusComponentException(status, componentInstanceId);
}
- if (resultOp.isLeft() && CollectionUtils.isNotEmpty(containerComponent.getInputs())) {
+ log.debug("The component instance {} has been removed from container component {}. ", componentInstanceId, containerComponent);
+ ComponentInstance deletedInstance = findAndRemoveComponentInstanceFromContainerComponent(componentInstanceId, containerComponent);
+
+ if (CollectionUtils.isNotEmpty(containerComponent.getInputs())) {
List<InputDefinition> inputsToDelete = containerComponent.getInputs().stream().filter(i -> i.getInstanceUniqueId() != null && i.getInstanceUniqueId().equals(componentInstanceId)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(inputsToDelete)) {
StorageOperationStatus deleteInputsRes = toscaOperationFacade.deleteComponentInstanceInputsFromTopologyTemplate(containerComponent, inputsToDelete);
if (deleteInputsRes != StorageOperationStatus.OK) {
log.debug("Failed to delete inputs of the component instance {} from container component. ", componentInstanceId);
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteInputsRes, containerComponentType), componentInstanceId));
+ throw new ByActionStatusComponentException(
+ componentsUtils.convertFromStorageResponse(deleteInputsRes, containerComponentType), componentInstanceId);
}
}
}
- return resultOp;
+ return deletedInstance;
}
private ComponentInstance findAndRemoveComponentInstanceFromContainerComponent(String componentInstanceId, Component containerComponent) {
@@ -1261,59 +1251,45 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return !relation.getToNode().equals(componentInstanceId) && !relation.getFromNode().equals(componentInstanceId);
}
- public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum) {
- return associateRIToRI(componentId, userId, requirementDef, componentTypeEnum, false, true, true);
+ public RequirementCapabilityRelDef associateRIToRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum) {
+ return associateRIToRI(componentId, userId, requirementDef, componentTypeEnum, false, true);
}
- public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum, boolean inTransaction, boolean needLock,
- boolean createNewTransaction) {
-
- validateUserExists(userId, "associate Ri To RI", inTransaction);
+ public RequirementCapabilityRelDef associateRIToRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum, boolean inTransaction, boolean needLock) {
- Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
+ validateUserExists(userId);
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(componentId, componentTypeEnum, null);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- }
- org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
+ RequirementCapabilityRelDef requirementCapabilityRelDef = null;
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
- }
- if (needLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "associateRIToRI");
-
- if (lockComponent.isRight()) {
- return Either.right(lockComponent.right().value());
- }
- }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists(componentId, componentTypeEnum, null);
+ validateCanWorkOnComponent(containerComponent, userId);
+ boolean failed = false;
try {
-
- resultOp = associateRIToRIOnGraph(validateComponentExists.left().value(), requirementDef, componentTypeEnum, inTransaction);
-
- return resultOp;
-
- } finally {
+ if (needLock) {
+ lockComponent(containerComponent, "associateRIToRI");
+ }
+ requirementCapabilityRelDef = associateRIToRIOnGraph(containerComponent, requirementDef);
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
if (needLock)
- unlockComponent(resultOp, containerComponent);
+ unlockComponent(failed, containerComponent);
}
+ return requirementCapabilityRelDef;
}
- public Either<RequirementCapabilityRelDef, ResponseFormat> associateRIToRIOnGraph(Component containerComponent, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum, boolean inTransaction) {
+ public RequirementCapabilityRelDef associateRIToRIOnGraph(Component containerComponent, RequirementCapabilityRelDef requirementDef) {
log.debug(TRY_TO_CREATE_ENTRY_ON_GRAPH);
- Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
- Either<RequirementCapabilityRelDef, StorageOperationStatus> result = toscaOperationFacade.associateResourceInstances(containerComponent.getUniqueId(), requirementDef);
+ Either<RequirementCapabilityRelDef, StorageOperationStatus> result = toscaOperationFacade.associateResourceInstances(null, containerComponent.getUniqueId(), requirementDef);
if (result.isLeft()) {
- log.debug("Enty on graph is created.");
+ log.debug(ENTITY_ON_GRAPH_IS_CREATED);
RequirementCapabilityRelDef requirementCapabilityRelDef = result.left().value();
- resultOp = Either.left(requirementCapabilityRelDef);
- return resultOp;
+ return requirementCapabilityRelDef;
} else {
log.debug("Failed to associate node: {} with node {}", requirementDef.getFromNode(), requirementDef.getToNode());
@@ -1331,9 +1307,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
toNameOrId = toResult.left().value().getName();
}
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true), fromNameOrId, toNameOrId, requirementDef.getRelationships().get(0).getRelation().getRequirement()));
-
- return resultOp;
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponseForResourceInstance
+ (result.right().value(), true), fromNameOrId, toNameOrId,
+ requirementDef.getRelationships().get(0).getRelation().getRequirement());
}
}
@@ -1351,112 +1327,71 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
List<RequirementCapabilityRelDef> requirementDefList,
ComponentTypeEnum componentTypeEnum) {
+ validateUserExists(userId);
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists(componentId, componentTypeEnum, null);
+ validateCanWorkOnComponent(containerComponent, userId);
+ boolean failed = false;
List<RequirementCapabilityRelDef> delOkResult = new ArrayList<>();
- Either<Component, ResponseFormat> validateResponse = validateDissociateRI(componentId, userId, componentTypeEnum);
- if (validateResponse.isRight()) {
-
- return delOkResult;
- }
- Component containerComponent = validateResponse.left().value();
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "associateRIToRI");
- if (lockComponent.isRight()) {
- return delOkResult;
- }
try {
+ lockComponent(containerComponent, "associateRIToRI");
for (RequirementCapabilityRelDef requirementDef : requirementDefList) {
- Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = dissociateRIFromRI(
- componentId, requirementDef, containerComponent);
-
- if (actionResponse.isLeft()) {
- delOkResult.add(actionResponse.left().value());
- }
+ RequirementCapabilityRelDef requirementCapabilityRelDef = dissociateRIFromRI(
+ componentId, userId, requirementDef, containerComponent.getComponentType());
+ delOkResult.add(requirementCapabilityRelDef);
}
- } finally {
- unlockComponent(validateResponse, containerComponent);
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponent(failed, containerComponent);
}
return delOkResult;
}
- public Either<RequirementCapabilityRelDef, ResponseFormat> dissociateRIFromRI(
- String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum) {
- Either<Component, ResponseFormat> validateResponse = validateDissociateRI(componentId, userId, componentTypeEnum);
- if(validateResponse.isRight())
- {
- return Either.right(validateResponse.right().value());
- }
- Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = null;
- Component containerComponent = validateResponse.left().value();
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "associateRIToRI");
- if (lockComponent.isRight()) {
- return Either.right(lockComponent.right().value());
- }
- try {
- actionResponse = dissociateRIFromRI(
- componentId, requirementDef,containerComponent);
- } finally {
- unlockComponent(validateResponse, containerComponent);
- }
- return actionResponse;
- }
-
- private Either<Component, ResponseFormat> validateDissociateRI(
- String componentId, String userId, ComponentTypeEnum componentTypeEnum) {
- validateUserExists(userId, "dissociate RI From RI", false);
-
-
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(componentId, componentTypeEnum, null);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- }
- org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
-
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
- }
- return Either.left(containerComponent);
- }
- private Either<RequirementCapabilityRelDef, ResponseFormat> dissociateRIFromRI(
- String componentId, RequirementCapabilityRelDef requirementDef, Component containerComponent) {
+ public RequirementCapabilityRelDef dissociateRIFromRI(String componentId, String userId, RequirementCapabilityRelDef requirementDef, ComponentTypeEnum componentTypeEnum) {
+ validateUserExists(userId);
Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null;
- log.debug(TRY_TO_CREATE_ENTRY_ON_GRAPH);
- Either<RequirementCapabilityRelDef, StorageOperationStatus> result = toscaOperationFacade.dissociateResourceInstances(
- componentId, requirementDef);
- if (result.isLeft()) {
- log.debug("Enty on graph is created.");
- RequirementCapabilityRelDef requirementCapabilityRelDef = result.left().value();
- resultOp = Either.left(requirementCapabilityRelDef);
- return resultOp;
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists(componentId, componentTypeEnum, null);
- } else {
+ validateCanWorkOnComponent(containerComponent, userId);
+ boolean failed = false;
+ try {
+ lockComponent(containerComponent, "associateRIToRI");
+ log.debug(TRY_TO_CREATE_ENTRY_ON_GRAPH);
+ Either<RequirementCapabilityRelDef, StorageOperationStatus> result = toscaOperationFacade.dissociateResourceInstances(componentId, requirementDef);
+ if (result.isLeft()) {
+ log.debug(ENTITY_ON_GRAPH_IS_CREATED);
+ return result.left().value();
+ } else {
- log.debug("Failed to dissocaite node {} from node {}", requirementDef.getFromNode(), requirementDef.getToNode());
- String fromNameOrId = "";
- String toNameOrId = "";
- Either<ComponentInstance, StorageOperationStatus> fromResult = getResourceInstanceById(
- containerComponent, requirementDef.getFromNode());
- Either<ComponentInstance, StorageOperationStatus> toResult = getResourceInstanceById(
- containerComponent, requirementDef.getToNode());
+ log.debug("Failed to dissocaite node {} from node {}", requirementDef.getFromNode(), requirementDef.getToNode());
+ String fromNameOrId = "";
+ String toNameOrId = "";
+ Either<ComponentInstance, StorageOperationStatus> fromResult = getResourceInstanceById(containerComponent, requirementDef.getFromNode());
+ Either<ComponentInstance, StorageOperationStatus> toResult = getResourceInstanceById(containerComponent, requirementDef.getToNode());
- toNameOrId = requirementDef.getFromNode();
- fromNameOrId = requirementDef.getFromNode();
- if (fromResult.isLeft()) {
- fromNameOrId = fromResult.left().value().getName();
- }
- if (toResult.isLeft()) {
- toNameOrId = toResult.left().value().getName();
- }
+ toNameOrId = requirementDef.getFromNode();
+ fromNameOrId = requirementDef.getFromNode();
+ if (fromResult.isLeft()) {
+ fromNameOrId = fromResult.left().value().getName();
+ }
+ if (toResult.isLeft()) {
+ toNameOrId = toResult.left().value().getName();
+ }
- resultOp = Either
- .right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponseForResourceInstance(
- result.right().value(), true), fromNameOrId, toNameOrId, requirementDef.getRelationships().get(0).getRelation().getRequirement()));
- return resultOp;
+ throw new ByActionStatusComponentException(
+ componentsUtils.convertFromStorageResponseForResourceInstance(result.right().value(), true),
+ fromNameOrId, toNameOrId, requirementDef.getRelationships().get(0).getRelation().getRequirement());
+ }
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponent(failed, containerComponent);
}
}
-
/**
* Allows to get relation contained in specified component according to received Id
* @param componentId
@@ -1473,23 +1408,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = null;
RequirementCapabilityRelDef foundRelation = null;
- validateUserExists(userId, "get relation by Id", false);
-
- if(resultOp == null){
- validateComponentExists = validateComponentExists(componentId, componentTypeEnum, null);
- if (validateComponentExists.isRight()) {
- resultOp = Either.right(validateComponentExists.right().value());
- }
- }
- if(resultOp == null){
- containerComponent = validateComponentExists.left().value();
- List<RequirementCapabilityRelDef> requirementCapabilityRelations = containerComponent.getComponentInstancesRelations();
- foundRelation = findRelation(relationId, requirementCapabilityRelations);
- if(foundRelation == null){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RELATION_NOT_FOUND, relationId, componentId);
- log.debug("Relation with id {} was not found on the component", relationId, componentId);
- resultOp = Either.right(responseFormat);
- }
+ validateUserExists(userId);
+ containerComponent = validateComponentExists(componentId, componentTypeEnum, null);
+ List<RequirementCapabilityRelDef> requirementCapabilityRelations = containerComponent.getComponentInstancesRelations();
+ foundRelation = findRelation(relationId, requirementCapabilityRelations);
+ if(foundRelation == null){
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RELATION_NOT_FOUND, relationId, componentId);
+ log.debug("Relation with id {} was not found on the component", relationId, componentId);
+ resultOp = Either.right(responseFormat);
}
if(resultOp == null){
resultOp = setRelatedCapability(foundRelation, containerComponent);
@@ -1526,7 +1452,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
if(result == null){
for(List<RequirementDefinition> requirements : instance.get().getRequirements().values()){
- foundRequirement = requirements.stream().filter(r -> isBelongingRequirement(relationshipInfo, r)).findFirst();
+ foundRequirement = requirements.stream().filter(r -> isBelongingCalcRequirement(relationshipInfo, r, containerComponent.getLifecycleState())).findFirst();
if(foundRequirement.isPresent()){
foundRelation.resolveSingleRelationship().setRequirement(foundRequirement.get());
result = Either.left(foundRelation);
@@ -1534,7 +1460,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
if(result == null){
- Either<RequirementDataDefinition, StorageOperationStatus> getfulfilledRequirementRes = toscaOperationFacade.getFulfilledRequirementByRelation(containerComponent.getUniqueId(), instanceId, foundRelation, (rel, req)->isBelongingRequirement(rel, req));
+ Either<RequirementDataDefinition, StorageOperationStatus> getfulfilledRequirementRes = toscaOperationFacade.getFulfilledRequirementByRelation(containerComponent.getUniqueId(), instanceId, foundRelation, this::isBelongingFullRequirement);
if(getfulfilledRequirementRes.isRight()){
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.REQUIREMENT_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, relationshipInfo.getRequirement(), instanceId, containerComponent.getUniqueId());
log.debug("Requirement {} of instance {} was not found on the container {}. ", relationshipInfo.getCapability(), instanceId, containerComponent.getUniqueId());
@@ -1549,12 +1475,18 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return result;
}
- private boolean isBelongingRequirement(RelationshipInfo relationshipInfo, RequirementDataDefinition req) {
+ private boolean isBelongingFullRequirement(RelationshipInfo relationshipInfo, RequirementDataDefinition req) {
return req.getName().equals(relationshipInfo.getRequirement()) &&
req.getUniqueId().equals(relationshipInfo.getRequirementUid()) &&
req.getOwnerId().equals(relationshipInfo.getRequirementOwnerId());
}
+ private boolean isBelongingCalcRequirement(RelationshipInfo relationshipInfo, RequirementDataDefinition req, LifecycleStateEnum state) {
+ return nameMatches(relationshipInfo.getRequirement(), req.getName(), req.getPreviousName(), state) &&
+ req.getUniqueId().equals(relationshipInfo.getRequirementUid()) &&
+ req.getOwnerId().equals(relationshipInfo.getRequirementOwnerId());
+ }
+
private Either<RequirementCapabilityRelDef, ResponseFormat> setRelatedCapability(RequirementCapabilityRelDef foundRelation, Component containerComponent) {
Either<RequirementCapabilityRelDef, ResponseFormat> result = null;
RelationshipInfo relationshipInfo = foundRelation.resolveSingleRelationship().getRelation();
@@ -1568,7 +1500,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
if(result == null){
for(List<CapabilityDefinition> capabilities : instance.get().getCapabilities().values()){
- foundCapability = capabilities.stream().filter(c -> isBelongingCapability(relationshipInfo, c)).findFirst();
+ foundCapability = capabilities.stream().filter(c -> isBelongingCalcCapability(relationshipInfo, c, containerComponent.getLifecycleState())).findFirst();
if(foundCapability.isPresent()){
foundRelation.resolveSingleRelationship().setCapability(foundCapability.get());
result = Either.left(foundRelation);
@@ -1577,7 +1509,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
if(result == null){
Either<CapabilityDataDefinition, StorageOperationStatus> getfulfilledRequirementRes =
- toscaOperationFacade.getFulfilledCapabilityByRelation(containerComponent.getUniqueId(), instanceId, foundRelation, (rel, cap)->isBelongingCapability(rel, cap));
+ toscaOperationFacade.getFulfilledCapabilityByRelation(containerComponent.getUniqueId(), instanceId, foundRelation, this::isBelongingFullCapability);
if(getfulfilledRequirementRes.isRight()){
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER, relationshipInfo.getCapability(), instanceId, containerComponent.getUniqueId());
log.debug("Capability {} of instance {} was not found on the container {}. ", relationshipInfo.getCapability(), instanceId, containerComponent.getUniqueId());
@@ -1592,12 +1524,24 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return result;
}
- private boolean isBelongingCapability(RelationshipInfo relationshipInfo, CapabilityDataDefinition cap) {
+ private boolean isBelongingFullCapability(RelationshipInfo relationshipInfo, CapabilityDataDefinition cap) {
return cap.getName().equals(relationshipInfo.getCapability()) &&
cap.getUniqueId().equals(relationshipInfo.getCapabilityUid()) &&
cap.getOwnerId().equals(relationshipInfo.getCapabilityOwnerId());
}
+ private boolean isBelongingCalcCapability(RelationshipInfo relationshipInfo, CapabilityDataDefinition cap, LifecycleStateEnum state) {
+ return nameMatches(relationshipInfo.getCapability(), cap.getName(), cap.getPreviousName(), state) &&
+ cap.getUniqueId().equals(relationshipInfo.getCapabilityUid()) &&
+ cap.getOwnerId().equals(relationshipInfo.getCapabilityOwnerId());
+ }
+
+ private boolean nameMatches(String nameFromRelationship, String currName, String previousName, LifecycleStateEnum state) {
+ return state == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT ?
+ currName.equals(nameFromRelationship):
+ previousName!= null && previousName.equals(nameFromRelationship);
+ }
+
private Either<ComponentInstanceProperty, ResponseFormat> updateAttributeValue(ComponentInstanceProperty attribute, String resourceInstanceId) {
Either<ComponentInstanceProperty, StorageOperationStatus> eitherAttribute = componentInstanceOperation.updateAttributeValueInResourceInstance(attribute, resourceInstanceId, true);
Either<ComponentInstanceProperty, ResponseFormat> result;
@@ -1660,7 +1604,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Either<ComponentInstanceProperty, ResponseFormat> result = null;
Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- validateUserExist(userId, "create Or Update Attribute Value");
+ validateUserExists(userId);
if (errorWrapper.isEmpty()) {
validateComponentTypeEnum(componentTypeEnum, "CreateOrUpdateAttributeValue", errorWrapper);
}
@@ -1696,45 +1640,12 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
- private boolean isNetworkRoleServiceProperty(ComponentInstanceProperty property, ComponentTypeEnum componentTypeEnum) {
- return StringUtils.isNotEmpty(property.getValue())
- && PropertyNames.NETWORK_ROLE.getPropertyName().equalsIgnoreCase(property.getName())
- && ComponentTypeEnum.SERVICE == componentTypeEnum;
- }
-
- // US833308 VLI in service - specific network_role property value logic
- private StorageOperationStatus concatServiceNameToVLINetworkRolePropertiesValues(ToscaOperationFacade toscaOperationFacade, ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, List<ComponentInstanceProperty> properties) {
- for (ComponentInstanceProperty property: properties) {
- if (isNetworkRoleServiceProperty(property, componentTypeEnum)) {
- ComponentParametersView componentParametersView = new ComponentParametersView();
- componentParametersView.disableAll();
- componentParametersView.setIgnoreComponentInstances(false);
- Either<Component, StorageOperationStatus> getServiceResult = toscaOperationFacade.getToscaElement(componentId, componentParametersView);
- if (getServiceResult.isRight()) {
- return getServiceResult.right().value();
- }
- Component service = getServiceResult.left().value();
- Optional<ComponentInstance> getInstance = service.getComponentInstances().stream().filter(p -> p.getUniqueId().equals(resourceInstanceId)).findAny();
- if (!getInstance.isPresent()) {
- return StorageOperationStatus.NOT_FOUND;
- }
- String prefix = service.getSystemName() + ".";
- String value = property.getValue();
- if (OriginTypeEnum.VL == getInstance.get().getOriginType() && (!value.startsWith(prefix) || value.equalsIgnoreCase(prefix))) {
- property.setValue(prefix + value);
- }
- }
- }
- return StorageOperationStatus.OK;
- }
-
public Either<List<ComponentInstanceProperty>, ResponseFormat> createOrUpdatePropertiesValues(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, List<ComponentInstanceProperty> properties, String userId) {
Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
/*-------------------------------Validations---------------------------------*/
-
- validateUserExists(userId, "create Or Update Properties Values", false);
+ validateUserExists(userId);
if (componentTypeEnum == null) {
BeEcompErrorManager.getInstance().logInvalidInputError("CreateOrUpdatePropertiesValues", INVALID_COMPONENT_TYPE, ErrorSeverity.INFO);
@@ -1745,51 +1656,45 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (getResourceResult.isRight()) {
log.debug(FAILED_TO_RETRIEVE_COMPONENT_COMPONENT_ID, componentId);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
- return resultOp;
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResourceResult.right().value(), componentTypeEnum);
+ return Either.right(componentsUtils.getResponseFormat(actionStatus, componentId));
}
Component containerComponent = getResourceResult.left().value();
if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
+ if (containerComponent.isArchived()) {
+ log.info("Component is archived. Component id: {}", componentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_IS_ARCHIVED, containerComponent.getName()));
+ }
log.info("Restricted operation for user: {} on service {}", userId, componentId);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
- return resultOp;
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
}
- //Validate value and Constraint of property
- Either<Boolean, ResponseFormat> constraintValidatorResponse =
- PropertyValueConstraintValidationUtil.getInstance().
- validatePropertyConstraints(properties, applicationDataTypeCache);
- if (constraintValidatorResponse.isRight()) {
- log.error("Failed validation value and constraint of property: {}",
- constraintValidatorResponse.right().value());
- return Either.right(constraintValidatorResponse.right().value());
- }
-
Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, resourceInstanceId);
if (resourceInstanceStatus.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, resourceInstanceId, componentId));
- return resultOp;
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER,
+ resourceInstanceId, "resource instance", "service", componentId));
}
ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
- // specific property value logic US833308
- StorageOperationStatus fetchByIdsStatus = concatServiceNameToVLINetworkRolePropertiesValues(toscaOperationFacade, componentTypeEnum, componentId, resourceInstanceId, properties);
- if (StorageOperationStatus.OK != fetchByIdsStatus) {
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(fetchByIdsStatus)));
- return resultOp;
- }
+
// lock resource
StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
if (lockStatus != StorageOperationStatus.OK) {
log.debug(FAILED_TO_LOCK_SERVICE, componentId);
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
- return resultOp;
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
}
-
+ List <ComponentInstanceProperty> updatedProperties = new ArrayList<>();
try {
for (ComponentInstanceProperty property: properties) {
+ validateMandatoryFields(property);
+ ComponentInstanceProperty componentInstanceProperty = validatePropertyExistsOnComponent(property, containerComponent, foundResourceInstance);
String propertyParentUniqueId = property.getParentUniqueId();
Either<String, ResponseFormat> updatedPropertyValue = updatePropertyObjectValue(property, false);
+ if (updatedPropertyValue.isRight()) {
+ log.error("Failed to update property object value of property: {}",
+ property);
+ throw new ByResponseFormatComponentException(updatedPropertyValue.right().value());
+ }
Optional<CapabilityDefinition>
capPropDefinition = getPropertyCapabilityOfChildInstance(propertyParentUniqueId, foundResourceInstance.getCapabilities());
if(capPropDefinition.isPresent()) {
@@ -1801,6 +1706,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
else {
updatedPropertyValue.bimap(updatedValue -> updatePropertyOnContainerComponent(property, updatedValue,
containerComponent, foundResourceInstance), Either::right);
+ updatedProperties.add(componentInstanceProperty);
}
}
@@ -1810,7 +1716,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
return resultOp;
}
- resultOp = Either.left(properties);
+ resultOp = Either.left(updatedProperties);
return resultOp;
} finally {
@@ -1824,17 +1730,29 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
+ private void validateMandatoryFields(PropertyDataDefinition property) {
+ if (StringUtils.isEmpty(property.getName())) {
+ throw new ByActionStatusComponentException (ActionStatus.MISSING_PROPERTY_NAME);
+ }
+ }
+
+ private ComponentInstanceProperty validatePropertyExistsOnComponent(ComponentInstanceProperty property, Component containerComponent, ComponentInstance foundResourceInstance) {
+ List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties().get(foundResourceInstance.getUniqueId());
+ Optional<ComponentInstanceProperty> instanceProperty = instanceProperties.stream().filter(p -> p.getName().equals(property.getName())).findAny();
+ if (!instanceProperty.isPresent()) {
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, property.getName());
+ }
+ return instanceProperty.get();
+ }
+
+
+
private ResponseFormat updateCapabilityPropertyOnContainerComponent(ComponentInstanceProperty property,
String newValue, Component containerComponent, ComponentInstance foundResourceInstance,
String capabilityType, String capabilityName) {
String componentInstanceUniqueId = foundResourceInstance.getUniqueId();
- StringBuilder sb = new StringBuilder(componentInstanceUniqueId);
- sb.append(ModelConverter.CAP_PROP_DELIM).append(property.getOwnerId()).append(ModelConverter.CAP_PROP_DELIM)
- .append(capabilityType).append(ModelConverter.CAP_PROP_DELIM).append(capabilityName);
- String capKey = sb.toString();
-
ResponseFormat actionStatus = updateCapPropOnContainerComponent(property, newValue, containerComponent,
- foundResourceInstance, capabilityType, capabilityName, componentInstanceUniqueId, capKey);
+ foundResourceInstance, capabilityType, capabilityName, componentInstanceUniqueId);
if (actionStatus != null) {
return actionStatus;
}
@@ -1858,14 +1776,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
} else {
propOwner = foundResourceInstance.getSourceModelUid();
}
- StringBuilder sb = new StringBuilder(componentInstanceUniqueId);
-
- sb.append(ModelConverter.CAP_PROP_DELIM).append(propOwner).append(ModelConverter.CAP_PROP_DELIM)
- .append(capabilityType).append(ModelConverter.CAP_PROP_DELIM).append(capabilityName);
- String capKey = sb.toString();
ResponseFormat actionStatus = updateCapPropOnContainerComponent(property, newValue, containerComponent,
- foundResourceInstance, capabilityType, capabilityName, componentInstanceUniqueId, capKey);
+ foundResourceInstance, capabilityType, capabilityName, componentInstanceUniqueId);
if (actionStatus != null) {
return actionStatus;
}
@@ -1877,7 +1790,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Component containerComponent,
ComponentInstance foundResourceInstance,
String capabilityType, String capabilityName,
- String componentInstanceUniqueId, String capKey) {
+ String componentInstanceUniqueId) {
Map<String, List<CapabilityDefinition>> capabilities =
Optional.ofNullable(foundResourceInstance.getCapabilities()).orElse(Collections.emptyMap());
List<CapabilityDefinition> capPerType =
@@ -1891,6 +1804,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
capProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
StorageOperationStatus status;
if (instanceProperty.isPresent()) {
+ String capKey = ModelConverter.buildCapabilityPropertyKey(foundResourceInstance.getOriginType().isAtomicType(), capabilityType, capabilityName, componentInstanceUniqueId, cap.get());
instanceProperty.get().setValue(newValue);
List<String> path = new ArrayList<>();
path.add(componentInstanceUniqueId);
@@ -1911,35 +1825,59 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return null;
}
- private ResponseFormat updatePropertyOnContainerComponent(ComponentInstanceProperty property, String newValue,
- Component containerComponent, ComponentInstance foundResourceInstance) {
- List<ComponentInstanceProperty> instanceProperties =
- containerComponent.getComponentInstancesProperties().get(foundResourceInstance.getUniqueId());
- Optional<ComponentInstanceProperty> instanceProperty =
- instanceProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
+ private ResponseFormat updatePropertyOnContainerComponent(ComponentInstanceProperty instanceProperty, String newValue, Component containerComponent, ComponentInstance foundResourceInstance) {
StorageOperationStatus status;
- instanceProperty.get().setValue(newValue);
- if (instanceProperty.isPresent()) {
- status = toscaOperationFacade
- .updateComponentInstanceProperty(containerComponent, foundResourceInstance.getUniqueId(),
- property);
- } else {
- status = toscaOperationFacade
- .addComponentInstanceProperty(containerComponent, foundResourceInstance.getUniqueId(),
- property);
- }
+ instanceProperty.setValue(newValue);
+ status = toscaOperationFacade.updateComponentInstanceProperty(containerComponent, foundResourceInstance.getUniqueId(), instanceProperty);
if (status != StorageOperationStatus.OK) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
return componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, "");
}
- List<String> path = new ArrayList<>();
- path.add(foundResourceInstance.getUniqueId());
- property.setPath(path);
-
foundResourceInstance.setCustomizationUUID(UUID.randomUUID().toString());
return componentsUtils.getResponseFormat(ActionStatus.OK);
}
+ private <T extends PropertyDefinition> Either<String,ResponseFormat> validatePropertyObjectValue(T property, String newValue, boolean isInput) {
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypesEither = dataTypeCache.getAll();
+ if (allDataTypesEither.isRight()) {
+ JanusGraphOperationStatus status = allDataTypesEither.right().value();
+ BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status))));
+ }
+ Map<String, DataTypeDefinition> allDataTypes = allDataTypesEither.left().value();
+ String propertyType = property.getType();
+ String innerType = getInnerType(property);
+
+ // Specific Update Logic
+ Either<Object, Boolean> isValid = propertyOperation.validateAndUpdatePropertyValue(property.getType(), newValue, true, innerType, allDataTypes);
+ if (isValid.isRight()) {
+ Boolean res = isValid.right().value();
+ if (!res) {
+ log.error("Invalid value {} of property {} ", newValue, property.getName());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ } else {
+ Object object = isValid.left().value();
+ if (object != null) {
+ newValue = object.toString();
+ }
+ }
+ if (validateAndUpdateRules(property, isInput, allDataTypes, innerType, propertyType))
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT))));
+ return Either.left(newValue);
+ }
+
+ private <T extends PropertyDefinition> boolean validateAndUpdateRules(T property, boolean isInput, Map<String, DataTypeDefinition> allDataTypes, String innerType, String propertyType) {
+ if (!isInput) {
+ ImmutablePair<String, Boolean> pair = propertyOperation.validateAndUpdateRules(propertyType, ((ComponentInstanceProperty) property).getRules(), innerType, allDataTypes, true);
+ if (pair.getRight() != null && !pair.getRight()) {
+ BeEcompErrorManager.getInstance().logBeInvalidValueError("Add property value", pair.getLeft(), property.getName(), propertyType);
+ return true;
+ }
+ }
+ return false;
+ }
+
private <T extends PropertyDefinition> Either<String,ResponseFormat> updatePropertyObjectValue(T property, boolean isInput) {
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypesEither = dataTypeCache.getAll();
if (allDataTypesEither.isRight()) {
@@ -1972,7 +1910,8 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (isValid.isRight()) {
Boolean res = isValid.right().value();
if (!res) {
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT))));
+ log.debug("validate and update property value has failed with value: {}", property.getValue());
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT)));
}
} else {
Object object = isValid.left().value();
@@ -1991,15 +1930,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
private ResponseFormat updateInputOnContainerComponent(ComponentInstanceInput input, String newValue, Component containerComponent, ComponentInstance foundResourceInstance) {
- List<ComponentInstanceInput> instanceProperties = containerComponent.getComponentInstancesInputs().get(foundResourceInstance.getUniqueId());
- Optional<ComponentInstanceInput> instanceProperty = instanceProperties.stream().filter(p -> p.getUniqueId().equals(input.getUniqueId())).findAny();
StorageOperationStatus status;
- if (instanceProperty.isPresent()) {
- instanceProperty.get().setValue(input.getValue());
- status = toscaOperationFacade.updateComponentInstanceInput(containerComponent, foundResourceInstance.getUniqueId(), input);
- } else {
- status = toscaOperationFacade.addComponentInstanceInput(containerComponent, foundResourceInstance.getUniqueId(), input);
- }
+ input.setValue(newValue);
+ status = toscaOperationFacade.updateComponentInstanceInput(containerComponent, foundResourceInstance.getUniqueId(), input);
if (status != StorageOperationStatus.OK) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
return componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, "");
@@ -2012,7 +1945,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Either<List<ComponentInstanceInput>, ResponseFormat> resultOp = null;
- validateUserExists(userId, "create Or Update Property Value", false);
+ validateUserExists(userId);
if (componentTypeEnum == null) {
BeEcompErrorManager.getInstance().logInvalidInputError(CREATE_OR_UPDATE_PROPERTY_VALUE, INVALID_COMPONENT_TYPE, ErrorSeverity.INFO);
@@ -2023,20 +1956,24 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (getResourceResult.isRight()) {
log.debug(FAILED_TO_RETRIEVE_COMPONENT_COMPONENT_ID, componentId);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
- return resultOp;
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResourceResult.right().value(), componentTypeEnum);
+ return Either.right(componentsUtils.getResponseFormat(actionStatus, componentId));
}
Component containerComponent = getResourceResult.left().value();
if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
+ if (containerComponent.isArchived()) {
+ log.info("Component is archived. Component id: {}", componentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_IS_ARCHIVED, containerComponent.getName()));
+ }
log.info("Restricted operation for user: {} on service {}", userId, componentId);
resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
return resultOp;
}
Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, resourceInstanceId);
if (resourceInstanceStatus.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, resourceInstanceId, componentId));
- return resultOp;
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER,
+ resourceInstanceId, "resource instance", "service", componentId));
}
ComponentInstance foundResourceInstance = resourceInstanceStatus.left().value();
@@ -2045,24 +1982,27 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
if (lockStatus != StorageOperationStatus.OK) {
log.debug(FAILED_TO_LOCK_SERVICE, componentId);
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
- return resultOp;
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
}
+ List <ComponentInstanceInput> updatedInputs = new ArrayList<>();
try {
for (ComponentInstanceInput input: inputs) {
- Either<String, ResponseFormat> updatedInputValue = updatePropertyObjectValue(input, true);
- updatedInputValue.bimap(updatedValue -> updateInputOnContainerComponent(input,updatedValue, containerComponent, foundResourceInstance),
- Either::right);
-
+ validateMandatoryFields(input);
+ ComponentInstanceInput componentInstanceInput = validateInputExistsOnComponent(input, containerComponent, foundResourceInstance);
+ Either<String, ResponseFormat> validatedInputValue = validatePropertyObjectValue(componentInstanceInput, input.getValue(), true);
+ if (validatedInputValue.isRight()){
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT, input.getName());
+ }
+ updateInputOnContainerComponent(componentInstanceInput, validatedInputValue.left().value(), containerComponent, foundResourceInstance);
+ updatedInputs.add(componentInstanceInput);
}
Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
-
if (updateContainerRes.isRight()) {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(updateContainerRes.right().value());
resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
return resultOp;
}
- resultOp = Either.left(inputs);
+ resultOp = Either.left(updatedInputs);
return resultOp;
} finally {
@@ -2077,12 +2017,20 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
- public Either<ComponentInstanceProperty, ResponseFormat> createOrUpdateGroupInstancePropertyValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, String groupInstanceId, ComponentInstanceProperty property,
- String userId) {
+ private ComponentInstanceInput validateInputExistsOnComponent(ComponentInstanceInput input, Component containerComponent, ComponentInstance foundResourceInstance) {
+ List<ComponentInstanceInput> instanceProperties = containerComponent.getComponentInstancesInputs().get(foundResourceInstance.getUniqueId());
+ Optional<ComponentInstanceInput> instanceInput = instanceProperties.stream().filter(p -> p.getName().equals(input.getName())).findAny();
+ if (!instanceInput.isPresent()) {
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, input.getName());
+ }
+ return instanceInput.get();
+ }
+
+ public Either<ComponentInstanceProperty, ResponseFormat> createOrUpdateGroupInstancePropertyValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, String groupInstanceId, ComponentInstanceProperty property, String userId) {
Either<ComponentInstanceProperty, ResponseFormat> resultOp = null;
- validateUserExists(userId, "create Or Update Property Value", false);
+ validateUserExists(userId);
if (componentTypeEnum == null) {
BeEcompErrorManager.getInstance().logInvalidInputError(CREATE_OR_UPDATE_PROPERTY_VALUE, INVALID_COMPONENT_TYPE, ErrorSeverity.INFO);
@@ -2172,98 +2120,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
- public Either<ComponentInstanceInput, ResponseFormat> createOrUpdateInputValue(ComponentTypeEnum componentTypeEnum, String componentId, String resourceInstanceId, ComponentInstanceInput inputProperty, String userId) {
-
- Either<ComponentInstanceInput, ResponseFormat> resultOp = null;
-
- validateUserExists(userId, "create Or Update Input Value", false);
-
- if (componentTypeEnum == null) {
- BeEcompErrorManager.getInstance().logInvalidInputError("createOrUpdateInputValue", INVALID_COMPONENT_TYPE, ErrorSeverity.INFO);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
- return resultOp;
- }
-
- if (!ComponentValidationUtils.canWorkOnComponent(componentId, toscaOperationFacade, userId)) {
- log.info("Restricted operation for user: {} on service: {}", userId, componentId);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
- return resultOp;
- }
- // lock resource
- StorageOperationStatus lockStatus = graphLockOperation.lockComponent(componentId, componentTypeEnum.getNodeType());
- if (lockStatus != StorageOperationStatus.OK) {
- log.debug(FAILED_TO_LOCK_SERVICE, componentId);
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(lockStatus)));
- return resultOp;
- }
- try {
- String propertyValueUid = inputProperty.getValueUniqueUid();
- if (propertyValueUid == null) {
-
- Either<Integer, StorageOperationStatus> counterRes = componentInstanceOperation.increaseAndGetResourceInstanceSpecificCounter(resourceInstanceId, GraphPropertiesDictionary.INPUT_COUNTER, true);
-
- if (counterRes.isRight()) {
- log.debug("increaseAndGetResourceInputCounter failed resource instance {} inputProperty {}", resourceInstanceId, inputProperty);
- StorageOperationStatus status = counterRes.right().value();
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(status);
- resultOp = Either.right(componentsUtils.getResponseFormat(actionStatus));
- }
- Integer index = counterRes.left().value();
- Either<ComponentInstanceInput, StorageOperationStatus> result = componentInstanceOperation.addInputValueToResourceInstance(inputProperty, resourceInstanceId, index, true);
-
- if (result.isLeft()) {
- log.debug("Property value was added to resource instance {}", resourceInstanceId);
- ComponentInstanceInput instanceProperty = result.left().value();
-
- resultOp = Either.left(instanceProperty);
- return resultOp;
-
- } else {
- log.debug("Failed to add input value {} to resource instance {}", inputProperty, resourceInstanceId);
-
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
-
- resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
-
- return resultOp;
- }
-
- } else {
- Either<ComponentInstanceInput, StorageOperationStatus> result = componentInstanceOperation.updateInputValueInResourceInstance(inputProperty, resourceInstanceId, true);
-
- if (result.isLeft()) {
- log.debug("Input value {} was updated on graph.", inputProperty.getValueUniqueUid());
- ComponentInstanceInput instanceProperty = result.left().value();
-
- resultOp = Either.left(instanceProperty);
- return resultOp;
-
- } else {
- log.debug("Failed to update property value {} in resource instance {}", inputProperty, resourceInstanceId);
-
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponseForResourceInstanceProperty(result.right().value());
-
- resultOp = Either.right(componentsUtils.getResponseFormatForResourceInstanceProperty(actionStatus, ""));
-
- return resultOp;
- }
- }
-
- } finally {
- if (resultOp == null || resultOp.isRight()) {
- janusGraphDao.rollback();
- } else {
- janusGraphDao.commit();
- }
- // unlock resource
- graphLockOperation.unlockComponent(componentId, componentTypeEnum.getNodeType());
- }
-
- }
-
public Either<ComponentInstanceProperty, ResponseFormat> deletePropertyValue(ComponentTypeEnum componentTypeEnum, String serviceId, String resourceInstanceId, String propertyValueId, String userId) {
- validateUserExists(userId, "delete Property Value", false);
+ validateUserExists(userId);
Either<ComponentInstanceProperty, ResponseFormat> resultOp = null;
@@ -2317,32 +2176,27 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
- private Either<Component, ResponseFormat> getAndValidateOriginComponentOfComponentInstance(ComponentTypeEnum containerComponentType, ComponentInstance componentInstance) {
+ private Component getAndValidateOriginComponentOfComponentInstance(Component containerComponent, ComponentInstance componentInstance) {
- Either<Component, ResponseFormat> eitherResponse = null;
- ComponentTypeEnum componentType = getComponentTypeByParentComponentType(containerComponentType);
+ ComponentTypeEnum componentType = getComponentTypeByParentComponentType(containerComponent.getComponentType());
Component component;
- ResponseFormat errorResponse;
Either<Component, StorageOperationStatus> getComponentRes = toscaOperationFacade.getToscaFullElement(componentInstance.getComponentUid());
if (getComponentRes.isRight()) {
log.debug("Failed to get the component with id {} for component instance {} creation. ", componentInstance.getComponentUid(), componentInstance.getName());
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getComponentRes.right().value(), componentType);
- errorResponse = componentsUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
- eitherResponse = Either.right(errorResponse);
+ throw new ByActionStatusComponentException(actionStatus, Constants.EMPTY_STRING);
}
- if (eitherResponse == null) {
- component = getComponentRes.left().value();
- LifecycleStateEnum resourceCurrState = component.getLifecycleState();
- if (resourceCurrState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
- ActionStatus actionStatus = ActionStatus.ILLEGAL_COMPONENT_STATE;
- errorResponse = componentsUtils.getResponseFormat(actionStatus, component.getComponentType().toString(), component.getName(), resourceCurrState.toString());
- eitherResponse = Either.right(errorResponse);
- }
+ component = getComponentRes.left().value();
+ LifecycleStateEnum resourceCurrState = component.getLifecycleState();
+ if (resourceCurrState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
+ ActionStatus actionStatus = ActionStatus.CONTAINER_CANNOT_CONTAIN_COMPONENT_IN_STATE;
+ throw new ByActionStatusComponentException(actionStatus, containerComponent.getComponentType().toString(), resourceCurrState.toString());
}
- if (eitherResponse == null) {
- eitherResponse = Either.left(getComponentRes.left().value());
+ if (component.isArchived() == true){
+ ActionStatus actionStatus = ActionStatus.COMPONENT_IS_ARCHIVED;
+ throw new ByActionStatusComponentException(actionStatus, component.getName());
}
- return eitherResponse;
+ return component;
}
public Either<Set<String>, ResponseFormat> forwardingPathOnVersionChange(String containerComponentParam,
@@ -2350,20 +2204,11 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
String componentInstanceId,
ComponentInstance newComponentInstance) {
Either<Set<String>, ResponseFormat> resultOp;
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
- if (validateComponentType.isRight()) {
- return Either.right(validateComponentType.right().value());
- }
- final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ final ComponentTypeEnum containerComponentType = validateComponentType(containerComponentParam);
ComponentParametersView componentParametersView = getComponentParametersViewForForwardingPath();
//Fetch Component
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists =
- validateComponentExists(containerComponentId, containerComponentType, componentParametersView);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- }
- Component containerComponent = validateComponentExists.left().value();
+ Component containerComponent = validateComponentExists(containerComponentId, containerComponentType, componentParametersView);
//Fetch current component instance
Either<ComponentInstance, StorageOperationStatus> eitherResourceInstance =
@@ -2379,7 +2224,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
String resourceId = newComponentInstance.getComponentUid();
Either<Boolean, StorageOperationStatus> componentExistsRes = toscaOperationFacade.validateComponentExists(resourceId);
if (componentExistsRes.isRight()) {
- log.debug("Failed to find resource {} ", resourceId);
+ log.debug("Failed to find resource {}", resourceId);
resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse
(componentExistsRes.right().value()), resourceId));
return resultOp;
@@ -2390,12 +2235,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
//Fetch component using new component instance uid
- Either<Component, ResponseFormat> eitherResourceName = getOriginComponentFromComponentInstance(newComponentInstance);
- if (eitherResourceName.isRight()) {
- resultOp = Either.right(eitherResourceName.right().value());
- return resultOp;
- }
- Component updatedContainerComponent=eitherResourceName.left().value();
+ Component updatedContainerComponent=getOriginComponentFromComponentInstance(newComponentInstance);
Set<String> toDeleteForwardingPaths = getForwardingPaths(containerComponent,
currentResourceInstance, updatedContainerComponent);
resultOp=Either.left(toDeleteForwardingPaths);
@@ -2406,7 +2246,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
private Set<String> getForwardingPaths(Component containerComponent, ComponentInstance currentResourceInstance,
Component updatedContainerComponent) {
DataForMergeHolder dataForMergeHolder=new DataForMergeHolder();
- dataForMergeHolder.setOrigComponentInstId(currentResourceInstance.getUniqueId());
+ dataForMergeHolder.setOrigComponentInstId(currentResourceInstance.getName());
Service service = (Service) containerComponent;
ForwardingPathUtils forwardingPathUtils = new ForwardingPathUtils();
@@ -2422,35 +2262,20 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return componentParametersView;
}
- public Either<ComponentInstance, ResponseFormat> changeComponentInstanceVersion(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance newComponentInstance) {
+ public ComponentInstance changeComponentInstanceVersion(String containerComponentParam, String containerComponentId, String componentInstanceId, String userId, ComponentInstance newComponentInstance) {
- User user = validateUserExists(userId, "change Component Instance Version", false);
-
- Either<ComponentInstance, ResponseFormat> resultOp = null;
-
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
- if (validateComponentType.isRight()) {
- return Either.right(validateComponentType.right().value());
- }
-
- final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
+ User user = validateUserExists(userId);
+ final ComponentTypeEnum containerComponentType = validateComponentType(containerComponentParam);
ComponentParametersView componentParametersView = new ComponentParametersView();
componentParametersView.setIgnoreCapabiltyProperties(false);
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = validateComponentExists(containerComponentId, containerComponentType, componentParametersView);
- if (validateComponentExists.isRight()) {
- return Either.right(validateComponentExists.right().value());
- }
- org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists.left().value();
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
- }
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists(containerComponentId, containerComponentType, componentParametersView);
+
+ validateCanWorkOnComponent(containerComponent, userId);
Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceId);
if (resourceInstanceStatus.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceId, containerComponentId));
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceId, containerComponentId);
}
ComponentInstance currentResourceInstance = resourceInstanceStatus.left().value();
@@ -2458,84 +2283,48 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
return changeInstanceVersion(containerComponent, currentResourceInstance, newComponentInstance, user, containerComponentType );
}
- public Either<ComponentInstance, ResponseFormat> changeInstanceVersion(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance currentResourceInstance,
- ComponentInstance newComponentInstance, User user, final ComponentTypeEnum containerComponentType ) {
- Either<ComponentInstance, ResponseFormat> resultOp = null;
+ public ComponentInstance changeInstanceVersion(org.openecomp.sdc.be.model.Component containerComponent, ComponentInstance currentResourceInstance,
+ ComponentInstance newComponentInstance, User user, final ComponentTypeEnum containerComponentType ) {
+ boolean failed = false;
Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus;
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(containerComponent, "changeComponentInstanceVersion");
- String containerComponentId = containerComponent.getUniqueId();
- String componentInstanceId = currentResourceInstance.getUniqueId();
- if (lockComponent.isRight()) {
- return Either.right(lockComponent.right().value());
- }
-
try {
-
-
+ lockComponent(containerComponent, "changeComponentInstanceVersion");
+ String containerComponentId = containerComponent.getUniqueId();
+ String componentInstanceId = currentResourceInstance.getUniqueId();
if (currentResourceInstance.getComponentUid().equals(newComponentInstance.getComponentUid())) {
- resultOp = Either.left(currentResourceInstance);
- return resultOp;
-
+ return currentResourceInstance;
}
String resourceId = newComponentInstance.getComponentUid();
-
-
Either<Boolean, StorageOperationStatus> componentExistsRes = toscaOperationFacade.validateComponentExists(resourceId);
if (componentExistsRes.isRight()) {
- log.debug("Failed to validate existing of the component {}. Status is {} ", resourceId);
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(componentExistsRes.right().value()), resourceId));
- return resultOp;
+ log.debug("Failed to validate existing of the component {}. Status is {} ", resourceId, componentExistsRes.right().value());
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(componentExistsRes.right().value()), resourceId);
} else if (!componentExistsRes.left().value()) {
log.debug("The resource {} not found ", resourceId);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceId));
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NOT_FOUND, resourceId);
}
- Either<Component, ResponseFormat> eitherOriginComponent = getInstanceOriginNode(currentResourceInstance);
+ Component eitherOriginComponent = getInstanceOriginNode(currentResourceInstance);
- if (eitherOriginComponent.isRight()) {
- resultOp = Either.right(eitherOriginComponent.right().value());
- return resultOp;
- }
- DataForMergeHolder dataHolder = compInstMergeDataBL.saveAllDataBeforeDeleting(containerComponent, currentResourceInstance, eitherOriginComponent.left().value());
- resultOp = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);
- if (resultOp.isRight()) {
- log.debug("failed to delete resource instance {}", resourceId);
- return resultOp;
- }
- ComponentInstance resResourceInfo = resultOp.left().value();
+ DataForMergeHolder dataHolder = compInstMergeDataBL.saveAllDataBeforeDeleting(containerComponent, currentResourceInstance, eitherOriginComponent);
+ ComponentInstance resResourceInfo = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentType);
Component origComponent = null;
OriginTypeEnum originType = currentResourceInstance.getOriginType();
if (originType == OriginTypeEnum.ServiceProxy) {
Either<Component, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade.getLatestByName("serviceProxy");
- if (serviceProxyOrigin.isRight()) {
- log.debug("Failed to fetch normative service proxy resource by tosca name, error {}", serviceProxyOrigin.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value())));
- }
+ if (isServiceProxyOrigin(serviceProxyOrigin))
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(serviceProxyOrigin.right().value()));
origComponent = serviceProxyOrigin.left().value();
StorageOperationStatus fillProxyRes = fillProxyInstanceData(newComponentInstance, origComponent);
- if (fillProxyRes != StorageOperationStatus.OK) {
- log.debug("Failed to fill service proxy resource data with data from service, error {}", fillProxyRes);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(fillProxyRes)));
-
- }
+ if (isFillProxyRes(fillProxyRes))
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(fillProxyRes));
newComponentInstance.setOriginType(originType);
}else{
-
-
- Either<Component, ResponseFormat> eitherResourceName = getOriginComponentFromComponentInstance(newComponentInstance);
-
- if (eitherResourceName.isRight()) {
- resultOp = Either.right(eitherResourceName.right().value());
- return resultOp;
- }
-
- origComponent = eitherResourceName.left().value();
-
+ origComponent = getOriginComponentFromComponentInstance(newComponentInstance);
newComponentInstance.setName(resResourceInfo.getName());
}
@@ -2544,28 +2333,13 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
newComponentInstance.setPosY(resResourceInfo.getPosY());
newComponentInstance.setDescription(resResourceInfo.getDescription());
- resultOp = createComponentInstanceOnGraph(containerComponent, origComponent, newComponentInstance, user);
-
- if (resultOp.isRight()) {
- log.debug("failed to create resource instance {}", resourceId);
- return resultOp;
- }
-
- ComponentInstance updatedComponentInstance = resultOp.left().value();
- if (resultOp.isRight()) {
- log.debug("failed to create resource instance {}", resourceId);
- return resultOp;
- }
-
+ ComponentInstance updatedComponentInstance = createComponentInstanceOnGraph(containerComponent, origComponent, newComponentInstance, user);
dataHolder.setCurrInstanceNode(origComponent);
- Either<Component, ResponseFormat> mergeStatusEither = compInstMergeDataBL.mergeComponentUserOrigData(user, dataHolder, containerComponent, containerComponentId, newComponentInstance.getUniqueId());
- if (mergeStatusEither.isRight()) {
- return Either.right(mergeStatusEither.right().value());
- }
+ Component mergeStatusEither = compInstMergeDataBL.mergeComponentUserOrigData(user, dataHolder, containerComponent, containerComponentId, newComponentInstance.getUniqueId());
ActionStatus postChangeVersionResult = onChangeInstanceOperationOrchestrator.doPostChangeVersionOperations(containerComponent, currentResourceInstance, newComponentInstance);
if (postChangeVersionResult != ActionStatus.OK) {
- return Either.right(componentsUtils.getResponseFormat(postChangeVersionResult));
+ throw new ByActionStatusComponentException(postChangeVersionResult);
}
ComponentParametersView filter = new ComponentParametersView(true);
@@ -2574,59 +2348,62 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (updatedComponentRes.isRight()) {
StorageOperationStatus storageOperationStatus = updatedComponentRes.right().value();
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus, containerComponent.getComponentType());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
log.debug("Component with id {} was not found", containerComponentId);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(actionStatus, Constants.EMPTY_STRING);
}
resourceInstanceStatus = getResourceInstanceById(updatedComponentRes.left().value(), updatedComponentInstance.getUniqueId());
if (resourceInstanceStatus.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceInstanceStatus.right().value()), updatedComponentInstance.getUniqueId()));
- return resultOp;
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse
+ (resourceInstanceStatus.right().value()), updatedComponentInstance.getUniqueId());
}
- resultOp = Either.left(resourceInstanceStatus.left().value());
- return resultOp;
+ return resourceInstanceStatus.left().value();
- } finally {
- unlockComponent(resultOp, containerComponent);
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponent(failed, containerComponent);
}
}
+ private boolean isFillProxyRes(StorageOperationStatus fillProxyRes) {
+ if (fillProxyRes != StorageOperationStatus.OK) {
+ log.debug("Failed to fill service proxy resource data with data from service, error {}", fillProxyRes);
+ return true;
+ }
+ return false;
+ }
+
// US831698
- public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesById(String containerComponentTypeParam, String containerComponentId, String componentInstanceUniqueId, String userId) {
- final String ECOMP_ERROR_CONTEXT = "Get Component Instance Properties By Id";
+ public List<ComponentInstanceProperty> getComponentInstancePropertiesById(String containerComponentTypeParam, String containerComponentId, String componentInstanceUniqueId, String userId) {
Component containerComponent = null;
- Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
+ boolean failed = false;
try {
- validateUserExists(userId, ECOMP_ERROR_CONTEXT, false);
-
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentTypeParam);
- if (validateComponentType.isRight()) {
- resultOp = Either.right(validateComponentType.right().value());
- return resultOp;
- }
+ validateUserExists(userId);
+ validateComponentType(containerComponentTypeParam);
Either<Component, StorageOperationStatus> validateContainerComponentExists = toscaOperationFacade.getToscaElement(containerComponentId);
if (validateContainerComponentExists.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(validateContainerComponentExists.right().value())));
- return resultOp;
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(validateContainerComponentExists.right().value()));
}
containerComponent = validateContainerComponentExists.left().value();
Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceUniqueId);
if (resourceInstanceStatus.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId));
- return resultOp;
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId);
}
List<ComponentInstanceProperty> instanceProperties = containerComponent.getComponentInstancesProperties().get(componentInstanceUniqueId);
if (CollectionUtils.isEmpty(instanceProperties)) {
instanceProperties = new ArrayList<>();
}
- resultOp = Either.left(instanceProperties);
- return resultOp;
- } finally {
- unlockComponent(resultOp, containerComponent);
+ return instanceProperties;
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponent(failed, containerComponent);
}
}
@@ -2668,20 +2445,17 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
public Either<ComponentInstance, ResponseFormat> deleteServiceProxy() {
// TODO Add implementation
- Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance());
- return result;
+ return Either.left(new ComponentInstance());
}
public Either<ComponentInstance, ResponseFormat> createServiceProxy() {
// TODO Add implementation
- Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance());
- return result;
+ return Either.left(new ComponentInstance());
}
public Either<ComponentInstance, ResponseFormat> changeServiceProxyVersion() {
// TODO Add implementation
- Either<ComponentInstance, ResponseFormat> result = Either.left(new ComponentInstance());
- return result;
+ return Either.left(new ComponentInstance());
}
private Boolean validateInstanceNameUniquenessUponUpdate(Component containerComponent, ComponentInstance oldComponentInstance, String newInstanceName) {
@@ -2753,6 +2527,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (resourceInstanceForUpdate.getSourceModelUid() == null) {
resourceInstanceForUpdate.setSourceModelUid(origInstanceForUpdate.getSourceModelUid());
}
+ if (resourceInstanceForUpdate.getCreatedFrom() == null) {
+ resourceInstanceForUpdate.setCreatedFrom(origInstanceForUpdate.getCreatedFrom());
+ }
return resourceInstanceForUpdate;
}
/**
@@ -2766,43 +2543,29 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
* @param ownerId
* @return
*/
- public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstanceCapabilityPropertiesById(String containerComponentType, String containerComponentId, String componentInstanceUniqueId, String capabilityType, String capabilityName, String ownerId, String userId) {
+ public List<ComponentInstanceProperty> getComponentInstanceCapabilityPropertiesById(String containerComponentType, String containerComponentId, String componentInstanceUniqueId, String capabilityType, String capabilityName, String ownerId, String userId) {
Component containerComponent = null;
- Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
+ List<ComponentInstanceProperty> resultOp = null;
try {
- validateUserExists(userId, "Get Component Instance Properties By Id", false);
- if(resultOp == null){
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentType);
- if (validateComponentType.isRight()) {
- resultOp = Either.right(validateComponentType.right().value());
- }
- }
- if(resultOp == null){
- Either<Component, StorageOperationStatus> validateContainerComponentExists = toscaOperationFacade.getToscaFullElement(containerComponentId);
- if (validateContainerComponentExists.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(validateContainerComponentExists.right().value())));
- } else {
- containerComponent = validateContainerComponentExists.left().value();
- }
- }
- if(resultOp == null){
- Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceUniqueId);
- if (resourceInstanceStatus.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId));
- } else {
- resultOp = findCapabilityOfInstance(containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, resourceInstanceStatus.left().value().getCapabilities());
- }
- }
- return resultOp;
- } finally {
- unlockComponent(resultOp, containerComponent);
- }
+ validateUserExists(userId);
+ validateComponentType(containerComponentType);
+ containerComponent = toscaOperationFacade.getToscaFullElement(containerComponentId).left().on(this::componentException);
+ ComponentInstance resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceUniqueId).left().on(this::componentInstanceException);
+ resultOp = findCapabilityOfInstance(containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, resourceInstanceStatus.getCapabilities());
+ } catch(StorageException e){
+ unlockRollbackWithException(containerComponent, e);
+ } catch (ComponentException e) {
+ unlockRollbackWithException(containerComponent, e);
+ } catch (Exception e){
+ unlockRollbackWithException(containerComponent, new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR));
+ }
+ unlockWithCommit(containerComponent);
+ return resultOp;
}
- private Either<List<ComponentInstanceProperty>, ResponseFormat> findCapabilityOfInstance( String componentId, String instanceId, String capabilityType, String capabilityName, String ownerId, Map<String, List<CapabilityDefinition>> instanceCapabilities) {
- Either<List<ComponentInstanceProperty>, ResponseFormat> result = null;
+ private List<ComponentInstanceProperty> findCapabilityOfInstance( String componentId, String instanceId, String capabilityType, String capabilityName, String ownerId, Map<String, List<CapabilityDefinition>> instanceCapabilities) {
CapabilityDefinition foundCapability;
if (MapUtils.isNotEmpty(instanceCapabilities)) {
List<CapabilityDefinition> capabilitiesPerType = instanceCapabilities.get(capabilityType);
@@ -2810,43 +2573,27 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Optional<CapabilityDefinition> capabilityOpt = capabilitiesPerType.stream().filter(c -> c.getName().equals(capabilityName) && c.getOwnerId().equals(ownerId)).findFirst();
if (capabilityOpt.isPresent()) {
foundCapability = capabilityOpt.get();
- result = Either.left(foundCapability.getProperties() == null ? new ArrayList<>() : foundCapability.getProperties());
+ return foundCapability.getProperties() == null ? new ArrayList<>() : foundCapability.getProperties();
}
}
}
- if (result == null) {
- result = fetchComponentInstanceCapabilityProperties(componentId, instanceId, capabilityType, capabilityName, ownerId);
- }
- return result;
+ return fetchComponentInstanceCapabilityProperties(componentId, instanceId, capabilityType, capabilityName, ownerId);
}
- private Either<List<ComponentInstanceProperty>, ResponseFormat> fetchComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityType, String capabilityName, String ownerId) {
- Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
+ private List<ComponentInstanceProperty> fetchComponentInstanceCapabilityProperties(String componentId, String instanceId, String capabilityType, String capabilityName, String ownerId) {
try {
- Either<List<ComponentInstanceProperty>, StorageOperationStatus> getComponentInstanceCapabilityProperties = toscaOperationFacade.getComponentInstanceCapabilityProperties(componentId, instanceId, capabilityName, capabilityType, ownerId);
- if(getComponentInstanceCapabilityProperties != null) {
- if (getComponentInstanceCapabilityProperties.isRight()) {
- resultOp = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getComponentInstanceCapabilityProperties.right().value()), capabilityType, instanceId, componentId));
- } else {
- resultOp = Either.left(getComponentInstanceCapabilityProperties.left().value());
- }
- } else {
- resultOp = Either.left(new ArrayList<>());
- }
+ return toscaOperationFacade.getComponentInstanceCapabilityProperties(componentId, instanceId, capabilityName, capabilityType, ownerId)
+ .left()
+ .on(this::componentInstancePropertyListException);
} catch(Exception e){
- log.error("The exception {} occurred upon the component {} instance {} capability {} properties retrieving. ", componentId, instanceId, capabilityName, e);
- resultOp = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ log.debug("The exception {} occurred upon the component {} instance {} capability {} properties retrieving. ", componentId, instanceId, capabilityName, e);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
- return resultOp;
}
- private ResponseFormat updateCapabilityPropertyOnContainerComponent(ComponentInstanceProperty property, String newValue, Component containerComponent, ComponentInstance foundResourceInstance,
+ /*private ResponseFormat updateCapabilityPropertyOnContainerComponent(ComponentInstanceProperty property, String newValue, Component containerComponent, ComponentInstance foundResourceInstance,
String capabilityType, String capabilityName, String ownerId) {
String componentInstanceUniqueId = foundResourceInstance.getUniqueId();
- StringBuilder sb = new StringBuilder(componentInstanceUniqueId);
- sb.append(ModelConverter.CAP_PROP_DELIM).append(property.getOwnerId()).append(ModelConverter.CAP_PROP_DELIM).append(capabilityType).append(ModelConverter.CAP_PROP_DELIM).append(capabilityName);
- String capKey = sb.toString();
-
Map<String, List<CapabilityDefinition>> capabilities = Optional.ofNullable(foundResourceInstance.getCapabilities())
.orElse(Collections.emptyMap());
List<CapabilityDefinition> capPerType = Optional.ofNullable(capabilities.get(capabilityType)).orElse(Collections.emptyList());
@@ -2857,6 +2604,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Optional<ComponentInstanceProperty> instanceProperty = capProperties.stream().filter(p -> p.getUniqueId().equals(property.getUniqueId())).findAny();
StorageOperationStatus status;
if (instanceProperty.isPresent()) {
+ String capKey = ModelConverter.buildCapabilityPropertyKey(foundResourceInstance.getOriginType().isAtomicType(), capabilityType, capabilityName, componentInstanceUniqueId, cap.get());
instanceProperty.get().setValue(newValue);
List<String> path = new ArrayList<>();
path.add(componentInstanceUniqueId);
@@ -2873,13 +2621,13 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
}
}
return componentsUtils.getResponseFormat(ActionStatus.OK);
- }
+ }*/
- public Either<List<ComponentInstanceProperty>, ResponseFormat> updateInstanceCapabilityProperties(ComponentTypeEnum componentTypeEnum, String containerComponentId, String componentInstanceUniqueId, String capabilityType, String capabilityName, String ownerId,
+ /*public Either<List<ComponentInstanceProperty>, ResponseFormat> updateInstanceCapabilityProperties(ComponentTypeEnum componentTypeEnum, String containerComponentId, String componentInstanceUniqueId, String capabilityType, String capabilityName, String ownerId,
List<ComponentInstanceProperty> properties, String userId) {
Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
- validateUserExists(userId, "update instance capability property", false);
+ validateUserExists(userId);
if (componentTypeEnum == null) {
BeEcompErrorManager.getInstance().logInvalidInputError("updateInstanceCapabilityProperty", INVALID_COMPONENT_TYPE, ErrorSeverity.INFO);
@@ -2894,7 +2642,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Component containerComponent = getResourceResult.left().value();
if (!ComponentValidationUtils.canWorkOnComponent(containerComponent, userId)) {
- log.info("Restricted operation for user: {sourcePropList} on component {}", userId, containerComponentId);
+ log.info("Restricted operation for user: {} on component {}", userId, containerComponentId);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
}
Either<ComponentInstance, StorageOperationStatus> resourceInstanceStatus = getResourceInstanceById(containerComponent, componentInstanceUniqueId);
@@ -2918,9 +2666,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
try {
for (ComponentInstanceProperty property : properties) {
- Either<String, ResponseFormat> newPropertyValueEither = updatePropertyObjectValue(property, false);
+ Either<String, ResponseFormat> newPropertyValueEither = validatePropertyObjectValue(property, false);
newPropertyValueEither.bimap(updatedValue ->
- updateCapabilityPropertyOnContainerComponent(property, updatedValue, containerComponent, foundResourceInstance, capabilityType, capabilityName, ownerId),
+ updateCapabilityPropertyOnContainerComponent(property,updatedValue, containerComponent, foundResourceInstance, capabilityType, capabilityName, ownerId),
Either::right);
}
Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
@@ -2942,14 +2690,13 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
// unlock resource
graphLockOperation.unlockComponent(containerComponentId, componentTypeEnum.getNodeType());
}
- }
+ }*/
public Either<List<ComponentInstanceProperty>, ResponseFormat> updateInstanceCapabilityProperties(ComponentTypeEnum componentTypeEnum, String containerComponentId, String componentInstanceUniqueId, String capabilityType, String capabilityName,
List<ComponentInstanceProperty> properties, String userId) {
Either<List<ComponentInstanceProperty>, ResponseFormat> resultOp = null;
- validateUserExists(userId, "update instance capability property", false);
-
+ validateUserExists(userId);
if (componentTypeEnum == null) {
BeEcompErrorManager.getInstance().logInvalidInputError("updateInstanceCapabilityProperty", INVALID_COMPONENT_TYPE, ErrorSeverity.INFO);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
@@ -2980,9 +2727,9 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
try {
for (ComponentInstanceProperty property : properties) {
- Either<String, ResponseFormat> newPropertyValueEither = updatePropertyObjectValue(property, false);
+ Either<String, ResponseFormat> newPropertyValueEither = validatePropertyObjectValue(property, property.getValue(), false);
newPropertyValueEither.bimap(updatedValue ->
- updateCapabilityPropertyOnContainerComponent(property, updatedValue, containerComponent, foundResourceInstance, capabilityType, capabilityName),
+ updateCapabilityPropertyOnContainerComponent(property,updatedValue, containerComponent, foundResourceInstance, capabilityType, capabilityName),
Either::right);
}
Either<Component, StorageOperationStatus> updateContainerRes = toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(containerComponent);
@@ -3021,62 +2768,67 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Component origComponent = getOrigComponent.left().value();
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(origComponent, "copyComponentInstance");
- if (lockComponent.isRight()) {
+ try {
+ lockComponent(origComponent, "copyComponentInstance");
+
+ } catch (ComponentException e) {
log.error("destComponentInstance's data is {}", origComponent.toString());
- return Either.right(lockComponent.right().value());
+ return Either.right(componentsUtils.getResponseFormat(
+ ActionStatus.USER_DEFINED, "Failed to lock component destComponentInstance's data is {}", origComponent.toString()));
}
-
- Either<ComponentInstance, ResponseFormat> actionResponse = null;
+ boolean failed = false;
+ ComponentInstance actionResponse = null;
try {
+
actionResponse = createComponentInstance(
"services", containerComponentId, userId, inputComponentInstance, true, false);
- if (actionResponse.isRight()) {
- log.error(FAILED_TO_COPY_COMP_INSTANCE_TO_CANVAS);
- return Either.right(componentsUtils.getResponseFormat(
- ActionStatus.USER_DEFINED, FAILED_TO_COPY_COMP_INSTANCE_TO_CANVAS));
- }
-
+ } catch (ComponentException e) {
+ failed = true;
+ throw e;
} finally {
// on failure of the create instance unlock the resource and rollback the transaction.
- if (null == actionResponse || actionResponse.isRight()) {
+ if (null == actionResponse || failed) {
janusGraphDao.rollback();
+ log.error("Failed to copy the component instance to the canvas");
+
+ unlockComponent(failed, origComponent);
+
+ return Either.right(componentsUtils.getResponseFormat(
+ ActionStatus.USER_DEFINED, "Failed to copy the component instance to the canvas"));
}
- unlockComponent(actionResponse, origComponent);
}
Either<String, ResponseFormat> resultOp = null;
try {
- ComponentInstance destComponentInstance = actionResponse.left().value();
+ ComponentInstance destComponentInstance = actionResponse;
log.debug("destComponentInstance's data is {}", destComponentInstance.toString());
resultOp = deepCopyComponentInstance(
origComponent, containerComponentId, componentInstanceId, destComponentInstance, userId);
- if (resultOp.isRight()) {
- log.error("Failed to deep copy component instance");
- return Either.right(componentsUtils.getResponseFormat(
- ActionStatus.USER_DEFINED, "Failed to deep copy the component instance to the canvas"));
- }
resultMap.put("componentInstance", destComponentInstance);
- return Either.left(resultMap);
} finally {
+ // unlock resource
if (resultOp == null || resultOp.isRight()) {
+ unlockComponent(true, origComponent);
janusGraphDao.rollback();
-
+ log.error("Failed to deep copy component instance");
+ return Either.right(componentsUtils.getResponseFormat(
+ ActionStatus.USER_DEFINED, "Failed to deep copy the component instance to the canvas"));
} else {
+ unlockComponent(false, origComponent);
janusGraphDao.commit();
log.debug("Success trasaction commit");
}
- // unlock resource
- unlockComponent(resultOp, origComponent);
}
+
+ return Either.left(resultMap);
}
private Either<String, ResponseFormat> deepCopyComponentInstance(
@@ -3160,8 +2912,8 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
log.debug("Now start to update inputs");
if (sourceProp.getGetInputValues() != null) {
- if (sourceProp.getGetInputValues().isEmpty()) {
- log.debug("source property input values empty");
+ if (sourceProp.getGetInputValues().size() < 1) {
+ log.debug("property is return from input, set by man");
break;
}
log.debug("Now starting to copy the {} property", destPropertyName);
@@ -3243,7 +2995,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
Either<ComponentInstanceProperty, ResponseFormat> resultOp = null;
- validateUserExists(userId, "Create or Update attribute value", false);
+ validateUserExists(userId);
if (componentTypeEnum == null) {
BeEcompErrorManager.getInstance().logInvalidInputError(
@@ -3398,22 +3150,12 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
List<String> deleteErrorIds = new ArrayList<>();
Map<String, List<String>> deleteErrorMap = new HashMap<>();
- Either<Component, ResponseFormat> validateResponse = validateUser(containerComponentType, componentId, userId);
- if (validateResponse.isRight()) {
- deleteErrorMap.put("deleteFailedIds", componentInstanceIdList);
- return deleteErrorMap;
- }
- Component containerComponent = validateResponse.left().value();
-
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(
- containerComponent, "batchDeleteComponentInstance");
- if (lockComponent.isRight()) {
- log.error("Failed to lockComponent containerComponent");
- deleteErrorMap.put("deleteFailedIds", componentInstanceIdList);
- return deleteErrorMap;
- }
+ validateUserExists(userId);
+ org.openecomp.sdc.be.model.Component containerComponent = validateComponentExists(componentId, ComponentTypeEnum.findByParamName(containerComponentType), null);
+ boolean failed = false;
try {
+ lockComponent(containerComponent, "batchDeleteComponentInstance");
for (String eachInstanceId : componentInstanceIdList) {
Either<ComponentInstance, ResponseFormat> actionResponse = batchDeleteComponentInstance(
containerComponent, containerComponentType, componentId, eachInstanceId);
@@ -3426,35 +3168,12 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
//sending the ids of the error nodes that were not deleted to UI
deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
return deleteErrorMap;
- } finally {
- unlockComponent(validateResponse, containerComponent);
- }
- }
-
- private Either<Component, ResponseFormat> validateUser(String containerComponentParam,
- String containerComponentId,
- String userId) {
- validateUserExists(userId, "delete Component Instance", false);
- Either<ComponentTypeEnum, ResponseFormat> validateComponentType = validateComponentType(containerComponentParam);
- if (validateComponentType.isRight()) {
- log.error("ComponentType[{}] doesn't support", containerComponentParam);
- return Either.right(validateComponentType.right().value());
- }
-
- final ComponentTypeEnum containerComponentType = validateComponentType.left().value();
- Either<Component, ResponseFormat> validateComponentExists = validateComponentExists(
- containerComponentId, containerComponentType, null);
- if (validateComponentExists.isRight()) {
- log.error("Component Id[{}] doesn't exist", containerComponentId);
- return Either.right(validateComponentExists.right().value());
- }
-
- Component containerComponent = validateComponentExists.left().value();
- Either<Boolean, ResponseFormat> validateCanWorkOnComponent = validateCanWorkOnComponent(containerComponent, userId);
- if (validateCanWorkOnComponent.isRight()) {
- return Either.right(validateCanWorkOnComponent.right().value());
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponent(failed, containerComponent);
}
- return Either.left(containerComponent);
}
private Either<ComponentInstance, ResponseFormat> batchDeleteComponentInstance(Component containerComponent,
@@ -3462,17 +3181,21 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
String containerComponentId,
String componentInstanceId) {
- Either<ComponentInstance, ResponseFormat> resultOp;
+ ComponentInstance resultOp;
final ComponentTypeEnum containerComponentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- resultOp = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentTypeEnum);
-
- if (resultOp.isRight()) {
+ boolean failed = false;
+ try {
+ resultOp = deleteComponentInstance(containerComponent, componentInstanceId, containerComponentTypeEnum);
+ log.info("Successfully deleted instance with id {}", componentInstanceId);
+ return Either.left(resultOp);
+ }
+ catch (ComponentException e){
log.error("Failed to deleteComponentInstance with instanceId[{}]", componentInstanceId);
- return Either.right(resultOp.right().value());
+ return Either.right(new ResponseFormat());
}
- log.info("Successfully deleted instance with id {}", componentInstanceId);
- return Either.left(resultOp.left().value());
+
}
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java
index ba256d4c84..14a193fde4 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java
@@ -22,20 +22,26 @@
package org.openecomp.sdc.be.components.impl;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.exception.ResponseFormat;
+import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.*;
+import java.security.SecureRandom;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -47,7 +53,7 @@ import java.util.stream.Collectors;
@Component("compositionBusinessLogic")
public class CompositionBusinessLogic {
private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
-
+ private static final Logger log = Logger.getLogger(CompositionBusinessLogic.class.getName());
private static final int VFC_CANVAS_ELEMENT_SIZE = 50;
private static final int CP_CANVAS_ELEMENT_SIZE = 21;
private static final int CANVAS_WIDTH = 1000;
@@ -73,17 +79,11 @@ public class CompositionBusinessLogic {
// Set Relative Locations According to Canvas Size
componentInstanceLocations.entrySet().forEach(this::setRelativePosition);
// Update in DB
- componentInstanceBusinessLogic.updateComponentInstance(ComponentTypeEnum.RESOURCE_PARAM_NAME,resource.getUniqueId(),
- userId, resource.getComponentInstances(), false)
- .left()
- .on(this::throwComponentException);
+ componentInstanceBusinessLogic.updateComponentInstance(ComponentTypeEnum.RESOURCE_PARAM_NAME,resource, resource.getUniqueId(),
+ userId, resource.getComponentInstances(), false);
}
}
- private List<ComponentInstance> throwComponentException(ResponseFormat responseFormat) {
- throw new ByResponseFormatComponentException(responseFormat);
- }
-
private void setRelativePosition(Entry<ImmutablePair<Double, Double>, ComponentInstance> entry) {
int xCenter = CANVAS_WIDTH / 2;
int yCenter = CANVAS_HEIGHT / 2;
@@ -284,5 +284,19 @@ public class CompositionBusinessLogic {
}
return relativeElementPosition;
}
+ protected void validateAndSetDefaultCoordinates(ComponentInstance resourceInstance) {
+ int xCenter = CANVAS_WIDTH / 2;
+ int yCenter = CANVAS_HEIGHT / 2;
+ double leftLimit = -10D;
+ double rightLimit = -1D;
+ double generatedDouble = leftLimit + new SecureRandom().nextDouble() * (rightLimit - leftLimit);
+
+ if (StringUtils.isEmpty(resourceInstance.getPosX())|| StringUtils.isEmpty(resourceInstance.getPosY())){
+ resourceInstance.setPosX(calculateCompositionPosition(xCenter, generatedDouble, resourceInstance));
+ resourceInstance.setPosY(calculateCompositionPosition(yCenter, generatedDouble, resourceInstance));
+ log.debug("Missing Failed PosX/PosY values. new values generated automatically. PosX = {} and PosY = {}", resourceInstance.getPosX(), resourceInstance.getPosY());
+ }
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
index 5c7c35a6b5..8b4c1c3e8b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ConsumerBusinessLogic.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -61,12 +62,12 @@ public class ConsumerBusinessLogic extends BaseBusinessLogic {
@Autowired
public ConsumerBusinessLogic(IElementOperation elementDao,
- IGroupOperation groupOperation,
- IGroupInstanceOperation groupInstanceOperation,
- IGroupTypeOperation groupTypeOperation,
- InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
- ArtifactsOperations artifactToscaOperation) {
+ IGroupOperation groupOperation,
+ IGroupInstanceOperation groupInstanceOperation,
+ IGroupTypeOperation groupTypeOperation,
+ InterfaceOperation interfaceOperation,
+ InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
+ ArtifactsOperations artifactToscaOperation) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
}
@@ -135,8 +136,10 @@ public class ConsumerBusinessLogic extends BaseBusinessLogic {
return Either.right(responseFormat);
}
log.debug("get user from DB");
- Either<User, ActionStatus> eitherCreator = userAdmin.getUser(user.getUserId(), false);
- if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ User userFromDB;
+ try {
+ userFromDB = userAdmin.getUser(user.getUserId(), false);
+ }catch (ByActionStatusComponentException e){
log.debug("createEcompUser method - user is not listed. userId= {}", user.getUserId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS);
log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
@@ -144,7 +147,7 @@ public class ConsumerBusinessLogic extends BaseBusinessLogic {
return Either.right(responseFormat);
}
- user = eitherCreator.left().value();
+ user = userFromDB;
// validate user role
log.debug("validate user role");
if (!user.getRole().equals(Role.ADMIN.name())) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java
index d29a2c4458..1757fcdf01 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java
@@ -34,7 +34,12 @@ import org.openecomp.sdc.exception.ResponseFormat;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -200,7 +205,7 @@ public class CsarValidationUtils {
return Either.left(new ImmutablePair<>(CsarUtils.ARTIFACTS_PATH + ARTIFACTS_METADATA_FILE, artifactsFileContents));
}
- public static Either<ImmutablePair<String, byte[]>, ResponseFormat> getArtifactsContent(String csarUUID, Map<String, byte[]> csar, String artifactPath, String artifactName, ComponentsUtils componentsUtils) {
+ public static Either<ImmutablePair<String, byte[]>, ResponseFormat> getArtifactContent(String csarUUID, Map<String, byte[]> csar, String artifactPath, String artifactName, ComponentsUtils componentsUtils) {
if (!csar.containsKey(artifactPath)) {
log.debug("Entry-Definitions entry not found in Artifacts/HEAT.meta file, csar ID {}", csarUUID);
BeEcompErrorManager.getInstance().logInternalDataError(ENTRY_DEFINITIONS_ENTRY_NOT_FOUND_IN_TOSCA_METADATA_TOSCA_META_FILE_CSAR_ID + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
index a9502b14f4..5ba9cfbe87 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
@@ -37,7 +37,11 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
@Component("dataTypeImportManager")
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java
index 5d9a06cc4c..087685292b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DistributionMonitoringBusinessLogic.java
@@ -39,13 +39,16 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent;
import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
-import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
@Component("distributionMonitoringBusinessLogic")
public class DistributionMonitoringBusinessLogic extends BaseBusinessLogic {
@@ -77,7 +80,7 @@ public class DistributionMonitoringBusinessLogic extends BaseBusinessLogic {
public Either<DistributionStatusListResponse, ResponseFormat> getListOfDistributionStatus(String did, String userId) {
- validateUserExists(userId, "get List Of Distribution Status", false);
+ validateUserExists(userId);
log.trace("getListOfDistributionStatus for did {}", did);
Either<List<DistributionStatusEvent>, ActionStatus> distributionStatus = cassandraDao.getListOfDistributionStatuses(did);
@@ -88,7 +91,7 @@ public class DistributionMonitoringBusinessLogic extends BaseBusinessLogic {
List<DistributionStatusInfo> distribStatusInfoList = new ArrayList<>();
List<DistributionStatusEvent> distributionStatusEventList = distributionStatus.left().value();
if (distributionStatusEventList != null) {
- for (ESTimeBasedEvent distributionStatusEvent : distributionStatusEventList) {
+ for (AuditingGenericEvent distributionStatusEvent : distributionStatusEventList) {
distribStatusInfoList.add(new DistributionStatusInfo(distributionStatusEvent));
}
}
@@ -100,7 +103,7 @@ public class DistributionMonitoringBusinessLogic extends BaseBusinessLogic {
}
public Either<DistributionStatusOfServiceListResponce, ResponseFormat> getListOfDistributionServiceStatus(String serviceUuid, String userId) {
- validateUserExists(userId, "get List Of Distribution Service Status", false);
+ validateUserExists(userId);
log.trace("getListOfDistributionServiceStatus for serviceUUID {}", serviceUuid);
Either<List<? extends AuditingGenericEvent>, ActionStatus> status = cassandraDao.getServiceDistributionStatusesList(serviceUuid);
@@ -127,7 +130,7 @@ public class DistributionMonitoringBusinessLogic extends BaseBusinessLogic {
String dNotifyStatus = "";
boolean isResult = false;
List<? extends AuditingGenericEvent> auditingGenericEventList = serviceDidMap.get(did);
- ESTimeBasedEvent resAuditingGenericEvent = null;
+ AuditingGenericEvent resAuditingGenericEvent = null;
for (AuditingGenericEvent auditingGenericEvent : auditingGenericEventList) {
auditingGenericEvent.fillFields();
@@ -174,7 +177,7 @@ public class DistributionMonitoringBusinessLogic extends BaseBusinessLogic {
return reslist;
}
- private String getStatusFromAuditEvent(ESTimeBasedEvent auditingGenericEvent) {
+ private String getStatusFromAuditEvent(AuditingGenericEvent auditingGenericEvent) {
String status = "";
Object requestStatus = auditingGenericEvent.getFields().get(AuditingFieldsKey.AUDIT_STATUS.getDisplayName());
if (requestStatus instanceof String) {
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 ca2e4a8078..711e6648ed 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
@@ -28,11 +28,13 @@ import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
@@ -40,14 +42,33 @@ import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
import org.openecomp.sdc.be.datamodel.utils.NodeTypeConvertUtils;
import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.*;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Product;
+import org.openecomp.sdc.be.model.PropertyScope;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.Tag;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.catalog.CatalogComponent;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.GroupingDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
+import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
@@ -56,9 +77,6 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.be.resources.data.ServiceMetadataData;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.category.CategoryData;
import org.openecomp.sdc.be.resources.data.category.SubCategoryData;
@@ -69,14 +87,25 @@ import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.beans.factory.annotation.Autowired;
import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+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.Objects;
+import java.util.Optional;
+import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
-import org.springframework.beans.factory.annotation.Autowired;
import static org.apache.commons.lang.BooleanUtils.isTrue;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.DEFAULT_ICON;
@org.springframework.stereotype.Component("elementsBusinessLogic")
public class ElementBusinessLogic extends BaseBusinessLogic {
@@ -106,7 +135,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
this.elementOperation = elementOperation;
this.userAdminManager = userAdminManager;
}
-
/**
*
* @param user
@@ -121,37 +149,25 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
Role currentRole = Role.valueOf(role);
switch (currentRole) {
- case DESIGNER:
- response = handleDesigner(userId);
- break;
-
- case TESTER:
- response = handleTester();
- break;
+ case DESIGNER:
+ response = handleDesigner(userId);
+ break;
- case GOVERNOR:
- response = handleGovernor();
- break;
+ case PRODUCT_STRATEGIST:
+ response = handleProductStrategist();
+ break;
- case OPS:
- response = handleOps();
- break;
+ case PRODUCT_MANAGER:
+ response = handleProductManager(userId);
+ break;
- case PRODUCT_STRATEGIST:
- response = handleProductStrategist();
- break;
+ case ADMIN:
+ response = handleAdmin();
+ break;
- case PRODUCT_MANAGER:
- response = handleProductManager(userId);
- break;
-
- case ADMIN:
- response = handleAdmin();
- break;
-
- default:
- response = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
- break;
+ default:
+ response = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ break;
}
// 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);
@@ -174,9 +190,8 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
Either<Map<String, Set<? extends Component>>, ResponseFormat> response;
// userId should stay null
Set<LifecycleStateEnum> lifecycleStates = new HashSet<>();
- Set<LifecycleStateEnum> lastStateStates = new HashSet<>();
lifecycleStates.add(LifecycleStateEnum.CERTIFIED);
- response = getFollowedResourcesAndServices(null, lifecycleStates, lastStateStates);
+ response = getFollowedResourcesAndServices(null, lifecycleStates, new HashSet<>());
return response;
}
@@ -186,11 +201,9 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
Either<Map<String, Set<? extends Component>>, ResponseFormat> response;
lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
- lifecycleStates.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
lifecycleStates.add(LifecycleStateEnum.CERTIFIED);
// more states
- lastStateStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ lastStateStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
response = getFollowedResourcesAndServices(userId, lifecycleStates, lastStateStates);
return response;
}
@@ -212,23 +225,13 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
Either<Map<String, Set<? extends Component>>, ResponseFormat> response;
lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
lifecycleStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
- lifecycleStates.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
lifecycleStates.add(LifecycleStateEnum.CERTIFIED);
// more states
- lastStateStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
+ lastStateStates.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
response = getFollowedProducts(userId, lifecycleStates, lastStateStates);
return response;
}
- private Either<Map<String, Set<? extends Component>>, ResponseFormat> handleOps() {
- Set<DistributionStatusEnum> distStatus = new HashSet<>();
- distStatus.add(DistributionStatusEnum.DISTRIBUTION_APPROVED);
- distStatus.add(DistributionStatusEnum.DISTRIBUTED);
-
- return handleFollowedCertifiedServices(distStatus);
- }
-
private Either<Map<String, Set<? extends Component>>, ResponseFormat> handleFollowedCertifiedServices(Set<DistributionStatusEnum> distStatus) {
Either<List<Service>, StorageOperationStatus> services = toscaOperationFacade.getCertifiedServicesWithDistStatus(distStatus);
@@ -243,14 +246,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
}
}
- private Either<Map<String, Set<? extends Component>>, ResponseFormat> handleTester() {
- Set<LifecycleStateEnum> lifecycleStates = new HashSet<>();
- lifecycleStates.add(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
- lifecycleStates.add(LifecycleStateEnum.READY_FOR_CERTIFICATION);
-
- return getFollowedResourcesAndServices(null, lifecycleStates, null);
- }
-
private Either<Map<String, Set<? extends Component>>, ResponseFormat> getFollowedResourcesAndServices(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates) {
try {
@@ -303,20 +298,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
String componentType = componentTypeEnum == null ? componentTypeParamName : componentTypeEnum.getValue();
CategoryTypeEnum categoryType = CategoryTypeEnum.CATEGORY;
- User user;
- Either<User, ResponseFormat> validateUser = validateUser(userId);
- if (validateUser.isRight()) {
- log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId);
- ResponseFormat responseFormat = validateUser.right().value();
- user = new User();
- user.setUserId(userId);
- String currCategoryName = (category == null ? null : category.getName());
- handleCategoryAuditing(responseFormat, user, currCategoryName, auditingAction, componentType);
- return Either.right(responseFormat);
- }
-
- user = validateUser.left().value();
-
+ User user = validateUserExists(userId);
if (category == null) {
log.debug("Category json is invalid");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
@@ -363,6 +345,11 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
category.setNormalizedName(normalizedName);
+ if (ValidationUtils.validateCategoryIconNotEmpty(category.getIcons())){
+ log.debug("createCategory: setting category icon to default icon since service category was created without an icon ");
+ category.setIcons(Arrays.asList(DEFAULT_ICON));
+ }
+
NodeTypeEnum nodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, categoryType);
Either<Boolean, ActionStatus> categoryUniqueEither = elementOperation.isCategoryUniqueForType(nodeType, normalizedName);
@@ -416,7 +403,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
String origSubCategoryName = subCategoryName;
User user;
try{
- user = validateUserExists(userId, "createSubCategory", false);
+ user = validateUserExists(userId);
} catch(ByActionStatusComponentException e){
ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName,
@@ -579,7 +566,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
User user;
try{
- user = validateUserExists(userId, "create Grouping", false);
+ user = validateUserExists(userId);
} catch(ByResponseFormatComponentException e){
ResponseFormat responseFormat = e.getResponseFormat();
handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName,
@@ -741,7 +728,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return Either.right(responseFormat);
}
try {
- user = validateUserExists(userId, "get All Categories", false);
+ user = validateUserExists(userId);
} catch (ByActionStatusComponentException e){
responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
handleComponentException(componentType, userId, responseFormat);
@@ -778,7 +765,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
ResponseFormat responseFormat;
UiCategories categories = new UiCategories();
- User user = validateUserExists(userId, "get all categories", false);
+ User user = validateUserExists(userId);
// GET resource categories
Either<List<CategoryDefinition>, ActionStatus> getResourceCategoriesByType = elementOperation.getAllCategories(NodeTypeEnum.ResourceNewCategory, false);
@@ -797,23 +784,13 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return Either.right(responseFormat);
}
categories.setServiceCategories(getServiceCategoriesByType.left().value());
-
- // GET product categories
- Either<List<CategoryDefinition>, ActionStatus> getProductCategoriesByType = elementOperation.getAllCategories(NodeTypeEnum.ProductCategory, false);
- if (getProductCategoriesByType.isRight()) {
- responseFormat = componentsUtils.getResponseFormat(getProductCategoriesByType.right().value());
- componentsUtils.auditGetCategoryHierarchy(user, ComponentTypeEnum.PRODUCT.getValue(), responseFormat);
- return Either.right(responseFormat);
- }
-
- categories.setProductCategories(getProductCategoriesByType.left().value());
+ categories.setProductCategories(new ArrayList<>());
return Either.left(categories);
-
}
public Either<CategoryDefinition, ResponseFormat> deleteCategory(String categoryId, String componentTypeParamName, String userId) {
- validateUserExists(userId, "delete Category", false);
+ validateUserExists(userId);
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
if (componentTypeEnum == null) {
@@ -835,7 +812,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
public Either<SubCategoryDefinition, ResponseFormat> deleteSubCategory(String parentSubCategoryId, String componentTypeParamName, String userId) {
- validateUserExists(userId, "delete Sub Category", false);
+ validateUserExists(userId);
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
if (componentTypeEnum == null) {
@@ -857,7 +834,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
public Either<GroupingDefinition, ResponseFormat> deleteGrouping(String groupingId, String componentTypeParamName, String userId) {
- validateUserExists(userId, "delete Grouping", false);
+ validateUserExists(userId);
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
if (componentTypeEnum == null) {
@@ -877,31 +854,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return Either.left(deletedGrouping);
}
- private Either<User, ResponseFormat> validateUser(String userId) {
-
- // validate user exists
- if (userId == null) {
- log.debug("UserId is null");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION));
- }
-
- Either<User, ActionStatus> userResult = userAdminManager.getUser(userId, false);
- if (userResult.isRight()) {
- ResponseFormat responseFormat;
- if (userResult.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
- log.debug("Not authorized user, userId = {}", userId);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- } else {
- log.debug("Failed to authorize user, userId = {}", userId);
- responseFormat = componentsUtils.getResponseFormat(userResult.right().value());
- }
-
- return Either.right(responseFormat);
- }
- return Either.left(userResult.left().value());
- // ========================================-
- }
-
private Either<Boolean, ResponseFormat> validateUserRole(User user, ComponentTypeEnum componentTypeEnum) {
String role = user.getRole();
boolean validAdminAction = role.equals(Role.ADMIN.name()) && (componentTypeEnum == ComponentTypeEnum.SERVICE || componentTypeEnum == ComponentTypeEnum.RESOURCE);
@@ -919,10 +871,10 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
boolean validResourceAction = componentType == ComponentTypeEnum.RESOURCE && (categoryType == CategoryTypeEnum.CATEGORY || categoryType == CategoryTypeEnum.SUBCATEGORY);
boolean validServiceAction = componentType == ComponentTypeEnum.SERVICE && categoryType == CategoryTypeEnum.CATEGORY;
boolean validProductAction = componentType == ComponentTypeEnum.PRODUCT; // can
- // be
- // any
- // category
- // type
+ // be
+ // any
+ // category
+ // type
if (!(validResourceAction || validServiceAction || validProductAction)) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
@@ -981,25 +933,25 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
*/
public Either<List<Tag>, ActionStatus> getAllTags(String userId) {
- Either<User, ActionStatus> resp = validateUserExistsActionStatus(userId, "get All Tags");
- if (resp.isRight()) {
- return Either.right(resp.right().value());
+ ActionStatus status = validateUserExistsActionStatus(userId);
+ if (ActionStatus.OK != status) {
+ return Either.right(status);
}
return elementOperation.getAllTags();
}
public Either<List<PropertyScope>, ActionStatus> getAllPropertyScopes(String userId) {
- Either<User, ActionStatus> resp = validateUserExistsActionStatus(userId, "get All Property Scopes");
- if (resp.isRight()) {
- return Either.right(resp.right().value());
+ ActionStatus status = validateUserExistsActionStatus(userId);
+ if (ActionStatus.OK != status) {
+ return Either.right(status);
}
return elementOperation.getAllPropertyScopes();
}
public Either<List<ArtifactType>, ActionStatus> getAllArtifactTypes(String userId) {
- Either<User, ActionStatus> resp = validateUserExistsActionStatus(userId, "get All Artifact Types");
- if (resp.isRight()) {
- return Either.right(resp.right().value());
+ ActionStatus status = validateUserExistsActionStatus(userId);
+ if (ActionStatus.OK != status) {
+ return Either.right(status);
}
return elementOperation.getAllArtifactTypes();
}
@@ -1008,13 +960,12 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return elementOperation.getAllDeploymentArtifactTypes();
}
- public Either<Integer, ActionStatus> getDefaultHeatTimeout() {
+ public Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> getDefaultHeatTimeout() {
return elementOperation.getDefaultHeatTimeout();
}
- public Either<Map<String, List<CatalogComponent>>, ResponseFormat> getCatalogComponents(String userId, List<OriginTypeEnum> excludeTypes) {
+ public Either<Map<String, List<CatalogComponent>>, ResponseFormat> getCatalogComponents(String userId, List<OriginTypeEnum> excludeTypes) {
try {
- validateUserExists(userId, "get Catalog Components", true);
return toscaOperationFacade.getCatalogOrArchiveComponents(true, excludeTypes)
.bimap(this::groupByComponentType,
err -> componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(err)));
@@ -1030,23 +981,19 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
if (map == null) {
map = new HashMap<>();
}
- if (map.get(RESOURCES) == null) {
- map.put(RESOURCES, new ArrayList());
- }
- if (map.get(SERVICES) == null) {
- map.put(SERVICES, new ArrayList());
- }
+ map.computeIfAbsent(RESOURCES, k -> new ArrayList());
+ map.computeIfAbsent(SERVICES, k -> new ArrayList());
return map;
}
private String cmptTypeToString(ComponentTypeEnum componentTypeEnum) {
switch (componentTypeEnum) {
- case RESOURCE:
- return RESOURCES;
- case SERVICE:
- return SERVICES;
- default:
- throw new IllegalStateException("resources or services only");
+ case RESOURCE:
+ return RESOURCES;
+ case SERVICE:
+ return SERVICES;
+ default:
+ throw new IllegalStateException("resources or services only");
}
}
@@ -1077,7 +1024,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value()), params.get(0), params.get(1), params.get(2)));
}
if (result.left().value().isEmpty()) {// no assets found for requested
- // criteria
+ // criteria
return Either.right(componentsUtils.getResponseFormat(ActionStatus.NO_ASSETS_FOUND, assetType, query));
}
return Either.left(result.left().value());
@@ -1087,7 +1034,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
Either<List<Component>, StorageOperationStatus> assetResult = Either.left(new LinkedList<>());
if (assetType == ComponentTypeEnum.RESOURCE) {
- assetResult = getFilteredResouces(filters, inTransaction);
+ assetResult = getFilteredResources(filters, inTransaction);
} else if (assetType == ComponentTypeEnum.SERVICE) {
@@ -1096,7 +1043,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return assetResult;
}
- private <T> Either<List<T>, StorageOperationStatus> getFilteredServices(Map<FilterKeyEnum, String> filters, boolean inTransaction) {
+ private <T extends Component> Either<List<T>, StorageOperationStatus> getFilteredServices(Map<FilterKeyEnum, String> filters, boolean inTransaction) {
Either<List<T>, StorageOperationStatus> components = null;
@@ -1109,9 +1056,9 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
}
if (categoryName != null) { // primary filter
- components = fetchByCategoryOrSubCategoryName(categoryName, NodeTypeEnum.ServiceNewCategory, NodeTypeEnum.Service, inTransaction, ServiceMetadataData.class, null);
+ components = fetchByCategoryOrSubCategoryName(categoryName, NodeTypeEnum.ServiceNewCategory, NodeTypeEnum.Service, inTransaction, null);
if (components.isLeft() && distEnum != null) {// secondary filter
- Predicate<T> statusFilter = p -> ((Service) p).getDistributionStatus().equals(distEnum);
+ Predicate<T> statusFilter = p -> ((Service) p).getDistributionStatus() == distEnum;
return Either.left(components.left().value().stream().filter(statusFilter).collect(Collectors.toList()));
}
filters.remove(FilterKeyEnum.DISTRIBUTION_STATUS);
@@ -1145,15 +1092,15 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
Map<GraphPropertyEnum, Object> additionalPropertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
switch (assetTypeEnum) {
- case RESOURCE:
- additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
- break;
- case SERVICE:
- additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
- break;
- default:
- log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not allowed for this API");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ case RESOURCE:
+ additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ break;
+ case SERVICE:
+ additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ break;
+ default:
+ log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not allowed for this API");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
Either<List<Component>, StorageOperationStatus> componentsListByUuid = toscaOperationFacade.getComponentListByUuid(uuid, additionalPropertiesToMatch);
@@ -1209,7 +1156,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return params;
}
- public Either<List<Component>, StorageOperationStatus> getFilteredResouces(Map<FilterKeyEnum, String> filters, boolean inTransaction) {
+ public Either<List<Component>, StorageOperationStatus> getFilteredResources(Map<FilterKeyEnum, String> filters, boolean inTransaction) {
String subCategoryName = filters.get(FilterKeyEnum.SUB_CATEGORY);
String categoryName = filters.get(FilterKeyEnum.CATEGORY);
@@ -1230,11 +1177,10 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
if (!subCategoryData.isPresent()) {
return Either.right(StorageOperationStatus.MATCH_NOT_FOUND);
}
- return fetchByCategoryOrSubCategoryUid((String) subCategoryData.get().getLeft().getUniqueId(), NodeTypeEnum.ResourceSubcategory, NodeTypeEnum.Resource, inTransaction,
- ResourceMetadataData.class, resourceType);
+ return fetchByCategoryOrSubCategoryUid(subCategoryData.get().getLeft().getUniqueId(), NodeTypeEnum.Resource, inTransaction, resourceType);
}
- return fetchByCategoryOrSubCategoryName(subCategoryName, NodeTypeEnum.ResourceSubcategory, NodeTypeEnum.Resource, inTransaction, ResourceMetadataData.class, resourceType);
+ return fetchByCategoryOrSubCategoryName(subCategoryName, NodeTypeEnum.ResourceSubcategory, NodeTypeEnum.Resource, inTransaction, resourceType);
}
if (subcategories != null) {
return fetchByMainCategory(subcategories.left().value(), inTransaction, resourceType);
@@ -1263,10 +1209,9 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return childNodes.stream().filter(matchName).findAny();
}
- protected <T, S extends ComponentMetadataData> Either<List<T>, StorageOperationStatus> fetchByCategoryOrSubCategoryUid(String categoryUid, NodeTypeEnum categoryType, NodeTypeEnum neededType, boolean inTransaction,
- Class<S> clazz, ResourceTypeEnum resourceType) {
+ protected <T extends Component> Either<List<T>, StorageOperationStatus> fetchByCategoryOrSubCategoryUid(String categoryUid, NodeTypeEnum categoryType, boolean inTransaction, ResourceTypeEnum resourceType) {
try {
- return collectComponents(neededType, categoryUid, categoryType, clazz, resourceType);
+ return collectComponents(categoryType, categoryUid, resourceType);
} finally {
if (!inTransaction) {
janusGraphDao.commit();
@@ -1274,8 +1219,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
}
}
- protected <T, S extends ComponentMetadataData> Either<List<T>, StorageOperationStatus> fetchByCategoryOrSubCategoryName(String categoryName, NodeTypeEnum categoryType, NodeTypeEnum neededType, boolean inTransaction,
- Class<S> clazz, ResourceTypeEnum resourceType) {
+ protected <T extends Component> Either<List<T>, StorageOperationStatus> fetchByCategoryOrSubCategoryName(String categoryName, NodeTypeEnum categoryType, NodeTypeEnum neededType, boolean inTransaction, ResourceTypeEnum resourceType) {
List<T> components = new ArrayList<>();
try {
Class categoryClazz = categoryType == NodeTypeEnum.ServiceNewCategory ? CategoryData.class : SubCategoryData.class;
@@ -1286,13 +1230,16 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return Either.right(StorageOperationStatus.CATEGORY_NOT_FOUND);
}
for (GraphNode category : getCategory.left().value()) {
- Either<List<T>, StorageOperationStatus> result = collectComponents(neededType, (String) category.getUniqueId(), categoryType, clazz, resourceType);
- if (result.isRight()) {
+ Either<List<T>, StorageOperationStatus> result = collectComponents(neededType, category.getUniqueId(), resourceType);
+ if (result.isRight() && result.right().value() != StorageOperationStatus.NOT_FOUND) {
return result;
+ } else if (result.isLeft()){
+ components.addAll(result.left().value());
}
- components.addAll(result.left().value());
}
-
+ if (components.isEmpty()){
+ return Either.right(StorageOperationStatus.NOT_FOUND);
+ }
return Either.left(components);
} finally {
if (!inTransaction) {
@@ -1302,25 +1249,38 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
}
- private <T, S extends ComponentMetadataData> Either<List<T>, StorageOperationStatus> collectComponents(NodeTypeEnum neededType, String categoryUid, NodeTypeEnum categoryType, Class<S> clazz, ResourceTypeEnum resourceType) {
+ private <T extends Component> Either<List<T>, StorageOperationStatus> collectComponents(NodeTypeEnum neededType, String categoryUid, ResourceTypeEnum resourceType) {
List<T> components = new ArrayList<>();
- Either<List<ImmutablePair<S, GraphEdge>>, JanusGraphOperationStatus> parentNodes = janusGraphGenericDao
- .getParentNodes(UniqueIdBuilder.getKeyByNodeType(categoryType), categoryUid, GraphEdgeLabels.CATEGORY, neededType, clazz);
- if (parentNodes.isLeft()) {
- for (ImmutablePair<S, GraphEdge> component : parentNodes.left().value()) {
- ComponentMetadataDataDefinition componentData = component.getLeft().getMetadataDataDefinition();
- Boolean isHighest = componentData.isHighestVersion();
- boolean isMatchingResourceType = isMatchingByResourceType(neededType, resourceType, componentData);
- boolean isDeleted = isTrue(componentData.isDeleted());
- boolean isArchived = isTrue(componentData.isArchived());
-
- if (isHighest && isMatchingResourceType && !isDeleted && !isArchived) {
- Either<T, StorageOperationStatus> result = (Either<T, StorageOperationStatus>) toscaOperationFacade.getToscaElement(componentData.getUniqueId(), JsonParseFlagEnum.ParseMetadata);
- if (result.isRight()) {
- return Either.right(result.right().value());
- }
- components.add(result.left().value());
+ Either<GraphVertex, JanusGraphOperationStatus> categoryVertexById = janusGraphDao.getVertexById(categoryUid, JsonParseFlagEnum.NoParse);
+ if (categoryVertexById.isRight()){
+ JanusGraphOperationStatus status = categoryVertexById.right().value();
+ log.debug("#collectComponents Failed to get category vertex with uid {}, status is {}.", categoryUid, status);
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+ }
+ GraphVertex categoryVertex = categoryVertexById.left().value();
+ Either<List<GraphVertex>, JanusGraphOperationStatus> componentsVertices = janusGraphDao.getParentVertices(categoryVertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.ParseMetadata);
+ if (componentsVertices.isRight()){
+ JanusGraphOperationStatus status = componentsVertices.right().value();
+ log.debug("#collectComponents Failed to get components vertices of category {}, status is {}.", categoryVertex, status);
+ return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+ }
+ List<ComponentMetadataDataDefinition> componentsMetadataDataDefinition = componentsVertices.left().value()
+ .stream()
+ .filter(Objects::nonNull)
+ .filter(componentsVertex -> Objects.nonNull(componentsVertex.getType()))
+ .map(ModelConverter::convertToComponentMetadataDataDefinition)
+ .collect(Collectors.toList());
+ for (ComponentMetadataDataDefinition component : componentsMetadataDataDefinition) {
+ boolean isHighest = isTrue(component.isHighestVersion());
+ boolean isMatchingResourceType = isMatchingByResourceType(neededType, resourceType, component);
+ boolean isDeleted = isTrue(component.isDeleted());
+ boolean isArchived = isTrue(component.isArchived());
+ if (isHighest && isMatchingResourceType && !isDeleted && !isArchived) {
+ Either<T, StorageOperationStatus> result = toscaOperationFacade.getToscaElement(component.getUniqueId(), JsonParseFlagEnum.ParseMetadata);
+ if (result.isRight()) {
+ return Either.right(result.right().value());
}
+ components.add(result.left().value());
}
}
return Either.left(components);
@@ -1341,12 +1301,12 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
return isMatching;
}
- private <T> Either<List<T>, StorageOperationStatus> fetchByMainCategory(List<ImmutablePair<SubCategoryData, GraphEdge>> subcategories, boolean inTransaction, ResourceTypeEnum resourceType) {
+ private <T extends Component> Either<List<T>, StorageOperationStatus> fetchByMainCategory(List<ImmutablePair<SubCategoryData, GraphEdge>> subcategories, boolean inTransaction, ResourceTypeEnum resourceType) {
List<T> components = new ArrayList<>();
for (ImmutablePair<SubCategoryData, GraphEdge> subCategory : subcategories) {
- Either<List<T>, StorageOperationStatus> fetched = fetchByCategoryOrSubCategoryUid((String) subCategory.getLeft().getUniqueId(), NodeTypeEnum.ResourceSubcategory, NodeTypeEnum.Resource,
- inTransaction, ResourceMetadataData.class, resourceType);
+ Either<List<T>, StorageOperationStatus> fetched = fetchByCategoryOrSubCategoryUid(subCategory.getLeft().getUniqueId(), NodeTypeEnum.Resource,
+ inTransaction, resourceType);
if (fetched.isRight()) {
continue;
}
@@ -1385,4 +1345,16 @@ public class ElementBusinessLogic extends BaseBusinessLogic {
}
}
}
+
+
+ public CatalogUpdateTimestamp getCatalogUpdateTime(String userId) {
+
+ try{
+ return toscaOperationFacade.getCatalogTimes();
+
+ } finally {
+ janusGraphDao.commit();
+ }
+
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ExternalRefsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ExternalRefsBusinessLogic.java
index 8340aa46ab..2c824c8e23 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ExternalRefsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ExternalRefsBusinessLogic.java
@@ -21,13 +21,14 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.lock.LockingTransactional;
import org.openecomp.sdc.be.components.validation.AccessValidations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.dto.ExternalRefDTO;
import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ExternalReferencesOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -82,62 +83,53 @@ public class ExternalRefsBusinessLogic {
}
}
- public Either<String, ActionStatus> addExternalReference(ComponentTypeEnum componentType, String userId, String uuid, String componentInstanceName, String objectType, ExternalRefDTO ref) {
- return this.doAction(componentType, userId, "POST", uuid, componentInstanceName, objectType, ref.getReferenceUUID(), "");
+ @LockingTransactional
+ public Either<String, ActionStatus> addExternalReference(String componentId, ComponentTypeEnum componentType, String userId, String componentInstanceName, String objectType, ExternalRefDTO ref) {
+ return this.doAction(componentId, componentType, userId, "POST", componentId, componentInstanceName, objectType, ref.getReferenceUUID(), "");
}
- public Either<String, ActionStatus> deleteExternalReference(ComponentTypeEnum componentType, String userId, String uuid, String componentInstanceName, String objectType, String reference) {
- return this.doAction(componentType, userId, "DELETE", uuid, componentInstanceName, objectType, reference, "");
+ @LockingTransactional
+ public Either<String, ActionStatus> deleteExternalReference(String componentId, ComponentTypeEnum componentType, String userId, String componentInstanceName, String objectType, String reference) {
+ return this.doAction(componentId, componentType, userId, "DELETE", componentId, componentInstanceName, objectType, reference, "");
}
- public Either<String, ActionStatus> updateExternalReference(ComponentTypeEnum componentType, String userId, String uuid, String componentInstanceName, String objectType, String oldRefValue, String newRefValue) {
- return this.doAction(componentType, userId, "PUT", uuid, componentInstanceName, objectType, oldRefValue, newRefValue);
+ @LockingTransactional
+ public Either<String, ActionStatus> updateExternalReference(String componentId, ComponentTypeEnum componentType, String userId, String componentInstanceName, String objectType, String oldRefValue, String newRefValue) {
+ return this.doAction(componentId, componentType, userId, "PUT", componentId, componentInstanceName, objectType, oldRefValue, newRefValue);
}
- private Either<String, ActionStatus> doAction(ComponentTypeEnum componentType, String userId, String action, String uuid, String componentInstanceName, String objectType, String ref1, String ref2){
+ public String fetchComponentUniqueIdByUuid(String uuid, ComponentTypeEnum componentType){
Either<Component, StorageOperationStatus> latestServiceByUuid = toscaOperationFacade.getLatestComponentByUuid(uuid, createPropsToMatch(componentType));
if (latestServiceByUuid == null || latestServiceByUuid.isRight()){
- return Either.right(ActionStatus.RESOURCE_NOT_FOUND);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NOT_FOUND, uuid);
}
//Get Component Unique ID
Component component = latestServiceByUuid.left().value();
- String uniqueId = component.getUniqueId();
-
- //Lock Asset
- this.componentLocker.lock(component);
- this.accessValidations.validateUserCanWorkOnComponent(component, userId, action + " EXTERNAL REF");
-
- Either<String, ActionStatus> opResult = Either.right(ActionStatus.GENERAL_ERROR);
- try {
- switch (action) {
- case "POST":
- opResult = this.externalReferencesOperation.addExternalReferenceWithCommit(uniqueId, componentInstanceName, objectType, ref1);
- break;
- case "PUT":
- opResult = this.externalReferencesOperation.updateExternalReferenceWithCommit(uniqueId, componentInstanceName, objectType, ref1, ref2);
- break;
- case "DELETE":
- opResult = this.externalReferencesOperation.deleteExternalReferenceWithCommit(uniqueId, componentInstanceName, objectType, ref1);
- break;
- default:
- break;
- }
- } catch (Exception e) {
- opResult = Either.right(ActionStatus.GENERAL_ERROR);
- log.error("Failed to execute external ref action:{} on asset:{} component:{} objectType:{}", action, uuid, componentInstanceName, objectType);
- log.error("Cause is:" , e);
- } finally {
- //Unlock Asset
- this.componentLocker.unlock(uniqueId, componentType);
+ return component.getUniqueId();
+ }
+
+
+ public Either<String, ActionStatus> doAction(String componentId, ComponentTypeEnum componentType, String userId, String action, String uuid, String componentInstanceName, String objectType, String ref1, String ref2){
+
+ accessValidations.validateUserCanWorkOnComponent(componentId, componentType, userId, action + " EXTERNAL REF");
+
+ switch (action) {
+ case "POST":
+ return this.externalReferencesOperation.addExternalReferenceWithCommit(componentId, componentInstanceName, objectType, ref1);
+ case "PUT":
+ return this.externalReferencesOperation.updateExternalReferenceWithCommit(componentId, componentInstanceName, objectType, ref1, ref2);
+ case "DELETE":
+ return this.externalReferencesOperation.deleteExternalReferenceWithCommit(componentId, componentInstanceName, objectType, ref1);
+ default:
+ return Either.right(ActionStatus.GENERAL_ERROR);
}
- return opResult;
+
}
private Map<GraphPropertyEnum, Object> createPropsToMatch(ComponentTypeEnum componentType) {
Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<>();
propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
- propertiesToMatch.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
return propertiesToMatch;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GenericArtifactBrowserBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GenericArtifactBrowserBusinessLogic.java
index d95045b87b..4f092c6bd9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GenericArtifactBrowserBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GenericArtifactBrowserBusinessLogic.java
@@ -27,8 +27,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
-import java.io.IOException;
-import java.lang.reflect.Type;
import org.onap.sdc.gab.GABService;
import org.onap.sdc.gab.GABServiceImpl;
import org.onap.sdc.gab.model.GABQuery;
@@ -43,6 +41,9 @@ import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.springframework.beans.factory.annotation.Autowired;
+import java.io.IOException;
+import java.lang.reflect.Type;
+
@org.springframework.stereotype.Component
public class GenericArtifactBrowserBusinessLogic extends BaseBusinessLogic {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java
index 1f906aefac..417380b5d9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java
@@ -31,6 +31,7 @@ import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.lock.LockingTransactional;
import org.openecomp.sdc.be.components.impl.policy.PolicyTargetsUpdateHandler;
import org.openecomp.sdc.be.components.utils.Utils;
@@ -47,12 +48,25 @@ import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
import org.openecomp.sdc.be.info.ArtifactDefinitionInfo;
import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
import org.openecomp.sdc.be.info.GroupDefinitionInfo;
-import org.openecomp.sdc.be.model.*;
+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.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.GroupInstanceProperty;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition.GroupInstancePropertyValueUpdateBehavior;
import org.openecomp.sdc.be.model.PropertyDefinition.PropertyNames;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.GroupsOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
@@ -66,13 +80,26 @@ import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -85,7 +112,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
public static final String GROUP_DELIMITER_REGEX = "\\.\\.";
- public static final String INITIAL_VERSION = "1";
+ public static final String INITIAL_VERSION = "0.0";
private static final String ADDING_GROUP = "AddingGroup";
@@ -99,6 +126,8 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
private static final Logger log = Logger.getLogger(GroupBusinessLogic.class);
+ public LoggerSupportability loggerSupportability= LoggerSupportability.getLogger(GroupBusinessLogic.class.getName());
+
private final AccessValidations accessValidations;
private final PolicyTargetsUpdateHandler policyTargetsUpdateHandler;
@@ -218,22 +247,14 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
public Either<GroupDefinition, ResponseFormat> validateAndUpdateGroupMetadata(String componentId, User user, ComponentTypeEnum componentType, GroupDefinition updatedGroup, boolean inTransaction , boolean shouldLock) {
Either<GroupDefinition, ResponseFormat> result = null;
+ boolean failed = false;
try {
// Validate user exist
- validateUserExists(user.getUserId(), UPDATE_GROUP, inTransaction);
+ validateUserExists(user.getUserId());
// Validate component exist
- Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, null);
- if (validateComponent.isRight()) {
- result = Either.right(validateComponent.right().value());
- return result;
- }
- org.openecomp.sdc.be.model.Component component = validateComponent.left().value();
+ org.openecomp.sdc.be.model.Component component = validateComponentExists(componentId, componentType, null);
// validate we can work on component
- Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, user.getUserId());
- if (canWork.isRight()) {
- result = Either.right(canWork.right().value());
- return result;
- }
+ validateCanWorkOnComponent(component, user.getUserId());
List<GroupDefinition> currentGroups = component.getGroups();
if (CollectionUtils.isEmpty(currentGroups)) {
log.error("Failed to update the metadata of group {} on component {}. The status is {}. ", updatedGroup.getName(), component.getName(), ActionStatus.GROUP_IS_MISSING);
@@ -249,11 +270,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
}
GroupDefinition currentGroup = currentGroupOpt.get();
if ( shouldLock ){
- Either<Boolean, ResponseFormat> lockResult = lockComponent(componentId, component, "Update GroupDefinition Metadata");
- if (lockResult.isRight()) {
- result = Either.right(lockResult.right().value());
- return result;
- }
+ lockComponent(componentId, component, "Update GroupDefinition Metadata");
}
// Validate group type is vfModule
if (currentGroup.getType().equals(Constants.GROUP_TOSCA_HEAT)) {
@@ -265,8 +282,11 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
result = updateGroupMetadata(component, currentGroup, updatedGroup);
return result;
- } finally {
- if (result != null && result.isLeft()) {
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ if (!failed) {
janusGraphDao.commit();
} else {
janusGraphDao.rollback();
@@ -293,23 +313,10 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
private Either<GroupDefinition, ResponseFormat> updateGroup(Component component, GroupDefinition updatedGroup, String currentGroupName) {
Either<GroupDefinition, StorageOperationStatus> handleGroupRes;
Either<GroupDefinition, ResponseFormat> result = null;
- if (updatedGroup.getName().equals(currentGroupName)) {
- handleGroupRes = groupsOperation.updateGroup(component, updatedGroup);
- if (handleGroupRes.isRight()) {
- log.debug("Failed to update a metadata of the group {} on component {}. ", updatedGroup.getName(), component.getName());
- result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(handleGroupRes.right().value())));
- }
- } else {
- StorageOperationStatus deleteStatus = groupsOperation.deleteGroup(component, currentGroupName);
- if (deleteStatus != StorageOperationStatus.OK) {
- log.debug("Failed to delete the group {} from component {}. ", updatedGroup.getName(), component.getName());
- result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteStatus)));
- }
- handleGroupRes = groupsOperation.addGroup(component, updatedGroup);
- if (handleGroupRes.isRight()) {
- log.debug("Failed to add the group {} to component {}. ", updatedGroup.getName(), component.getName());
- result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(handleGroupRes.right().value())));
- }
+ handleGroupRes = groupsOperation.updateGroup(component, updatedGroup);
+ if (handleGroupRes.isRight()) {
+ log.debug("Failed to update a metadata of the group {} on component {}. ", updatedGroup.getName(), component.getName());
+ result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(handleGroupRes.right().value())));
}
if (result == null) {
result = Either.left(updatedGroup);
@@ -424,7 +431,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
Either<GroupDefinitionInfo, ResponseFormat> result = null;
// Validate user exist
- validateUserExists(userId, GET_GROUP, true);
+ validateUserExists(userId);
// Validate component exist
org.openecomp.sdc.be.model.Component component = null;
@@ -435,17 +442,12 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
componentParametersView.setIgnoreArtifacts(false);
componentParametersView.setIgnoreUsers(false);
- Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
- if (validateComponent.isRight()) {
- result = Either.right(validateComponent.right().value());
- return result;
- }
- component = validateComponent.left().value();
+ component = validateComponentExists(componentId, componentType, componentParametersView);
Either<GroupDefinition, StorageOperationStatus> groupEither = findGroupOnComponent(component, groupId);
if (groupEither.isRight()) {
- log.debug("Faild to find group {} under component {}", groupId, component.getUniqueId());
+ log.debug("Failed to find group {} under component {}", groupId, component.getUniqueId());
BeEcompErrorManager.getInstance().logInvalidInputError(GET_GROUP, "group " + groupId + " not found under component " + component.getUniqueId(), ErrorSeverity.INFO);
String componentTypeForResponse = getComponentTypeForResponse(component);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_IS_MISSING, groupId, component.getSystemName(), componentTypeForResponse));
@@ -453,18 +455,8 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
}
GroupDefinition group = groupEither.left().value();
- Boolean isBase = null;
List<GroupProperty> props = group.convertToGroupProperties();
- if (props != null && !props.isEmpty()) {
- Optional<GroupProperty> isBasePropOp = props.stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
- if (isBasePropOp.isPresent()) {
- GroupProperty propIsBase = isBasePropOp.get();
- isBase = Boolean.parseBoolean(propIsBase.getValue());
-
- } else {
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_GROUP, "failed to find prop isBase " + component.getNormalizedName(), ErrorSeverity.INFO);
- }
- }
+ Boolean isBase = isBaseProp(component, props);
List<ArtifactDefinitionInfo> artifacts = new ArrayList<>();
List<ArtifactDefinition> artifactsFromComponent = new ArrayList<>();
@@ -485,12 +477,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
}
artifactsFromComponent.add(deploymentArtifacts.get(id));
}
- if (!artifactsFromComponent.isEmpty()) {
- for (ArtifactDefinition artifactDefinition : artifactsFromComponent) {
- ArtifactDefinitionInfo artifactDefinitionInfo = new ArtifactDefinitionInfo(artifactDefinition);
- artifacts.add(artifactDefinitionInfo);
- }
- }
+ addArtifactsToList(artifacts, artifactsFromComponent);
}
GroupDefinitionInfo resultInfo = new GroupDefinitionInfo(group);
@@ -503,21 +490,28 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
return result;
} finally {
+ closeTransaction(inTransaction, result);
+ }
- if (!inTransaction) {
+ }
- if (result == null || result.isRight()) {
- log.debug("Going to execute rollback on create group.");
- janusGraphDao.rollback();
- } else {
- log.debug("Going to execute commit on create group.");
- janusGraphDao.commit();
- }
+ private void addArtifactsToList(List<ArtifactDefinitionInfo> artifacts, List<ArtifactDefinition> artifactsFromComponent) {
+ artifactsFromComponent.forEach(a-> artifacts.add(new ArtifactDefinitionInfo(a)));
+ }
- }
+ private Boolean isBaseProp(Component component, List<GroupProperty> props) {
+ Boolean isBase = null;
+ if (CollectionUtils.isNotEmpty(props)) {
+ Optional<GroupProperty> isBasePropOp = props.stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
+ if (isBasePropOp.isPresent()) {
+ GroupProperty propIsBase = isBasePropOp.get();
+ isBase = Boolean.parseBoolean(propIsBase.getValue());
+ } else {
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_GROUP, "failed to find prop isBase " + component.getNormalizedName(), ErrorSeverity.INFO);
+ }
}
-
+ return isBase;
}
private Either<GroupDefinition, StorageOperationStatus> findGroupOnComponent(Component component, String groupId) {
@@ -591,6 +585,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
newGroupNameRes = validateGenerateVfModuleGroupName(resourceSystemName, description, counter);
if (newGroupNameRes.isRight()) {
log.debug("Failed to generate new vf module group name. Status is {} ", newGroupNameRes.right().value());
+ loggerSupportability.log(LogLevel.INFO,LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML.getName(),StatusCode.ERROR.name(),"Failed to generate new vf module group name. Status is: "+newGroupNameRes.right().value());
result = Either.right(newGroupNameRes.right().value());
break;
}
@@ -655,9 +650,9 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
Either<GroupDefinitionInfo, ResponseFormat> result = null;
// Validate user exist
- validateUserExists(userId, UPDATE_GROUP, true);
+ validateUserExists(userId);
// Validate component exist
- org.openecomp.sdc.be.model.Component component = null;
+ org.openecomp.sdc.be.model.Component component;
try {
ComponentParametersView componentParametersView = new ComponentParametersView();
@@ -666,12 +661,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
componentParametersView.setIgnoreComponentInstances(false);
componentParametersView.setIgnoreArtifacts(false);
- Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
- if (validateComponent.isRight()) {
- result = Either.right(validateComponent.right().value());
- return result;
- }
- component = validateComponent.left().value();
+ component = validateComponentExists(componentId, componentType, componentParametersView);
Either<ImmutablePair<ComponentInstance, GroupInstance>, StorageOperationStatus> findComponentInstanceAndGroupInstanceRes = findComponentInstanceAndGroupInstanceOnComponent(component, componentInstanceId, groupInstId);
if (findComponentInstanceAndGroupInstanceRes.isRight()) {
@@ -683,18 +673,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
GroupInstance group = findComponentInstanceAndGroupInstanceRes.left().value().getRight();
- Boolean isBase = null;
- List<? extends GroupProperty> props = group.convertToGroupInstancesProperties();
- if (props != null && !props.isEmpty()) {
- Optional<? extends GroupProperty> isBasePropOp = props.stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
- if (isBasePropOp.isPresent()) {
- GroupProperty propIsBase = isBasePropOp.get();
- isBase = Boolean.parseBoolean(propIsBase.getValue());
-
- } else {
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_GROUP, "failed to find prop isBase " + component.getNormalizedName(), ErrorSeverity.INFO);
- }
- }
+ Boolean isBase = isBaseProperty(component, group);
List<ArtifactDefinitionInfo> artifacts = new ArrayList<>();
List<String> artifactsIds = group.getArtifacts();
@@ -702,25 +681,9 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
List<ComponentInstance> instances = component.getComponentInstances();
if (instances != null) {
- Optional<ComponentInstance> findFirst = instances.stream().filter(i -> i.getUniqueId().equals(componentInstanceId)).findFirst();
- if (findFirst.isPresent()) {
- ComponentInstance ci = findFirst.get();
- Map<String, ArtifactDefinition> deploymentArtifacts = ci.getDeploymentArtifacts();
- for (String id : artifactsIds) {
- Optional<ArtifactDefinition> artOp = deploymentArtifacts.values().stream().filter(a -> a.getUniqueId().equals(id)).findFirst();
- if (artOp.isPresent()) {
- artifacts.add(new ArtifactDefinitionInfo(artOp.get()));
- }
- }
- List<String> instArtifactsIds = group.getGroupInstanceArtifacts();
- for (String id : instArtifactsIds) {
- Optional<ArtifactDefinition> artOp = deploymentArtifacts.values().stream().filter(a -> a.getUniqueId().equals(id)).findFirst();
- if (artOp.isPresent()) {
- artifacts.add(new ArtifactDefinitionInfo(artOp.get()));
- }
- }
- }
-
+ instances.stream().filter(i -> i.getUniqueId().equals(componentInstanceId))
+ .findFirst()
+ .ifPresent(f->getFirstComponentInstance(group, artifacts, artifactsIds, f));
}
}
GroupDefinitionInfo resultInfo = new GroupDefinitionInfo(group);
@@ -733,19 +696,51 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
return result;
} finally {
+ closeTransaction(inTransaction, result);
+ }
+ }
- if (!inTransaction) {
+ private void getFirstComponentInstance(GroupInstance group, List<ArtifactDefinitionInfo> artifacts, List<String> artifactsIds, ComponentInstance ci) {
+ Map<String, ArtifactDefinition> deploymentArtifacts = ci.getDeploymentArtifacts();
+ artifactsIds.forEach(id -> deploymentArtifacts.values().stream()
+ .filter(a -> a.getUniqueId().equals(id))
+ .findFirst()
+ .ifPresent(g -> artifacts.add(new ArtifactDefinitionInfo(g))));
- if (result == null || result.isRight()) {
- log.debug("Going to execute rollback on create group.");
- janusGraphDao.rollback();
- } else {
- log.debug("Going to execute commit on create group.");
- janusGraphDao.commit();
- }
+ List<String> instArtifactsIds = group.getGroupInstanceArtifacts();
+ instArtifactsIds.forEach(id -> deploymentArtifacts.values()
+ .stream()
+ .filter(a -> a.getUniqueId().equals(id))
+ .findFirst()
+ .ifPresent(g -> artifacts.add(new ArtifactDefinitionInfo(g))));
+ }
+
+ private Boolean isBaseProperty(Component component, GroupInstance group) {
+
+ Boolean isBase = null;
+ List<? extends GroupProperty> props = group.convertToGroupInstancesProperties();
+ if (props != null && !props.isEmpty()) {
+ Optional<? extends GroupProperty> isBasePropOp = props.stream().filter(p -> p.getName().equals(Constants.IS_BASE)).findAny();
+ if (isBasePropOp.isPresent()) {
+ GroupProperty propIsBase = isBasePropOp.get();
+ isBase = Boolean.parseBoolean(propIsBase.getValue());
+ } else {
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_GROUP, "failed to find prop isBase " + component.getNormalizedName(), ErrorSeverity.INFO);
}
+ }
+ return isBase;
+ }
+ private void closeTransaction(boolean inTransaction, Either<GroupDefinitionInfo, ResponseFormat> result) {
+ if (!inTransaction) {
+ if (result == null || result.isRight()) {
+ log.debug("Going to execute rollback on create group.");
+ janusGraphDao.rollback();
+ } else {
+ log.debug("Going to execute commit on create group.");
+ janusGraphDao.commit();
+ }
}
}
@@ -768,56 +763,51 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
return result;
}
- private Either<Boolean, ResponseFormat> validateMinMaxAndInitialCountPropertyLogic(Map<PropertyNames, String> newValues, Map<PropertyNames, String> currValues, Map<PropertyNames, String> parentValues) {
+ private Boolean validateMinMaxAndInitialCountPropertyLogic(Map<PropertyNames, String> newValues, Map<PropertyNames, String> currValues, Map<PropertyNames, String> parentValues) {
- Either<Boolean, ResponseFormat> result;
for (Entry<PropertyNames, String> entry : newValues.entrySet()) {
PropertyNames currPropertyName = entry.getKey();
if (currPropertyName == PropertyNames.MIN_INSTANCES) {
String minValue = parentValues.get(PropertyNames.MIN_INSTANCES);
- String maxValue = newValues.containsKey(PropertyNames.INITIAL_COUNT) ? newValues.get(PropertyNames.MAX_INSTANCES) : currValues.get(PropertyNames.INITIAL_COUNT);
- result = validateValueInRange(new ImmutablePair<>(currPropertyName, entry.getValue()), new ImmutablePair<>(PropertyNames.MIN_INSTANCES, minValue),
+ String maxValue = getMaxValue(newValues, currValues);
+ validateValueInRange(new ImmutablePair<>(currPropertyName, entry.getValue()), new ImmutablePair<>(PropertyNames.MIN_INSTANCES, minValue),
new ImmutablePair<>(PropertyNames.MAX_INSTANCES, maxValue));
- if (result.isRight()) {
- return result;
- }
} else if (currPropertyName == PropertyNames.INITIAL_COUNT) {
String minValue = newValues.containsKey(PropertyNames.MIN_INSTANCES) ? newValues.get(PropertyNames.MIN_INSTANCES) : currValues.get(PropertyNames.MIN_INSTANCES);
String maxValue = newValues.containsKey(PropertyNames.MAX_INSTANCES) ? newValues.get(PropertyNames.MAX_INSTANCES) : currValues.get(PropertyNames.MAX_INSTANCES);
- result = validateValueInRange(new ImmutablePair<>(currPropertyName, entry.getValue()), new ImmutablePair<>(PropertyNames.MIN_INSTANCES, minValue),
+ validateValueInRange(new ImmutablePair<>(currPropertyName, entry.getValue()), new ImmutablePair<>(PropertyNames.MIN_INSTANCES, minValue),
new ImmutablePair<>(PropertyNames.MAX_INSTANCES, maxValue));
- if (result.isRight()) {
- return result;
- }
} else if (currPropertyName == PropertyNames.MAX_INSTANCES) {
- String minValue = newValues.containsKey(PropertyNames.INITIAL_COUNT) ? newValues.get(PropertyNames.MIN_INSTANCES) : currValues.get(PropertyNames.INITIAL_COUNT);
+ String minValue = getMinValue(newValues, currValues);
String maxValue = parentValues.get(PropertyNames.MAX_INSTANCES);
- result = validateValueInRange(new ImmutablePair<>(currPropertyName, entry.getValue()), new ImmutablePair<>(PropertyNames.MIN_INSTANCES, minValue),
+ validateValueInRange(new ImmutablePair<>(currPropertyName, entry.getValue()), new ImmutablePair<>(PropertyNames.MIN_INSTANCES, minValue),
new ImmutablePair<>(PropertyNames.MAX_INSTANCES, maxValue));
- if (result.isRight()) {
- return result;
- }
}
}
- return Either.left(true);
+ return true;
}
- private Either<Boolean, ResponseFormat> validateValueInRange(ImmutablePair<PropertyNames, String> newValue, ImmutablePair<PropertyNames, String> min, ImmutablePair<PropertyNames, String> max) {
- Either<Boolean, ResponseFormat> result;
+ private String getMaxValue(Map<PropertyNames, String> newValues, Map<PropertyNames, String> currValues) {
+ return newValues.containsKey(PropertyNames.INITIAL_COUNT) ? newValues.get(PropertyNames.MAX_INSTANCES) : currValues.get(PropertyNames.INITIAL_COUNT);
+ }
+
+ private String getMinValue(Map<PropertyNames, String> newValues, Map<PropertyNames, String> currValues) {
+ return newValues.containsKey(PropertyNames.INITIAL_COUNT) ? newValues.get(PropertyNames.MIN_INSTANCES) : currValues.get(PropertyNames.INITIAL_COUNT);
+ }
+
+ private Boolean validateValueInRange(ImmutablePair<PropertyNames, String> newValue, ImmutablePair<PropertyNames, String> min, ImmutablePair<PropertyNames, String> max) {
final String warnMessage = "Failed to validate {} as property value of {}. It must be not higher than {}, and not lower than {}.";
int newValueInt = parseIntValue(newValue.getValue(), newValue.getKey());
int minInt = parseIntValue(min.getValue(), min.getKey());
int maxInt = parseIntValue(max.getValue(), max.getKey());
if (newValueInt < 0 || minInt < 0 || maxInt < 0) {
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY);
} else if (newValueInt < minInt || newValueInt > maxInt) {
log.debug(warnMessage, newValue.getValue(), newValue.getKey().getPropertyName(), min.getValue(), max.getValue());
- result = Either
- .right(componentsUtils.getResponseFormat(ActionStatus.INVALID_GROUP_MIN_MAX_INSTANCES_PROPERTY_VALUE, newValue.getKey().getPropertyName(), maxInt == Integer.MAX_VALUE ? Constants.UNBOUNDED : max.getValue(), min.getValue()));
- } else {
- result = Either.left(true);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_GROUP_MIN_MAX_INSTANCES_PROPERTY_VALUE, newValue.getKey().getPropertyName(),
+ maxInt == Integer.MAX_VALUE ? Constants.UNBOUNDED : max.getValue(), min.getValue());
}
- return result;
+ return true;
}
private int parseIntValue(String value, PropertyNames propertyName) {
@@ -843,13 +833,9 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
Either<GroupInstance, ResponseFormat> actionResult = null;
Either<GroupInstance, StorageOperationStatus> updateGroupInstanceResult = null;
- Either<List<GroupInstanceProperty>, ResponseFormat> validateRes = validateReduceGroupInstancePropertiesBeforeUpdate(oldGroupInstance, newProperties);
- if (validateRes.isRight()) {
- log.debug("Failed to validate group instance {} properties before update. ", oldGroupInstance.getName());
- actionResult = Either.right(validateRes.right().value());
- }
+ List<GroupInstanceProperty> validateRes = validateReduceGroupInstancePropertiesBeforeUpdate(oldGroupInstance, newProperties);
if (actionResult == null) {
- List<GroupInstanceProperty> validatedReducedNewProperties = validateRes.left().value();
+ List<GroupInstanceProperty> validatedReducedNewProperties = validateRes;
updateGroupInstanceResult = groupsOperation.updateGroupInstancePropertyValuesOnGraph(componentId, instanceId, oldGroupInstance, validatedReducedNewProperties);
if (updateGroupInstanceResult.isRight()) {
log.debug("Failed to update group instance {} property values. ", oldGroupInstance.getName());
@@ -862,10 +848,10 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
return actionResult;
}
- private Either<List<GroupInstanceProperty>, ResponseFormat> validateReduceGroupInstancePropertiesBeforeUpdate(GroupInstance oldGroupInstance, List<GroupInstanceProperty> newProperties) {
+ private List<GroupInstanceProperty> validateReduceGroupInstancePropertiesBeforeUpdate(GroupInstance oldGroupInstance, List<GroupInstanceProperty> newProperties) {
- Either<Boolean, ResponseFormat> validationRes = null;
- Either<List<GroupInstanceProperty>, ResponseFormat> actionResult;
+ Boolean validationRes = null;
+ List<GroupInstanceProperty> actionResult = null;
Map<String, GroupInstanceProperty> existingProperties = oldGroupInstance.convertToGroupInstancesProperties().stream().collect(Collectors.toMap(PropertyDataDefinition::getName, p -> p));
Map<PropertyNames, String> newPropertyValues = new EnumMap<>(PropertyNames.class);
List<GroupInstanceProperty> reducedProperties = new ArrayList<>();
@@ -874,25 +860,19 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
for (GroupInstanceProperty currNewProperty : newProperties) {
currPropertyName = currNewProperty.getName();
validationRes = handleAndAddProperty(reducedProperties, newPropertyValues, currNewProperty, existingProperties.get(currPropertyName));
- if (validationRes.isRight()) {
- log.debug("Failed to handle property {} of group instance {}. ", currPropertyName, oldGroupInstance.getName());
- break;
- }
}
- if (validationRes == null || validationRes.isLeft()) {
+ if (validationRes == null || validationRes) {
Map<PropertyNames, String> existingPropertyValues = new EnumMap<>(PropertyNames.class);
Map<PropertyNames, String> parentPropertyValues = new EnumMap<>(PropertyNames.class);
fillValuesAndParentValuesFromExistingProperties(existingProperties, existingPropertyValues, parentPropertyValues);
validationRes = validateMinMaxAndInitialCountPropertyLogic(newPropertyValues, existingPropertyValues, parentPropertyValues);
}
- if (validationRes.isLeft()) {
- actionResult = Either.left(reducedProperties);
- } else {
- actionResult = Either.right(validationRes.right().value());
+ if (validationRes) {
+ actionResult = reducedProperties;
}
} catch (Exception e) {
log.error("Exception occured during validation and reducing group instance properties. The message is {}", e.getMessage(), e);
- actionResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
return actionResult;
}
@@ -907,9 +887,9 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
}
}
- private Either<Boolean, ResponseFormat> handleAndAddProperty(List<GroupInstanceProperty> reducedProperties, Map<PropertyNames, String> newPropertyValues, GroupInstanceProperty currNewProperty, GroupInstanceProperty currExistingProperty) {
+ private Boolean handleAndAddProperty(List<GroupInstanceProperty> reducedProperties, Map<PropertyNames, String> newPropertyValues, GroupInstanceProperty currNewProperty, GroupInstanceProperty currExistingProperty) {
- Either<Boolean, ResponseFormat> validationRes = null;
+ Boolean validationRes = null;
String currPropertyName = currNewProperty.getName();
PropertyNames propertyName = PropertyNames.findName(currPropertyName);
try {
@@ -917,20 +897,15 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
log.warn("The value of property with the name {} cannot be updated. The property not found on group instance. ", currPropertyName);
} else if (isUpdatable(propertyName)) {
validationRes = validateAndUpdatePropertyValue(currNewProperty, currExistingProperty);
- if (validationRes.isRight()) {
- log.debug("Failed to validate property value {} of property {}. ", currNewProperty.getValue(), currPropertyName);
- } else {
- addPropertyUpdatedValues(reducedProperties, propertyName, newPropertyValues, currNewProperty, currExistingProperty);
- }
+ addPropertyUpdatedValues(reducedProperties, propertyName, newPropertyValues, currNewProperty, currExistingProperty);
} else {
validateImmutableProperty(currExistingProperty, currNewProperty);
}
if (validationRes == null) {
- validationRes = Either.left(true);
+ validationRes = true;
}
} catch (Exception e) {
log.error("Exception occured during handle and adding property. The message is {}", e.getMessage(), e);
- validationRes = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
return validationRes;
}
@@ -970,9 +945,8 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
return result;
}
- private Either<Boolean, ResponseFormat> validateAndUpdatePropertyValue(GroupInstanceProperty newProperty, GroupInstanceProperty existingProperty) {
+ private Boolean validateAndUpdatePropertyValue(GroupInstanceProperty newProperty, GroupInstanceProperty existingProperty) {
- Either<Boolean, ResponseFormat> validationRes = null;
String parentValue = existingProperty.getParentValue();
newProperty.setParentValue(parentValue);
@@ -985,12 +959,9 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
StorageOperationStatus status = groupOperation.validateAndUpdatePropertyValue(newProperty);
if (status != StorageOperationStatus.OK) {
log.debug("Failed to validate property value {} of property with name {}. Status is {}. ", newProperty.getValue(), newProperty.getName(), status);
- validationRes = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
}
- if (validationRes == null) {
- validationRes = Either.left(true);
- }
- return validationRes;
+ return true;
}
private void validateImmutableProperty(GroupProperty oldProperty, GroupProperty newProperty) {
@@ -1069,7 +1040,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
private int getNewGroupCounter(Component component) {
List<String> existingNames = component.getGroups()
.stream()
- .map(GroupDataDefinition::getName)
+ .map(GroupDataDefinition::getInvariantName)
.collect(toList());
List<String> existingIds = component.getGroups()
.stream()
@@ -1180,7 +1151,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
break;
}
GroupDefinition handledGroup = handleGroupRes.left().value();
- groups.put(handledGroup.getName(), new GroupDataDefinition(handledGroup));
+ groups.put(handledGroup.getInvariantName(), new GroupDataDefinition(handledGroup));
}
}
@@ -1196,6 +1167,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
if (result == null) {
result = Either.left(groupDefinitions);
}
+ component.setGroups(groupDefinitions);
return result;
}
@@ -1258,6 +1230,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
if (createGroupsResult.isRight()) {
result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(createGroupsResult.right().value())));
}
+ component.addGroups(createGroupsResult.left().value());
}
if (result == null) {
addCalculatedCapabilitiesWithPropertiesToComponent(component, groupDefinitions, fromCsar);
@@ -1278,6 +1251,9 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
} else {
deleteCalculatedCapabilitiesWithPropertiesFromComponent(component, groupDefinitions);
}
+ if (component.getGroups()!=null) {
+ component.getGroups().removeAll(deleteGroupsResult.left().value());
+ }
return Either.left(deleteGroupsResult.left().value());
}
@@ -1291,7 +1267,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
Either<List<GroupDefinition>, ResponseFormat> result = null;
Either<List<GroupDefinition>, StorageOperationStatus> createGroupsResult;
- createGroupsResult = groupsOperation.updateGroups(component, groupDefinitions.stream().map(GroupDataDefinition::new).collect(toList()), true);
+ createGroupsResult = groupsOperation.updateGroups(component, groupDefinitions.stream().map(GroupDataDefinition::new).collect(toList()), PromoteVersionEnum.MINOR);
if (createGroupsResult.isRight()) {
result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(createGroupsResult.right().value())));
}
@@ -1307,6 +1283,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
private Either<GroupDefinition, ResponseFormat> handleGroup(Component component, GroupDefinition groupDefinition, Map<String, DataTypeDefinition> allDAtaTypes) {
log.trace("Going to create group {}", groupDefinition);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_GROUP_POLICY,component.getComponentMetadataForSupportLog(),StatusCode.STARTED,"Start to create group: {}",groupDefinition.getName()+ " for component " + component.getName());
// 3. verify group not already exist
String groupDefinitionName = groupDefinition.getName();
if (groupExistsInComponent(groupDefinitionName, component)) {
@@ -1322,6 +1299,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
if (getGroupType.isRight()) {
StorageOperationStatus status = getGroupType.right().value();
if (status == StorageOperationStatus.NOT_FOUND) {
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_GROUP_POLICY,component.getComponentMetadataForSupportLog(), StatusCode.ERROR,"group {} cannot be found",groupDefinition.getName());
BeEcompErrorManager.getInstance().logInvalidInputError(CREATE_GROUP, "group type " + groupType + " cannot be found", ErrorSeverity.INFO);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_TYPE_IS_INVALID, groupType));
} else {
@@ -1351,6 +1329,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
if (CollectionUtils.isNotEmpty(properties)) {
if (CollectionUtils.isEmpty(groupTypeProperties)) {
BeEcompErrorManager.getInstance().logInvalidInputError(ADDING_GROUP, "group type does not have properties", ErrorSeverity.INFO);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_GROUP_POLICY,component.getComponentMetadataForSupportLog(), StatusCode.ERROR,"group {} does not have properties ",groupDefinition.getName());
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.MATCH_NOT_FOUND))));
}
@@ -1379,7 +1358,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
groupDefinition.setGroupUUID(UniqueIdBuilder.generateUUID());
groupDefinition.setVersion(INITIAL_VERSION);
groupDefinition.setTypeUid(groupTypeDefinition.getUniqueId());
-
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_GROUP_POLICY,component.getComponentMetadataForSupportLog(), StatusCode.COMPLETE,"group {} has been created ",groupDefinition.getName());
return Either.left(groupDefinition);
}
@@ -1387,7 +1366,9 @@ public class GroupBusinessLogic extends BaseBusinessLogic {
boolean found = false;
List<GroupDefinition> groups = component.getGroups();
if (CollectionUtils.isNotEmpty(groups)) {
- found = groups.stream().filter(p -> p.getName().equalsIgnoreCase(groupDefinitionName)).findFirst().orElse(null) != null;
+ found = groups.stream().filter(p -> (p.getName().equalsIgnoreCase(groupDefinitionName))
+ || p.getInvariantName().equalsIgnoreCase(groupDefinitionName))
+ .findFirst().orElse(null) != null;
}
return found;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java
index 5a5e941c24..eb576a46f6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java
@@ -33,7 +33,12 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
+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.GroupProperty;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.GroupsOperation;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -41,7 +46,11 @@ import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.springframework.transaction.annotation.Transactional;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import static org.openecomp.sdc.be.components.impl.BaseBusinessLogic.enumHasValueFilter;
@@ -66,7 +75,7 @@ public class GroupBusinessLogicNew {
Component component = accessValidations.validateUserCanWorkOnComponent(componentId, componentType, userId, "UPDATE GROUP MEMBERS");
GroupDefinition groupDefinition = getGroup(component, groupUniqueId);
groupDefinition.setMembers(buildMembersMap(component, members));
- groupsOperation.updateGroupOnComponent(componentId, groupDefinition);
+ groupsOperation.updateGroupOnComponent(componentId, groupDefinition, PromoteVersionEnum.MINOR);
return new ArrayList<>(groupDefinition.getMembers().values());
}
@@ -75,7 +84,7 @@ public class GroupBusinessLogicNew {
Component component = accessValidations.validateUserCanWorkOnComponent(componentId, componentType, userId, "UPDATE GROUP PROPERTIES");
GroupDefinition currentGroup = getGroup(component, groupUniqueId);
validateUpdatedPropertiesAndSetEmptyValues(currentGroup, newProperties);
- return groupsOperation.updateGroupPropertiesOnComponent(componentId, currentGroup, newProperties)
+ return groupsOperation.updateGroupPropertiesOnComponent(componentId, currentGroup, newProperties, PromoteVersionEnum.MINOR)
.left()
.on(this::onUpdatePropertyError);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java
index 80d6d65a06..ee53c35884 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java
@@ -57,7 +57,7 @@ public class GroupTypeBusinessLogic {
public List<GroupTypeDefinition> getAllGroupTypes(String userId, String internalComponentType) {
try {
- userValidations.validateUserExists(userId, "get group types", true);
+ userValidations.validateUserExists(userId);
Set<String> excludeGroupTypes = getExcludedGroupTypes(internalComponentType);
return groupTypeOperation.getAllGroupTypes(excludeGroupTypes);
} finally {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index 7001c0c05f..d557de1dec 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -22,20 +22,32 @@ package org.openecomp.sdc.be.components.impl;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import fj.data.Either;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringEscapeUtils;
-import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.Annotation;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
+import org.openecomp.sdc.be.model.HeatParameterDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.heat.HeatParameterType;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
+import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
@@ -52,7 +64,14 @@ import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.resolver.Resolver;
import java.lang.reflect.Type;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -303,21 +322,60 @@ public final class ImportUtils {
}
private static void setPropertyConstraints(Map<String, Object> propertyValue, PropertyDefinition property) {
- Either<List<Object>, ResultStatusEnum> propertyFieldconstraints = findFirstToscaListElement(propertyValue, TypeUtils.ToscaTagNamesEnum.CONSTRAINTS);
- if (propertyFieldconstraints.isLeft()) {
- List<Object> jsonConstraintList = propertyFieldconstraints.left().value();
+ List<PropertyConstraint> constraints = getPropertyConstraints(propertyValue, property.getType());
+ if (CollectionUtils.isNotEmpty(constraints)) {
+ property.setConstraints(constraints);
+ }
+ }
+ private static List<PropertyConstraint> getPropertyConstraints(Map<String, Object> propertyValue, String propertyType) {
+ List<Object> propertyFieldConstraints = findCurrentLevelConstraintsElement(propertyValue);
+ if (CollectionUtils.isNotEmpty(propertyFieldConstraints)) {
List<PropertyConstraint> constraintList = new ArrayList<>();
Type constraintType = new TypeToken<PropertyConstraint>() {
}.getType();
Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
- for (Object constraintJson : jsonConstraintList) {
- PropertyConstraint propertyConstraint = gson.fromJson(gson.toJson(constraintJson), constraintType);
+ for (Object constraintJson : propertyFieldConstraints) {
+ PropertyConstraint propertyConstraint = validateAndGetPropertyConstraint(propertyType, constraintType, gson, constraintJson);
constraintList.add(propertyConstraint);
}
- property.setConstraints(constraintList);
+ return constraintList;
}
+ return null;
+ }
+
+ private static List<Object> findCurrentLevelConstraintsElement(Map<String, Object> toscaJson) {
+ List<Object> constraints = null;
+ if (toscaJson.containsKey(TypeUtils.ToscaTagNamesEnum.CONSTRAINTS.getElementName())) {
+ try {
+ constraints = (List<Object>) toscaJson.get(TypeUtils.ToscaTagNamesEnum.CONSTRAINTS.getElementName());
+ } catch (ClassCastException e){
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS_FORMAT, toscaJson.get(TypeUtils.ToscaTagNamesEnum.CONSTRAINTS.getElementName()).toString());
+ }
+ }
+ return constraints;
+
+ }
+
+ private static PropertyConstraint validateAndGetPropertyConstraint(String propertyType, Type constraintType, Gson gson, Object constraintJson) {
+ PropertyConstraint propertyConstraint;
+ try{
+ propertyConstraint = gson.fromJson(gson.toJson(constraintJson), constraintType);
+ } catch (ClassCastException|JsonParseException e){
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS_FORMAT, constraintJson.toString());
+ }
+ if(propertyConstraint!= null && propertyConstraint instanceof ValidValuesConstraint){
+ try {
+ ((ValidValuesConstraint)propertyConstraint).validateType(propertyType);
+ } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("GetInitializedPropertyConstraint",
+ e.getMessage(), BeEcompErrorManager.ErrorSeverity.ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_CONSTRAINTS, ConstraintType.VALID_VALUES.name(),
+ ((ValidValuesConstraint) propertyConstraint).getValidValues().toString(), propertyType);
+ }
+ }
+ return propertyConstraint;
}
public static PropertyDefinition createModuleProperty(Map<String, Object> propertyValue) {
@@ -445,35 +503,29 @@ public final class ImportUtils {
}
private static void setScheme(Map<String, Object> propertyValue, PropertyDefinition propertyDefinition) {
- Either<SchemaDefinition, ResultStatusEnum> eitherSchema = getSchema(propertyValue);
- if (eitherSchema.isLeft()) {
- SchemaDefinition schemaDef = new SchemaDefinition();
- schemaDef.setProperty(eitherSchema.left().value().getProperty());
+ Either<Object, ResultStatusEnum> schemaElementRes = findSchemaElement(propertyValue);
+ if (schemaElementRes.isLeft()) {
+ SchemaDefinition schemaDef = getSchema(schemaElementRes.left().value());
propertyDefinition.setSchema(schemaDef);
}
-
}
- private static Either<SchemaDefinition, ResultStatusEnum> getSchema(Map<String, Object> propertyValue) {
- Either<SchemaDefinition, ResultStatusEnum> result = Either.right(ResultStatusEnum.ELEMENT_NOT_FOUND);
- Either<Object, ResultStatusEnum> propertyFieldEntryScheme = findToscaElement(propertyValue, TypeUtils.ToscaTagNamesEnum.ENTRY_SCHEMA, ToscaElementTypeEnum.ALL);
- if (propertyFieldEntryScheme.isLeft()) {
- if (propertyFieldEntryScheme.left().value() instanceof String) {
- String schemaType = (String) propertyFieldEntryScheme.left().value();
- SchemaDefinition schema = new SchemaDefinition();
- PropertyDefinition schemeProperty = new PropertyDefinition();
- schemeProperty.setType(schemaType);
- schema.setProperty(schemeProperty);
- result = Either.left(schema);
+ private static Either<Object,ResultStatusEnum> findSchemaElement(Map<String, Object> propertyValue) {
+ return findToscaElement(propertyValue, TypeUtils.ToscaTagNamesEnum.ENTRY_SCHEMA, ToscaElementTypeEnum.ALL);
+ }
- } else if (propertyFieldEntryScheme.left().value() instanceof Map) {
- PropertyDefinition schemeProperty = createModuleProperty((Map<String, Object>) propertyFieldEntryScheme.left().value());
- SchemaDefinition schema = new SchemaDefinition();
- schema.setProperty(schemeProperty);
- result = Either.left(schema);
- }
+ private static SchemaDefinition getSchema(Object propertyFieldEntryScheme) {
+ SchemaDefinition schema = new SchemaDefinition();
+ if (propertyFieldEntryScheme instanceof String) {
+ String schemaType = (String) propertyFieldEntryScheme;
+ PropertyDefinition schemeProperty = new PropertyDefinition();
+ schemeProperty.setType(schemaType);
+ schema.setProperty(schemeProperty);
+ } else if (propertyFieldEntryScheme instanceof Map) {
+ PropertyDefinition schemeProperty = createModuleProperty((Map<String, Object>) propertyFieldEntryScheme);
+ schema.setProperty(schemeProperty);
}
- return result;
+ return schema;
}
public static void setField(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum tagName, Consumer<String> setter) {
@@ -665,7 +717,7 @@ public final class ImportUtils {
return null;
}
ToscaPropertyType validType = ToscaPropertyType.isValidType(type);
- if (validType == null || validType.equals(ToscaPropertyType.JSON) ||validType.equals(ToscaPropertyType.MAP) || validType.equals(ToscaPropertyType.LIST)) {
+ if (validType == null || validType == ToscaPropertyType.JSON || validType == ToscaPropertyType.MAP || validType == ToscaPropertyType.LIST) {
return gson.toJson(value);
}
return value.toString();
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 bcd48a24c0..02d6e0b565 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
@@ -22,21 +22,15 @@
package org.openecomp.sdc.be.components.impl;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
+import fj.data.Either;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.validation.ComponentValidations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -69,11 +63,23 @@ import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import fj.data.Either;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
@Component("inputsBusinessLogic")
public class InputsBusinessLogic extends BaseBusinessLogic {
@@ -87,6 +93,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
private static final String FAILED_TO_FOUND_INPUT_UNDER_COMPONENT_ERROR = "Failed to found input {} under component {}, error: {}";
private static final String GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP = "Going to execute rollback on create group.";
private static final String GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP = "Going to execute commit on create group.";
+ public LoggerSupportability loggerSupportability=LoggerSupportability.getLogger(InputsBusinessLogic.class.getName());
private final PropertyDeclarationOrchestrator propertyDeclarationOrchestrator;
private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
@@ -118,7 +125,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
*/
public Either<List<InputDefinition>, ResponseFormat> getInputs(String userId, String componentId) {
- validateUserExists(userId, "get Inputs", false);
+ validateUserExists(userId);
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
@@ -140,7 +147,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
public Either<List<ComponentInstanceInput>, ResponseFormat> getComponentInstanceInputs(String userId, String componentId, String componentInstanceId) {
- validateUserExists(userId, "get Inputs", false);
+ validateUserExists(userId);
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
filters.setIgnoreInputs(false);
@@ -159,6 +166,8 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
if(!ComponentValidations.validateComponentInstanceExist(component, componentInstanceId)){
ActionStatus actionStatus = ActionStatus.COMPONENT_INSTANCE_NOT_FOUND;
log.debug("Failed to found component instance inputs {}, error: {}", componentInstanceId, actionStatus);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS,component.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"Failed to found component instance inputs componentInstanceId: {}",componentInstanceId);
return Either.right(componentsUtils.getResponseFormat(actionStatus));
}
Map<String, List<ComponentInstanceInput>> ciInputs =
@@ -181,7 +190,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
*/
public Either<List<ComponentInstanceProperty>, ResponseFormat> getComponentInstancePropertiesByInputId(String userId, String componentId, String instanceId, String inputId) {
- validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
+ validateUserExists(userId);
String parentId = componentId;
org.openecomp.sdc.be.model.Component component;
ComponentParametersView filters = new ComponentParametersView();
@@ -234,7 +243,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
- private Either<String,ResponseFormat> updateInputObjectValue(InputDefinition currentInput, InputDefinition newInput, Map<String, DataTypeDefinition> dataTypes) {
+ private String updateInputObjectValue(InputDefinition currentInput, InputDefinition newInput, Map<String, DataTypeDefinition> dataTypes) {
String innerType = null;
String propertyType = currentInput.getType();
ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
@@ -244,12 +253,12 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
SchemaDefinition def = currentInput.getSchema();
if (def == null) {
log.debug("Schema doesn't exists for property of type {}", type);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE));
}
PropertyDataDefinition propDef = def.getProperty();
if (propDef == null) {
log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE));
}
innerType = propDef.getType();
}
@@ -261,8 +270,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
if (isValid.isRight()) {
Boolean res = isValid.right().value();
if (Boolean.FALSE.equals(res)) {
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(
- JanusGraphOperationStatus.ILLEGAL_ARGUMENT))));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus.ILLEGAL_ARGUMENT)));
}
} else {
Object object = isValid.left().value();
@@ -270,7 +278,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
newValue = object.toString();
}
}
- return Either.left(newValue);
+ return newValue;
}
private InputDefinition getInputFromInputsListById(List<InputDefinition> componentsOldInputs, InputDefinition input) {
@@ -284,7 +292,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
org.openecomp.sdc.be.model.Component component = null;
try {
- validateUserExists(userId, "get input", false);
+ validateUserExists(userId);
ComponentParametersView componentParametersView = new ComponentParametersView();
componentParametersView.disableAll();
@@ -294,43 +302,29 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
componentParametersView.setIgnoreComponentInstancesProperties(false);
componentParametersView.setIgnoreComponentInstances(false);
- Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentType, componentParametersView);
-
- if (validateComponent.isRight()) {
- result = Either.right(validateComponent.right().value());
- return result;
- }
- component = validateComponent.left().value();
+ component = validateComponentExists(componentId, componentType, componentParametersView);
if (shouldLockComp) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, UPDATE_INPUT);
- if (lockComponent.isRight()) {
- result = Either.right(lockComponent.right().value());
+ try {
+ lockComponent(component, UPDATE_INPUT);
+ }catch (ComponentException e){
+ result = Either.right(e.getResponseFormat());
return result;
}
}
- Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
- if (canWork.isRight()) {
- result = Either.right(canWork.right().value());
- return result;
- }
-
- //Validate value and Constraint of input
+ //Validate value and Constraint of input
Either<Boolean, ResponseFormat> constraintValidatorResponse = validateInputValueConstraint(inputs);
- if (constraintValidatorResponse.isRight()) {
- log.error("Failed validation value and constraint of property: {}",
- constraintValidatorResponse.right().value());
- return Either.right(constraintValidatorResponse.right().value());
- }
-
- Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
- if (allDataTypes.isRight()) {
- result = Either.right(allDataTypes.right().value());
- return result;
+ if (constraintValidatorResponse.isRight()) {
+ log.error("Failed validation value and constraint of property: {}",
+ constraintValidatorResponse.right().value());
+ return Either.right(constraintValidatorResponse.right().value());
}
- Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+ validateCanWorkOnComponent(component, userId);
+ Map<String, DataTypeDefinition> dataTypes;
+ dataTypes = getAllDataTypes(applicationDataTypeCache);
+
List<InputDefinition> componentsOldInputs = Optional.ofNullable(component.getInputs()).orElse(Collections.emptyList());
for (InputDefinition newInput: inputs) {
InputDefinition currInput = getInputFromInputsListById(componentsOldInputs, newInput);
@@ -340,13 +334,8 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
result = Either.right(componentsUtils.getResponseFormat(actionStatus));
return result;
}
- Either<String, ResponseFormat> updateInputObjectValue = updateInputObjectValue(currInput, newInput, dataTypes);
- if ( updateInputObjectValue.isRight()) {
- return Either.right(updateInputObjectValue.right().value());
- }
- String newValue = updateInputObjectValue.left().value();
- currInput.setValue(newValue);
- currInput.setDefaultValue(newValue);
+ String updateInputObjectValue = updateInputObjectValue(currInput, newInput, dataTypes);
+ currInput.setDefaultValue(updateInputObjectValue);
currInput.setOwnerId(userId);
Either<InputDefinition, StorageOperationStatus> status = toscaOperationFacade.updateInputOfComponent(component, currInput);
if(status.isRight()){
@@ -358,22 +347,16 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
}
result = Either.left(returnInputs);
- return result;
- } finally {
- if (!inTransaction) {
- if (result == null || result.isRight()) {
- log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP);
- janusGraphDao.rollback();
- } else {
- log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP);
- janusGraphDao.commit();
- }
- }
- // unlock resource
- if (shouldLockComp && component != null) {
- graphLockOperation.unlockComponent(componentId, componentType.getNodeType());
- }
- }
+ }catch (ComponentException e) {
+ log.debug(GOING_TO_EXECUTE_ROLLBACK_ON_CREATE_GROUP);
+ unlockRollbackWithException(component, e);
+ } catch (Exception e){
+ unlockRollbackWithException(component, new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR));
+ }
+ log.debug(GOING_TO_EXECUTE_COMMIT_ON_CREATE_GROUP);
+ unlockWithCommit(component);
+ return result;
+
}
private Either<Boolean, ResponseFormat> validateInputValueConstraint(List<InputDefinition> inputs) {
@@ -399,7 +382,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
}
public Either<List<ComponentInstanceInput>, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) {
- validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
+ validateUserExists(userId);
org.openecomp.sdc.be.model.Component component = null;
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
@@ -442,7 +425,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
org.openecomp.sdc.be.model.Component component = null;
try {
- validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
+ validateUserExists(userId);
component = getAndValidateComponentForCreate(userId, componentId, componentType, shouldLockComp);
@@ -498,7 +481,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
try {
/* check if user exists */
- validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
+ validateUserExists(userId);
component = getAndValidateComponentForCreate(userId, componentId, componentType, shouldLockComp);
@@ -579,23 +562,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
private org.openecomp.sdc.be.model.Component getAndValidateComponentForCreate(
String userId, String componentId, ComponentTypeEnum componentType, boolean shouldLockComp
) {
-
ComponentParametersView componentParametersView = getBaseComponentParametersView();
-
- Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither =
- // get Component Object
- validateComponentExists(componentId, componentType, componentParametersView)
- .left().bind(component -> {
- if (shouldLockComp) {
- // lock the component
- return lockComponent(component, CREATE_INPUT).left().map(result -> component);
- }
- return Either.left(component);
- }).left().bind(component -> validateCanWorkOnComponent(component, userId).left().map(result -> component));
- if (componentEither.isRight()) {
- throw new ByResponseFormatComponentException(componentEither.right().value());
+ org.openecomp.sdc.be.model.Component component = validateComponentExists(componentId, componentType, componentParametersView);
+ if (shouldLockComp) {
+ // lock the component
+ lockComponent(component, CREATE_INPUT);
}
- return componentEither.left().value();
+ validateCanWorkOnComponent(component, userId);
+ return component;
}
private DataTypeDefinition prepareDataTypeForListInput(ComponentInstInputsMap inputsMap, InputDefinition input) {
@@ -615,7 +589,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
DataTypeDefinition dataType = new DataTypeDefinition();
List<ComponentInstancePropInput> propInputs = inputsMap.resolvePropertiesToDeclare().getRight();
dataType.setName(desiredTypeName);
- dataType.setDerivedFromName(ToscaPropertyType.Root.getType());
+ dataType.setDerivedFromName(ToscaPropertyType.ROOT.getType());
// Copy properties from inputsMap
dataType.setProperties(propInputs.stream().map(PropertyDefinition::new).collect(Collectors.toList()));
return dataType;
@@ -639,12 +613,8 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
public Either<List<InputDefinition>, ResponseFormat> createInputsInGraph(Map<String, InputDefinition> inputs, org.openecomp.sdc.be.model.Component component) {
List<InputDefinition> resourceProperties = component.getInputs();
- Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
- if (allDataTypes.isRight()) {
- return Either.right(allDataTypes.right().value());
- }
- Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+ Map<String, DataTypeDefinition> dataTypes = getAllDataTypes(applicationDataTypeCache);
for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
String inputName = inputDefinition.getKey();
@@ -668,6 +638,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
Either<List<InputDefinition>, StorageOperationStatus> associateInputsEither = toscaOperationFacade.createAndAssociateInputs(inputs, component.getUniqueId());
if(associateInputsEither.isRight()){
log.debug("Failed to create inputs under component {}. Status is {}", component.getUniqueId(), associateInputsEither.right().value());
+
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(associateInputsEither.right().value())));
}
return Either.left(associateInputsEither.left().value());
@@ -677,13 +648,9 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
Map<String, DataTypeDefinition> privateDataTypes, org.openecomp.sdc.be.model.Component component) {
log.trace("#createListInputsInGraph: enter");
- Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(
- applicationDataTypeCache);
- if (allDataTypes.isRight()) {
- return Either.right(allDataTypes.right().value());
- }
- Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+ Map<String, DataTypeDefinition> dataTypes = getAllDataTypes(
+ applicationDataTypeCache);
dataTypes.putAll(privateDataTypes);
for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
@@ -717,14 +684,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
* @param inputId
* @return
*/
- public Either<InputDefinition, ResponseFormat> deleteInput(String componentId, String userId, String inputId) {
+ public InputDefinition deleteInput(String componentId, String userId, String inputId) {
Either<InputDefinition, ResponseFormat> deleteEither = null;
if (log.isDebugEnabled()) {
log.debug("Going to delete input id: {}", inputId);
}
- validateUserExists(userId, "Delete input", true);
+ validateUserExists(userId);
ComponentParametersView componentParametersView = getBaseComponentParametersView();
componentParametersView.setIgnoreInterfaces(false);
@@ -734,9 +701,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
Either<org.openecomp.sdc.be.model.Component, StorageOperationStatus> componentEither =
toscaOperationFacade.getToscaElement(componentId, componentParametersView);
if (componentEither.isRight()) {
- deleteEither = Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(componentEither.right().value())));
- return deleteEither;
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(componentEither.right().value()));
}
org.openecomp.sdc.be.model.Component component = componentEither.left().value();
@@ -747,57 +712,43 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
// Get the input
findAny();
if (!optionalInput.isPresent()) {
- return Either.right(
- componentsUtils.getResponseFormat(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId));
+ throw new ByActionStatusComponentException(ActionStatus.INPUT_IS_NOT_CHILD_OF_COMPONENT, inputId, componentId);
}
InputDefinition inputForDelete = optionalInput.get();
// Lock component
- Either<Boolean, ResponseFormat> lockResultEither =
- lockComponent(componentId, component, "deleteInput");
- if (lockResultEither.isRight()) {
- ResponseFormat responseFormat = lockResultEither.right().value();
- deleteEither = Either.right(responseFormat);
- return deleteEither;
- }
-
+ lockComponent(componentId, component, "deleteInput");
// Delete input operations
+ boolean failed = false;
try {
StorageOperationStatus status =
toscaOperationFacade.deleteInputOfResource(component, inputForDelete.getName());
if (status != StorageOperationStatus.OK) {
log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
- deleteEither = Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(status), component.getName()));
- return deleteEither;
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), component.getName());
}
if (BooleanUtils.isTrue(inputForDelete.getIsDeclaredListInput())){
deleteEither = deleteListInput(componentId, inputId, component, inputForDelete, status);
- return deleteEither;
+ if (deleteEither.isRight()){
+ throw new ByResponseFormatComponentException(deleteEither.right().value());
+ }
+ return deleteEither.left().value();
}
StorageOperationStatus storageOperationStatus =
propertyDeclarationOrchestrator.unDeclarePropertiesAsInputs(component, inputForDelete);
if (storageOperationStatus != StorageOperationStatus.OK) {
log.debug("Component id: {} update properties declared as input for input id: {} failed", componentId, inputId);
- deleteEither = Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(status), component.getName()));
- return deleteEither;
- }
-
- deleteEither = Either.left(inputForDelete);
- return deleteEither;
- } finally {
- if (deleteEither == null || deleteEither.isRight()) {
- log.debug("Component id: {} delete input id: {} failed", componentId, inputId);
- janusGraphDao.rollback();
- } else {
- log.debug("Component id: {} delete input id: {} success", componentId, inputId);
- janusGraphDao.commit();
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageOperationStatus), component.getName());
}
- unlockComponent(deleteEither, component);
+ return inputForDelete;
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponent(failed, component);
}
}
@@ -858,7 +809,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
Either<InputDefinition, ResponseFormat> result = null;
try {
- validateUserExists(userId, GET_PROPERTIES_BY_INPUT, false);
+ validateUserExists(userId);
ComponentParametersView filters = new ComponentParametersView();
filters.disableAll();
filters.setIgnoreComponentInstances(false);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
index 7a1c96e1ef..f6a2e5bd3e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceLifecycleTypeImportManager.java
@@ -32,7 +32,11 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
@Component("interfaceLifecycleTypeImportManager")
public class InterfaceLifecycleTypeImportManager {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
index add5df225c..a0ea5c9d04 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
@@ -17,33 +17,11 @@
package org.openecomp.sdc.be.components.impl;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedCapabilityPropertyDefaultValue;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedInputPropertyDefaultValue;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationFromInterfaceDefinition;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
-import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityFromAllCapProps;
-import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
-import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
-
import com.google.gson.Gson;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.UUID;
-import java.util.stream.Collectors;
-
import fj.data.Either;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -77,6 +55,28 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedCapabilityPropertyDefaultValue;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedInputPropertyDefaultValue;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.createMappedOutputDefaultValue;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationFromInterfaceDefinition;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.getPropertyCapabilityFromAllCapProps;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
+import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
+
@Component("interfaceOperationBusinessLogic")
public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
@@ -107,7 +107,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
public Either<List<InterfaceDefinition>, ResponseFormat> deleteInterfaceOperation(String componentId,
String interfaceId, List<String> operationsToDelete, User user, boolean lock) {
- validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true);
+ validateUserExists(user.getUserId());
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()) {
@@ -115,11 +115,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- Either<Boolean, ResponseFormat> lockResult =
- lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION);
- if (lockResult.isRight()) {
- return Either.right(lockResult.right().value());
- }
+ lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION);
+
try {
Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
@@ -208,10 +205,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
janusGraphDao.rollback();
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
} finally {
- if (lockResult.isLeft() && lockResult.left().value()) {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
- }
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
@@ -228,18 +223,19 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock,
org.openecomp.sdc.be.model.Component component, String action) {
if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action);
- if (lockResult.isRight()) {
- janusGraphDao.rollback();
- return Either.right(lockResult.right().value());
- }
+ try {
+ lockComponent(component.getUniqueId(), component, action);
+ } catch (ComponentException e) {
+ janusGraphDao.rollback();
+ throw e;
}
+ }
return Either.left(true);
}
public Either<List<InterfaceDefinition>, ResponseFormat> getInterfaceOperation(String componentId,
String interfaceId, List<String> operationsToGet, User user, boolean lock) {
- validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
+ validateUserExists(user);
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()) {
@@ -247,11 +243,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- Either<Boolean, ResponseFormat> lockResult =
- lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION);
- if (lockResult.isRight()) {
- return Either.right(lockResult.right().value());
- }
+ lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION);
try {
Optional<InterfaceDefinition> optionalInterface = getInterfaceDefinitionFromComponentByInterfaceId(
@@ -280,10 +272,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
return Either.right(
componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
} finally {
- if (lockResult.isLeft() && lockResult.left().value()) {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
- }
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
@@ -296,7 +286,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
private Either<List<InterfaceDefinition>, ResponseFormat> createOrUpdateInterfaceOperation(String componentId,
List<InterfaceDefinition> interfaceDefinitions, User user, boolean isUpdate, String errorContext,
boolean lock) {
- validateUserExists(user.getUserId(), errorContext, true);
+ validateUserExists(user);
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()) {
@@ -304,10 +294,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, errorContext);
- if (lockResult.isRight()) {
- return Either.right(lockResult.right().value());
- }
+ lockComponentResult(lock, storedComponent, errorContext);
+
Either<Map<String, InterfaceDefinition>, ResponseFormat> interfaceLifecycleTypes =
getAllInterfaceLifecycleTypes();
@@ -416,10 +404,8 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
LOGGER.error(EXCEPTION_OCCURRED_DURING_INTERFACE_OPERATION, "addOrUpdate", e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
- if (lockResult.isLeft() && lockResult.left().value()) {
- graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
- NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
- }
+ graphLockOperation.unlockComponent(storedComponent.getUniqueId(),
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
@@ -566,7 +552,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
- validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
+ validateUserExists(user.getUserId());
Either<Boolean, ResponseFormat> lockResult = lockComponentResult(true, storedComponent, GET_INTERFACE_OPERATION);
if (lockResult.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogic.java
deleted file mode 100644
index b0bdf45c5a..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/MonitoringBusinessLogic.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * ============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.sdc.be.components.impl;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.impl.MonitoringDao;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.monitoring.MonitoringEvent;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.stereotype.Component;
-
-@Component("monitoringBusinessLogic")
-public class MonitoringBusinessLogic {
-
- private static final Logger log = Logger.getLogger(MonitoringBusinessLogic.class);
-
- @javax.annotation.Resource
- private MonitoringDao monitoringDao;
-
- @javax.annotation.Resource
- private ComponentsUtils componentsUtils;
-
- public Either<Boolean, ResponseFormat> logMonitoringEvent(MonitoringEvent monitoringEvent) {
- if (monitoringDao == null) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- ActionStatus status = monitoringDao.addRecord(monitoringEvent);
- if (!status.equals(ActionStatus.OK)) {
- log.warn("Failed to persist monitoring event: {}", status);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- return Either.left(true);
- }
-
- public String getEsHost() {
-
- String res = monitoringDao.getEsHost();
- res = res.replaceAll("[\\[\\]]", "");
- res = res.split(",")[0];
- res = res.replaceAll("[']", "");
- res = res.split(":")[0];
- return res;
- }
-
- public String getEsPort() {
- return monitoringDao.getEsPort();
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java
index e622a3037a..927c8b17b7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/NodeFilterUploadCreator.java
@@ -16,17 +16,18 @@
package org.openecomp.sdc.be.components.impl;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.model.UploadNodeFilterCapabilitiesInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
import org.openecomp.sdc.be.utils.TypeUtils;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
public class NodeFilterUploadCreator {
public UploadNodeFilterInfo createNodeFilterData(Object obj) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
index 17233d6663..2d0ee0dd66 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java
@@ -20,31 +20,19 @@
package org.openecomp.sdc.be.components.impl;
-import static java.util.stream.Collectors.toMap;
-import static org.openecomp.sdc.be.components.validation.PolicyUtils.getExcludedPolicyTypesByComponent;
-import static org.openecomp.sdc.be.components.validation.PolicyUtils.getNextPolicyCounter;
-import static org.openecomp.sdc.be.components.validation.PolicyUtils.validatePolicyFields;
-
import fj.data.Either;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import javax.inject.Inject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.validation.PolicyUtils;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
@@ -65,6 +53,20 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static java.util.stream.Collectors.toMap;
+import static org.openecomp.sdc.be.components.validation.PolicyUtils.getExcludedPolicyTypesByComponent;
+import static org.openecomp.sdc.be.components.validation.PolicyUtils.getNextPolicyCounter;
+import static org.openecomp.sdc.be.components.validation.PolicyUtils.validatePolicyFields;
+
/**
* Provides specified business logic to create, retrieve, update, delete a policy
*/
@@ -105,7 +107,23 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
* @return a policy or an error in a response format
*/
- public Either<PolicyDefinition, ResponseFormat> createPolicy(ComponentTypeEnum componentType, String componentId, String policyTypeName, String userId, boolean shouldLock) {
+ public PolicyDefinition createPolicy(ComponentTypeEnum componentType, String componentId, String policyTypeName, String userId, boolean shouldLock) {
+
+ log.trace("#createPolicy - starting to create policy of the type {} on the component {}. ", policyTypeName, componentId);
+ Component component = null;
+ boolean failed = false;
+ try {
+ component = validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock);
+ return createPolicy(policyTypeName, component);
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponent(shouldLock, failed, component);
+ }
+ }
+
+ /*public Either<PolicyDefinition, ResponseFormat> createPolicy(ComponentTypeEnum componentType, String componentId, String policyTypeName, String userId, boolean shouldLock) {
Either<PolicyDefinition, ResponseFormat> result = null;
log.trace("#createPolicy - starting to create policy of the type {} on the component {}. ", policyTypeName, componentId);
@@ -118,22 +136,24 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
return createPolicy(policyTypeName, c);
});
} catch (Exception e) {
+ if (ComponentException.class.equals(e.getClass())) {
+ throw e;
+ }
log.error("#createPolicy - the exception occurred upon creation of a policy of the type {} for the component {}: ", policyTypeName, componentId, e);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
-
+ //TODO Andrey result = boolean
unlockComponent(shouldLock, result, component);
}
return result;
- }
+ }*/
public Either<List<PolicyDefinition>, ResponseFormat> getPoliciesList(ComponentTypeEnum componentType, String componentId, String userId) {
Either<List<PolicyDefinition>, ResponseFormat> result;
log.trace("#getPolicies - starting to retrieve policies of component {}. ", componentId);
try {
- result = validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId)
- .left()
- .bind(c -> Either.left(c.resolvePoliciesList()));
+ Component component = validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId);
+ result = Either.left(component.resolvePoliciesList());
} catch (Exception e) {
log.error("#getPolicy - the exception occurred upon retrieving policies list of component {}: ", componentId, e);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
@@ -141,6 +161,8 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
return result;
}
+
+
/**
* Retrieves the policy of the component by UniqueId
*
@@ -148,9 +170,15 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
* @param componentId the ID of the component
* @param policyId the ID of the policy
* @param userId the ID of the user
- * @return either policy or error response
+ * @return either policy or error response
*/
- public Either<PolicyDefinition, ResponseFormat> getPolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId) {
+ public PolicyDefinition getPolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId) {
+ log.trace("#getPolicy - starting to retrieve the policy {} of the component {}. ", policyId, componentId);
+ Component component = validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId);
+ return getPolicyById(component, policyId);
+ }
+
+ /*public Either<PolicyDefinition, ResponseFormat> getPolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId) {
Either<PolicyDefinition, ResponseFormat> result;
log.trace("#getPolicy - starting to retrieve the policy {} of the component {}. ", policyId, componentId);
try {
@@ -162,7 +190,7 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
return result;
- }
+ }*/
/**
* Updates the policy of the component
@@ -174,7 +202,25 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
* @param shouldLock the flag defining if the component should be locked
* @return a policy or an error in a response format
*/
- public Either<PolicyDefinition, ResponseFormat> updatePolicy(ComponentTypeEnum componentType, String componentId, PolicyDefinition policy, String userId, boolean shouldLock) {
+ public PolicyDefinition updatePolicy(ComponentTypeEnum componentType, String componentId, PolicyDefinition policy, String userId, boolean shouldLock) {
+ Component component = null;
+ boolean failed = false;
+ log.trace("#updatePolicy - starting to update the policy {} on the component {}. ", policy.getUniqueId(), componentId);
+ try {
+ component = validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock);
+ return validateAndUpdatePolicy(component, policy);
+ } catch (ComponentException e) {
+ failed = true;
+ log.error("#updatePolicy - the exception occurred upon update of a policy of the type {} for the component {}: ", policy.getUniqueId(), componentId, e);
+ throw e;
+ } finally {
+ //TODO Andrey result = boolean
+ unlockComponent(shouldLock, failed, component);
+ }
+ }
+
+
+ /*public Either<PolicyDefinition, ResponseFormat> updatePolicy(ComponentTypeEnum componentType, String componentId, PolicyDefinition policy, String userId, boolean shouldLock) {
Either<PolicyDefinition, ResponseFormat> result = null;
log.trace("#updatePolicy - starting to update the policy {} on the component {}. ", policy.getUniqueId(), componentId);
Wrapper<Component> component = new Wrapper<>();
@@ -189,10 +235,11 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
log.error("#updatePolicy - the exception occurred upon update of a policy of the type {} for the component {}: ", policy.getUniqueId(), componentId, e);
result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
+ //TODO Andrey result = boolean
unlockComponent(shouldLock, result, component);
}
return result;
- }
+ }*/
/**
* Deletes the policy from the component
@@ -204,7 +251,25 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
* @param shouldLock the flag defining if the component should be locked
* @return a policy or an error in a response format
*/
- public Either<PolicyDefinition, ResponseFormat> deletePolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId, boolean shouldLock) {
+ public PolicyDefinition deletePolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId, boolean shouldLock) {
+ PolicyDefinition result = null;
+ log.trace("#deletePolicy - starting to update the policy {} on the component {}. ", policyId, componentId);
+ Component component = null;
+ boolean failed= false;
+ try {
+ component = validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock);
+ return deletePolicy(component, policyId);
+ } catch (ComponentException e) {
+ failed = true;
+ log.error("#deletePolicy - the exception occurred upon update of a policy of the type {} for the component {}: ", policyId, componentId, e);
+ throw e;
+ } finally {
+ unlockComponent(shouldLock, failed, component);
+ }
+ }
+
+
+ /*public Either<PolicyDefinition, ResponseFormat> deletePolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId, boolean shouldLock) {
Either<PolicyDefinition, ResponseFormat> result = null;
log.trace("#deletePolicy - starting to update the policy {} on the component {}. ", policyId, componentId);
Wrapper<Component> component = new Wrapper<>();
@@ -254,18 +319,14 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
} finally {
unlockComponent(shouldLock, result, component);
}
- }
+ }*/
public Either<PolicyDefinition, ResponseFormat> undeclarePolicy(ComponentTypeEnum componentType, String componentId, String policyId, String userId, boolean shouldLock) {
Either<PolicyDefinition, ResponseFormat> result = null;
log.trace("#undeclarePolicy - starting to undeclare policy {} on component {}. ", policyId, componentId);
Wrapper<Component> component = new Wrapper<>();
try {
- Either<Component, ResponseFormat> componentEither =
- validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock);
- if (componentEither.isRight()) {
- return Either.right(componentEither.right().value());
- }
+ validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock);
ComponentParametersView componentParametersView = new ComponentParametersView();
componentParametersView.disableAll();
@@ -287,117 +348,113 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
}
return result;
- } catch (Exception e) {
+ }catch (Exception e) {
log.error("#undeclarePolicy - the exception occurred upon update of a policy of type {} for component {}: ", policyId, componentId, e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, e.getMessage()));
} finally {
- unlockComponent(shouldLock, result, component);
+ if (result == null || result.isRight()){
+ unlockComponent(shouldLock, true, component);
+ } else {
+ unlockComponent(shouldLock, false, component);
+ }
}
}
-
- private Either<PolicyDefinition, ResponseFormat> undeclarePolicy(PolicyDefinition policyDefinition, Component containerComponent) {
- StorageOperationStatus undeclareStatus = propertyDeclarationOrchestrator
- .unDeclarePropertiesAsPolicies(containerComponent, policyDefinition);
- if(undeclareStatus != StorageOperationStatus.OK){
- return Either.right(componentsUtils.getResponseFormat(undeclareStatus));
- } else {
- return Either.left(policyDefinition);
+ private Either<PolicyDefinition, ResponseFormat> undeclarePolicy(PolicyDefinition policyDefinition, Component containerComponent) {
+ StorageOperationStatus undeclareStatus = propertyDeclarationOrchestrator
+ .unDeclarePropertiesAsPolicies(containerComponent, policyDefinition);
+ if(undeclareStatus != StorageOperationStatus.OK){
+ return Either.right(componentsUtils.getResponseFormat(undeclareStatus));
+ } else {
+ return Either.left(policyDefinition);
+ }
}
- }
- private Optional<PolicyDefinition> getPolicyForUndeclaration(String policyId, Component component) {
- Map<String, PolicyDefinition> policies = component.getPolicies();
- if(MapUtils.isNotEmpty(policies) && policies.containsKey(policyId)) {
- return Optional.of(policies.get(policyId));
- }
+ private Optional<PolicyDefinition> getPolicyForUndeclaration(String policyId, Component component) {
+ Map<String, PolicyDefinition> policies = component.getPolicies();
+ if(MapUtils.isNotEmpty(policies) && policies.containsKey(policyId)) {
+ return Optional.of(policies.get(policyId));
+ }
- Map<String, List<ComponentInstanceProperty>> componentInstancesProperties =
- MapUtils.isEmpty(component.getComponentInstancesProperties()) ? new HashMap<>() : component.getComponentInstancesProperties();
+ Map<String, List<ComponentInstanceProperty>> componentInstancesProperties =
+ MapUtils.isEmpty(component.getComponentInstancesProperties()) ? new HashMap<>() : component.getComponentInstancesProperties();
- for(Map.Entry<String, List<ComponentInstanceProperty>> instancePropertyEntry : componentInstancesProperties.entrySet()) {
- Optional<ComponentInstanceProperty> propertyCandidate = getPropertyForDeclaredPolicy(policyId, instancePropertyEntry.getValue());
+ for(Map.Entry<String, List<ComponentInstanceProperty>> instancePropertyEntry : componentInstancesProperties.entrySet()) {
+ Optional<ComponentInstanceProperty> propertyCandidate = getPropertyForDeclaredPolicy(policyId, instancePropertyEntry.getValue());
- if(propertyCandidate.isPresent()) {
- return Optional.of(
- PolicyUtils.getDeclaredPolicyDefinition(instancePropertyEntry.getKey(), propertyCandidate.get()));
+ if(propertyCandidate.isPresent()) {
+ return Optional.of(
+ PolicyUtils.getDeclaredPolicyDefinition(instancePropertyEntry.getKey(), propertyCandidate.get()));
+ }
}
- }
- return Optional.empty();
- }
+ return Optional.empty();
+ }
- private Optional<ComponentInstanceProperty> getPropertyForDeclaredPolicy(String policyId, List<ComponentInstanceProperty> componentInstanceProperties) {
- for(ComponentInstanceProperty property : componentInstanceProperties) {
- Optional<GetPolicyValueDataDefinition> getPolicyCandidate = property.safeGetGetPolicyValues().stream()
- .filter(getPolicyValue -> getPolicyValue.getPolicyId()
- .equals(policyId))
- .findAny();
+ private Optional<ComponentInstanceProperty> getPropertyForDeclaredPolicy(String policyId, List<ComponentInstanceProperty> componentInstanceProperties) {
+ for(ComponentInstanceProperty property : componentInstanceProperties) {
+ Optional<GetPolicyValueDataDefinition> getPolicyCandidate = property.safeGetGetPolicyValues().stream()
+ .filter(getPolicyValue -> getPolicyValue.getPolicyId()
+ .equals(policyId))
+ .findAny();
- if(getPolicyCandidate.isPresent()) {
- return Optional.of(property);
+ if(getPolicyCandidate.isPresent()) {
+ return Optional.of(property);
+ }
}
+
+ return Optional.empty();
}
- return Optional.empty();
- }
- public Either<PolicyDefinition, ResponseFormat> updatePolicyTargets(ComponentTypeEnum componentTypeEnum, String componentId, String policyId, Map<PolicyTargetType, List<String>> targets, String userId) {
+ public PolicyDefinition updatePolicyTargets(ComponentTypeEnum componentTypeEnum, String componentId, String policyId, Map<PolicyTargetType, List<String>> targets, String userId) {
Either<PolicyDefinition, ResponseFormat> result = null;
log.debug("updating the policy id {} targets with the components {}. ", policyId, componentId);
+ boolean failed = false;
try {
//not right error response
- result = validateAndLockComponentAndUserBeforeWriteOperation(componentTypeEnum, componentId, userId, true)
- .left()
- .bind(cmpt -> validateAndUpdatePolicyTargets(cmpt, policyId, targets));
-
- return result;
- } finally {
-
- unlockComponentById(result, componentId);
-
+ Component component = validateAndLockComponentAndUserBeforeWriteOperation(componentTypeEnum, componentId, userId, true);
+ return validateAndUpdatePolicyTargets(component, policyId, targets);
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ unlockComponentById(failed, componentId);
}
-
}
- private Either<PolicyDefinition, ResponseFormat> validateAndUpdatePolicyTargets(Component component, String policyId, Map<PolicyTargetType, List<String>> targets) {
- return validateTargetsExistAndTypesCorrect(component.getUniqueId(), targets)
- .left()
- .bind(cmp ->updateTargets(component.getUniqueId(), component.getPolicyById(policyId), targets, policyId));
-
+ private PolicyDefinition validateAndUpdatePolicyTargets(Component component, String policyId, Map<PolicyTargetType, List<String>> targets) {
+ validateTargetsExistAndTypesCorrect(component.getUniqueId(), targets);
+ return updateTargets(component.getUniqueId(), component.getPolicyById(policyId), targets, policyId);
}
- private Either<Component, ResponseFormat> validateTargetsExistAndTypesCorrect(String componentId, Map<PolicyTargetType, List<String>> targets) {
+ private Component validateTargetsExistAndTypesCorrect(String componentId, Map<PolicyTargetType, List<String>> targets) {
Either<Component, StorageOperationStatus> componentEither = toscaOperationFacade.getToscaFullElement(componentId);
if (componentEither.isRight()) {
- return Either.right(componentsUtils.getResponseFormat(componentEither.right().value()));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(componentEither.right().value()));
}
Component parentComponent = componentEither.left().value();
return validateTargetExists(parentComponent, targets.entrySet());
}
-
- private Either<Component, ResponseFormat> validateTargetExists(Component parentComponent, Set<Map.Entry<PolicyTargetType, List<String>>> entries) {
- for(Map.Entry<PolicyTargetType, List<String>> entry : entries){
- Either<Component, ResponseFormat> result = checkTargetNotExistOnComponentByType(parentComponent, entry);
- if(result.isRight()){
- return result;
- }
+ private Component validateTargetExists(Component parentComponent, Set<Map.Entry<PolicyTargetType, List<String>>> entries) {
+ for (Map.Entry<PolicyTargetType, List<String>> entry : entries) {
+ checkTargetNotExistOnComponentByType(parentComponent, entry);
}
- return Either.left(parentComponent);
+ return parentComponent;
}
- private Either<Component, ResponseFormat> checkTargetNotExistOnComponentByType(Component parentComponent, Map.Entry<PolicyTargetType, List<String>> targetEntry) {
+ private Component checkTargetNotExistOnComponentByType(Component parentComponent, Map.Entry<PolicyTargetType, List<String>> targetEntry) {
- for(String id : targetEntry.getValue()){
- if(checkNotPresenceInComponentByType(parentComponent, id, targetEntry.getKey().getName())){
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.POLICY_TARGET_DOES_NOT_EXIST, id));
+ for (String id : targetEntry.getValue()) {
+ if (checkNotPresenceInComponentByType(parentComponent, id, targetEntry.getKey().getName())) {
+ throw new ByActionStatusComponentException(ActionStatus.POLICY_TARGET_DOES_NOT_EXIST, id);
}
}
- return Either.left(parentComponent);
+ return parentComponent;
}
private boolean checkNotPresenceInComponentByType(Component parentComponent, String uniqueId, String type) {
@@ -422,7 +479,17 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
* @param userId the user id
* @return a list of policy properties or an error in a response format
*/
- public Either<List<PropertyDataDefinition>, ResponseFormat> getPolicyProperties(ComponentTypeEnum componentType, String componentId, String policyId, String userId) {
+ public List<PropertyDataDefinition> getPolicyProperties(ComponentTypeEnum componentType, String componentId, String policyId, String userId) {
+ log.debug("#getPolicyProperties - fetching policy properties for component {} and policy {}", componentId, policyId);
+ try {
+ Component component = validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId);
+ return getPolicyById(component, policyId).getProperties();
+ } finally {
+ janusGraphDao.commit();
+ }
+ }
+
+ /*public Either<List<PropertyDataDefinition>, ResponseFormat> getPolicyProperties(ComponentTypeEnum componentType, String componentId, String policyId, String userId) {
log.debug("#getPolicyProperties - fetching policy properties for component {} and policy {}", componentId, policyId);
try {
return validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId)
@@ -431,7 +498,7 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
} finally {
janusGraphDao.commit();
}
- }
+ }*/
/**
* Updates the policy properties of the component
@@ -444,19 +511,18 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
* @param shouldLock the flag defining if the component should be locked
* @return a list of policy properties or anerrorin a response format
*/
- public Either<List<PropertyDataDefinition>, ResponseFormat> updatePolicyProperties(ComponentTypeEnum componentType, String componentId, String policyId, PropertyDataDefinition[] properties, String userId, boolean shouldLock) {
- Either<List<PropertyDataDefinition>, ResponseFormat> result = null;
+ public List<PropertyDataDefinition> updatePolicyProperties(ComponentTypeEnum componentType, String componentId, String policyId, PropertyDataDefinition[] properties, String userId, boolean shouldLock) {
+ List<PropertyDataDefinition> result;
+ Component component = null;
log.trace("#updatePolicyProperties - starting to update properties of the policy {} on the component {}. ", policyId, componentId);
- Wrapper<Component> component = new Wrapper<>();
+ boolean failed = true;
try {
- result = validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock).left()
- .bind(c -> setComponentValidateUpdatePolicyProperties(policyId, properties, component, c));
- } catch (Exception e) {
- log.error("#updatePolicyProperties - the exception {} occurred upon update properties of the policy {} for the component {}: ", policyId, componentId, e);
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ component = validateAndLockComponentAndUserBeforeWriteOperation(componentType, componentId, userId, shouldLock);
+ failed = false;
+ result = setComponentValidateUpdatePolicyProperties(policyId, properties, component);
} finally {
- if (shouldLock && !component.isEmpty()) {
- unlockComponent(result, component.getInnerElement());
+ if (shouldLock && !failed) {
+ unlockComponent(failed, component);
}
}
return result;
@@ -476,7 +542,7 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
org.openecomp.sdc.be.model.Component component = null;
try {
- validateUserExists(userId, DECLARE_PROPERTIES_TO_POLICIES, false);
+ validateUserExists(userId);
ComponentParametersView componentParametersView = new ComponentParametersView();
componentParametersView.disableAll();
@@ -485,27 +551,13 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
componentParametersView.setIgnorePolicies(false);
componentParametersView.setIgnoreUsers(false);
- Either<? extends org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponent = validateComponentExists(componentId, componentTypeEnum, componentParametersView);
-
- if (validateComponent.isRight()) {
- result = Either.right(validateComponent.right().value());
- return result;
- }
- component = validateComponent.left().value();
+ component = validateComponentExists(componentId, componentTypeEnum, componentParametersView);
if (shouldLock) {
- Either<Boolean, ResponseFormat> lockComponent = lockComponent(component, DECLARE_PROPERTIES_TO_POLICIES);
- if (lockComponent.isRight()) {
- result = Either.right(lockComponent.right().value());
- return result;
- }
+ lockComponent(component, DECLARE_PROPERTIES_TO_POLICIES);
}
- Either<Boolean, ResponseFormat> canWork = validateCanWorkOnComponent(component, userId);
- if (canWork.isRight()) {
- result = Either.right(canWork.right().value());
- return result;
- }
+ validateCanWorkOnComponent(component, userId);
Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesEither =
propertyDeclarationOrchestrator.declarePropertiesToPolicies(component, componentInstInputsMap);
@@ -527,60 +579,96 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
}
}
- private Either<List<PropertyDataDefinition>, ResponseFormat> setComponentValidateUpdatePolicyProperties(String policyId, PropertyDataDefinition[] properties, Wrapper<Component> component, Component c) {
- component.setInnerElement(c);
+ private List<PropertyDataDefinition> setComponentValidateUpdatePolicyProperties(String policyId, PropertyDataDefinition[] properties, Component component) {
Set<String> updatedPropertyNames = Arrays.stream(properties).map(PropertyDataDefinition::getName).collect(Collectors.toSet());
- return validateAndUpdatePolicyProperties(c, policyId, properties)
- .left()
- .map(policyDefinition -> getFilteredProperties(policyDefinition.getProperties(), updatedPropertyNames));
+
+ PolicyDefinition policyDefinition = validateAndUpdatePolicyProperties(component, policyId, properties);
+ return getFilteredProperties(policyDefinition.getProperties(), updatedPropertyNames);
}
private List<PropertyDataDefinition> getFilteredProperties(List<PropertyDataDefinition> all, Set<String> filtered) {
return all.stream().filter(pd -> filtered.contains(pd.getName())).collect(Collectors.toList());
}
- private void unlockComponent(boolean shouldLock, Either<PolicyDefinition, ResponseFormat> result, Wrapper<Component> component) {
+ private void unlockComponent(boolean shouldLock, boolean result, Component component) {
+ if (shouldLock && component != null) {
+ unlockComponent(result, component);
+ }
+ }
+
+
+ private void unlockComponent(boolean shouldLock, boolean result, Wrapper<Component> component) {
if (shouldLock && !component.isEmpty()) {
unlockComponent(result, component.getInnerElement());
}
}
- private Either<PolicyDefinition, ResponseFormat> getPolicyById(Component component, String policyId) {
+ private PolicyDefinition getPolicyById(Component component, String policyId) {
PolicyDefinition policyById = component.getPolicyById(policyId);
if (policyById == null) {
String cmptId = component.getUniqueId();
log.debug("#getPolicyById - policy with id {} does not exist on component with id {}", policyId, cmptId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.POLICY_NOT_FOUND_ON_CONTAINER, policyId, cmptId));
+ throw new ByActionStatusComponentException(ActionStatus.POLICY_NOT_FOUND_ON_CONTAINER, policyId, cmptId);
}
- return Either.left(policyById);
+ return policyById;
+ }
+
+ private PolicyDefinition createPolicy(String policyTypeName, Component component) {
+ PolicyTypeDefinition policyTypeDefinition = validatePolicyTypeOnCreatePolicy(policyTypeName, component);
+ return addPolicyToComponent(policyTypeDefinition, component);
}
- private Either<PolicyDefinition, ResponseFormat> createPolicy(String policyTypeName, Component component) {
+ /*private Either<PolicyDefinition, ResponseFormat> createPolicy(String policyTypeName, Component component) {
return validatePolicyTypeOnCreatePolicy(policyTypeName, component).left().bind(type -> addPolicyToComponent(type, component));
+ }*/
+
+ private PolicyDefinition addPolicyToComponent(PolicyTypeDefinition policyType, Component component) {
+ Either<PolicyDefinition, StorageOperationStatus> associatePolicyToComponent =
+ toscaOperationFacade.associatePolicyToComponent(component.getUniqueId(), new PolicyDefinition(policyType), getNextPolicyCounter(component.getPolicies()));
+ if(associatePolicyToComponent.isRight()){
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(associatePolicyToComponent.right().value()));
+ }
+ return associatePolicyToComponent.left().value();
}
- private Either<PolicyDefinition, ResponseFormat> addPolicyToComponent(PolicyTypeDefinition policyType, Component component) {
+ /*private Either<PolicyDefinition, ResponseFormat> addPolicyToComponent(PolicyTypeDefinition policyType, Component component) {
return toscaOperationFacade.associatePolicyToComponent(component.getUniqueId(), new PolicyDefinition(policyType), getNextPolicyCounter(component.getPolicies()))
.either(Either::left, r -> Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(r))));
+ }*/
+
+ private PolicyTypeDefinition validatePolicyTypeOnCreatePolicy(String policyTypeName, Component component) {
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyTypeByType = policyTypeOperation.getLatestPolicyTypeByType(policyTypeName);
+ if(latestPolicyTypeByType.isRight()){
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(latestPolicyTypeByType.right().value()));
+ }
+ return validatePolicyTypeNotExcluded(latestPolicyTypeByType.left().value(), component);
}
- private Either<PolicyTypeDefinition, ResponseFormat> validatePolicyTypeOnCreatePolicy(String policyTypeName, Component component) {
+ /*private Either<PolicyTypeDefinition, ResponseFormat> validatePolicyTypeOnCreatePolicy(String policyTypeName, Component component) {
return policyTypeOperation.getLatestPolicyTypeByType(policyTypeName)
.either(l -> validatePolicyTypeNotExcluded(l, component), r -> Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(r))));
- }
+ }*/
- private Either<PolicyTypeDefinition, ResponseFormat> validatePolicyTypeNotExcluded(PolicyTypeDefinition policyType, Component component) {
+ private PolicyTypeDefinition validatePolicyTypeNotExcluded(PolicyTypeDefinition policyType, Component component) {
if (getExcludedPolicyTypesByComponent(component).contains(policyType.getType())) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCLUDED_POLICY_TYPE, policyType.getType(), getComponentOrResourceTypeName(component)));
+ throw new ByActionStatusComponentException(ActionStatus.EXCLUDED_POLICY_TYPE, policyType.getType(), getComponentOrResourceTypeName(component));
}
- return Either.left(policyType);
+ return policyType;
}
private String getComponentOrResourceTypeName(Component component) {
return component.getComponentType() == ComponentTypeEnum.SERVICE ? ComponentTypeEnum.SERVICE.name() : ((Resource) component).getResourceType().name();
}
- private Either<Component, ResponseFormat> validateAndLockComponentAndUserBeforeWriteOperation(ComponentTypeEnum componentType, String componentId, String userId, boolean shouldLock) {
+ private Component validateAndLockComponentAndUserBeforeWriteOperation(ComponentTypeEnum componentType, String componentId, String userId, boolean shouldLock) {
+ Component component = validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId);
+ validateComponentIsTopologyTemplate(component);
+ validateCanWorkOnComponent(component, userId);
+ lockComponent(component, shouldLock, "policyWritingOperation");
+ return component;
+ }
+
+ /*private Either<Component, ResponseFormat> validateAndLockComponentAndUserBeforeWriteOperation(ComponentTypeEnum componentType, String componentId, String userId, boolean shouldLock) {
Wrapper<Component> component = new Wrapper<>();
return validateContainerComponentAndUserBeforeReadOperation(componentType, componentId, userId)
.left()
@@ -588,7 +676,8 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
.left()
.bind(c -> {
component.setInnerElement(c);
- return validateCanWorkOnComponent(c, userId);
+ validateCanWorkOnComponent(c, userId);
+ return Either.left(component);
})
.left()
.bind(l -> lockComponent(component.getInnerElement(), shouldLock, "policyWritingOperation"))
@@ -596,28 +685,32 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
log.error(FAILED_TO_VALIDATE_COMPONENT, componentId);
return Either.right(r);
});
+ }*/
+
+ private Component validateComponentIsTopologyTemplate(Component component) {
+ if (!component.isTopologyTemplate()) {
+ log.error("#validateComponentIsTopologyTemplate - policy association to a component of Tosca type {} is not allowed. ",
+ component.getToscaType());
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_CANNOT_CONTAIN_POLICIES,
+ "#validateAndLockComponentAndUserBeforeWriteOperation", component.getUniqueId(), component.getToscaType());
+ }
+ return component;
}
- private Either<Component, ResponseFormat> validateComponentIsTopologyTemplate(Component component) {
+ /*private Either<Component, ResponseFormat> validateComponentIsTopologyTemplate(Component component) {
if (!component.isTopologyTemplate()) {
log.error("#validateComponentIsTopologyTemplate - policy association to a component of Tosca type {} is not allowed. ", component.getToscaType());
return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_CANNOT_CONTAIN_POLICIES, "#validateAndLockComponentAndUserBeforeWriteOperation", component.getUniqueId(), component.getToscaType()));
}
return Either.left(component);
- }
-
- private Either<Component, ResponseFormat> validateContainerComponentAndUserBeforeReadOperation(ComponentTypeEnum componentType, String componentId, String userId) {
- Either<Component, ResponseFormat> result;
+ }*/
+ private Component validateContainerComponentAndUserBeforeReadOperation(ComponentTypeEnum componentType, String componentId, String userId) {
log.trace("#validateContainerComponentAndUserBeforeReadOperation - starting to validate the user {} before policy processing. ", userId);
- validateUserExists(userId, "create Policy", false);
- result = validateComponentExists(componentType, componentId);
- if (result.isRight()) {
- log.error(FAILED_TO_VALIDATE_COMPONENT, "#validateContainerComponentAndUserBeforeReadOperation", componentId);
- }
- return result;
+ validateUserExists(userId);
+ return validateComponentExists(componentType, componentId);
}
- private Either<Component, ResponseFormat> validateComponentExists(ComponentTypeEnum componentType, String componentId) {
+ private Component validateComponentExists(ComponentTypeEnum componentType, String componentId) {
ComponentParametersView filter = new ComponentParametersView(true);
filter.setIgnorePolicies(false);
@@ -628,89 +721,101 @@ public class PolicyBusinessLogic extends BaseBusinessLogic {
}
- private Either<PolicyDefinition, ResponseFormat> validateAndUpdatePolicy(Component component, PolicyDefinition policy) {
+ private PolicyDefinition validateAndUpdatePolicy(Component component, PolicyDefinition policy) {
+ PolicyDefinition policyById = getPolicyById(component, policy.getUniqueId());
+ PolicyDefinition policyDefinition = validateUpdatePolicyBeforeUpdate(policy, policyById, component.getPolicies());
+ return updatePolicyOfComponent(component, policyDefinition);
+ }
+
+ /*private Either<PolicyDefinition, ResponseFormat> validateAndUpdatePolicy(Component component, PolicyDefinition policy) {
return getPolicyById(component, policy.getUniqueId())
.left()
.bind(np -> validateUpdatePolicyBeforeUpdate(policy, np, component.getPolicies()))
.left()
.bind(p -> updatePolicyOfComponent(component, p));
- }
+ }*/
- private Either<PolicyDefinition, ResponseFormat> validateAndUpdatePolicyProperties(Component component, String policyId, PropertyDataDefinition[] properties) {
- return getPolicyById(component, policyId)
- .left()
- .bind(p -> validateUpdatePolicyPropertiesBeforeUpdate(p, properties))
- .left().bind(l -> updatePolicyOfComponent(component.getUniqueId(), l));
+ private PolicyDefinition validateAndUpdatePolicyProperties(Component component, String policyId, PropertyDataDefinition[] properties) {
+
+ PolicyDefinition policyById = getPolicyById(component, policyId);
+ policyById = validateUpdatePolicyPropertiesBeforeUpdate(policyById, properties);
+ return updatePolicyOfComponent(component.getUniqueId(), policyById);
}
- private Either<PolicyDefinition, ResponseFormat> updatePolicyOfComponent(String componentId, PolicyDefinition policy) {
- return toscaOperationFacade.updatePolicyOfComponent(componentId, policy)
- .right()
- .bind(r -> Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(r))));
+ private PolicyDefinition updatePolicyOfComponent(String componentId, PolicyDefinition policy) {
+ return toscaOperationFacade.updatePolicyOfComponent(componentId, policy, PromoteVersionEnum.MINOR)
+ .left()
+ .on(ce->componentExceptionPolicyDefinition(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(ce))));
}
- private Either<PolicyDefinition, ResponseFormat> validateUpdatePolicyPropertiesBeforeUpdate(PolicyDefinition policy, PropertyDataDefinition[] newProperties) {
+ private PolicyDefinition validateUpdatePolicyPropertiesBeforeUpdate(PolicyDefinition policy, PropertyDataDefinition[] newProperties) {
if (CollectionUtils.isEmpty(policy.getProperties())) {
log.error("#validateUpdatePolicyPropertiesBeforeUpdate - failed to update properites of the policy. Properties were not found on the policy. ");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND);
}
return updatePropertyValues(policy, newProperties);
}
- private Either<PolicyDefinition, ResponseFormat> updatePropertyValues(PolicyDefinition policy, PropertyDataDefinition[] newProperties) {
+ private PolicyDefinition updatePropertyValues(PolicyDefinition policy, PropertyDataDefinition[] newProperties) {
Map<String, PropertyDataDefinition> oldProperties = policy.getProperties().stream().collect(toMap(PropertyDataDefinition::getName, Function.identity()));
for (PropertyDataDefinition newProperty : newProperties) {
if (!oldProperties.containsKey(newProperty.getName())) {
log.error("#updatePropertyValues - failed to update properites of the policy {}. Properties were not found on the policy. ", policy.getName());
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, newProperty.getName()));
- }
- Either<String, ResponseFormat> newPropertyValueEither = updateInputPropertyObjectValue(newProperty);
- if (newPropertyValueEither.isRight()) {
- return Either.right(newPropertyValueEither.right().value());
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, newProperty.getName());
}
- oldProperties.get(newProperty.getName()).setValue(newPropertyValueEither.left().value());
+ String newPropertyValueEither = updateInputPropertyObjectValue(newProperty);
+ oldProperties.get(newProperty.getName()).setValue(newPropertyValueEither);
}
- return Either.left(policy);
+ return policy;
}
- private Either<PolicyDefinition, ResponseFormat> deletePolicy(Component component, String policyId) {
- return getPolicyById(component, policyId)
- .left()
- .bind(p -> removePolicyFromComponent(component, p));
+ private PolicyDefinition deletePolicy(Component component, String policyId) {
+ PolicyDefinition policyById = getPolicyById(component, policyId);
+ return removePolicyFromComponent(component, policyById);
}
- private Either<PolicyDefinition, ResponseFormat> updatePolicyOfComponent(Component component, PolicyDefinition policy) {
- Either<PolicyDefinition, StorageOperationStatus> updatePolicyRes = toscaOperationFacade.updatePolicyOfComponent(component.getUniqueId(), policy);
+ private PolicyDefinition updatePolicyOfComponent(Component component, PolicyDefinition policy) {
+
+ Either<PolicyDefinition, StorageOperationStatus> updatePolicyRes = toscaOperationFacade.updatePolicyOfComponent(component.getUniqueId(), policy, PromoteVersionEnum.MINOR);
if (updatePolicyRes.isRight()) {
log.error("#updatePolicyOfComponent - failed to update policy {} of the component {}. The status is {}. ", policy.getUniqueId(), component.getName(), updatePolicyRes.right().value());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updatePolicyRes.right().value())));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(updatePolicyRes.right().value()));
} else {
log.trace("#updatePolicyOfComponent - the policy with the name {} was updated. ", updatePolicyRes.left().value().getName());
- return Either.left(updatePolicyRes.left().value());
+ return updatePolicyRes.left().value();
}
}
- private Either<PolicyDefinition, ResponseFormat> removePolicyFromComponent(Component component, PolicyDefinition policy) {
+ private PolicyDefinition removePolicyFromComponent(Component component, PolicyDefinition policy) {
StorageOperationStatus updatePolicyStatus = toscaOperationFacade.removePolicyFromComponent(component.getUniqueId(), policy.getUniqueId());
if (updatePolicyStatus != StorageOperationStatus.OK) {
log.error("#removePolicyFromComponent - failed to remove policy {} from the component {}. The status is {}. ", policy.getUniqueId(), component.getName(), updatePolicyStatus);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updatePolicyStatus)));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(updatePolicyStatus));
} else {
log.trace("#removePolicyFromComponent - the policy with the name {} was deleted. ", updatePolicyStatus);
- return Either.left(policy);
+ return policy;
}
}
- private Either<PolicyDefinition, ResponseFormat> validateUpdatePolicyBeforeUpdate(PolicyDefinition recievedPolicy, PolicyDefinition oldPolicy, Map<String, PolicyDefinition> policies) {
+ private PolicyDefinition validateUpdatePolicyBeforeUpdate(PolicyDefinition recievedPolicy, PolicyDefinition oldPolicy, Map<String, PolicyDefinition> policies) {
+
+ Either<PolicyDefinition, ActionStatus> policyDefinitionActionStatusEither = validatePolicyFields(recievedPolicy, new PolicyDefinition(oldPolicy), policies);
+ if(policyDefinitionActionStatusEither.isRight()){
+ throw new ByActionStatusComponentException(policyDefinitionActionStatusEither.right().value(), recievedPolicy.getName());
+ }
+ return policyDefinitionActionStatusEither.left().value();
+ }
+
+ /*private Either<PolicyDefinition, ResponseFormat> validateUpdatePolicyBeforeUpdate(PolicyDefinition recievedPolicy, PolicyDefinition oldPolicy, Map<String, PolicyDefinition> policies) {
return validatePolicyFields(recievedPolicy, new PolicyDefinition(oldPolicy), policies)
.right()
.bind(r -> Either.right(componentsUtils.getResponseFormat(r, recievedPolicy.getName())));
- }
+ }*/
- private Either<PolicyDefinition, ResponseFormat> updateTargets(String componentId, PolicyDefinition policy, Map<PolicyTargetType, List<String>> targets, String policyId) {
- if(policy == null){
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.POLICY_NOT_FOUND_ON_CONTAINER, policyId, componentId));
+ private PolicyDefinition updateTargets(String componentId, PolicyDefinition policy, Map<PolicyTargetType, List<String>> targets, String policyId) {
+ if (policy == null) {
+ throw new ByActionStatusComponentException(ActionStatus.POLICY_NOT_FOUND_ON_CONTAINER, policyId, componentId);
}
PolicyDefinition updatedPolicy = setPolicyTargets(policy, targets);
return updatePolicyOfComponent(componentId, updatedPolicy);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
index 2213719b41..6154061056 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java
@@ -59,7 +59,7 @@ public class PolicyTypeBusinessLogic {
@Transactional
public List<PolicyTypeDefinition> getAllPolicyTypes(String userId, String internalComponentType) {
Set<String> excludedPolicyTypes = getExcludedPolicyTypes(internalComponentType);
- userValidations.validateUserExists(userId, "get policy types", true);
+ userValidations.validateUserExists(userId);
return getPolicyTypes(excludedPolicyTypes);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
index 090d3b2d3c..377feb470d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java
@@ -30,10 +30,10 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
-import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.IPolicyTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
+import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;
@@ -47,14 +47,14 @@ public class PolicyTypeImportManager {
private final IPolicyTypeOperation policyTypeOperation;
private final ComponentsUtils componentsUtils;
- private final IGroupOperation groupOperation;
+ private final GroupOperation groupOperation;
private final ToscaOperationFacade toscaOperationFacade;
private final CommonImportManager commonImportManager;
- private final IGroupTypeOperation groupTypeOperation;
+ private final GroupTypeOperation groupTypeOperation;
public PolicyTypeImportManager(IPolicyTypeOperation policyTypeOperation, ComponentsUtils componentsUtils,
- IGroupOperation groupOperation, ToscaOperationFacade toscaOperationFacade,
- CommonImportManager commonImportManager, IGroupTypeOperation groupTypeOperation) {
+ GroupOperation groupOperation, ToscaOperationFacade toscaOperationFacade,
+ CommonImportManager commonImportManager, GroupTypeOperation groupTypeOperation) {
this.policyTypeOperation = policyTypeOperation;
this.componentsUtils = componentsUtils;
this.groupOperation = groupOperation;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
index 8f3d17b74d..c643d9f937 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java
@@ -24,6 +24,14 @@ package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentIconValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentNameValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentProjectCodeValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentTagsValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -53,7 +61,12 @@ import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
@org.springframework.stereotype.Component("productBusinessLogic")
@@ -80,9 +93,18 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
ArtifactsBusinessLogic artifactsBusinessLogic,
ComponentInstanceBusinessLogic componentInstanceBusinessLogic,
- ArtifactsOperations artifactToscaOperation) {
+ ArtifactsOperations artifactToscaOperation,
+ ComponentContactIdValidator componentContactIdValidator,
+ ComponentNameValidator componentNameValidator,
+ ComponentTagsValidator componentTagsValidator,
+ ComponentValidator componentValidator,
+ ComponentIconValidator componentIconValidator,
+ ComponentProjectCodeValidator componentProjectCodeValidator,
+ ComponentDescriptionValidator componentDescriptionValidator){
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation);
+ interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation,
+ componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
creationRoles = new ArrayList<>();
@@ -201,9 +223,10 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
return componentNameValidation;
}
- Either<Boolean, ResponseFormat> componentNameUniquenessValidation = validateComponentNameUnique(user, product, actionEnum);
- if (componentNameUniquenessValidation.isRight()) {
- return componentNameUniquenessValidation;
+ try {
+ componentNameValidator.validateComponentNameUnique(user, product, actionEnum);
+ } catch (ComponentException exp) {
+ return Either.right(exp.getResponseFormat());
}
// To be removed in 1607 and replaced with generic
@@ -215,11 +238,12 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
return tagsValidation;
}
- validateIcon(user, product, actionEnum);
+ componentTagsValidator.validateAndCorrectField(user, product, actionEnum);
- Either<Boolean, ResponseFormat> projectCodeValidation = validateProjectCode(user, product, actionEnum);
- if (projectCodeValidation.isRight()) {
- return projectCodeValidation;
+ try {
+ componentProjectCodeValidator.validateAndCorrectField(user, product, actionEnum);
+ } catch (ComponentException exp) {
+ return Either.right(exp.getResponseFormat());
}
Either<Boolean, ResponseFormat> categoryValidation = validateGrouping(user, product, actionEnum);
if (categoryValidation.isRight()) {
@@ -236,14 +260,14 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
return productFullNameValidation;
}
- validateDescriptionAndCleanup(user, product, actionEnum);
+ componentDescriptionValidator.validateAndCorrectField(user, product, actionEnum);
return Either.left(true);
}
public Either<Map<String, Boolean>, ResponseFormat> validateProductNameExists(String productName, String userId) {
- validateUserExists(userId, "validate Product Name Exists", false);
+ validateUserExists(userId);
Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade.validateComponentNameUniqueness(productName, null, ComponentTypeEnum.PRODUCT);
// DE242223
janusGraphDao.commit();
@@ -287,7 +311,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
User contactUser;
try{
- contactUser = validateUserExists(contact, CREATE_PRODUCT, false);
+ contactUser = validateUserExists(contact);
validateUserRole(contactUser, contactsRoles);
} catch(ByActionStatusComponentException e){
log.debug("Cannot set contact with userId {} as product contact, error: {}", contact, e.getActionStatus());
@@ -465,13 +489,13 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
public Either<Product, ResponseFormat> getProduct(String productId, User user) {
String ecompErrorContext = "Get product";
validateUserNotEmpty(user, ecompErrorContext);
- validateUserExists(user, ecompErrorContext, false);
+ validateUserExists(user);
Either<Product, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(productId);
if (storageStatus.isRight()) {
log.debug("failed to get resource by id {}", productId);
- if (storageStatus.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ if (storageStatus.right().value() == StorageOperationStatus.NOT_FOUND) {
// TODO check error
return Either.right(componentsUtils.getResponseFormat(ActionStatus.PRODUCT_NOT_FOUND, ComponentTypeEnum.PRODUCT.getValue()));
} else {
@@ -484,7 +508,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
public Either<Product, ResponseFormat> deleteProduct(String productId, User user) {
String ecompErrorContext = "Delete product";
validateUserNotEmpty(user, ecompErrorContext);
- validateUserExists(user, ecompErrorContext, false);
+ validateUserExists(user);
Either<Product, StorageOperationStatus> storageStatus = toscaOperationFacade.deleteToscaComponent(productId);
@@ -563,9 +587,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
// component name, and BE will add it by itself after all needed
// normalizations.
private Either<Boolean, ResponseFormat> validateTagsListAndRemoveDuplicates(User user, Product product, String oldProductName, AuditingActionEnum actionEnum) {
- List<String> tagsList = product.getTags();
- validateComponentTags(tagsList, oldProductName, ComponentTypeEnum.PRODUCT, user, product, actionEnum);
- ValidationUtils.removeDuplicateFromList(tagsList);
+ componentTagsValidator.validateAndCorrectField(user, product, actionEnum);
return Either.left(true);
}
@@ -587,7 +609,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
Either<Product, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(productId);
if (storageStatus.isRight()) {
- if (storageStatus.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ if (storageStatus.right().value() == StorageOperationStatus.NOT_FOUND) {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.PRODUCT_NOT_FOUND, ComponentTypeEnum.PRODUCT.name().toLowerCase()));
}
return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), typeEnum), ""));
@@ -608,10 +630,7 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
Product productToUpdate = validationRsponse.left().value();
// lock resource
- Either<Boolean, ResponseFormat> lockResult = lockComponent(currentProduct.getUniqueId(), currentProduct, "Update Product Metadata");
- if (lockResult.isRight()) {
- return Either.right(lockResult.right().value());
- }
+ lockComponent(currentProduct.getUniqueId(), currentProduct, "Update Product Metadata");
try {
Either<Product, StorageOperationStatus> updateResponse = toscaOperationFacade.updateToscaElement(productToUpdate);
if (updateResponse.isRight()) {
@@ -704,9 +723,10 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
}
updatedProductName = updatedProduct.getName();
if (!currentProductName.equals(updatedProductName)) {
- Either<Boolean, ResponseFormat> productNameUniquenessValidation = validateComponentNameUnique(user, updatedProduct, null);
- if (productNameUniquenessValidation.isRight()) {
- return productNameUniquenessValidation;
+ try {
+ componentNameValidator.validateComponentNameUnique(user, updatedProduct, null);
+ } catch (ComponentException exp) {
+ return Either.right(exp.getResponseFormat());
}
currentProduct.setName(updatedProductName);
tags = updatedProductName;
@@ -791,13 +811,8 @@ public class ProductBusinessLogic extends ComponentBusinessLogic {
return Either.left(new ArrayList<>());
}
- @Override
- protected boolean validateTagPattern(String tag) {
- return ValidationUtils.validateCategoryDisplayNameFormat(tag);
- }
-
public Either<Product, ResponseFormat> getProductByNameAndVersion(String productName, String productVersion, String userId) {
- validateUserExists(userId, "get Service By Name And Version", false);
+ validateUserExists(userId);
Either<Product, StorageOperationStatus> storageStatus = toscaOperationFacade.getComponentByNameAndVersion(ComponentTypeEnum.PRODUCT, productName, productVersion);
if (storageStatus.isRight()) {
log.debug("failed to get service by name {} and version {}", productName, productVersion);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java
index 1391e205cd..b271ea0137 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java
@@ -22,13 +22,6 @@ package org.openecomp.sdc.be.components.impl;
import com.google.gson.JsonElement;
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Supplier;
-import javax.servlet.ServletContext;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -72,6 +65,15 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
+import javax.servlet.ServletContext;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Supplier;
+
+
@org.springframework.stereotype.Component("propertyBusinessLogic")
public class PropertyBusinessLogic extends BaseBusinessLogic {
@@ -101,7 +103,7 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
return webApplicationContext.getBean(class1);
}
- public Either<Map<String, DataTypeDefinition>, ResponseFormat> getAllDataTypes() {
+ public Map<String, DataTypeDefinition> getAllDataTypes() {
return getAllDataTypes(applicationDataTypeCache);
}
@@ -121,7 +123,7 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
String userId) {
Either<EntryData<String, PropertyDefinition>, ResponseFormat> result = null;
- validateUserExists(userId, "create Property", false);
+ validateUserExists(userId);
Either<Component, StorageOperationStatus> serviceElement =
toscaOperationFacade.getToscaElement(componentId);
@@ -160,16 +162,10 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
} else {
- Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(applicationDataTypeCache);
- if (allDataTypes.isRight()) {
- result = Either.right(allDataTypes.right().value());
- return result;
- }
-
- Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
+ Map<String, DataTypeDefinition> allDataTypes = getAllDataTypes(applicationDataTypeCache);
// validate property default values
- Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newPropertyDefinition, dataTypes);
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue(newPropertyDefinition, allDataTypes);
if (defaultValuesValidation.isRight()) {
result = Either.right(defaultValuesValidation.right().value());
return result;
@@ -191,7 +187,7 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
String convertedValue = null;
if (newPropertyDefinition.getDefaultValue() != null) {
convertedValue = converter.convert(
- newPropertyDefinition.getDefaultValue(), innerType, allDataTypes.left().value());
+ newPropertyDefinition.getDefaultValue(), innerType, allDataTypes);
newPropertyDefinition.setDefaultValue(convertedValue);
}
}
@@ -208,16 +204,13 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
return result;
}
}
-
result = Either.left(new EntryData<>(propertyName, newPropertyDefinition));
return result;
-
} finally {
commitOrRollback(result);
// unlock component
graphLockOperation.unlockComponent(componentId, nodeType);
}
-
}
/**
@@ -300,7 +293,7 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
public Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> getComponentProperty(String componentId, String propertyId, String userId) {
- validateUserExists(userId, "create Component Instance", false);
+ validateUserExists(userId);
// Get the resource from DB
Either<Component, StorageOperationStatus> status =
toscaOperationFacade.getToscaElement(componentId);
@@ -324,7 +317,7 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
public Either<List<PropertyDefinition>, ResponseFormat> getPropertiesList(String componentId,
String userId) {
- validateUserExists(userId, "create Component Instance", false);
+ validateUserExists(userId);
// Get the resource from DB
ComponentParametersView filter = new ComponentParametersView(true);
@@ -354,7 +347,7 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> result = null;
- validateUserExists(userId, "delete Property", false);
+ validateUserExists(userId);
// Get the resource from DB
Either<Component, StorageOperationStatus> getComponentRes = toscaOperationFacade.getToscaElement(componentId);
@@ -605,8 +598,8 @@ public class PropertyBusinessLogic extends BaseBusinessLogic {
}
Optional<PropertyDefinition> propertyCandidate =
- properties.stream().filter(property -> property.getName().equals(propertyName))
- .findAny();
+ properties.stream().filter(property -> property.getName().equals(propertyName))
+ .findAny();
return propertyCandidate.isPresent();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java
index 5ca6255db8..e231ed7ffe 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeBusinessLogic.java
@@ -16,8 +16,6 @@
package org.openecomp.sdc.be.components.impl;
-import java.util.Map;
-
import fj.data.Either;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -29,6 +27,8 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.Map;
+
@Component("relationshipTypeBusinessLogic")
public class RelationshipTypeBusinessLogic {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
index a2da4cca2f..993d0136f6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RelationshipTypeImportManager.java
@@ -16,9 +16,6 @@
package org.openecomp.sdc.be.components.impl;
-import java.util.List;
-import java.util.Map;
-
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum;
@@ -32,6 +29,9 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Map;
+
@Component("relationshipTypeImportManager")
public class RelationshipTypeImportManager {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementBusinessLogic.java
index 067b5db97c..f3aca5696a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/RequirementBusinessLogic.java
@@ -19,6 +19,7 @@ package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.RequirementValidation;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -88,7 +89,7 @@ public class RequirementBusinessLogic extends BaseBusinessLogic {
public Either<List<RequirementDefinition>, ResponseFormat> createRequirements(
String componentId, List<RequirementDefinition> requirementDefinitions,
User user, String errorContext, boolean lock) {
- validateUserExists(user.getUserId(), errorContext, true);
+ validateUserExists(user.getUserId());
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither
= getComponentDetails(componentId);
if (componentEither.isRight()) {
@@ -160,7 +161,7 @@ public class RequirementBusinessLogic extends BaseBusinessLogic {
public Either<List<RequirementDefinition>, ResponseFormat> updateRequirements(
String componentId, List<RequirementDefinition> requirementDefinitions,
User user, String errorContext, boolean lock) {
- validateUserExists(user.getUserId(), errorContext, true);
+ validateUserExists(user.getUserId());
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither
= getComponentDetails(componentId);
if (componentEither.isRight()) {
@@ -327,7 +328,7 @@ public class RequirementBusinessLogic extends BaseBusinessLogic {
public Either<RequirementDefinition, ResponseFormat> getRequirement(String componentId,
String requirementIdToGet, User user, boolean lock) {
- validateUserExists(user.getUserId(), GET_REQUIREMENTS, true);
+ validateUserExists(user.getUserId());
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither = getComponentDetails(componentId);
if (componentEither.isRight()) {
return Either.right(componentEither.right().value());
@@ -369,7 +370,7 @@ public class RequirementBusinessLogic extends BaseBusinessLogic {
public Either<RequirementDefinition, ResponseFormat> deleteRequirement(String componentId,
String requirementIdToDelete,
User user, boolean lock) {
- validateUserExists(user.getUserId(), DELETE_REQUIREMENTS, true);
+ validateUserExists(user.getUserId());
Either<org.openecomp.sdc.be.model.Component, ResponseFormat> componentEither
= getComponentDetails(componentId);
if (componentEither.isRight()) {
@@ -476,12 +477,13 @@ public class RequirementBusinessLogic extends BaseBusinessLogic {
org.openecomp.sdc.be.model.Component component,
String action) {
if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action);
- if (lockResult.isRight()) {
+ try{
+ lockComponent(component.getUniqueId(), component, action);
+ } catch (ComponentException e){
LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, component.getName(),
- lockResult.right().value().getFormattedMessage());
+ e.getMessage());
janusGraphDao.rollback();
- return Either.right(lockResult.right().value());
+ throw e;
}
}
return Either.left(true);
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 bf848bf8f3..99f4dc6ddd 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
@@ -16,46 +16,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- * Modifications copyright (c) 2019 Nokia
- * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
-import static java.util.stream.Collectors.joining;
-import static java.util.stream.Collectors.toList;
-import static java.util.stream.Collectors.toMap;
-import static java.util.stream.Collectors.toSet;
-import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
-import static org.apache.commons.collections.MapUtils.isEmpty;
-import static org.apache.commons.collections.MapUtils.isNotEmpty;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
-import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
-
+import com.google.common.annotations.VisibleForTesting;
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.regex.Pattern;
-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.collections4.ListUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
@@ -70,8 +43,18 @@ import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
+import org.openecomp.sdc.be.components.merge.TopologyComparator;
+import org.openecomp.sdc.be.components.merge.property.PropertyDataValueMergeBusinessLogic;
import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
+import org.openecomp.sdc.be.components.property.PropertyConstraintsUtils;
+import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentIconValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentNameValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentProjectCodeValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentTagsValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -83,6 +66,7 @@ import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
@@ -152,7 +136,6 @@ import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.be.tosca.CsarUtils.NonMetaArtifactInfo;
import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
-import org.openecomp.sdc.be.user.IUserBusinessLogic;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.be.utils.CommonBeUtils;
import org.openecomp.sdc.be.utils.TypeUtils;
@@ -161,37 +144,67 @@ import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.context.WebApplicationContext;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
+import javax.servlet.ServletContext;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+import static org.apache.commons.collections.MapUtils.isEmpty;
+import static org.apache.commons.collections.MapUtils.isNotEmpty;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
+import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
+import static org.openecomp.sdc.common.api.Constants.DEFAULT_GROUP_VF_MODULE;
+
@org.springframework.stereotype.Component("resourceBusinessLogic")
public class ResourceBusinessLogic extends ComponentBusinessLogic {
- private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ResourceBusinessLogic.class);
-
- private static final String DELETE_RESOURCE = "Delete Resource";
- private static final String IN_RESOURCE = " in resource {} ";
- private static final String PLACE_HOLDER_RESOURCE_TYPES = "validForResourceTypes";
- public static final String INITIAL_VERSION = "0.1";
- private static final Logger log = Logger.getLogger(ResourceBusinessLogic.class);
- private static final String CERTIFICATION_ON_IMPORT = "certification on import";
- private static final String CREATE_RESOURCE = "Create Resource";
- private static final String VALIDATE_DERIVED_BEFORE_UPDATE = "validate derived before update";
- private static final String CATEGORY_IS_EMPTY = "Resource category is empty";
- private static final String CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES = "Create Resource - validateCapabilityTypesCreate";
- private static final String COMPONENT_INSTANCE_WITH_NAME = "component instance with name ";
- private static final String COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE = "component instance with name {} in resource {} ";
-
- private ICapabilityTypeOperation capabilityTypeOperation;
+ private static final String DELETE_RESOURCE = "Delete Resource";
+ private static final String IN_RESOURCE = " in resource {} ";
+ private static final String PLACE_HOLDER_RESOURCE_TYPES = "validForResourceTypes";
+ public static final String INITIAL_VERSION = "0.1";
+ private static final Logger log = Logger.getLogger(ResourceBusinessLogic.class);
+ private static final String CERTIFICATION_ON_IMPORT = "certification on import";
+ private static final String CREATE_RESOURCE = "Create Resource";
+ private static final String VALIDATE_DERIVED_BEFORE_UPDATE = "validate derived before update";
+ private static final String CATEGORY_IS_EMPTY = "Resource category is empty";
+ private static final String CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES = "Create Resource - validateCapabilityTypesCreate";
+ private static final String COMPONENT_INSTANCE_WITH_NAME = "component instance with name ";
+ private static final String COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE = "component instance with name {} in resource {} ";
+ public LoggerSupportability loggerSupportability=LoggerSupportability.getLogger(ResourceBusinessLogic.class.getName());
+
+
private IInterfaceLifecycleOperation interfaceTypeOperation;
private LifecycleBusinessLogic lifecycleBusinessLogic;
@@ -205,7 +218,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
private final UiComponentDataConverter uiComponentDataConverter;
private final CsarBusinessLogic csarBusinessLogic;
private final PropertyBusinessLogic propertyBusinessLogic;
- private final SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
@Autowired
public ResourceBusinessLogic(IElementOperation elementDao,
@@ -222,9 +234,16 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic, MergeInstanceUtils mergeInstanceUtils,
UiComponentDataConverter uiComponentDataConverter, CsarBusinessLogic csarBusinessLogic,
ArtifactsOperations artifactToscaOperation, PropertyBusinessLogic propertyBusinessLogic,
- SoftwareInformationBusinessLogic softwareInformationBusinessLogic) {
+ ComponentContactIdValidator componentContactIdValidator,
+ ComponentNameValidator componentNameValidator, ComponentTagsValidator componentTagsValidator,
+ ComponentValidator componentValidator,
+ ComponentIconValidator componentIconValidator,
+ ComponentProjectCodeValidator componentProjectCodeValidator,
+ ComponentDescriptionValidator componentDescriptionValidator) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation);
+ interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation,
+ componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
this.resourceImportManager = resourceImportManager;
this.inputsBusinessLogic = inputsBusinessLogic;
@@ -235,43 +254,75 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
this.uiComponentDataConverter = uiComponentDataConverter;
this.csarBusinessLogic = csarBusinessLogic;
this.propertyBusinessLogic = propertyBusinessLogic;
- this.softwareInformationBusinessLogic = softwareInformationBusinessLogic;
}
- public LifecycleBusinessLogic getLifecycleBusinessLogic() {
- return lifecycleBusinessLogic;
- }
+ @Autowired
+ private ICapabilityTypeOperation capabilityTypeOperation;
+
+ @Autowired
+ private TopologyComparator topologyComparator;
+
+ @Autowired
+ private ComponentValidator componentValidator;
+
+ @Autowired
+ private PropertyDataValueMergeBusinessLogic propertyDataValueMergeBusinessLogic;
+
+ @Autowired
+ private SoftwareInformationBusinessLogic softwareInformationBusinessLogic;
+
+
+ public LifecycleBusinessLogic getLifecycleBusinessLogic() {
+ return lifecycleBusinessLogic;
+ }
@Autowired
public void setLifecycleManager(LifecycleBusinessLogic lifecycleBusinessLogic) {
this.lifecycleBusinessLogic = lifecycleBusinessLogic;
}
- public IElementOperation getElementDao() {
- return elementDao;
- }
+ @VisibleForTesting
+ protected void setComponentValidator(ComponentValidator componentValidator) {
+ this.componentValidator = componentValidator;
+ }
- public IUserBusinessLogic getUserAdmin() {
- return this.userAdmin;
- }
+ public IElementOperation getElementDao() {
+ return elementDao;
+ }
- @Autowired
- public void setUserAdmin(UserBusinessLogic userAdmin) {
- this.userAdmin = userAdmin;
- }
+ public void setElementDao(IElementOperation elementDao) {
+ this.elementDao = elementDao;
+ }
- public ComponentsUtils getComponentsUtils() {
- return this.componentsUtils;
- }
+ public UserBusinessLogic getUserAdmin() {
+ return this.userAdmin;
+ }
- @Autowired
- public void setComponentsUtils(ComponentsUtils componentsUtils) {
- this.componentsUtils = componentsUtils;
- }
+ @Autowired
+ public void setUserAdmin(UserBusinessLogic userAdmin) {
+ this.userAdmin = userAdmin;
+ }
- public ApplicationDataTypeCache getApplicationDataTypeCache() {
- return applicationDataTypeCache;
- }
+ public ComponentsUtils getComponentsUtils() {
+ return this.componentsUtils;
+ }
+
+ @Autowired
+ public void setComponentsUtils(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ public ArtifactsBusinessLogic getArtifactsManager() {
+ return artifactsBusinessLogic;
+ }
+
+ public void setArtifactsManager(ArtifactsBusinessLogic artifactsManager) {
+ this.artifactsBusinessLogic = artifactsManager;
+ }
+
+ public ApplicationDataTypeCache getApplicationDataTypeCache() {
+ return applicationDataTypeCache;
+ }
@Autowired
public void setApplicationDataTypeCache(ApplicationDataTypeCache applicationDataTypeCache) {
@@ -283,1066 +334,1241 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
this.interfaceTypeOperation = interfaceTypeOperation;
}
- /**
- * the method returns a list of all the resources that are certified, the
- * returned resources are only abstract or only none abstract according to
- * the given param
- *
- * @param getAbstract
- * @param userId TODO
- * @return
- */
- public List<Resource> getAllCertifiedResources(boolean getAbstract,
- HighestFilterEnum highestFilter, String userId) {
- User user = validateUserExists(userId, "get All Certified Resources", false);
- Boolean isHighest = null;
- switch (highestFilter) {
- case ALL:
- break;
- case HIGHEST_ONLY:
- isHighest = true;
- break;
- case NON_HIGHEST_ONLY:
- isHighest = false;
- break;
- default:
- break;
- }
- Either<List<Resource>, StorageOperationStatus> getResponse = toscaOperationFacade
- .getAllCertifiedResources(getAbstract, isHighest);
+ /**
+ * the method returns a list of all the resources that are certified, the
+ * returned resources are only abstract or only none abstract according to
+ * the given param
+ *
+ * @param getAbstract
+ * @param userId
+ * TODO
+ * @return
+ */
+ public List<Resource> getAllCertifiedResources(boolean getAbstract, HighestFilterEnum highestFilter,
+ String userId) {
+ User user = validateUserExists(userId);
+ Boolean isHighest = null;
+ switch (highestFilter) {
+ case ALL:
+ break;
+ case HIGHEST_ONLY:
+ isHighest = true;
+ break;
+ case NON_HIGHEST_ONLY:
+ isHighest = false;
+ break;
+ default:
+ break;
+ }
+ Either<List<Resource>, StorageOperationStatus> getResponse = toscaOperationFacade
+ .getAllCertifiedResources(getAbstract, isHighest);
- if (getResponse.isRight()) {
- throw new StorageException(getResponse.right().value());
- }
+ if (getResponse.isRight()) {
+ throw new StorageException(getResponse.right()
+ .value());
+ }
- return getResponse.left().value();
- }
+ return getResponse.left()
+ .value();
+ }
- public Either<Map<String, Boolean>, ResponseFormat> validateResourceNameExists(String resourceName,
- ResourceTypeEnum resourceTypeEnum, String userId) {
+ public Either<Map<String, Boolean>, ResponseFormat> validateResourceNameExists(String resourceName,
+ ResourceTypeEnum resourceTypeEnum, String userId) {
- validateUserExists(userId, "validate Resource Name Exists", false);
+ validateUserExists(userId);
- Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
- .validateComponentNameUniqueness(resourceName, resourceTypeEnum, ComponentTypeEnum.RESOURCE);
- // DE242223
+ Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
+ .validateComponentNameUniqueness(resourceName, resourceTypeEnum, ComponentTypeEnum.RESOURCE);
+ // DE242223
janusGraphDao.commit();
- if (dataModelResponse.isLeft()) {
- Map<String, Boolean> result = new HashMap<>();
- result.put("isValid", dataModelResponse.left().value());
- log.debug("validation was successfully performed.");
- return Either.left(result);
- }
-
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()));
-
- return Either.right(responseFormat);
- }
-
- public Resource createResource(Resource resource, AuditingActionEnum auditingAction,
- User user, Map<String, byte[]> csarUIPayload, String payloadName) {
- validateResourceBeforeCreate(resource, user, false);
- String csarUUID = payloadName == null ? resource.getCsarUUID() : payloadName;
- if (StringUtils.isNotEmpty(csarUUID)) {
- csarBusinessLogic.validateCsarBeforeCreate(resource, auditingAction, user, csarUUID);
- log.debug("CsarUUID is {} - going to create resource from CSAR", csarUUID);
- return createResourceFromCsar(resource, user, csarUIPayload, csarUUID);
- }
-
- return createResourceByDao(resource, user, auditingAction, false, false);
- }
+ if (dataModelResponse.isLeft()) {
+ Map<String, Boolean> result = new HashMap<>();
+ result.put("isValid", dataModelResponse.left()
+ .value());
+ log.debug("validation was successfully performed.");
+ return Either.left(result);
+ }
- public Resource validateAndUpdateResourceFromCsar(Resource resource, User user,
- Map<String, byte[]> csarUIPayload, String payloadName, String resourceUniqueId) {
- String csarUUID = payloadName;
- String csarVersion = null;
- Resource updatedResource = null;
- if (payloadName == null) {
- csarUUID = resource.getCsarUUID();
- csarVersion = resource.getCsarVersion();
- }
- if (csarUUID != null && !csarUUID.isEmpty()) {
- Resource oldResource = getResourceByUniqueId(resourceUniqueId);
- validateCsarUuidMatching(oldResource, resource, csarUUID, resourceUniqueId, user);
- validateCsarIsNotAlreadyUsed(oldResource, resource, csarUUID, user);
- if (oldResource != null && ValidationUtils.hasBeenCertified(oldResource.getVersion())) {
- overrideImmutableMetadata(oldResource, resource);
- }
- validateResourceBeforeCreate(resource, user, false);
- String oldCsarVersion = oldResource.getCsarVersion();
- log.debug("CsarUUID is {} - going to update resource with UniqueId {} from CSAR", csarUUID,
- resourceUniqueId);
- // (on boarding flow): If the update includes same csarUUID and
- // same csarVersion as already in the VF - no need to import the
- // csar (do only metadata changes if there are).
- if (csarVersion != null && oldCsarVersion != null && oldCsarVersion.equals(csarVersion)) {
- updatedResource = updateResourceMetadata(resourceUniqueId, resource, oldResource, user,
- false);
- } else {
- updatedResource = updateResourceFromCsar(oldResource, resource, user,
- AuditingActionEnum.UPDATE_RESOURCE_METADATA, false, csarUIPayload, csarUUID);
- }
- } else {
- log.debug("Failed to update resource {}, csarUUID or payload name is missing", resource.getSystemName());
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CSAR_UUID,
- resource.getName());
- componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.CREATE_RESOURCE);
- throw new ByActionStatusComponentException(ActionStatus.MISSING_CSAR_UUID, resource.getName());
- }
- return updatedResource;
- }
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(dataModelResponse.right()
+ .value()));
- private void validateCsarIsNotAlreadyUsed(Resource oldResource,
- Resource resource, String csarUUID, User user) {
- // (on boarding flow): If the update includes a csarUUID: verify this
- // csarUUID is not in use by another VF, If it is - use same error as
- // above:
- // "Error: The VSP with UUID %1 was already imported for VF %2. Please
- // select another or update the existing VF." %1 - csarUUID, %2 - VF
- // name
- Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = toscaOperationFacade
- .getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, csarUUID, resource.getSystemName());
- if (resourceLinkedToCsarRes.isRight()) {
- if (!StorageOperationStatus.NOT_FOUND.equals(resourceLinkedToCsarRes.right().value())) {
- log.debug("Failed to find previous resource by CSAR {} and system name {}", csarUUID,
- resource.getSystemName());
- throw new StorageException(resourceLinkedToCsarRes.right().value());
- }
- } else if (!resourceLinkedToCsarRes.left().value().getUniqueId().equals(oldResource.getUniqueId())
- && !resourceLinkedToCsarRes.left().value().getName().equals(oldResource.getName())) {
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VSP_ALREADY_EXISTS, csarUUID,
- resourceLinkedToCsarRes.left().value().getName());
- componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA);
- throw new ByActionStatusComponentException(ActionStatus.VSP_ALREADY_EXISTS, csarUUID,
- resourceLinkedToCsarRes.left().value().getName());
- }
- }
+ return Either.right(responseFormat);
+ }
- private void validateCsarUuidMatching(Resource resource,
- Resource oldResource, String csarUUID, String resourceUniqueId, User user) {
- // (on boarding flow): If the update includes csarUUID which is
- // different from the csarUUID of the VF - fail with
- // error: "Error: Resource %1 cannot be updated using since it is linked
- // to a different VSP" %1 - VF name
- String oldCsarUUID = oldResource.getCsarUUID();
- if (oldCsarUUID != null && !oldCsarUUID.isEmpty() && !csarUUID.equals(oldCsarUUID)) {
- log.debug(
- "Failed to update resource with UniqueId {} using Csar {}, since the resource is linked to a different VSP {}",
- resourceUniqueId, csarUUID, oldCsarUUID);
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(
- ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID);
- componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA);
- throw new ByActionStatusComponentException(ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID);
- }
- }
+ public Resource createResource(Resource resource, AuditingActionEnum auditingAction, User user,
+ Map<String, byte[]> csarUIPayload, String payloadName) {
+ validateResourceBeforeCreate(resource, user, false);
+ String csarUUID = payloadName == null ? resource.getCsarUUID() : payloadName;
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE,resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,"Starting to create resource from CSAR by user {} ", user.getUserId());
+ if (StringUtils.isNotEmpty(csarUUID)) {
+ csarBusinessLogic.validateCsarBeforeCreate(resource, auditingAction, user, csarUUID);
+ log.debug("CsarUUID is {} - going to create resource from CSAR", csarUUID);
+
+ Resource createResourceFromCsar = createResourceFromCsar(resource, user, csarUIPayload, csarUUID);
+ return updateCatalog(createResourceFromCsar, ChangeTypeEnum.LIFECYCLE).left()
+ .map(r -> (Resource) r)
+ .left()
+ .value();
+ }
- private Resource getResourceByUniqueId(String resourceUniqueId) {
- Either<Resource, StorageOperationStatus> oldResourceRes = toscaOperationFacade.getToscaFullElement(resourceUniqueId);
- if (oldResourceRes.isRight()) {
- log.debug("Failed to find previous resource by UniqueId {}, status: {}", resourceUniqueId,
- oldResourceRes.right().value());
- throw new StorageException(oldResourceRes.right().value());
- }
- return oldResourceRes.left().value();
- }
+ final Resource createResourceByDao = createResourceByDao(resource, user, auditingAction, false, false);
+ return updateCatalog(createResourceByDao, ChangeTypeEnum.LIFECYCLE).left()
+ .map(r -> (Resource) r)
+ .left()
+ .value();
+ }
- private void overrideImmutableMetadata(Resource oldRresource, Resource resource) {
- resource.setName(oldRresource.getName());
- resource.setIcon(oldRresource.getIcon());
- resource.setTags(oldRresource.getTags());
- resource.setCategories(oldRresource.getCategories());
- resource.setDerivedFrom(oldRresource.getDerivedFrom());
- }
+ public Resource validateAndUpdateResourceFromCsar(Resource resource, User user, Map<String, byte[]> csarUIPayload,
+ String payloadName, String resourceUniqueId) {
+ String csarUUID = payloadName;
+ String csarVersion = null;
+ Resource updatedResource = null;
+ if (payloadName == null) {
+ csarUUID = resource.getCsarUUID();
+ csarVersion = resource.getCsarVersion();
+ }
+ if (csarUUID != null && !csarUUID.isEmpty()) {
+ Resource oldResource = getResourceByUniqueId(resourceUniqueId);
+ validateCsarUuidMatching(oldResource, resource, csarUUID, resourceUniqueId, user);
+ validateCsarIsNotAlreadyUsed(oldResource, resource, csarUUID, user);
+ if (oldResource != null && ValidationUtils.hasBeenCertified(oldResource.getVersion())) {
+ overrideImmutableMetadata(oldResource, resource);
+ }
+ validateResourceBeforeCreate(resource, user, false);
+ String oldCsarVersion = oldResource.getCsarVersion();
+ log.debug("CsarUUID is {} - going to update resource with UniqueId {} from CSAR", csarUUID,
+ resourceUniqueId);
+ // (on boarding flow): If the update includes same csarUUID and
+ // same csarVersion as already in the VF - no need to import the
+ // csar (do only metadata changes if there are).
+ if (csarVersion != null && oldCsarVersion != null && oldCsarVersion.equals(csarVersion)) {
+ updatedResource = updateResourceMetadata(resourceUniqueId, resource, oldResource, user, false);
+ } else {
+ updatedResource = updateResourceFromCsar(oldResource, resource, user,
+ AuditingActionEnum.UPDATE_RESOURCE_METADATA, false, csarUIPayload, csarUUID);
+ }
+ } else {
+ log.debug("Failed to update resource {}, csarUUID or payload name is missing", resource.getSystemName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CSAR_UUID,
+ resource.getName());
+ componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.CREATE_RESOURCE);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_CSAR_UUID, resource.getName());
+ }
+ return updatedResource;
+ }
- private Resource updateResourceFromCsar(Resource oldResource, Resource newResource,
- User user, AuditingActionEnum updateResource, boolean inTransaction,
- Map<String, byte[]> csarUIPayload, String csarUUID) {
- Resource updatedResource = null;
- validateLifecycleState(oldResource, user);
- String lockedResourceId = oldResource.getUniqueId();
- List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(newResource, oldResource, user, csarUIPayload, csarUUID);
- Either<Boolean, ResponseFormat> lockResult = lockComponent(lockedResourceId, oldResource,
- "update Resource From Csar");
- if (lockResult.isRight()) {
- throw new ByResponseFormatComponentException(lockResult.right().value());
- }
+ private void validateCsarIsNotAlreadyUsed(Resource oldResource, Resource resource, String csarUUID, User user) {
+ // (on boarding flow): If the update includes a csarUUID: verify this
+ // csarUUID is not in use by another VF, If it is - use same error as
+ // above:
+ // "Error: The VSP with UUID %1 was already imported for VF %2. Please
+ // select another or update the existing VF." %1 - csarUUID, %2 - VF
+ // name
+ Either<Resource, StorageOperationStatus> resourceLinkedToCsarRes = toscaOperationFacade
+ .getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, csarUUID, resource.getSystemName());
+ if (resourceLinkedToCsarRes.isRight()) {
+ if (StorageOperationStatus.NOT_FOUND != resourceLinkedToCsarRes.right().value()) {
+ log.debug("Failed to find previous resource by CSAR {} and system name {}", csarUUID,
+ resource.getSystemName());
+ throw new StorageException(resourceLinkedToCsarRes.right()
+ .value());
+ }
+ } else if (!resourceLinkedToCsarRes.left()
+ .value()
+ .getUniqueId()
+ .equals(oldResource.getUniqueId())
+ && !resourceLinkedToCsarRes.left()
+ .value()
+ .getName()
+ .equals(oldResource.getName())) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VSP_ALREADY_EXISTS, csarUUID,
+ resourceLinkedToCsarRes.left()
+ .value()
+ .getName());
+ componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA);
+ throw new ByActionStatusComponentException(ActionStatus.VSP_ALREADY_EXISTS, csarUUID, resourceLinkedToCsarRes.left()
+ .value()
+ .getName());
+ }
+ }
- Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo();
+ private void validateCsarUuidMatching(Resource resource, Resource oldResource, String csarUUID,
+ String resourceUniqueId, User user) {
+ // (on boarding flow): If the update includes csarUUID which is
+ // different from the csarUUID of the VF - fail with
+ // error: "Error: Resource %1 cannot be updated using since it is linked
+ // to a different VSP" %1 - VF name
+ String oldCsarUUID = oldResource.getCsarUUID();
+ if (oldCsarUUID != null && !oldCsarUUID.isEmpty() && !csarUUID.equals(oldCsarUUID)) {
+ log.debug(
+ "Failed to update resource with UniqueId {} using Csar {}, since the resource is linked to a different VSP {}",
+ resourceUniqueId, csarUUID, oldCsarUUID);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(
+ ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID);
+ componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID,
+ oldCsarUUID);
+ }
+ }
- Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(
- nodeTypesInfo, csarInfo, oldResource);
- if (findNodeTypesArtifactsToHandleRes.isRight()) {
- log.debug("failed to find node types for update with artifacts during import csar {}. ",
- csarInfo.getCsarUUID());
- throw new ByResponseFormatComponentException(findNodeTypesArtifactsToHandleRes.right().value());
- }
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = findNodeTypesArtifactsToHandleRes
- .left().value();
- try {
- updatedResource = updateResourceFromYaml(oldResource, newResource, updateResource, createdArtifacts, csarInfo.getMainTemplateName(),
- csarInfo.getMainTemplateContent(), csarInfo, nodeTypesInfo, nodeTypesArtifactsToHandle, null, false);
+ private Resource getResourceByUniqueId(String resourceUniqueId) {
+ Either<Resource, StorageOperationStatus> oldResourceRes = toscaOperationFacade
+ .getToscaFullElement(resourceUniqueId);
+ if (oldResourceRes.isRight()) {
+ log.debug("Failed to find previous resource by UniqueId {}, status: {}", resourceUniqueId,
+ oldResourceRes.right()
+ .value());
+ throw new StorageException(oldResourceRes.right()
+ .value());
+ }
+ return oldResourceRes.left()
+ .value();
+ }
- connectUiRelations(oldResource, updatedResource);
+ private void overrideImmutableMetadata(Resource oldResource, Resource resource) {
+ resource.setName(oldResource.getName());
+ resource.setIcon(oldResource.getIcon());
+ resource.setTags(oldResource.getTags());
+ resource.setCategories(oldResource.getCategories());
+ resource.setDerivedFrom(oldResource.getDerivedFrom());
+ }
- } catch (ComponentException|StorageException e){
- rollback(inTransaction, newResource, createdArtifacts, null);
- throw e;
+ private Resource updateResourceFromCsar(Resource oldResource, Resource newResource, User user,
+ AuditingActionEnum updateResource, boolean inTransaction, Map<String, byte[]> csarUIPayload,
+ String csarUUID) {
+ Resource updatedResource = null;
+ validateLifecycleState(oldResource, user);
+ String lockedResourceId = oldResource.getUniqueId();
+ List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
+ CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(newResource, oldResource, user, csarUIPayload, csarUUID);
+ lockComponent(lockedResourceId, oldResource, "update Resource From Csar");
+
+ Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo();
+
+ Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(
+ nodeTypesInfo, csarInfo, oldResource);
+ if (findNodeTypesArtifactsToHandleRes.isRight()) {
+ log.debug("failed to find node types for update with artifacts during import csar {}. ",
+ csarInfo.getCsarUUID());
+ throw new ByResponseFormatComponentException(findNodeTypesArtifactsToHandleRes.right()
+ .value());
+ }
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = findNodeTypesArtifactsToHandleRes
+ .left()
+ .value();
+ try {
+ updatedResource = updateResourceFromYaml(oldResource, newResource, updateResource, createdArtifacts,
+ csarInfo.getMainTemplateName(), csarInfo.getMainTemplateContent(), csarInfo, nodeTypesInfo,
+ nodeTypesArtifactsToHandle, null, false);
+
+ } catch (ComponentException | StorageException e) {
+ rollback(inTransaction, newResource, createdArtifacts, null);
+ throw e;
}
finally {
janusGraphDao.commit();
- log.debug("unlock resource {}", lockedResourceId);
- graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
- }
- return updatedResource;
-
- }
-
- private void validateLifecycleState(Resource oldResource, User user) {
- if (LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.equals(oldResource.getLifecycleState()) &&
- !oldResource.getLastUpdaterUserId().equals(user.getUserId())) {
- log.debug("#validateLifecycleState - Current user is not last updater, last updater userId: {}, current user userId: {}",
- oldResource.getLastUpdaterUserId(), user.getUserId());
- throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
- }
- }
-
- private Either<Resource, ResponseFormat> connectUiRelations(Resource oldResource, Resource newResource) {
- Either<Resource, ResponseFormat> result;
-
- List<RequirementCapabilityRelDef> updatedUiRelations = mergeInstanceUtils.updateUiRelationsInResource(oldResource, newResource);
+ log.debug("unlock resource {}", lockedResourceId);
+ graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
+ }
+ return updatedResource;
- StorageOperationStatus status = toscaOperationFacade.associateResourceInstances(newResource.getUniqueId(), updatedUiRelations);
- if (status == StorageOperationStatus.OK) {
- newResource.getComponentInstancesRelations().addAll(updatedUiRelations);
- result = Either.left(newResource);
- } else {
- result = Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(status), newResource));
- }
+ }
- return result;
- }
+ private void validateLifecycleState(Resource oldResource, User user) {
+ if (LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == oldResource.getLifecycleState()
+ && !oldResource.getLastUpdaterUserId()
+ .equals(user.getUserId())) {
+ log.debug(
+ "#validateLifecycleState - Current user is not last updater, last updater userId: {}, current user userId: {}",
+ oldResource.getLastUpdaterUserId(), user.getUserId());
+ throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
+ }
+ }
- private Resource updateResourceFromYaml(Resource oldRresource, Resource newRresource,
- AuditingActionEnum actionEnum, List<ArtifactDefinition> createdArtifacts,
- String yamlFileName, String yamlFileContent, CsarInfo csarInfo, Map<String, NodeTypeInfo> nodeTypesInfo,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
- String nodeName, boolean isNested) {
- boolean inTransaction = true;
- boolean shouldLock = false;
- Resource preparedResource = null;
- ParsedToscaYamlInfo uploadComponentInstanceInfoMap = null;
- try {
- uploadComponentInstanceInfoMap = csarBusinessLogic.getParsedToscaYamlInfo(yamlFileContent, yamlFileName, nodeTypesInfo, csarInfo, nodeName);
- Map<String, UploadComponentInstanceInfo> instances = uploadComponentInstanceInfoMap.getInstances();
- if (MapUtils.isEmpty(instances) && newRresource.getResourceType() != ResourceTypeEnum.PNF) {
+ private Resource updateResourceFromYaml(Resource oldResource, Resource newResource, AuditingActionEnum actionEnum,
+ List<ArtifactDefinition> createdArtifacts, String yamlFileName, String yamlFileContent, CsarInfo csarInfo,
+ Map<String, NodeTypeInfo> nodeTypesInfo,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
+ String nodeName, boolean isNested) {
+ boolean inTransaction = true;
+ boolean shouldLock = false;
+ Resource preparedResource = null;
+ ParsedToscaYamlInfo uploadComponentInstanceInfoMap;
+ try {
+ uploadComponentInstanceInfoMap = csarBusinessLogic.getParsedToscaYamlInfo(yamlFileContent, yamlFileName,
+ nodeTypesInfo, csarInfo, nodeName);
+ Map<String, UploadComponentInstanceInfo> instances = uploadComponentInstanceInfoMap.getInstances();
+ if (MapUtils.isEmpty(instances) && newResource.getResourceType() != ResourceTypeEnum.PNF) {
throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlFileName);
}
- preparedResource = updateExistingResourceByImport(newRresource, oldRresource, csarInfo.getModifier(),
- inTransaction, shouldLock, isNested).left;
- log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContent);
- handleResourceGenericType(preparedResource);
- handleNodeTypes(yamlFileName, preparedResource, yamlFileContent,
- shouldLock, nodeTypesArtifactsToHandle, createdArtifacts, nodeTypesInfo, csarInfo, nodeName);
- preparedResource = createInputsOnResource(preparedResource, uploadComponentInstanceInfoMap.getInputs());
- preparedResource = createResourceInstances(yamlFileName, preparedResource, instances, csarInfo.getCreatedNodes());
- preparedResource = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, instances);
- } catch (ByResponseFormatComponentException e) {
- ResponseFormat responseFormat = e.getResponseFormat();
- log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat);
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum);
- throw e;
- } catch (ByActionStatusComponentException e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat);
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum);
- throw e;
- } catch (StorageException e){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
- log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat);
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum);
- throw e;
- }
- Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic
- .validateUpdateVfGroupNames(uploadComponentInstanceInfoMap.getGroups(),
- preparedResource.getSystemName());
- if (validateUpdateVfGroupNamesRes.isRight()) {
+ preparedResource = updateExistingResourceByImport(newResource, oldResource, csarInfo.getModifier(),
+ inTransaction, shouldLock, isNested).left;
+ log.trace("YAML topology file found in CSAR, file name: {}, contents: {}", yamlFileName, yamlFileContent);
+ handleResourceGenericType(preparedResource);
+ handleNodeTypes(yamlFileName, preparedResource, yamlFileContent, shouldLock, nodeTypesArtifactsToHandle,
+ createdArtifacts, nodeTypesInfo, csarInfo, nodeName);
+ preparedResource = createInputsOnResource(preparedResource, uploadComponentInstanceInfoMap.getInputs());
+ Map<String, Resource> existingNodeTypesByResourceNames = new HashMap<>();
+ preparedResource = createResourceInstances(yamlFileName, preparedResource, oldResource, instances, csarInfo.getCreatedNodes(), existingNodeTypesByResourceNames);
+ preparedResource = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, oldResource, instances, existingNodeTypesByResourceNames);
+ } catch (ComponentException e) {
+ ResponseFormat responseFormat = e.getResponseFormat() == null
+ ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
+ log.debug("#updateResourceFromYaml - failed to update newResource from yaml {} .The error is {}", yamlFileName,
+ responseFormat);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(),
+ preparedResource == null ? oldResource : preparedResource, actionEnum);
+ throw e;
+ } catch (StorageException e) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
+ log.debug("#updateResourceFromYaml - failed to update newResource from yaml {} .The error is {}", yamlFileName,
+ responseFormat);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(),
+ preparedResource == null ? oldResource : preparedResource, actionEnum);
+ throw e;
+ }
+ Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic
+ .validateUpdateVfGroupNames(uploadComponentInstanceInfoMap.getGroups(),
+ preparedResource.getSystemName());
+ if (validateUpdateVfGroupNamesRes.isRight()) {
- throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right().value());
- }
- // add groups to resource
- Map<String, GroupDefinition> groups;
+ throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right()
+ .value());
+ }
+ // add groups to newResource
+ Map<String, GroupDefinition> groups;
+
+ if (!validateUpdateVfGroupNamesRes.left()
+ .value()
+ .isEmpty()) {
+ groups = validateUpdateVfGroupNamesRes.left()
+ .value();
+ } else {
+ groups = uploadComponentInstanceInfoMap.getGroups();
+ }
+ handleGroupsProperties(preparedResource, groups);
+ Either<Boolean, ActionStatus> isTopologyChanged = topologyComparator.isTopologyChanged(oldResource, preparedResource);
+
+ preparedResource = updateGroupsOnResource(preparedResource, groups);
+
+ NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName,
+ nodeTypesArtifactsToHandle);
+
+ Either<Resource, ResponseFormat> updateArtifactsEither = createOrUpdateArtifacts(ArtifactOperationEnum.UPDATE,
+ createdArtifacts, yamlFileName, csarInfo, preparedResource, nodeTypeInfoToUpdateArtifacts,
+ inTransaction, shouldLock);
+ if (updateArtifactsEither.isRight()) {
+ log.debug("failed to update artifacts {}", updateArtifactsEither.right()
+ .value());
+ throw new ByResponseFormatComponentException(updateArtifactsEither.right()
+ .value());
+ }
+ preparedResource = getResourceWithGroups(updateArtifactsEither.left()
+ .value()
+ .getUniqueId());
- if (!validateUpdateVfGroupNamesRes.left().value().isEmpty()) {
- groups = validateUpdateVfGroupNamesRes.left().value();
- } else {
- groups = uploadComponentInstanceInfoMap.getGroups();
- }
- handleGroupsProperties(preparedResource, groups);
- preparedResource = updateGroupsOnResource(preparedResource, groups);
- NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName,
- nodeTypesArtifactsToHandle);
-
- Either<Resource, ResponseFormat> updateArtifactsEither = createOrUpdateArtifacts(ArtifactOperationEnum.UPDATE, createdArtifacts, yamlFileName,
- csarInfo, preparedResource, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock);
- if (updateArtifactsEither.isRight()) {
- log.debug("failed to update artifacts {}", updateArtifactsEither.right().value());
- throw new ByResponseFormatComponentException(updateArtifactsEither.right().value());
- }
- preparedResource = getResourceWithGroups(updateArtifactsEither.left().value().getUniqueId());
+ updateGroupsName(oldResource, preparedResource, isTopologyChanged.left().value());
+ updateResourceInstancesNames(oldResource, csarInfo, preparedResource, isTopologyChanged.left().value());
- ActionStatus mergingPropsAndInputsStatus = resourceDataMergeBusinessLogic.mergeResourceEntities(oldRresource, preparedResource);
- if (mergingPropsAndInputsStatus != ActionStatus.OK) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(mergingPropsAndInputsStatus,
- preparedResource);
- throw new ByResponseFormatComponentException(responseFormat);
- }
- compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, csarInfo.getModifier().getUserId());
- return preparedResource;
- }
+ preparedResource = getResourceWithGroups(preparedResource.getUniqueId());
- private Either<Resource, ResponseFormat> createOrUpdateArtifacts(ArtifactOperationEnum operation, List<ArtifactDefinition> createdArtifacts,
- String yamlFileName, CsarInfo csarInfo, Resource preparedResource,
- NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts, boolean inTransaction, boolean shouldLock) {
-
- String nodeName = nodeTypeInfoToUpdateArtifacts.getNodeName();
- Resource resource = preparedResource;
-
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = nodeTypeInfoToUpdateArtifacts
- .getNodeTypesArtifactsToHandle();
- if (preparedResource.getResourceType() == ResourceTypeEnum.CVFC) {
- if (nodeName != null && nodeTypesArtifactsToHandle.get(nodeName) != null && !nodeTypesArtifactsToHandle.get(nodeName).isEmpty()) {
- Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes =
- handleNodeTypeArtifacts(preparedResource, nodeTypesArtifactsToHandle.get(nodeName), createdArtifacts, csarInfo.getModifier(), inTransaction, true);
- if (handleNodeTypeArtifactsRes.isRight()) {
- return Either.right(handleNodeTypeArtifactsRes.right().value());
- }
- }
- } else {
- Either<Resource, ResponseFormat> createdCsarArtifactsEither = handleVfCsarArtifacts(preparedResource, csarInfo, createdArtifacts,
- artifactsBusinessLogic.new ArtifactOperationInfo(false, false, operation), shouldLock, inTransaction);
- log.trace("************* Finished to add artifacts from yaml {}", yamlFileName);
- if (createdCsarArtifactsEither.isRight()) {
- return createdCsarArtifactsEither;
+ updateVolumeGroup(preparedResource);
- }
- resource = createdCsarArtifactsEither.left().value();
- }
- return Either.left(resource);
- }
+ ActionStatus mergingPropsAndInputsStatus = resourceDataMergeBusinessLogic.mergeResourceEntities(oldResource, preparedResource);
+ if (mergingPropsAndInputsStatus != ActionStatus.OK) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(mergingPropsAndInputsStatus,
+ preparedResource);
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+ compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, csarInfo.getModifier()
+ .getUserId());
+ return preparedResource;
+ }
- private Resource handleResourceGenericType(Resource resource) {
- Resource genericResource = fetchAndSetDerivedFromGenericType(resource);
- if (resource.shouldGenerateInputs()) {
- generateAndAddInputsFromGenericTypeProperties(resource, genericResource);
- }
- return genericResource;
- }
+ protected void updateVolumeGroup(Resource preparedResource) {
+ List<GroupDefinition> groups = preparedResource.safeGetGroups();
+ for (GroupDefinition group : groups) {
+ Map<String, ArtifactDefinition> createdNewArtifacts = preparedResource.getDeploymentArtifacts();
+ if (DEFAULT_GROUP_VF_MODULE.equals(group.getType())) {
+ List<PropertyDataDefinition> volumePropList = group.getProperties().stream().filter(p -> "volume_group".equals(p.getName())).collect(Collectors.toList());
+ if (!volumePropList.isEmpty()) {
+ PropertyDataDefinition volumeProp = volumePropList.get(0);
+ if (volumeProp != null) {
+ boolean isVolumeGroup = isVolumeGroup(group.getArtifacts(), new ArrayList<>(createdNewArtifacts.values()));
+
+ if (!volumePropList.get(0).getValue().equals(String.valueOf(isVolumeGroup))) {
+ volumeProp.setValue(String.valueOf(isVolumeGroup));
+ volumeProp.setDefaultValue(String.valueOf(isVolumeGroup));
+ }
+ }
+ }
+ }
+ }
+ }
- private Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle(
- Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, Resource oldResource) {
+ private void updateGroupsName(Resource oldResource, Resource preparedResource, boolean isTopologyChanged) {
+ if (CollectionUtils.isNotEmpty(oldResource.getGroups())
+ && CollectionUtils.isNotEmpty(preparedResource.getGroups())) {
+ Map<String, String> oldGroups = oldResource.getGroups()
+ .stream()
+ .collect(toMap(GroupDataDefinition::getInvariantName, GroupDataDefinition::getName));
+
+ List<GroupDefinition> updatedGroups = preparedResource.getGroups()
+ .stream()
+ .filter(group -> oldGroups.containsKey(group.getInvariantName()) && !group.getName()
+ .equals(oldGroups.get(group.getInvariantName())))
+ .collect(toList());
+
+ if (CollectionUtils.isNotEmpty(updatedGroups)) {
+ if (isTopologyChanged) {
+ updatedGroups.stream().filter(group -> !group.isVspOriginated())
+ .forEach(group -> group.setName(oldGroups.get(group.getInvariantName())));
+ } else {
+ updatedGroups.forEach(group -> group.setName(oldGroups.get(group.getInvariantName())));
+ }
+ groupBusinessLogic.updateGroups(preparedResource, updatedGroups, false);
+ }
+ }
+ }
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
- Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> nodeTypesArtifactsToHandleRes
- = Either.left(nodeTypesArtifactsToHandle);
+ private void updateResourceInstancesNames(Resource oldResource, CsarInfo csarInfo, Resource preparedResource, boolean isTopologyChanged) {
+ if(CollectionUtils.isNotEmpty(oldResource.getComponentInstances())){
+ Map<String, String> oldInstances = oldResource.getComponentInstances()
+ .stream()
+ .collect(toMap(ComponentInstance::getInvariantName, ComponentInstance::getName));
+ List<ComponentInstance> updatedInstances = preparedResource.getComponentInstances()
+ .stream()
+ .filter(i -> oldInstances.containsKey(i.getInvariantName()) && !i.getName()
+ .equals(oldInstances.get(i.getInvariantName())))
+ .collect(toList());
+ if (CollectionUtils.isNotEmpty(updatedInstances)) {
+ if(isTopologyChanged) {
+ updatedInstances.stream().filter(i -> !i.isCreatedFromCsar())
+ .forEach(i -> i.setName(oldInstances.get(i.getInvariantName())));
+ }
+ else{
+ updatedInstances.forEach(i -> i.setName(oldInstances.get(i.getInvariantName())));
+ }
+ }
- try {
- Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts = CsarUtils.extractVfcsArtifactsFromCsar(csarInfo.getCsar());
- Map<String, ImmutablePair<String, String>> extractedVfcToscaNames =
- extractVfcToscaNames(nodeTypesInfo, oldResource.getName(), csarInfo);
- log.debug("Going to fetch node types for resource with name {} during import csar with UUID {}. ",
- oldResource.getName(), csarInfo.getCsarUUID());
- extractedVfcToscaNames.forEach((namespace, vfcToscaNames) -> findAddNodeTypeArtifactsToHandle(csarInfo, nodeTypesArtifactsToHandle, oldResource,
- extractedVfcsArtifacts,
- namespace, vfcToscaNames));
- } catch (Exception e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- nodeTypesArtifactsToHandleRes = Either.right(responseFormat);
- log.debug("Exception occured when findNodeTypesUpdatedArtifacts, error is:{}", e.getMessage(), e);
- }
- return nodeTypesArtifactsToHandleRes;
- }
+ }
+ componentInstanceBusinessLogic.updateComponentInstance(ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ null, preparedResource.getUniqueId(), csarInfo.getModifier()
+ .getUserId(),
+ preparedResource.getComponentInstances(), false);
+ }
- private void findAddNodeTypeArtifactsToHandle(CsarInfo csarInfo, Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
- Resource resource, Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts, String namespace, ImmutablePair<String, String> vfcToscaNames){
+ private Either<Resource, ResponseFormat> createOrUpdateArtifacts(ArtifactOperationEnum operation,
+ List<ArtifactDefinition> createdArtifacts, String yamlFileName, CsarInfo csarInfo,
+ Resource preparedResource, NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts,
+ boolean inTransaction, boolean shouldLock) {
+
+ String nodeName = nodeTypeInfoToUpdateArtifacts.getNodeName();
+ Resource resource = preparedResource;
+
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = nodeTypeInfoToUpdateArtifacts
+ .getNodeTypesArtifactsToHandle();
+ if (preparedResource.getResourceType() == ResourceTypeEnum.CVFC) {
+ if (nodeName != null && nodeTypesArtifactsToHandle.get(nodeName) != null
+ && !nodeTypesArtifactsToHandle.get(nodeName)
+ .isEmpty()) {
+ Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = handleNodeTypeArtifacts(
+ preparedResource, nodeTypesArtifactsToHandle.get(nodeName), createdArtifacts,
+ csarInfo.getModifier(), inTransaction, true);
+ if (handleNodeTypeArtifactsRes.isRight()) {
+ return Either.right(handleNodeTypeArtifactsRes.right()
+ .value());
+ }
+ }
+ } else {
+ Either<Resource, ResponseFormat> createdCsarArtifactsEither = handleVfCsarArtifacts(preparedResource,
+ csarInfo, createdArtifacts,
+ artifactsBusinessLogic.new ArtifactOperationInfo(false, false, operation), shouldLock,
+ inTransaction);
+ log.trace("************* Finished to add artifacts from yaml {}", yamlFileName);
+ if (createdCsarArtifactsEither.isRight()) {
+ return createdCsarArtifactsEither;
- EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> curNodeTypeArtifactsToHandle = null;
- log.debug("Going to fetch node type with tosca name {}. ", vfcToscaNames.getLeft());
- Resource curNodeType = findVfcResource(csarInfo, resource, vfcToscaNames.getLeft(), vfcToscaNames.getRight(), null);
- if (!isEmpty(extractedVfcsArtifacts)) {
- List<ArtifactDefinition> currArtifacts = new ArrayList<>();
- if (extractedVfcsArtifacts.containsKey(namespace)) {
- handleAndAddExtractedVfcsArtifacts(currArtifacts, extractedVfcsArtifacts.get(namespace));
- }
- curNodeTypeArtifactsToHandle = findNodeTypeArtifactsToHandle(curNodeType, currArtifacts);
- } else if (curNodeType != null) {
- // delete all artifacts if have not received artifacts from
- // csar
- curNodeTypeArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
- List<ArtifactDefinition> artifactsToDelete = new ArrayList<>();
- // delete all informational artifacts
- artifactsToDelete.addAll(curNodeType.getArtifacts().values().stream()
- .filter(a -> a.getArtifactGroupType() == ArtifactGroupTypeEnum.INFORMATIONAL)
- .collect(toList()));
- // delete all deployment artifacts
- artifactsToDelete.addAll(curNodeType.getDeploymentArtifacts().values());
- if (!artifactsToDelete.isEmpty()) {
- curNodeTypeArtifactsToHandle.put(ArtifactOperationEnum.DELETE, artifactsToDelete);
- }
- }
- if (isNotEmpty(curNodeTypeArtifactsToHandle)) {
- nodeTypesArtifactsToHandle.put(namespace, curNodeTypeArtifactsToHandle);
- }
- }
+ }
+ resource = createdCsarArtifactsEither.left()
+ .value();
+ }
+ return Either.left(resource);
+ }
- private Resource findVfcResource(CsarInfo csarInfo, Resource resource, String currVfcToscaName, String previousVfcToscaName, StorageOperationStatus status) {
- if (status != null && status != StorageOperationStatus.NOT_FOUND) {
- log.debug("Error occured during fetching node type with tosca name {}, error: {}", currVfcToscaName, status);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.CREATE_RESOURCE);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
- } else if (StringUtils.isNotEmpty(currVfcToscaName)) {
- return (Resource)toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName)
- .left()
- .on(st -> findVfcResource(csarInfo, resource, previousVfcToscaName, null, st));
- }
- return null;
- }
+ private Resource handleResourceGenericType(Resource resource) {
+ Resource genericResource = fetchAndSetDerivedFromGenericType(resource);
+ if (resource.shouldGenerateInputs()) {
+ generateAndAddInputsFromGenericTypeProperties(resource, genericResource);
+ }
+ return genericResource;
+ }
- private EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> findNodeTypeArtifactsToHandle(
- Resource curNodeType, List<ArtifactDefinition> extractedArtifacts) {
+ private Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandle(
+ Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, Resource oldResource) {
+
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
+ Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> nodeTypesArtifactsToHandleRes = Either
+ .left(nodeTypesArtifactsToHandle);
+
+ try {
+ Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts = CsarUtils
+ .extractVfcsArtifactsFromCsar(csarInfo.getCsar());
+ Map<String, ImmutablePair<String, String>> extractedVfcToscaNames = extractVfcToscaNames(nodeTypesInfo,
+ oldResource.getName(), csarInfo);
+ log.debug("Going to fetch node types for resource with name {} during import csar with UUID {}. ",
+ oldResource.getName(), csarInfo.getCsarUUID());
+ extractedVfcToscaNames.forEach((namespace, vfcToscaNames) -> findAddNodeTypeArtifactsToHandle(csarInfo,
+ nodeTypesArtifactsToHandle, oldResource, extractedVfcsArtifacts, namespace, vfcToscaNames));
+ } catch (Exception e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ nodeTypesArtifactsToHandleRes = Either.right(responseFormat);
+ log.debug("Exception occurred when findNodeTypesUpdatedArtifacts, error is:{}", e.getMessage(), e);
+ }
+ return nodeTypesArtifactsToHandleRes;
+ }
- EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = null;
- try {
- List<ArtifactDefinition> artifactsToUpload = new ArrayList<>(extractedArtifacts);
- List<ArtifactDefinition> artifactsToUpdate = new ArrayList<>();
- List<ArtifactDefinition> artifactsToDelete = new ArrayList<>();
- processExistingNodeTypeArtifacts(extractedArtifacts, artifactsToUpload, artifactsToUpdate, artifactsToDelete,
- collectExistingArtifacts(curNodeType));
- nodeTypeArtifactsToHandle = putFoundArtifacts(artifactsToUpload, artifactsToUpdate, artifactsToDelete);
- } catch (Exception e) {
- log.debug("Exception occured when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage(), e);
- throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
- }
- return nodeTypeArtifactsToHandle;
- }
+ private void findAddNodeTypeArtifactsToHandle(CsarInfo csarInfo,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
+ Resource resource, Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts, String namespace,
+ ImmutablePair<String, String> vfcToscaNames) {
+
+ EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> curNodeTypeArtifactsToHandle = null;
+ log.debug("Going to fetch node type with tosca name {}. ", vfcToscaNames.getLeft());
+ Resource curNodeType = findVfcResource(csarInfo, resource, vfcToscaNames.getLeft(), vfcToscaNames.getRight(),
+ null);
+ if (!isEmpty(extractedVfcsArtifacts)) {
+ List<ArtifactDefinition> currArtifacts = new ArrayList<>();
+ if (extractedVfcsArtifacts.containsKey(namespace)) {
+ handleAndAddExtractedVfcsArtifacts(currArtifacts, extractedVfcsArtifacts.get(namespace));
+ }
+ curNodeTypeArtifactsToHandle = findNodeTypeArtifactsToHandle(curNodeType, currArtifacts);
+ } else if (curNodeType != null) {
+ // delete all artifacts if have not received artifacts from
+ // csar
+ curNodeTypeArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
+ List<ArtifactDefinition> artifactsToDelete = new ArrayList<>();
+ // delete all informational artifacts
+ artifactsToDelete.addAll(curNodeType.getArtifacts()
+ .values()
+ .stream()
+ .filter(a -> a.getArtifactGroupType() == ArtifactGroupTypeEnum.INFORMATIONAL)
+ .collect(toList()));
+ // delete all deployment artifacts
+ artifactsToDelete.addAll(curNodeType.getDeploymentArtifacts()
+ .values());
+ if (!artifactsToDelete.isEmpty()) {
+ curNodeTypeArtifactsToHandle.put(ArtifactOperationEnum.DELETE, artifactsToDelete);
+ }
+ }
+ if (isNotEmpty(curNodeTypeArtifactsToHandle)) {
+ nodeTypesArtifactsToHandle.put(namespace, curNodeTypeArtifactsToHandle);
+ }
+ }
- private EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> putFoundArtifacts(List<ArtifactDefinition> artifactsToUpload, List<ArtifactDefinition> artifactsToUpdate, List<ArtifactDefinition> artifactsToDelete) {
- EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = null;
- if (!artifactsToUpload.isEmpty() || !artifactsToUpdate.isEmpty() || !artifactsToDelete.isEmpty()) {
- nodeTypeArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
- if (!artifactsToUpload.isEmpty()) {
- nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.CREATE, artifactsToUpload);
- }
- if (!artifactsToUpdate.isEmpty()) {
- nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.UPDATE, artifactsToUpdate);
- }
- if (!artifactsToDelete.isEmpty()) {
- nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.DELETE, artifactsToDelete);
- }
- }
- return nodeTypeArtifactsToHandle;
- }
+ private Resource findVfcResource(CsarInfo csarInfo, Resource resource, String currVfcToscaName,
+ String previousVfcToscaName, StorageOperationStatus status) {
+ if (status != null && status != StorageOperationStatus.NOT_FOUND) {
+ log.debug("Error occurred during fetching node type with tosca name {}, error: {}", currVfcToscaName,
+ status);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource,
+ AuditingActionEnum.CREATE_RESOURCE);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
+ } else if (StringUtils.isNotEmpty(currVfcToscaName)) {
+ return (Resource) toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName)
+ .left()
+ .on(st -> findVfcResource(csarInfo, resource, previousVfcToscaName, null, st));
+ }
+ return null;
+ }
- private void processExistingNodeTypeArtifacts(List<ArtifactDefinition> extractedArtifacts, List<ArtifactDefinition> artifactsToUpload,
- List<ArtifactDefinition> artifactsToUpdate, List<ArtifactDefinition> artifactsToDelete,
- Map<String, ArtifactDefinition> existingArtifacts) {
- if (!existingArtifacts.isEmpty()) {
- extractedArtifacts.stream().forEach(a -> processNodeTypeArtifact(artifactsToUpload, artifactsToUpdate, existingArtifacts, a));
- artifactsToDelete.addAll(existingArtifacts.values());
- }
- }
+ private EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> findNodeTypeArtifactsToHandle(Resource curNodeType,
+ List<ArtifactDefinition> extractedArtifacts) {
+
+ EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = null;
+ try {
+ List<ArtifactDefinition> artifactsToUpload = new ArrayList<>(extractedArtifacts);
+ List<ArtifactDefinition> artifactsToUpdate = new ArrayList<>();
+ List<ArtifactDefinition> artifactsToDelete = new ArrayList<>();
+ processExistingNodeTypeArtifacts(extractedArtifacts, artifactsToUpload, artifactsToUpdate,
+ artifactsToDelete, collectExistingArtifacts(curNodeType));
+ nodeTypeArtifactsToHandle = putFoundArtifacts(artifactsToUpload, artifactsToUpdate, artifactsToDelete);
+ } catch (Exception e) {
+ log.debug("Exception occurred when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage(), e);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ return nodeTypeArtifactsToHandle;
+ }
- private void processNodeTypeArtifact(List<ArtifactDefinition> artifactsToUpload, List<ArtifactDefinition> artifactsToUpdate, Map<String, ArtifactDefinition> existingArtifacts, ArtifactDefinition currNewArtifact) {
- Optional<ArtifactDefinition> foundArtifact = existingArtifacts.values()
- .stream()
- .filter(a -> a.getArtifactName().equals(currNewArtifact.getArtifactName()))
- .findFirst();
- if (foundArtifact.isPresent()) {
- if (foundArtifact.get().getArtifactType().equals(currNewArtifact.getArtifactType())) {
- updateFoundArtifact(artifactsToUpdate, currNewArtifact, foundArtifact.get());
- existingArtifacts.remove(foundArtifact.get().getArtifactLabel());
- artifactsToUpload.remove(currNewArtifact);
- } else {
- log.debug("Can't upload two artifact with the same name {}.", currNewArtifact.getArtifactName());
- throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR,
- currNewArtifact.getArtifactName(), currNewArtifact.getArtifactType(),
- foundArtifact.get().getArtifactType());
- }
- }
- }
+ private EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> putFoundArtifacts(
+ List<ArtifactDefinition> artifactsToUpload, List<ArtifactDefinition> artifactsToUpdate,
+ List<ArtifactDefinition> artifactsToDelete) {
+ EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = null;
+ if (!artifactsToUpload.isEmpty() || !artifactsToUpdate.isEmpty() || !artifactsToDelete.isEmpty()) {
+ nodeTypeArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
+ if (!artifactsToUpload.isEmpty()) {
+ nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.CREATE, artifactsToUpload);
+ }
+ if (!artifactsToUpdate.isEmpty()) {
+ nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.UPDATE, artifactsToUpdate);
+ }
+ if (!artifactsToDelete.isEmpty()) {
+ nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.DELETE, artifactsToDelete);
+ }
+ }
+ return nodeTypeArtifactsToHandle;
+ }
- private void updateFoundArtifact(List<ArtifactDefinition> artifactsToUpdate, ArtifactDefinition currNewArtifact, ArtifactDefinition foundArtifact) {
- if (!foundArtifact.getArtifactChecksum().equals(currNewArtifact.getArtifactChecksum())) {
- foundArtifact.setPayload(currNewArtifact.getPayloadData());
- foundArtifact.setPayloadData(
- Base64.encodeBase64String(currNewArtifact.getPayloadData()));
- foundArtifact.setArtifactChecksum(GeneralUtility
- .calculateMD5Base64EncodedByByteArray(currNewArtifact.getPayloadData()));
- artifactsToUpdate.add(foundArtifact);
- }
- }
+ private void processExistingNodeTypeArtifacts(List<ArtifactDefinition> extractedArtifacts,
+ List<ArtifactDefinition> artifactsToUpload, List<ArtifactDefinition> artifactsToUpdate,
+ List<ArtifactDefinition> artifactsToDelete, Map<String, ArtifactDefinition> existingArtifacts) {
+ if (!existingArtifacts.isEmpty()) {
+ extractedArtifacts.stream()
+ .forEach(a -> processNodeTypeArtifact(artifactsToUpload, artifactsToUpdate, existingArtifacts, a));
+ artifactsToDelete.addAll(existingArtifacts.values());
+ }
+ }
- private Map<String, ArtifactDefinition> collectExistingArtifacts(Resource curNodeType) {
- Map<String, ArtifactDefinition> existingArtifacts = new HashMap<>();
- if (curNodeType == null) {
- return existingArtifacts;
- }
- if (MapUtils.isNotEmpty(curNodeType.getDeploymentArtifacts())) {
- existingArtifacts.putAll(curNodeType.getDeploymentArtifacts());
- }
- if (MapUtils.isNotEmpty(curNodeType.getArtifacts())) {
- existingArtifacts
- .putAll(curNodeType.getArtifacts().entrySet()
- .stream()
- .filter(e -> e.getValue().getArtifactGroupType() == ArtifactGroupTypeEnum.INFORMATIONAL)
- .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)));
- }
- return existingArtifacts;
- }
+ private void processNodeTypeArtifact(List<ArtifactDefinition> artifactsToUpload,
+ List<ArtifactDefinition> artifactsToUpdate, Map<String, ArtifactDefinition> existingArtifacts,
+ ArtifactDefinition currNewArtifact) {
+ Optional<ArtifactDefinition> foundArtifact = existingArtifacts.values()
+ .stream()
+ .filter(a -> a.getArtifactName()
+ .equals(currNewArtifact.getArtifactName()))
+ .findFirst();
+ if (foundArtifact.isPresent()) {
+ if (foundArtifact.get()
+ .getArtifactType()
+ .equals(currNewArtifact.getArtifactType())) {
+ updateFoundArtifact(artifactsToUpdate, currNewArtifact, foundArtifact.get());
+ existingArtifacts.remove(foundArtifact.get()
+ .getArtifactLabel());
+ artifactsToUpload.remove(currNewArtifact);
+ } else {
+ log.debug("Can't upload two artifact with the same name {}.", currNewArtifact.getArtifactName());
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR,
+ currNewArtifact.getArtifactName(), currNewArtifact.getArtifactType(), foundArtifact.get()
+ .getArtifactType());
+ }
+ }
+ }
- /**
- * Changes resource life cycle state to checked out
- *
- * @param resource
- * @param user
- * @param inTransaction
- * @return
- */
- private Either<Resource, ResponseFormat> checkoutResource(Resource resource, User user, boolean inTransaction) {
- Either<Resource, ResponseFormat> checkoutResourceRes;
- try {
- if (!resource.getComponentMetadataDefinition().getMetadataDataDefinition().getState()
- .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
- log.debug(
- "************* Going to change life cycle state of resource {} to not certified checked out. ",
- resource.getName());
- Either<? extends Component, ResponseFormat> checkoutRes = lifecycleBusinessLogic.changeComponentState(
- resource.getComponentType(), resource.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT,
- new LifecycleChangeInfoWithAction(CERTIFICATION_ON_IMPORT,
- LifecycleChanceActionEnum.CREATE_FROM_CSAR),
- inTransaction, true);
- if (checkoutRes.isRight()) {
- log.debug("Could not change state of component {} with uid {} to checked out. Status is {}. ",
- resource.getComponentType().getNodeType(), resource.getUniqueId(),
- checkoutRes.right().value().getStatus());
- checkoutResourceRes = Either.right(checkoutRes.right().value());
- } else {
- checkoutResourceRes = Either.left((Resource) checkoutRes.left().value());
- }
- } else {
- checkoutResourceRes = Either.left(resource);
- }
- } catch (Exception e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- checkoutResourceRes = Either.right(responseFormat);
- log.debug("Exception occured when checkoutResource {} , error is:{}", resource.getName(), e.getMessage(),
- e);
- }
- return checkoutResourceRes;
- }
+ private void updateFoundArtifact(List<ArtifactDefinition> artifactsToUpdate, ArtifactDefinition currNewArtifact,
+ ArtifactDefinition foundArtifact) {
+ if (!foundArtifact.getArtifactChecksum()
+ .equals(currNewArtifact.getArtifactChecksum())) {
+ foundArtifact.setPayload(currNewArtifact.getPayloadData());
+ foundArtifact.setPayloadData(Base64.encodeBase64String(currNewArtifact.getPayloadData()));
+ foundArtifact.setArtifactChecksum(
+ GeneralUtility.calculateMD5Base64EncodedByByteArray(currNewArtifact.getPayloadData()));
+ artifactsToUpdate.add(foundArtifact);
+ }
+ }
- /**
- * Handles Artifacts of NodeType
- *
- * @param nodeTypeResource
- * @param nodeTypeArtifactsToHandle
- * @param user
- * @param inTransaction
- * @return
- */
- public Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource,
- Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
- List<ArtifactDefinition> createdArtifacts, User user, boolean inTransaction, boolean ignoreLifecycleState) {
- Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRequestRes;
- Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = null;
- Either<Resource, ResponseFormat> changeStateResponse;
- try {
- changeStateResponse = checkoutResource(nodeTypeResource, user, inTransaction);
- if (changeStateResponse.isRight()) {
- return Either.right(changeStateResponse.right().value());
- }
- nodeTypeResource = changeStateResponse.left().value();
-
- List<ArtifactDefinition> handledNodeTypeArtifacts = new ArrayList<>();
- log.debug("************* Going to handle artifacts of node type resource {}. ", nodeTypeResource.getName());
- for (Entry<ArtifactOperationEnum, List<ArtifactDefinition>> curOperationEntry : nodeTypeArtifactsToHandle
- .entrySet()) {
- ArtifactOperationEnum curOperation = curOperationEntry.getKey();
- List<ArtifactDefinition> curArtifactsToHandle = curOperationEntry.getValue();
- if (curArtifactsToHandle != null && !curArtifactsToHandle.isEmpty()) {
- log.debug("************* Going to {} artifact to vfc {}", curOperation.name(),
- nodeTypeResource.getName());
- handleNodeTypeArtifactsRequestRes = artifactsBusinessLogic
- .handleArtifactsRequestForInnerVfcComponent(curArtifactsToHandle, nodeTypeResource, user,
- createdArtifacts, artifactsBusinessLogic.new ArtifactOperationInfo(false,
- ignoreLifecycleState, curOperation),
- false, inTransaction);
- if (handleNodeTypeArtifactsRequestRes.isRight()) {
- handleNodeTypeArtifactsRes = Either.right(handleNodeTypeArtifactsRequestRes.right().value());
- break;
- }
- if (ArtifactOperationEnum.isCreateOrLink(curOperation)) {
- createdArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value());
- }
- handledNodeTypeArtifacts.addAll(handleNodeTypeArtifactsRequestRes.left().value());
- }
- }
- if (handleNodeTypeArtifactsRes == null) {
- handleNodeTypeArtifactsRes = Either.left(handledNodeTypeArtifacts);
- }
- } catch (Exception e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- handleNodeTypeArtifactsRes = Either.right(responseFormat);
- log.debug("Exception occured when handleVfcArtifacts, error is:{}", e.getMessage(), e);
- }
- return handleNodeTypeArtifactsRes;
- }
+ private Map<String, ArtifactDefinition> collectExistingArtifacts(Resource curNodeType) {
+ Map<String, ArtifactDefinition> existingArtifacts = new HashMap<>();
+ if (curNodeType == null) {
+ return existingArtifacts;
+ }
+ if (MapUtils.isNotEmpty(curNodeType.getDeploymentArtifacts())) {
+ existingArtifacts.putAll(curNodeType.getDeploymentArtifacts());
+ }
+ if (MapUtils.isNotEmpty(curNodeType.getArtifacts())) {
+ existingArtifacts.putAll(curNodeType.getArtifacts()
+ .entrySet()
+ .stream()
+ .filter(e -> e.getValue()
+ .getArtifactGroupType() == ArtifactGroupTypeEnum.INFORMATIONAL)
+ .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)));
+ }
+ return existingArtifacts;
+ }
- private Map<String, ImmutablePair<String, String>> extractVfcToscaNames(Map<String, NodeTypeInfo> nodeTypesInfo,
- String vfResourceName, CsarInfo csarInfo) {
- Map<String, ImmutablePair<String, String>> vfcToscaNames = new HashMap<>();
-
- Map<String, Object> nodes = extractAllNodes(nodeTypesInfo, csarInfo);
- if (!nodes.isEmpty()) {
- Iterator<Entry<String, Object>> nodesNameEntry = nodes.entrySet().iterator();
- while (nodesNameEntry.hasNext()) {
- Entry<String, Object> nodeType = nodesNameEntry.next();
- ImmutablePair<String, String> toscaResourceName = buildNestedToscaResourceName(
- ResourceTypeEnum.VFC.name(), vfResourceName, nodeType.getKey());
- vfcToscaNames.put(nodeType.getKey(), toscaResourceName);
- }
- }
- for (NodeTypeInfo cvfc : nodeTypesInfo.values()) {
- vfcToscaNames.put(cvfc.getType(),
- buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), vfResourceName, cvfc.getType()));
- }
- return vfcToscaNames;
- }
+ /**
+ * Changes resource life cycle state to checked out
+ *
+ * @param resource
+ * @param user
+ * @param inTransaction
+ * @return
+ */
+ private Either<Resource, ResponseFormat> checkoutResource(Resource resource, User user, boolean inTransaction) {
+ Either<Resource, ResponseFormat> checkoutResourceRes;
+ try {
+ if (!resource.getComponentMetadataDefinition()
+ .getMetadataDataDefinition()
+ .getState()
+ .equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ log.debug(
+ "************* Going to change life cycle state of resource {} to not certified checked out. ",
+ resource.getName());
+ Either<? extends Component, ResponseFormat> checkoutRes = lifecycleBusinessLogic.changeComponentState(
+ resource.getComponentType(), resource.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT,
+ new LifecycleChangeInfoWithAction(CERTIFICATION_ON_IMPORT,
+ LifecycleChanceActionEnum.CREATE_FROM_CSAR),
+ inTransaction, true);
+ if (checkoutRes.isRight()) {
+ log.debug("Could not change state of component {} with uid {} to checked out. Status is {}. ",
+ resource.getComponentType()
+ .getNodeType(),
+ resource.getUniqueId(), checkoutRes.right()
+ .value()
+ .getStatus());
+ checkoutResourceRes = Either.right(checkoutRes.right()
+ .value());
+ } else {
+ checkoutResourceRes = Either.left((Resource) checkoutRes.left()
+ .value());
+ }
+ } else {
+ checkoutResourceRes = Either.left(resource);
+ }
+ } catch (Exception e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ checkoutResourceRes = Either.right(responseFormat);
+ log.debug("Exception occurred when checkoutResource {} , error is:{}", resource.getName(), e.getMessage(),
+ e);
+ }
+ return checkoutResourceRes;
+ }
- private Map<String, Object> extractAllNodes(Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo) {
- Map<String, Object> nodes = new HashMap<>();
- for (NodeTypeInfo nodeTypeInfo : nodeTypesInfo.values()) {
- extractNodeTypes(nodes, nodeTypeInfo.getMappedToscaTemplate());
- }
- extractNodeTypes(nodes, csarInfo.getMappedToscaMainTemplate());
- return nodes;
- }
+ /**
+ * Handles Artifacts of NodeType
+ *
+ * @param nodeTypeResource
+ * @param nodeTypeArtifactsToHandle
+ * @param user
+ * @param inTransaction
+ * @return
+ */
+ public Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifacts(Resource nodeTypeResource,
+ Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
+ List<ArtifactDefinition> createdArtifacts, User user, boolean inTransaction, boolean ignoreLifecycleState) {
+ List<ArtifactDefinition> handleNodeTypeArtifactsRequestRes;
+ Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes = null;
+ Either<Resource, ResponseFormat> changeStateResponse;
+ try {
+ changeStateResponse = checkoutResource(nodeTypeResource, user, inTransaction);
+ if (changeStateResponse.isRight()) {
+ return Either.right(changeStateResponse.right()
+ .value());
+ }
+ nodeTypeResource = changeStateResponse.left()
+ .value();
+
+ List<ArtifactDefinition> handledNodeTypeArtifacts = new ArrayList<>();
+ log.debug("************* Going to handle artifacts of node type resource {}. ", nodeTypeResource.getName());
+ for (Entry<ArtifactOperationEnum, List<ArtifactDefinition>> curOperationEntry : nodeTypeArtifactsToHandle
+ .entrySet()) {
+ ArtifactOperationEnum curOperation = curOperationEntry.getKey();
+ List<ArtifactDefinition> curArtifactsToHandle = curOperationEntry.getValue();
+ if (curArtifactsToHandle != null && !curArtifactsToHandle.isEmpty()) {
+ log.debug("************* Going to {} artifact to vfc {}", curOperation.name(),
+ nodeTypeResource.getName());
+ handleNodeTypeArtifactsRequestRes = artifactsBusinessLogic
+ .handleArtifactsRequestForInnerVfcComponent(curArtifactsToHandle, nodeTypeResource, user,
+ createdArtifacts, artifactsBusinessLogic.new ArtifactOperationInfo(false,
+ ignoreLifecycleState, curOperation),
+ false, inTransaction);
+ if (ArtifactOperationEnum.isCreateOrLink(curOperation)) {
+ createdArtifacts.addAll(handleNodeTypeArtifactsRequestRes);
+ }
+ handledNodeTypeArtifacts.addAll(handleNodeTypeArtifactsRequestRes);
+ }
+ }
+ if (handleNodeTypeArtifactsRes == null) {
+ handleNodeTypeArtifactsRes = Either.left(handledNodeTypeArtifacts);
+ }
+ } catch (Exception e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ handleNodeTypeArtifactsRes = Either.right(responseFormat);
+ log.debug("Exception occurred when handleVfcArtifacts, error is:{}", e.getMessage(), e);
+ }
+ return handleNodeTypeArtifactsRes;
+ }
- private void extractNodeTypes(Map<String, Object> nodes, Map<String, Object> mappedToscaTemplate) {
- Either<Map<String, Object>, ResultStatusEnum> eitherNodeTypes = ImportUtils
- .findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES);
- if (eitherNodeTypes.isLeft()) {
- nodes.putAll(eitherNodeTypes.left().value());
- }
- }
+ private Map<String, ImmutablePair<String, String>> extractVfcToscaNames(Map<String, NodeTypeInfo> nodeTypesInfo,
+ String vfResourceName, CsarInfo csarInfo) {
+ Map<String, ImmutablePair<String, String>> vfcToscaNames = new HashMap<>();
+
+ Map<String, Object> nodes = extractAllNodes(nodeTypesInfo, csarInfo);
+ if (!nodes.isEmpty()) {
+ Iterator<Entry<String, Object>> nodesNameEntry = nodes.entrySet()
+ .iterator();
+ while (nodesNameEntry.hasNext()) {
+ Entry<String, Object> nodeType = nodesNameEntry.next();
+ ImmutablePair<String, String> toscaResourceName = buildNestedToscaResourceName(
+ ResourceTypeEnum.VFC.name(), vfResourceName, nodeType.getKey());
+ vfcToscaNames.put(nodeType.getKey(), toscaResourceName);
+ }
+ }
+ for (NodeTypeInfo cvfc : nodeTypesInfo.values()) {
+ vfcToscaNames.put(cvfc.getType(),
+ buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), vfResourceName, cvfc.getType()));
+ }
+ return vfcToscaNames;
+ }
- public Resource createResourceFromCsar(Resource resource, User user,
- Map<String, byte[]> csarUIPayload, String csarUUID) {
- log.trace("************* created successfully from YAML, resource TOSCA ");
+ private Map<String, Object> extractAllNodes(Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo) {
+ Map<String, Object> nodes = new HashMap<>();
+ for (NodeTypeInfo nodeTypeInfo : nodeTypesInfo.values()) {
+ extractNodeTypes(nodes, nodeTypeInfo.getMappedToscaTemplate());
+ }
+ extractNodeTypes(nodes, csarInfo.getMappedToscaMainTemplate());
+ return nodes;
+ }
- CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, csarUIPayload, csarUUID);
+ private void extractNodeTypes(Map<String, Object> nodes, Map<String, Object> mappedToscaTemplate) {
+ Either<Map<String, Object>, ResultStatusEnum> eitherNodeTypes = ImportUtils
+ .findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES);
+ if (eitherNodeTypes.isLeft()) {
+ nodes.putAll(eitherNodeTypes.left()
+ .value());
+ }
+ }
- Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo();
- Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(
- nodeTypesInfo, csarInfo, resource);
- if (findNodeTypesArtifactsToHandleRes.isRight()) {
- log.debug("failed to find node types for update with artifacts during import csar {}. ",
- csarInfo.getCsarUUID());
- throw new ByResponseFormatComponentException(findNodeTypesArtifactsToHandleRes.right().value());
- }
- Resource vfResource = createResourceFromYaml(resource, csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(),
- nodeTypesInfo, csarInfo, findNodeTypesArtifactsToHandleRes.left().value(), true, false,
- null);
- log.trace("*************VF Resource created successfully from YAML, resource TOSCA name: {}",
- vfResource.getToscaResourceName());
- return vfResource;
- }
+ public Resource createResourceFromCsar(Resource resource, User user, Map<String, byte[]> csarUIPayload,
+ String csarUUID) {
+ log.trace("************* created successfully from YAML, resource TOSCA ");
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML,StatusCode.STARTED,"Starting to create Resource From Csar by user {}", user.getUserId() );
+ CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, csarUIPayload, csarUUID);
+ Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo();
+ Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(
+ nodeTypesInfo, csarInfo, resource);
+ if (findNodeTypesArtifactsToHandleRes.isRight()) {
+ log.debug("failed to find node types for update with artifacts during import csar {}. ",
+ csarInfo.getCsarUUID());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"error: {}",findNodeTypesArtifactsToHandleRes.right().value());
+ throw new ByResponseFormatComponentException(findNodeTypesArtifactsToHandleRes.right().value());
+ }
+ Resource vfResource = createResourceFromYaml(resource, csarInfo.getMainTemplateContent(),
+ csarInfo.getMainTemplateName(), nodeTypesInfo, csarInfo, findNodeTypesArtifactsToHandleRes.left()
+ .value(),
+ true, false, null);
+ log.trace("*************VF Resource created successfully from YAML, resource TOSCA name: {}",
+ vfResource.getToscaResourceName());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML,StatusCode.COMPLETE,"Ended create Resource From Csar by user {}", user.getUserId() );
+ return vfResource;
+ }
- private Resource validateResourceBeforeCreate(Resource resource, User user, boolean inTransaction) {
- log.trace("validating resource before create");
- user.copyData(validateUser(user, CREATE_RESOURCE, resource, AuditingActionEnum.CREATE_RESOURCE, false));
- // validate user role
- validateUserRole(user, resource, new ArrayList<>(), AuditingActionEnum.CREATE_RESOURCE, null);
- // VF / PNF "derivedFrom" should be null (or ignored)
- if (ModelConverter.isAtomicComponent(resource)) {
- validateDerivedFromNotEmpty(user, resource, AuditingActionEnum.CREATE_RESOURCE);
- }
- return validateResourceBeforeCreate(resource, user, AuditingActionEnum.CREATE_RESOURCE, inTransaction, null);
+ private Resource validateResourceBeforeCreate(Resource resource, User user, boolean inTransaction) {
+ log.trace("validating resource before create");
+ user.copyData(validateUser(user, CREATE_RESOURCE, resource, AuditingActionEnum.CREATE_RESOURCE, false));
+ // validate user role
+ validateUserRole(user, resource, new ArrayList<>(), AuditingActionEnum.CREATE_RESOURCE, null);
+ // VF / PNF "derivedFrom" should be null (or ignored)
+ if (ModelConverter.isAtomicComponent(resource)) {
+ validateDerivedFromNotEmpty(user, resource, AuditingActionEnum.CREATE_RESOURCE);
+ }
+ return validateResourceBeforeCreate(resource, user, AuditingActionEnum.CREATE_RESOURCE, inTransaction, null);
- }
+ }
- // resource, yamlFileContents, yamlFileName, nodeTypesInfo,csarInfo,
- // nodeTypesArtifactsToCreate, true, false, null
- private Resource createResourceFromYaml(Resource resource, String topologyTemplateYaml,
- String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
- boolean shouldLock, boolean inTransaction, String nodeName) {
+ // resource, yamlFileContents, yamlFileName, nodeTypesInfo,csarInfo,
+ // nodeTypesArtifactsToCreate, true, false, null
+ private Resource createResourceFromYaml(Resource resource, String topologyTemplateYaml, String yamlName,
+ Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
+ boolean shouldLock, boolean inTransaction, String nodeName) {
- List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- Resource createdResource;
- try{
+ List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
+ Resource createdResource;
+ try {
ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic.getParsedToscaYamlInfo(topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, nodeName);
if (MapUtils.isEmpty(parsedToscaYamlInfo.getInstances()) && resource.getResourceType() != ResourceTypeEnum.PNF) {
throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
}
- log.debug("#createResourceFromYaml - Going to create resource {} and RIs ", resource.getName());
- createdResource = createResourceAndRIsFromYaml(yamlName, resource,
- parsedToscaYamlInfo, AuditingActionEnum.IMPORT_RESOURCE, false, createdArtifacts, topologyTemplateYaml,
- nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName);
- log.debug("#createResourceFromYaml - The resource {} has been created ", resource.getName());
- } catch (ByActionStatusComponentException e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
- throw e;
- } catch (ByResponseFormatComponentException e) {
- ResponseFormat responseFormat = e.getResponseFormat();
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
- throw e;
- } catch (StorageException e){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
- throw e;
- }
- return createdResource;
-
- }
+ log.debug("#createResourceFromYaml - Going to create resource {} and RIs ", resource.getName());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML,resource.getComponentMetadataForSupportLog(),
+ StatusCode.STARTED,"");
+ createdResource = createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo,
+ AuditingActionEnum.IMPORT_RESOURCE, false, createdArtifacts, topologyTemplateYaml, nodeTypesInfo,
+ csarInfo, nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName);
+ log.debug("#createResourceFromYaml - The resource {} has been created ", resource.getName());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML,resource.getComponentMetadataForSupportLog(),
+ StatusCode.COMPLETE,"The resource has been created: {}",resource.getName());
+ } catch (ComponentException e) {
+ ResponseFormat responseFormat = e.getResponseFormat() == null
+ ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource,
+ AuditingActionEnum.IMPORT_RESOURCE);
+ throw e;
+ } catch (StorageException e) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource,
+ AuditingActionEnum.IMPORT_RESOURCE);
+ throw e;
+ }
+ return createdResource;
- public Map<String, Resource> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource, Map<String, Object> mappedToscaTemplate, boolean needLock,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo,
- CsarInfo csarInfo) {
+ }
- Either<String, ResultStatusEnum> toscaVersion = findFirstToscaStringElement(mappedToscaTemplate,
- TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION);
- if (toscaVersion.isRight()) {
- throw new ByActionStatusComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE);
- }
- Map<String, Object> mapToConvert = new HashMap<>();
- mapToConvert.put(TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), toscaVersion.left().value());
- Map<String, Object> nodeTypes = getNodeTypesFromTemplate(mappedToscaTemplate);
- createNodeTypes(yamlName, resource, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, mapToConvert, nodeTypes);
- return csarInfo.getCreatedNodes();
- }
+ public Map<String, Resource> createResourcesFromYamlNodeTypesList(String yamlName, Resource resource,
+ Map<String, Object> mappedToscaTemplate, boolean needLock,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo,
+ CsarInfo csarInfo) {
- private Map<String,Object> getNodeTypesFromTemplate(Map<String, Object> mappedToscaTemplate) {
- return ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES)
- .left().orValue(HashMap::new);
- }
+ Either<String, ResultStatusEnum> toscaVersion = findFirstToscaStringElement(mappedToscaTemplate,
+ TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION);
+ if (toscaVersion.isRight()) {
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE);
+ }
+ Map<String, Object> mapToConvert = new HashMap<>();
+ mapToConvert.put(TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), toscaVersion.left()
+ .value());
+ Map<String, Object> nodeTypes = getNodeTypesFromTemplate(mappedToscaTemplate);
+ createNodeTypes(yamlName, resource, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
+ nodeTypesInfo, csarInfo, mapToConvert, nodeTypes);
+ return csarInfo.getCreatedNodes();
+ }
- private void createNodeTypes(String yamlName, Resource resource, boolean needLock, Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo, Map<String, Object> mapToConvert, Map<String, Object> nodeTypes) {
- Iterator<Entry<String, Object>> nodesNameValueIter = nodeTypes.entrySet().iterator();
- Resource vfcCreated = null;
- while (nodesNameValueIter.hasNext()) {
- Entry<String, Object> nodeType = nodesNameValueIter.next();
- Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = nodeTypesArtifactsToHandle == null
- || nodeTypesArtifactsToHandle.isEmpty() ? null
- : nodeTypesArtifactsToHandle.get(nodeType.getKey());
-
- if (nodeTypesInfo.containsKey(nodeType.getKey())) {
- log.trace("************* Going to handle nested vfc {}", nodeType.getKey());
- vfcCreated = handleNestedVfc(resource,
- nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
- nodeType.getKey());
- log.trace("************* Finished to handle nested vfc {}", nodeType.getKey());
- } else if (csarInfo.getCreatedNodesToscaResourceNames() != null
- && !csarInfo.getCreatedNodesToscaResourceNames().containsKey(nodeType.getKey())) {
- log.trace("************* Going to create node {}", nodeType.getKey());
- ImmutablePair<Resource, ActionStatus> resourceCreated = createNodeTypeResourceFromYaml(yamlName, nodeType, csarInfo.getModifier(), mapToConvert,
- resource, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, true,
- csarInfo, true);
- log.debug("************* Finished to create node {}", nodeType.getKey());
-
- vfcCreated = resourceCreated.getLeft();
- csarInfo.getCreatedNodesToscaResourceNames().put(nodeType.getKey(),
- vfcCreated.getToscaResourceName());
- }
- if (vfcCreated != null) {
- csarInfo.getCreatedNodes().put(nodeType.getKey(), vfcCreated);
- }
- mapToConvert.remove(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName());
- }
- }
+ private Map<String, Object> getNodeTypesFromTemplate(Map<String, Object> mappedToscaTemplate) {
+ return ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES)
+ .left()
+ .orValue(HashMap::new);
+ }
- private Resource handleNestedVfc(Resource resource, Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
- List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
- String nodeName) {
+ private void createNodeTypes(String yamlName, Resource resource, boolean needLock,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo,
+ CsarInfo csarInfo, Map<String, Object> mapToConvert, Map<String, Object> nodeTypes) {
+ Iterator<Entry<String, Object>> nodesNameValueIter = nodeTypes.entrySet()
+ .iterator();
+ Resource vfcCreated = null;
+ while (nodesNameValueIter.hasNext()) {
+ Entry<String, Object> nodeType = nodesNameValueIter.next();
+ Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = nodeTypesArtifactsToHandle == null
+ || nodeTypesArtifactsToHandle.isEmpty() ? null : nodeTypesArtifactsToHandle.get(nodeType.getKey());
+
+ if (nodeTypesInfo.containsKey(nodeType.getKey())) {
+ log.trace("************* Going to handle nested vfc {}", nodeType.getKey());
+ vfcCreated = handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
+ nodeTypesInfo, csarInfo, nodeType.getKey());
+ log.trace("************* Finished to handle nested vfc {}", nodeType.getKey());
+ } else if (csarInfo.getCreatedNodesToscaResourceNames() != null
+ && !csarInfo.getCreatedNodesToscaResourceNames()
+ .containsKey(nodeType.getKey())) {
+ log.trace("************* Going to create node {}", nodeType.getKey());
+ ImmutablePair<Resource, ActionStatus> resourceCreated = createNodeTypeResourceFromYaml(yamlName,
+ nodeType, csarInfo.getModifier(), mapToConvert, resource, needLock, nodeTypeArtifactsToHandle,
+ nodeTypesNewCreatedArtifacts, true, csarInfo, true);
+ log.debug("************* Finished to create node {}", nodeType.getKey());
+
+ vfcCreated = resourceCreated.getLeft();
+ csarInfo.getCreatedNodesToscaResourceNames()
+ .put(nodeType.getKey(), vfcCreated.getToscaResourceName());
+ }
+ if (vfcCreated != null) {
+ csarInfo.getCreatedNodes()
+ .put(nodeType.getKey(), vfcCreated);
+ }
+ mapToConvert.remove(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName());
+ }
+ }
- String yamlName = nodesInfo.get(nodeName).getTemplateFileName();
- Map<String, Object> nestedVfcJsonMap = nodesInfo.get(nodeName).getMappedToscaTemplate();
+ private Resource handleNestedVfc(Resource resource,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
+ List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
+ String nodeName) {
+
+ String yamlName = nodesInfo.get(nodeName)
+ .getTemplateFileName();
+ Map<String, Object> nestedVfcJsonMap = nodesInfo.get(nodeName)
+ .getMappedToscaTemplate();
+
+ log.debug("************* Going to create node types from yaml {}", yamlName);
+ createResourcesFromYamlNodeTypesList(yamlName, resource, nestedVfcJsonMap, false, nodesArtifactsToHandle,
+ createdArtifacts, nodesInfo, csarInfo);
+ log.debug("************* Finished to create node types from yaml {}", yamlName);
+
+ if (nestedVfcJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE.getElementName())) {
+ log.debug("************* Going to handle complex VFC from yaml {}", yamlName);
+ resource = handleComplexVfc(resource, nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo,
+ nodeName, yamlName);
+ }
+ return resource;
+ }
- log.debug("************* Going to create node types from yaml {}", yamlName);
- createResourcesFromYamlNodeTypesList(yamlName, resource, nestedVfcJsonMap, false,
- nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo);
- log.debug("************* Finished to create node types from yaml {}", yamlName);
+ private Resource handleComplexVfc(Resource resource,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
+ List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
+ String nodeName, String yamlName) {
+
+ Resource oldComplexVfc = null;
+ Resource newComplexVfc = buildValidComplexVfc(resource, csarInfo, nodeName, nodesInfo);
+ Either<Resource, StorageOperationStatus> oldComplexVfcRes = toscaOperationFacade
+ .getFullLatestComponentByToscaResourceName(newComplexVfc.getToscaResourceName());
+ if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right()
+ .value() == StorageOperationStatus.NOT_FOUND) {
+ oldComplexVfcRes = toscaOperationFacade.getFullLatestComponentByToscaResourceName(
+ buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), csarInfo.getVfResourceName(), nodeName)
+ .getRight());
+ }
+ if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right()
+ .value() != StorageOperationStatus.NOT_FOUND) {
+ log.debug("Failed to fetch previous complex VFC by tosca resource name {}. Status is {}. ",
+ newComplexVfc.getToscaResourceName(), oldComplexVfcRes.right()
+ .value());
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ } else if (oldComplexVfcRes.isLeft()) {
+ log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
+ Either<Boolean, ResponseFormat> eitherValidation = validateNestedDerivedFromDuringUpdate(
+ oldComplexVfcRes.left()
+ .value(),
+ newComplexVfc, ValidationUtils.hasBeenCertified(oldComplexVfcRes.left()
+ .value()
+ .getVersion()));
+ if (eitherValidation.isLeft()) {
+ oldComplexVfc = oldComplexVfcRes.left()
+ .value();
+ }
+ }
+ newComplexVfc = handleComplexVfc(nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName,
+ yamlName, oldComplexVfc, newComplexVfc);
+ csarInfo.getCreatedNodesToscaResourceNames()
+ .put(nodeName, newComplexVfc.getToscaResourceName());
+ LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(CERTIFICATION_ON_IMPORT,
+ LifecycleChanceActionEnum.CREATE_FROM_CSAR);
+ log.debug("Going to certify cvfc {}. ", newComplexVfc.getName());
+ Resource result = propagateStateToCertified(csarInfo.getModifier(), newComplexVfc,
+ lifecycleChangeInfo, true, false, true);
+ csarInfo.getCreatedNodes()
+ .put(nodeName, result);
+ csarInfo.removeNodeFromQueue();
+ return result;
+ }
- if (nestedVfcJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE.getElementName())) {
- log.debug("************* Going to handle complex VFC from yaml {}", yamlName);
- resource = handleComplexVfc(resource, nodesArtifactsToHandle, createdArtifacts, nodesInfo,
- csarInfo, nodeName, yamlName);
- }
- return resource;
- }
+ private Resource handleComplexVfc(
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
+ List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
+ String nodeName, String yamlName, Resource oldComplexVfc, Resource newComplexVfc) {
+
+ Resource handleComplexVfcRes;
+ Map<String, Object> mappedToscaTemplate = nodesInfo.get(nodeName)
+ .getMappedToscaTemplate();
+ String yamlContent = new String(csarInfo.getCsar()
+ .get(yamlName));
+ Map<String, NodeTypeInfo> newNodeTypesInfo = nodesInfo.entrySet()
+ .stream()
+ .collect(toMap(Entry::getKey, e -> e.getValue()
+ .getUnmarkedCopy()));
+ CsarInfo.markNestedVfc(mappedToscaTemplate, newNodeTypesInfo);
+ if (oldComplexVfc == null) {
+ handleComplexVfcRes = createResourceFromYaml(newComplexVfc, yamlContent, yamlName, newNodeTypesInfo,
+ csarInfo, nodesArtifactsToHandle, false, true, nodeName);
+ } else {
+ handleComplexVfcRes = updateResourceFromYaml(oldComplexVfc, newComplexVfc,
+ AuditingActionEnum.UPDATE_RESOURCE_METADATA, createdArtifacts, yamlContent, yamlName, csarInfo,
+ newNodeTypesInfo, nodesArtifactsToHandle, nodeName, true);
+ }
+ return handleComplexVfcRes;
+ }
- private Resource handleComplexVfc(Resource resource, Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
- List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
- String nodeName, String yamlName) {
-
- Resource oldComplexVfc = null;
- Resource newComplexVfc = buildValidComplexVfc(resource, csarInfo, nodeName, nodesInfo);
- Either<Resource, StorageOperationStatus> oldComplexVfcRes = toscaOperationFacade
- .getFullLatestComponentByToscaResourceName(newComplexVfc.getToscaResourceName());
- if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() == StorageOperationStatus.NOT_FOUND) {
- oldComplexVfcRes = toscaOperationFacade.getFullLatestComponentByToscaResourceName(
- buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), csarInfo.getVfResourceName(),
- nodeName).getRight());
- }
- if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() != StorageOperationStatus.NOT_FOUND) {
- log.debug("Failed to fetch previous complex VFC by tosca resource name {}. Status is {}. ",
- newComplexVfc.getToscaResourceName(), oldComplexVfcRes.right().value());
- throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
- } else if (oldComplexVfcRes.isLeft()) {
- log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
- Either<Boolean, ResponseFormat> eitherValidation = validateNestedDerivedFromDuringUpdate(
- oldComplexVfcRes.left().value(), newComplexVfc,
- ValidationUtils.hasBeenCertified(oldComplexVfcRes.left().value().getVersion()));
- if (eitherValidation.isLeft()) {
- oldComplexVfc = oldComplexVfcRes.left().value();
- }
- }
- newComplexVfc = handleComplexVfc(nodesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName,
- oldComplexVfc, newComplexVfc);
- csarInfo.getCreatedNodesToscaResourceNames().put(nodeName, newComplexVfc.getToscaResourceName());
- LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(
- CERTIFICATION_ON_IMPORT, LifecycleChanceActionEnum.CREATE_FROM_CSAR);
- log.debug("Going to certify cvfc {}. ", newComplexVfc.getName());
- Either<Resource, ResponseFormat> result = propagateStateToCertified(csarInfo.getModifier(), newComplexVfc, lifecycleChangeInfo, true, false,
- true);
- if (result.isRight()) {
- log.debug("Failed to certify complex VFC resource {}. ", newComplexVfc.getName());
- }
- csarInfo.getCreatedNodes().put(nodeName, result.left().value());
- csarInfo.removeNodeFromQueue();
- return result.left().value();
- }
+ private Resource buildValidComplexVfc(Resource resource, CsarInfo csarInfo, String nodeName,
+ Map<String, NodeTypeInfo> nodesInfo) {
- private Resource handleComplexVfc(Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodesArtifactsToHandle,
- List<ArtifactDefinition> createdArtifacts, Map<String, NodeTypeInfo> nodesInfo, CsarInfo csarInfo,
- String nodeName, String yamlName, Resource oldComplexVfc, Resource newComplexVfc) {
-
- Resource handleComplexVfcRes;
- Map<String, Object> mappedToscaTemplate = nodesInfo.get(nodeName).getMappedToscaTemplate();
- String yamlContent = new String(csarInfo.getCsar().get(yamlName));
- Map<String, NodeTypeInfo> newNodeTypesInfo = nodesInfo.entrySet().stream()
- .collect(toMap(Entry::getKey, e -> e.getValue().getUnmarkedCopy()));
- CsarInfo.markNestedVfc(mappedToscaTemplate, newNodeTypesInfo);
- if (oldComplexVfc == null) {
- handleComplexVfcRes = createResourceFromYaml(newComplexVfc, yamlContent, yamlName, newNodeTypesInfo,
- csarInfo, nodesArtifactsToHandle, false, true, nodeName);
- } else {
- handleComplexVfcRes = updateResourceFromYaml(oldComplexVfc, newComplexVfc,
- AuditingActionEnum.UPDATE_RESOURCE_METADATA, createdArtifacts, yamlContent, yamlName, csarInfo,
- newNodeTypesInfo, nodesArtifactsToHandle, nodeName, true);
- }
- return handleComplexVfcRes;
- }
+ Resource complexVfc = buildComplexVfcMetadata(resource, csarInfo, nodeName, nodesInfo);
+ log.debug("************* Going to validate complex VFC from yaml {}", complexVfc.getName());
+ csarInfo.addNodeToQueue(nodeName);
+ return validateResourceBeforeCreate(complexVfc, csarInfo.getModifier(), AuditingActionEnum.IMPORT_RESOURCE,
+ true, csarInfo);
+ }
- private Resource buildValidComplexVfc(Resource resource, CsarInfo csarInfo, String nodeName,
- Map<String, NodeTypeInfo> nodesInfo) {
+ private String getNodeTypeActualName(String fullName) {
+ String nameWithouNamespacePrefix = fullName
+ .substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+ String[] findTypes = nameWithouNamespacePrefix.split("\\.");
+ String resourceType = findTypes[0];
+ return nameWithouNamespacePrefix.substring(resourceType.length());
+ }
- Resource complexVfc = buildComplexVfcMetadata(resource, csarInfo, nodeName, nodesInfo);
- log.debug("************* Going to validate complex VFC from yaml {}", complexVfc.getName());
- csarInfo.addNodeToQueue(nodeName);
- return validateResourceBeforeCreate(complexVfc, csarInfo.getModifier(),
- AuditingActionEnum.IMPORT_RESOURCE, true, csarInfo);
- }
+ private ImmutablePair<Resource, ActionStatus> createNodeTypeResourceFromYaml(String yamlName,
+ Entry<String, Object> nodeNameValue, User user, Map<String, Object> mapToConvert, Resource resourceVf,
+ boolean needLock, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo,
+ boolean isNested) {
- private String getNodeTypeActualName(String fullName) {
- String nameWithouNamespacePrefix = fullName
- .substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
- String[] findTypes = nameWithouNamespacePrefix.split("\\.");
- String resourceType = findTypes[0];
- return nameWithouNamespacePrefix.substring(resourceType.length());
- }
+ UploadResourceInfo resourceMetaData = fillResourceMetadata(yamlName, resourceVf, nodeNameValue.getKey(), user);
- private ImmutablePair<Resource, ActionStatus> createNodeTypeResourceFromYaml(
- String yamlName, Entry<String, Object> nodeNameValue, User user, Map<String, Object> mapToConvert,
- Resource resourceVf, boolean needLock,
- Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo,
- boolean isNested) {
-
- UploadResourceInfo resourceMetaData = fillResourceMetadata(yamlName, resourceVf, nodeNameValue.getKey(), user);
-
- String singleVfcYaml = buildNodeTypeYaml(nodeNameValue, mapToConvert,
- resourceMetaData.getResourceType(), csarInfo);
- user = validateUser(user, "CheckIn Resource", resourceVf, AuditingActionEnum.CHECKIN_RESOURCE, true);
- return createResourceFromNodeType(singleVfcYaml, resourceMetaData, user, true, needLock,
- nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo,
- nodeNameValue.getKey(), isNested);
- }
+ String singleVfcYaml = buildNodeTypeYaml(nodeNameValue, mapToConvert, resourceMetaData.getResourceType(),
+ csarInfo);
+ user = validateUser(user, "CheckIn Resource", resourceVf, AuditingActionEnum.CHECKIN_RESOURCE, true);
+ return createResourceFromNodeType(singleVfcYaml, resourceMetaData, user, true, needLock,
+ nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo,
+ nodeNameValue.getKey(), isNested);
+ }
- private String buildNodeTypeYaml(Entry<String, Object> nodeNameValue, Map<String, Object> mapToConvert,
- String nodeResourceType, CsarInfo csarInfo) {
- // We need to create a Yaml from each node_types in order to create
- // resource from each node type using import normative flow.
- DumperOptions options = new DumperOptions();
- options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
- Yaml yaml = new Yaml(options);
+ private String buildNodeTypeYaml(Entry<String, Object> nodeNameValue, Map<String, Object> mapToConvert,
+ String nodeResourceType, CsarInfo csarInfo) {
+ // We need to create a Yaml from each node_types in order to create
+ // resource from each node type using import normative flow.
+ DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ Yaml yaml = new Yaml(options);
- Map<String, Object> node = new HashMap<>();
- node.put(buildNestedToscaResourceName(nodeResourceType, csarInfo.getVfResourceName(), nodeNameValue.getKey())
- .getLeft(), nodeNameValue.getValue());
- mapToConvert.put(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName(), node);
+ Map<String, Object> node = new HashMap<>();
+ node.put(buildNestedToscaResourceName(nodeResourceType, csarInfo.getVfResourceName(), nodeNameValue.getKey())
+ .getLeft(), nodeNameValue.getValue());
+ mapToConvert.put(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName(), node);
- return yaml.dumpAsMap(mapToConvert);
- }
+ return yaml.dumpAsMap(mapToConvert);
+ }
- public Either<Boolean, ResponseFormat> validateResourceCreationFromNodeType(Resource resource, User creator) {
- validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE);
- return Either.left(true);
- }
+ public Boolean validateResourceCreationFromNodeType(Resource resource, User creator) {
+ validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE);
+ return true;
+ }
- public ImmutablePair<Resource, ActionStatus> createResourceFromNodeType(String nodeTypeYaml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction, boolean needLock,
- Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo,
- String nodeName, boolean isNested) {
-
- LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(CERTIFICATION_ON_IMPORT,
- LifecycleChanceActionEnum.CREATE_FROM_CSAR);
- Function<Resource, Either<Boolean, ResponseFormat>> validator = resource -> validateResourceCreationFromNodeType(resource, creator);
- return resourceImportManager.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator,
- lifecycleChangeInfo, isInTransaction, true, needLock, nodeTypeArtifactsToHandle,
- nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeName, isNested)
- .left().on(this::failOnCertification);
- }
+ public ImmutablePair<Resource, ActionStatus> createResourceFromNodeType(String nodeTypeYaml,
+ UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction, boolean needLock,
+ Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo,
+ String nodeName, boolean isNested) {
+
+ LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(CERTIFICATION_ON_IMPORT,
+ LifecycleChanceActionEnum.CREATE_FROM_CSAR);
+ Function<Resource, Boolean> validator = resource -> validateResourceCreationFromNodeType(
+ resource, creator);
+ return resourceImportManager.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator,
+ lifecycleChangeInfo, isInTransaction, true, needLock, nodeTypeArtifactsToHandle,
+ nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeName, isNested);
+ }
- private ImmutablePair<Resource,ActionStatus> failOnCertification(ResponseFormat error) {
- throw new ByResponseFormatComponentException(error);
- }
+ /*private ImmutablePair<Resource, ActionStatus> failOnCertification(ResponseFormat error) {
+ throw new ByResponseFormatComponentException();
+ }*/
- private UploadResourceInfo fillResourceMetadata(String yamlName, Resource resourceVf,
- String nodeName, User user) {
- UploadResourceInfo resourceMetaData = new UploadResourceInfo();
+ private UploadResourceInfo fillResourceMetadata(String yamlName, Resource resourceVf, String nodeName, User user) {
+ UploadResourceInfo resourceMetaData = new UploadResourceInfo();
- // validate nodetype name prefix
- if (!nodeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) {
- log.debug("invalid nodeName:{} does not start with {}.", nodeName,
- Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
- throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE,
- yamlName, resourceMetaData.getName(), nodeName);
- }
+ // validate nodetype name prefix
+ if (!nodeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) {
+ log.debug("invalid nodeName:{} does not start with {}.", nodeName,
+ Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(),
+ nodeName);
+ }
- String actualName = this.getNodeTypeActualName(nodeName);
- String namePrefix = nodeName.replace(actualName, "");
- String resourceType = namePrefix.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+ String actualName = this.getNodeTypeActualName(nodeName);
+ String namePrefix = nodeName.replace(actualName, "");
+ String resourceType = namePrefix.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
- // if we import from csar, the node_type name can be
- // org.openecomp.resource.abstract.node_name - in this case we always
- // create a vfc
- if (resourceType.equals(Constants.ABSTRACT)) {
- resourceType = ResourceTypeEnum.VFC.name().toLowerCase();
- }
- // validating type
- if (!ResourceTypeEnum.containsName(resourceType.toUpperCase())) {
- log.debug("invalid resourceType:{} the type is not one of the valide types:{}.", resourceType.toUpperCase(),
- ResourceTypeEnum.values());
- throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE,
- yamlName, resourceMetaData.getName(), nodeName);
- }
+ // if we import from csar, the node_type name can be
+ // org.openecomp.resource.abstract.node_name - in this case we always
+ // create a vfc
+ if (resourceType.equals(Constants.ABSTRACT)) {
+ resourceType = ResourceTypeEnum.VFC.name()
+ .toLowerCase();
+ }
+ // validating type
+ if (!ResourceTypeEnum.containsName(resourceType.toUpperCase())) {
+ log.debug("invalid resourceType:{} the type is not one of the valide types:{}.", resourceType.toUpperCase(),
+ ResourceTypeEnum.values());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(),
+ nodeName);
+ }
- // Setting name
- resourceMetaData.setName(resourceVf.getSystemName() + actualName);
-
- // Setting type from name
- String type = resourceType.toUpperCase();
- resourceMetaData.setResourceType(type);
-
- resourceMetaData.setDescription(ImportUtils.Constants.INNER_VFC_DESCRIPTION);
- resourceMetaData.setIcon(ImportUtils.Constants.DEFAULT_ICON);
- resourceMetaData.setContactId(user.getUserId());
- resourceMetaData.setVendorName(resourceVf.getVendorName());
- resourceMetaData.setVendorRelease(resourceVf.getVendorRelease());
-
- // Setting tag
- List<String> tags = new ArrayList<>();
- tags.add(resourceMetaData.getName());
- resourceMetaData.setTags(tags);
-
- // Setting category
- CategoryDefinition category = new CategoryDefinition();
- category.setName(ImportUtils.Constants.ABSTRACT_CATEGORY_NAME);
- SubCategoryDefinition subCategory = new SubCategoryDefinition();
- subCategory.setName(ImportUtils.Constants.ABSTRACT_SUBCATEGORY);
- category.addSubCategory(subCategory);
- List<CategoryDefinition> categories = new ArrayList<>();
- categories.add(category);
- resourceMetaData.setCategories(categories);
-
- return resourceMetaData;
- }
+ // Setting name
+ resourceMetaData.setName(resourceVf.getSystemName() + actualName);
+
+ // Setting type from name
+ String type = resourceType.toUpperCase();
+ resourceMetaData.setResourceType(type);
+
+ resourceMetaData.setDescription(ImportUtils.Constants.INNER_VFC_DESCRIPTION);
+ resourceMetaData.setIcon(ImportUtils.Constants.DEFAULT_ICON);
+ resourceMetaData.setContactId(user.getUserId());
+ resourceMetaData.setVendorName(resourceVf.getVendorName());
+ resourceMetaData.setVendorRelease(resourceVf.getVendorRelease());
+
+ // Setting tag
+ List<String> tags = new ArrayList<>();
+ tags.add(resourceMetaData.getName());
+ resourceMetaData.setTags(tags);
+
+ // Setting category
+ CategoryDefinition category = new CategoryDefinition();
+ category.setName(ImportUtils.Constants.ABSTRACT_CATEGORY_NAME);
+ SubCategoryDefinition subCategory = new SubCategoryDefinition();
+ subCategory.setName(ImportUtils.Constants.ABSTRACT_SUBCATEGORY);
+ category.addSubCategory(subCategory);
+ List<CategoryDefinition> categories = new ArrayList<>();
+ categories.add(category);
+ resourceMetaData.setCategories(categories);
+
+ return resourceMetaData;
+ }
- private Resource buildComplexVfcMetadata(Resource resourceVf, CsarInfo csarInfo, String nodeName,
- Map<String, NodeTypeInfo> nodesInfo) {
- Resource cvfc = new Resource();
- NodeTypeInfo nodeTypeInfo = nodesInfo.get(nodeName);
- cvfc.setName(buildCvfcName(csarInfo.getVfResourceName(), nodeName));
- cvfc.setNormalizedName(ValidationUtils.normaliseComponentName(cvfc.getName()));
- cvfc.setSystemName(ValidationUtils.convertToSystemName(cvfc.getName()));
- cvfc.setResourceType(ResourceTypeEnum.CVFC);
- cvfc.setAbstract(true);
- cvfc.setDerivedFrom(nodeTypeInfo.getDerivedFrom());
- cvfc.setDescription(ImportUtils.Constants.CVFC_DESCRIPTION);
- cvfc.setIcon(ImportUtils.Constants.DEFAULT_ICON);
- cvfc.setContactId(csarInfo.getModifier().getUserId());
- cvfc.setCreatorUserId(csarInfo.getModifier().getUserId());
- cvfc.setVendorName(resourceVf.getVendorName());
- cvfc.setVendorRelease(resourceVf.getVendorRelease());
- cvfc.setResourceVendorModelNumber(resourceVf.getResourceVendorModelNumber());
- cvfc.setToscaResourceName(
- buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), csarInfo.getVfResourceName(), nodeName)
- .getLeft());
- cvfc.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
-
- List<String> tags = new ArrayList<>();
- tags.add(cvfc.getName());
- cvfc.setTags(tags);
-
- CategoryDefinition category = new CategoryDefinition();
- category.setName(ImportUtils.Constants.ABSTRACT_CATEGORY_NAME);
- SubCategoryDefinition subCategory = new SubCategoryDefinition();
- subCategory.setName(ImportUtils.Constants.ABSTRACT_SUBCATEGORY);
- category.addSubCategory(subCategory);
- List<CategoryDefinition> categories = new ArrayList<>();
- categories.add(category);
- cvfc.setCategories(categories);
-
- cvfc.setVersion(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION);
- cvfc.setLifecycleState(ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE_NOT_CERTIFIED_CHECKOUT);
- cvfc.setHighestVersion(ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION);
-
- return cvfc;
- }
+ private Resource buildComplexVfcMetadata(Resource resourceVf, CsarInfo csarInfo, String nodeName,
+ Map<String, NodeTypeInfo> nodesInfo) {
+ Resource cvfc = new Resource();
+ NodeTypeInfo nodeTypeInfo = nodesInfo.get(nodeName);
+ cvfc.setName(buildCvfcName(csarInfo.getVfResourceName(), nodeName));
+ cvfc.setNormalizedName(ValidationUtils.normaliseComponentName(cvfc.getName()));
+ cvfc.setSystemName(ValidationUtils.convertToSystemName(cvfc.getName()));
+ cvfc.setResourceType(ResourceTypeEnum.CVFC);
+ cvfc.setAbstract(true);
+ cvfc.setDerivedFrom(nodeTypeInfo.getDerivedFrom());
+ cvfc.setDescription(ImportUtils.Constants.CVFC_DESCRIPTION);
+ cvfc.setIcon(ImportUtils.Constants.DEFAULT_ICON);
+ cvfc.setContactId(csarInfo.getModifier()
+ .getUserId());
+ cvfc.setCreatorUserId(csarInfo.getModifier()
+ .getUserId());
+ cvfc.setVendorName(resourceVf.getVendorName());
+ cvfc.setVendorRelease(resourceVf.getVendorRelease());
+ cvfc.setResourceVendorModelNumber(resourceVf.getResourceVendorModelNumber());
+ cvfc.setToscaResourceName(
+ buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), csarInfo.getVfResourceName(), nodeName)
+ .getLeft());
+ cvfc.setInvariantUUID(UniqueIdBuilder.buildInvariantUUID());
+
+ List<String> tags = new ArrayList<>();
+ tags.add(cvfc.getName());
+ cvfc.setTags(tags);
+
+ CategoryDefinition category = new CategoryDefinition();
+ category.setName(ImportUtils.Constants.ABSTRACT_CATEGORY_NAME);
+ SubCategoryDefinition subCategory = new SubCategoryDefinition();
+ subCategory.setName(ImportUtils.Constants.ABSTRACT_SUBCATEGORY);
+ category.addSubCategory(subCategory);
+ List<CategoryDefinition> categories = new ArrayList<>();
+ categories.add(category);
+ cvfc.setCategories(categories);
+
+ cvfc.setVersion(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION);
+ cvfc.setLifecycleState(ImportUtils.Constants.NORMATIVE_TYPE_LIFE_CYCLE_NOT_CERTIFIED_CHECKOUT);
+ cvfc.setHighestVersion(ImportUtils.Constants.NORMATIVE_TYPE_HIGHEST_VERSION);
+
+ return cvfc;
+ }
- private String buildCvfcName(String resourceVfName, String nodeName) {
- String nameWithouNamespacePrefix = nodeName
- .substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
- String[] findTypes = nameWithouNamespacePrefix.split("\\.");
- String resourceType = findTypes[0];
- String resourceName = resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1);
- return addCvfcSuffixToResourceName(resourceName);
- }
+ private String buildCvfcName(String resourceVfName, String nodeName) {
+ String nameWithouNamespacePrefix = nodeName
+ .substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+ String[] findTypes = nameWithouNamespacePrefix.split("\\.");
+ String resourceType = findTypes[0];
+ String resourceName = resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1);
+ return addCvfcSuffixToResourceName(resourceName);
+ }
- private Resource createResourceAndRIsFromYaml(String yamlName, Resource resource,
- ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative,
- List<ArtifactDefinition> createdArtifacts, String topologyTemplateYaml,
- Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
- boolean shouldLock, boolean inTransaction, String nodeName) {
+ private Resource createResourceAndRIsFromYaml(String yamlName, Resource resource,
+ ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative,
+ List<ArtifactDefinition> createdArtifacts, String topologyTemplateYaml,
+ Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
+ boolean shouldLock, boolean inTransaction, String nodeName) {
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
if (shouldLock) {
Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource,
@@ -1355,16 +1581,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
try {
log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS,resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,"Starting to add inputs from yaml: {}",yamlName);
final Resource genericResource = fetchAndSetDerivedFromGenericType(resource);
- resource = createResourceTransaction(resource, csarInfo.getModifier(), isNormative);
+ resource = createResourceTransaction(resource,
+ csarInfo.getModifier(), isNormative);
log.trace("************* createResourceFromYaml after full create resource {}", yamlName);
log.trace("************* Going to add inputs from yaml {}", yamlName);
- if (resource.shouldGenerateInputs()) {
+ if (resource.shouldGenerateInputs())
generateAndAddInputsFromGenericTypeProperties(resource, genericResource);
- }
+
final Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
resource = createInputsOnResource(resource, inputs);
log.trace("************* Finish to add inputs from yaml {}", yamlName);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.COMPLETE,"Finish to add inputs from yaml: {}",yamlName);
if (resource.getResourceType() == ResourceTypeEnum.PNF) {
log.trace("************* Adding generic properties to PNF");
resource = (Resource) propertyBusinessLogic.copyPropertyToComponent(resource, genericResource.getProperties());
@@ -1372,20 +1602,21 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
softwareInformationBusinessLogic.setSoftwareInformation(resource, csarInfo);
log.trace("************* Removing non-mano software information file from PNF");
if (csarInfo.getSoftwareInformationPath().isPresent() &&
- !softwareInformationBusinessLogic.removeSoftwareInformationFile(csarInfo)) {
+ !softwareInformationBusinessLogic.removeSoftwareInformationFile(csarInfo)) {
log.warn(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR , ResourceBusinessLogic.class.getName(),
- "catalog-be", "Could not remove the software information file.");
+ "catalog-be", "Could not remove the software information file.");
}
}
Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo
.getInstances();
- log.trace("************* Going to create nodes, Resource Instances and Relations from yaml {}", yamlName);
+ log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML,resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,"Start create nodes, RI and Relations from yaml: {}",yamlName);
resource = createRIAndRelationsFromYaml(yamlName, resource, uploadComponentInstanceInfoMap,
topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo,
nodeTypesArtifactsToCreate, nodeName);
-
- log.trace("************* Finished to create nodes, Resource Instances and Relations from yaml {}", yamlName);
+ log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.COMPLETE,"Finished to create nodes, RI and Relation from yaml: {}",yamlName);
// validate update vf module group names
Either<Map<String, GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic
.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), resource.getSystemName());
@@ -1393,1739 +1624,1979 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right().value());
}
-
// add groups to resource
Map<String, GroupDefinition> groups;
log.trace("************* Going to add groups from yaml {}", yamlName);
-
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_GROUPS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.STARTED,"Start to add groups from yaml: {}",yamlName);
if (!validateUpdateVfGroupNamesRes.left().value().isEmpty()) {
groups = validateUpdateVfGroupNamesRes.left().value();
} else {
groups = parsedToscaYamlInfo.getGroups();
}
- Either<Resource, ResponseFormat> createGroupsOnResource = createGroupsOnResource(resource,
- groups);
- if (createGroupsOnResource.isRight()) {
- rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
- throw new ByResponseFormatComponentException(createGroupsOnResource.right().value());
- }
- resource = createGroupsOnResource.left().value();
- log.trace("************* Finished to add groups from yaml {}", yamlName);
-
- log.trace("************* Going to add artifacts from yaml {}", yamlName);
-
- NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName,
- nodeTypesArtifactsToCreate);
-
- Either<Resource, ResponseFormat> createArtifactsEither = createOrUpdateArtifacts(ArtifactOperationEnum.CREATE, createdArtifacts, yamlName,
- csarInfo, resource, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock);
- if (createArtifactsEither.isRight()) {
- rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
- throw new ByResponseFormatComponentException(createArtifactsEither.right().value());
- }
-
- resource = getResourceWithGroups(createArtifactsEither.left().value().getUniqueId());
-
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, actionEnum);
- ASDCKpiApi.countCreatedResourcesKPI();
- return resource;
+ Either<Resource, ResponseFormat> createGroupsOnResource = createGroupsOnResource(resource, groups);
+ if (createGroupsOnResource.isRight()) {
+ rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_GROUPS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR while adding groups from yaml: {}",yamlName);
+ throw new ByResponseFormatComponentException(createGroupsOnResource.right()
+ .value());
+ }
+ resource = createGroupsOnResource.left()
+ .value();
+ log.trace("************* Finished to add groups from yaml {}", yamlName);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_GROUPS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.COMPLETE,"Finished to add groups from yaml: {}",yamlName);
+
+ log.trace("************* Going to add artifacts from yaml {}", yamlName);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_ARTIFACTS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.STARTED,"Started to add artifacts from yaml: {}",yamlName);
+
+ NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName,
+ nodeTypesArtifactsToCreate);
+
+ Either<Resource, ResponseFormat> createArtifactsEither = createOrUpdateArtifacts(
+ ArtifactOperationEnum.CREATE, createdArtifacts, yamlName, csarInfo, resource,
+ nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock);
+ if (createArtifactsEither.isRight()) {
+ rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_ARTIFACTS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"error happened {}",createArtifactsEither.right()
+ .value());
+ throw new ByResponseFormatComponentException(createArtifactsEither.right()
+ .value());
+ }
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_ARTIFACTS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.COMPLETE,"Finished to add artifacts from yaml: "+resource.getToscaResourceName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, actionEnum);
+ ASDCKpiApi.countCreatedResourcesKPI();
+ return resource;
} catch (final ComponentException | StorageException e) {
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw e;
} catch (final ToscaOperationException e) {
- LOGGER.error("An error has occurred during resource and resource instance creation", e);
+ log.error("An error has occurred during resource and resource instance creation", e);
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR
, ResourceBusinessLogic.class.getName(), "catalog-be", e.getMessage());
throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
} catch (final BusinessLogicException e) {
- LOGGER.error("An error has occurred during resource and resource instance creation", e);
+ log.error("An error has occurred during resource and resource instance creation", e);
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ByResponseFormatComponentException(e.getResponseFormat());
} finally {
if (!inTransaction) {
janusGraphDao.commit();
- }
- if (shouldLock) {
- graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(),
- NodeTypeEnum.Resource);
- }
- }
- }
+ }
+ if (shouldLock) {
+ graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(),
+ NodeTypeEnum.Resource);
+ }
+ }
+ }
- private void rollback(boolean inTransaction, Resource resource, List<ArtifactDefinition> createdArtifacts, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) {
- if(!inTransaction) {
+ private void rollback(boolean inTransaction, Resource resource, List<ArtifactDefinition> createdArtifacts,
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts) {
+ if (!inTransaction) {
janusGraphDao.rollback();
- }
- if (isNotEmpty(createdArtifacts) && isNotEmpty(nodeTypesNewCreatedArtifacts)) {
- createdArtifacts.addAll(nodeTypesNewCreatedArtifacts);
- log.debug("Found {} newly created artifacts to deleted, the component name: {}",createdArtifacts.size(), resource.getName());
- }
- }
-
- private Resource getResourceWithGroups(String resourceId) {
-
- ComponentParametersView filter = new ComponentParametersView();
- filter.setIgnoreGroups(false);
- Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade.getToscaElement(resourceId, filter);
- if (updatedResource.isRight()) {
- rollbackWithException(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resourceId);
- }
- return updatedResource.left().value();
- }
-
- private Either<Resource, ResponseFormat> createGroupsOnResource(Resource resource,
- Map<String, GroupDefinition> groups) {
- if (groups != null && !groups.isEmpty()) {
- List<GroupDefinition> groupsAsList = updateGroupsMembersUsingResource(
- groups, resource);
- handleGroupsProperties(resource, groups);
- fillGroupsFinalFields(groupsAsList);
- Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.createGroups(resource,
- groupsAsList, true);
- if (createGroups.isRight()) {
- return Either.right(createGroups.right().value());
- }
- } else {
- return Either.left(resource);
- }
- Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade
- .getToscaElement(resource.getUniqueId());
- if (updatedResource.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource);
- return Either.right(responseFormat);
- }
- return Either.left(updatedResource.left().value());
- }
-
- private void handleGroupsProperties(Resource resource, Map<String, GroupDefinition> groups) {
- List<InputDefinition> inputs = resource.getInputs();
- if (MapUtils.isNotEmpty(groups)) {
- groups.values()
- .stream()
- .filter(g -> isNotEmpty(g.getProperties()))
- .flatMap(g -> g.getProperties().stream())
- .forEach(p -> handleGetInputs(p, inputs));
- }
- }
-
- private void handleGetInputs(PropertyDataDefinition property, List<InputDefinition> inputs) {
- if (isNotEmpty(property.getGetInputValues())) {
- if (inputs == null || inputs.isEmpty()) {
- log.debug("Failed to add property {} to group. Inputs list is empty ", property);
- rollbackWithException(ActionStatus.INPUTS_NOT_FOUND, property.getGetInputValues()
- .stream()
- .map(GetInputValueDataDefinition::getInputName)
- .collect(toList()).toString());
- }
- ListIterator<GetInputValueDataDefinition> getInputValuesIter = property.getGetInputValues().listIterator();
- while (getInputValuesIter.hasNext()) {
- GetInputValueDataDefinition getInput = getInputValuesIter.next();
- InputDefinition input = findInputByName(inputs, getInput);
- getInput.setInputId(input.getUniqueId());
- if (getInput.getGetInputIndex() != null) {
- GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
- input = findInputByName(inputs, getInputIndex);
- getInputIndex.setInputId(input.getUniqueId());
- getInputValuesIter.add(getInputIndex);
- }
- }
- }
- }
-
- private InputDefinition findInputByName(List<InputDefinition> inputs, GetInputValueDataDefinition getInput) {
- Optional<InputDefinition> inputOpt = inputs.stream()
- .filter(p -> p.getName().equals(getInput.getInputName()))
- .findFirst();
- if (!inputOpt.isPresent()) {
- log.debug("#findInputByName - Failed to find the input {} ", getInput.getInputName());
- rollbackWithException(ActionStatus.INPUTS_NOT_FOUND, getInput.getInputName());
- }
- return inputOpt.get();
- }
-
- private void fillGroupsFinalFields(List<GroupDefinition> groupsAsList) {
- groupsAsList.forEach(groupDefinition -> {
- groupDefinition.setInvariantName(groupDefinition.getName());
- groupDefinition.setCreatedFrom(CreatedFrom.CSAR);
- });
- }
-
- private Resource updateGroupsOnResource(Resource resource, Map<String, GroupDefinition> groups) {
- if (isEmpty(groups)) {
- return resource;
- } else {
- updateOrCreateGroups(resource, groups);
- }
- Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade
- .getToscaElement(resource.getUniqueId());
- if (updatedResource.isRight()) {
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource));
- }
- return updatedResource.left().value();
- }
+ }
+ if (isNotEmpty(createdArtifacts) && isNotEmpty(nodeTypesNewCreatedArtifacts)) {
+ createdArtifacts.addAll(nodeTypesNewCreatedArtifacts);
+ log.debug("Found {} newly created artifacts to deleted, the component name: {}", createdArtifacts.size(),
+ resource.getName());
+ }
+ }
- private void updateOrCreateGroups(Resource resource, Map<String, GroupDefinition> groups) {
- List<GroupDefinition> groupsFromResource = resource.getGroups();
- List<GroupDefinition> groupsAsList = updateGroupsMembersUsingResource(groups, resource);
- List<GroupDefinition> groupsToUpdate = new ArrayList<>();
- List<GroupDefinition> groupsToDelete = new ArrayList<>();
- List<GroupDefinition> groupsToCreate = new ArrayList<>();
- if (isNotEmpty(groupsFromResource)) {
- addGroupsToCreateOrUpdate(groupsFromResource, groupsAsList, groupsToUpdate, groupsToCreate);
- addGroupsToDelete(groupsFromResource, groupsAsList, groupsToDelete);
- } else {
- groupsToCreate.addAll(groupsAsList);
- }
- if (isNotEmpty(groupsToCreate)) {
- fillGroupsFinalFields(groupsToCreate);
- if (isNotEmpty(groupsFromResource)) {
- groupBusinessLogic.addGroups(resource,
- groupsToCreate, true)
- .left()
- .on(this::throwComponentException);
- } else {
- groupBusinessLogic.createGroups(resource,
- groupsToCreate, true)
- .left()
- .on(this::throwComponentException);
- }
- }
- if (isNotEmpty(groupsToDelete)) {
- groupBusinessLogic.deleteGroups(resource, groupsToDelete)
- .left()
- .on(this::throwComponentException);
- }
- if (isNotEmpty(groupsToUpdate)) {
- groupBusinessLogic.updateGroups(resource, groupsToUpdate, true)
- .left()
- .on(this::throwComponentException);
- }
- }
+ private Resource getResourceWithGroups(String resourceId) {
- private void addGroupsToDelete(List<GroupDefinition> groupsFromResource, List<GroupDefinition> groupsAsList, List<GroupDefinition> groupsToDelete) {
- for (GroupDefinition group : groupsFromResource) {
- Optional<GroupDefinition> op = groupsAsList.stream()
- .filter(p -> p.getName().equalsIgnoreCase(group.getName())).findAny();
- if (!op.isPresent() && (group.getArtifacts() == null || group.getArtifacts().isEmpty())) {
- groupsToDelete.add(group);
- }
- }
- }
+ ComponentParametersView filter = new ComponentParametersView();
+ filter.setIgnoreGroups(false);
+ Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade.getToscaElement(resourceId,
+ filter);
+ if (updatedResource.isRight()) {
+ rollbackWithException(componentsUtils.convertFromStorageResponse(updatedResource.right()
+ .value()), resourceId);
+ }
+ return updatedResource.left()
+ .value();
+ }
- private void addGroupsToCreateOrUpdate(List<GroupDefinition> groupsFromResource, List<GroupDefinition> groupsAsList, List<GroupDefinition> groupsToUpdate, List<GroupDefinition> groupsToCreate) {
- for (GroupDefinition group : groupsAsList) {
- Optional<GroupDefinition> op = groupsFromResource.stream()
- .filter(p -> p.getInvariantName().equalsIgnoreCase(group.getInvariantName())).findAny();
- if (op.isPresent()) {
- GroupDefinition groupToUpdate = op.get();
- groupToUpdate.setMembers(group.getMembers());
- groupToUpdate.setCapabilities(group.getCapabilities());
- groupToUpdate.setProperties(group.getProperties());
- groupsToUpdate.add(groupToUpdate);
- } else {
- groupsToCreate.add(group);
- }
- }
- }
+ private Either<Resource, ResponseFormat> createGroupsOnResource(Resource resource,
+ Map<String, GroupDefinition> groups) {
+ if (groups != null && !groups.isEmpty()) {
+ List<GroupDefinition> groupsAsList = updateGroupsMembersUsingResource(groups, resource);
+ handleGroupsProperties(resource, groups);
+ fillGroupsFinalFields(groupsAsList);
+ Either<List<GroupDefinition>, ResponseFormat> createGroups = groupBusinessLogic.createGroups(resource,
+ groupsAsList, true);
+ if (createGroups.isRight()) {
+ return Either.right(createGroups.right()
+ .value());
+ }
+ }
+ return Either.left(resource);
+ }
- private Resource createInputsOnResource(Resource resource, Map<String, InputDefinition> inputs) {
- List<InputDefinition> resourceProperties = resource.getInputs();
- if (MapUtils.isNotEmpty(inputs)|| isNotEmpty(resourceProperties)) {
+ private void handleGroupsProperties(Resource resource, Map<String, GroupDefinition> groups) {
+ List<InputDefinition> inputs = resource.getInputs();
+ if (MapUtils.isNotEmpty(groups)) {
+ groups.values()
+ .stream()
+ .filter(g -> isNotEmpty(g.getProperties()))
+ .flatMap(g -> g.getProperties()
+ .stream())
+ .forEach(p -> handleGetInputs(p, inputs));
+ }
+ }
- Either<List<InputDefinition>, ResponseFormat> createInputs = inputsBusinessLogic.createInputsInGraph(inputs,
- resource);
- if (createInputs.isRight()) {
- throw new ByResponseFormatComponentException(createInputs.right().value());
- }
- } else {
- return resource;
- }
- Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade
- .getToscaElement(resource.getUniqueId());
- if (updatedResource.isRight()) {
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource));
- }
- return updatedResource.left().value();
- }
+ private void handleGetInputs(PropertyDataDefinition property, List<InputDefinition> inputs) {
+ if (isNotEmpty(property.getGetInputValues())) {
+ if (inputs == null || inputs.isEmpty()) {
+ log.debug("Failed to add property {} to group. Inputs list is empty ", property);
+ rollbackWithException(ActionStatus.INPUTS_NOT_FOUND, property.getGetInputValues()
+ .stream()
+ .map(GetInputValueDataDefinition::getInputName)
+ .collect(toList())
+ .toString());
+ }
+ ListIterator<GetInputValueDataDefinition> getInputValuesIter = property.getGetInputValues()
+ .listIterator();
+ while (getInputValuesIter.hasNext()) {
+ GetInputValueDataDefinition getInput = getInputValuesIter.next();
+ InputDefinition input = findInputByName(inputs, getInput);
+ getInput.setInputId(input.getUniqueId());
+ if (getInput.getGetInputIndex() != null) {
+ GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
+ input = findInputByName(inputs, getInputIndex);
+ getInputIndex.setInputId(input.getUniqueId());
+ getInputValuesIter.add(getInputIndex);
+ }
+ }
+ }
+ }
- private List<GroupDefinition> updateGroupsMembersUsingResource(Map<String, GroupDefinition> groups, Resource component) {
+ private InputDefinition findInputByName(List<InputDefinition> inputs, GetInputValueDataDefinition getInput) {
+ Optional<InputDefinition> inputOpt = inputs.stream()
+ .filter(p -> p.getName()
+ .equals(getInput.getInputName()))
+ .findFirst();
+ if (!inputOpt.isPresent()) {
+ log.debug("#findInputByName - Failed to find the input {} ", getInput.getInputName());
+ rollbackWithException(ActionStatus.INPUTS_NOT_FOUND, getInput.getInputName());
+ }
+ return inputOpt.get();
+ }
- List<GroupDefinition> result = new ArrayList<>();
- List<ComponentInstance> componentInstances = component.getComponentInstances();
+ private void fillGroupsFinalFields(List<GroupDefinition> groupsAsList) {
+ groupsAsList.forEach(groupDefinition -> {
+ groupDefinition.setInvariantName(groupDefinition.getName());
+ groupDefinition.setCreatedFrom(CreatedFrom.CSAR);
+ });
+ }
- if (groups != null) {
- Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies = validateCyclicGroupsDependencies(groups);
- if (validateCyclicGroupsDependencies.isRight()) {
- throw new ByResponseFormatComponentException(validateCyclicGroupsDependencies.right().value());
- }
- for (Entry<String, GroupDefinition> entry : groups.entrySet()) {
- String groupName = entry.getKey();
- GroupDefinition groupDefinition = entry.getValue();
- GroupDefinition updatedGroupDefinition = new GroupDefinition(groupDefinition);
- updatedGroupDefinition.setMembers(null);
- Map<String, String> members = groupDefinition.getMembers();
- if (members != null) {
- updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
- }
- result.add(updatedGroupDefinition);
- }
- }
- return result;
- }
+ private Resource updateGroupsOnResource(Resource resource, Map<String, GroupDefinition> groups) {
+ if (isEmpty(groups)) {
+ return resource;
+ }
+ return updateOrCreateGroups(resource, groups);
+ }
- private void updateGroupMembers(Map<String, GroupDefinition> groups, GroupDefinition updatedGroupDefinition, Resource component, List<ComponentInstance> componentInstances, String groupName, Map<String, String> members) {
- Set<String> compInstancesNames = members.keySet();
+ private Resource updateOrCreateGroups(Resource resource, Map<String, GroupDefinition> groups) {
+ List<GroupDefinition> groupsFromResource = resource.getGroups();
+ List<GroupDefinition> groupsAsList = updateGroupsMembersUsingResource(groups, resource);
+ List<GroupDefinition> groupsToUpdate = new ArrayList<>();
+ List<GroupDefinition> groupsToDelete = new ArrayList<>();
+ List<GroupDefinition> groupsToCreate = new ArrayList<>();
+ if (isNotEmpty(groupsFromResource)) {
+ addGroupsToCreateOrUpdate(groupsFromResource, groupsAsList, groupsToUpdate, groupsToCreate);
+ addGroupsToDelete(groupsFromResource, groupsAsList, groupsToDelete);
+ } else {
+ groupsToCreate.addAll(groupsAsList);
+ }
+ if (isNotEmpty(groupsToCreate)) {
+ fillGroupsFinalFields(groupsToCreate);
+ if (isNotEmpty(groupsFromResource)) {
+ groupBusinessLogic.addGroups(resource, groupsToCreate, true)
+ .left()
+ .on(this::throwComponentException);
+ } else {
+ groupBusinessLogic.createGroups(resource, groupsToCreate, true)
+ .left()
+ .on(this::throwComponentException);
+ }
+ }
+ if (isNotEmpty(groupsToDelete)) {
+ groupBusinessLogic.deleteGroups(resource, groupsToDelete)
+ .left()
+ .on(this::throwComponentException);
+ }
+ if (isNotEmpty(groupsToUpdate)) {
+ groupBusinessLogic.updateGroups(resource, groupsToUpdate, true)
+ .left()
+ .on(this::throwComponentException);
+ }
+ return resource;
- if (CollectionUtils.isEmpty(componentInstances)) {
- String membersAstString = compInstancesNames.stream().collect(joining(","));
- log.debug("The members: {}, in group: {}, cannot be found in component {}. There are no component instances.",
- membersAstString, groupName, component.getNormalizedName());
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
- ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName,
- component.getNormalizedName(), getComponentTypeForResponse(component)));
- }
- // Find all component instances with the member names
- Map<String, String> memberNames = componentInstances.stream()
- .collect(toMap(ComponentInstance::getName, ComponentInstance::getUniqueId));
- memberNames.putAll(groups.keySet().stream().collect(toMap(g -> g, g -> "")));
- Map<String, String> relevantInstances = memberNames.entrySet().stream()
- .filter(n -> compInstancesNames.contains(n.getKey()))
- .collect(toMap(Entry::getKey, Entry::getValue));
-
- if (relevantInstances == null || relevantInstances.size() != compInstancesNames.size()) {
-
- List<String> foundMembers = new ArrayList<>();
- if (relevantInstances != null) {
- foundMembers = relevantInstances.keySet().stream().collect(toList());
- }
- compInstancesNames.removeAll(foundMembers);
- String membersAstString = compInstancesNames.stream().collect(joining(","));
- log.debug("The members: {}, in group: {}, cannot be found in component: {}", membersAstString,
- groupName, component.getNormalizedName());
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
- ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName,
- component.getNormalizedName(), getComponentTypeForResponse(component)));
- }
- updatedGroupDefinition.setMembers(relevantInstances);
- }
+ }
- /**
- * This Method validates that there is no cyclic group dependencies. meaning
- * group A as member in group B which is member in group A
- *
- * @param allGroups
- * @return
- */
- private Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies(Map<String, GroupDefinition> allGroups) {
+ private void addGroupsToDelete(List<GroupDefinition> groupsFromResource, List<GroupDefinition> groupsAsList,
+ List<GroupDefinition> groupsToDelete) {
+ for (GroupDefinition group : groupsFromResource) {
+ Optional<GroupDefinition> op = groupsAsList.stream()
+ .filter(p -> p.getInvariantName()
+ .equalsIgnoreCase(group.getInvariantName()))
+ .findAny();
+ if (!op.isPresent() && (group.getArtifacts() == null || group.getArtifacts()
+ .isEmpty())) {
+ groupsToDelete.add(group);
+ }
+ }
+ }
- Either<Boolean, ResponseFormat> result = Either.left(true);
- try {
- Iterator<Entry<String, GroupDefinition>> allGroupsItr = allGroups.entrySet().iterator();
- while (allGroupsItr.hasNext() && result.isLeft()) {
- Entry<String, GroupDefinition> groupAEntry = allGroupsItr.next();
- // Fetches a group member A
- String groupAName = groupAEntry.getKey();
- // Finds all group members in group A
- Set<String> allGroupAMembersNames = new HashSet<>();
- fillAllGroupMemebersRecursivly(groupAEntry.getKey(), allGroups, allGroupAMembersNames);
- // If A is a group member of itself found cyclic dependency
- if (allGroupAMembersNames.contains(groupAName)) {
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.GROUP_HAS_CYCLIC_DEPENDENCY, groupAName);
- result = Either.right(responseFormat);
- }
- }
- } catch (Exception e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- result = Either.right(responseFormat);
- log.debug("Exception occured when validateCyclicGroupsDependencies, error is:{}", e.getMessage(), e);
- }
- return result;
- }
+ private void addGroupsToCreateOrUpdate(List<GroupDefinition> groupsFromResource, List<GroupDefinition> groupsAsList,
+ List<GroupDefinition> groupsToUpdate, List<GroupDefinition> groupsToCreate) {
+ for (GroupDefinition group : groupsAsList) {
+ Optional<GroupDefinition> op = groupsFromResource.stream()
+ .filter(p -> p.getInvariantName()
+ .equalsIgnoreCase(group.getInvariantName()))
+ .findAny();
+ if (op.isPresent()) {
+ GroupDefinition groupToUpdate = op.get();
+ groupToUpdate.setMembers(group.getMembers());
+ groupToUpdate.setCapabilities(group.getCapabilities());
+ groupToUpdate.setProperties(group.getProperties());
+ groupsToUpdate.add(groupToUpdate);
+ } else {
+ groupsToCreate.add(group);
+ }
+ }
+ }
- /**
- * This Method fills recursively the set groupMembers with all the members
- * of the given group which are also of type group.
- *
- * @param groupName
- * @param allGroups
- * @param allGroupMembers
- * @return
- */
- private void fillAllGroupMemebersRecursivly(String groupName, Map<String, GroupDefinition> allGroups,
- Set<String> allGroupMembers) {
-
- // Found Cyclic dependency
- if (isfillGroupMemebersRecursivlyStopCondition(groupName, allGroups, allGroupMembers)) {
- return;
- }
- GroupDefinition groupDefinition = allGroups.get(groupName);
- // All Members Of Current Group Resource Instances & Other Groups
- Set<String> currGroupMembers = groupDefinition.getMembers().keySet();
- // Filtered Members Of Current Group containing only members which
- // are groups
- List<String> currGroupFilteredMembers = currGroupMembers.stream().
- // Keep Only Elements of type group and not Resource Instances
- filter(allGroups::containsKey).
- // Add Filtered Elements to main Set
- peek(allGroupMembers::add).
- // Collect results
- collect(toList());
-
- // Recursively call the method for all the filtered group members
- for (String innerGroupName : currGroupFilteredMembers) {
- fillAllGroupMemebersRecursivly(innerGroupName, allGroups, allGroupMembers);
- }
+ private Resource createInputsOnResource(Resource resource, Map<String, InputDefinition> inputs) {
+ List<InputDefinition> resourceProperties = resource.getInputs();
+ if (MapUtils.isNotEmpty(inputs) || isNotEmpty(resourceProperties)) {
+
+ Either<List<InputDefinition>, ResponseFormat> createInputs = inputsBusinessLogic.createInputsInGraph(inputs,
+ resource);
+ if (createInputs.isRight()) {
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"failed to add inputs from yaml: {}",createInputs.right()
+ .value());
+ throw new ByResponseFormatComponentException(createInputs.right()
+ .value());
+ }
+ resource.setInputs(createInputs.left().value());
+ }
+ return resource;
+ }
- }
+ private List<GroupDefinition> updateGroupsMembersUsingResource(Map<String, GroupDefinition> groups,
+ Resource component) {
- private boolean isfillGroupMemebersRecursivlyStopCondition(String groupName, Map<String, GroupDefinition> allGroups,
- Set<String> allGroupMembers) {
+ List<GroupDefinition> result = new ArrayList<>();
+ List<ComponentInstance> componentInstances = component.getComponentInstances();
- boolean stop = false;
- // In Case Not Group Stop
- if (!allGroups.containsKey(groupName)) {
- stop = true;
- }
- // In Case Group Has no members stop
- if (!stop) {
- GroupDefinition groupDefinition = allGroups.get(groupName);
- stop = isEmpty(groupDefinition.getMembers());
+ if (groups != null) {
+ Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies = validateCyclicGroupsDependencies(groups);
+ if (validateCyclicGroupsDependencies.isRight()) {
+ throw new ByResponseFormatComponentException(validateCyclicGroupsDependencies.right().value());
+ }
+ for (Entry<String, GroupDefinition> entry : groups.entrySet()) {
+ String groupName = entry.getKey();
+ GroupDefinition groupDefinition = entry.getValue();
+ GroupDefinition updatedGroupDefinition = new GroupDefinition(groupDefinition);
+ updatedGroupDefinition.setMembers(null);
+ Map<String, String> members = groupDefinition.getMembers();
+ if (members != null) {
+ updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName,
+ members);
+ }
+ result.add(updatedGroupDefinition);
+ }
+ }
+ return result;
+ }
- }
- // In Case all group members already contained stop
- if (!stop) {
- final Set<String> allMembers = allGroups.get(groupName).getMembers().keySet();
- Set<String> membersOfTypeGroup = allMembers.stream().
- // Filter In Only Group members
- filter(allGroups::containsKey).
- // Collect
- collect(toSet());
- stop = allGroupMembers.containsAll(membersOfTypeGroup);
- }
- return stop;
- }
+ private void updateGroupMembers(Map<String, GroupDefinition> groups, GroupDefinition updatedGroupDefinition,
+ Resource component, List<ComponentInstance> componentInstances, String groupName,
+ Map<String, String> members) {
+ Set<String> compInstancesNames = members.keySet();
+
+ if (CollectionUtils.isEmpty(componentInstances)) {
+ String membersAstString = compInstancesNames.stream()
+ .collect(joining(","));
+ log.debug(
+ "The members: {}, in group: {}, cannot be found in component {}. There are no component instances.",
+ membersAstString, groupName, component.getNormalizedName());
+ throw new ByActionStatusComponentException(
+ ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString,
+ groupName, component.getNormalizedName(), getComponentTypeForResponse(component));
+ }
+ // Find all component instances with the member names
+ Map<String, String> memberNames = componentInstances.stream()
+ .collect(toMap(ComponentInstance::getName, ComponentInstance::getUniqueId));
+ memberNames.putAll(groups.keySet()
+ .stream()
+ .collect(toMap(g -> g, g -> "")));
+ Map<String, String> relevantInstances = memberNames.entrySet()
+ .stream()
+ .filter(n -> compInstancesNames.contains(n.getKey()))
+ .collect(toMap(Entry::getKey, Entry::getValue));
+
+ if (relevantInstances == null || relevantInstances.size() != compInstancesNames.size()) {
+
+ List<String> foundMembers = new ArrayList<>();
+ if (relevantInstances != null) {
+ foundMembers = relevantInstances.keySet()
+ .stream()
+ .collect(toList());
+ }
+ compInstancesNames.removeAll(foundMembers);
+ String membersAstString = compInstancesNames.stream()
+ .collect(joining(","));
+ log.debug("The members: {}, in group: {}, cannot be found in component: {}", membersAstString, groupName,
+ component.getNormalizedName());
+ throw new ByActionStatusComponentException(
+ ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString,
+ groupName, component.getNormalizedName(), getComponentTypeForResponse(component));
+ }
+ updatedGroupDefinition.setMembers(relevantInstances);
+ }
- private Resource createRIAndRelationsFromYaml(String yamlName, Resource resource,
- Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap,
- String topologyTemplateYaml, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
- Map<String, NodeTypeInfo> nodeTypesInfo, CsarInfo csarInfo,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
- String nodeName) {
-
- log.debug("************* Going to create all nodes {}", yamlName);
- handleNodeTypes(yamlName, resource, topologyTemplateYaml, false, nodeTypesArtifactsToCreate, nodeTypesNewCreatedArtifacts,
- nodeTypesInfo, csarInfo, nodeName);
- log.debug("************* Finished to create all nodes {}", yamlName);
- log.debug("************* Going to create all resource instances {}", yamlName);
- resource = createResourceInstances(yamlName, resource,
- uploadComponentInstanceInfoMap, csarInfo.getCreatedNodes());
- log.debug("************* Finished to create all resource instances {}", yamlName);
- log.debug("************* Going to create all relations {}", yamlName);
- resource = createResourceInstancesRelations(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap);
- log.debug("************* Finished to create all relations {}", yamlName);
- log.debug("************* Going to create positions {}", yamlName);
- compositionBusinessLogic.setPositionsForComponentInstances(resource, csarInfo.getModifier().getUserId());
- log.debug("************* Finished to set positions {}", yamlName);
- return resource;
- }
+ /**
+ * This Method validates that there is no cyclic group dependencies. meaning
+ * group A as member in group B which is member in group A
+ *
+ * @param allGroups
+ * @return
+ */
+ private Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies(Map<String, GroupDefinition> allGroups) {
+
+ Either<Boolean, ResponseFormat> result = Either.left(true);
+ try {
+ Iterator<Entry<String, GroupDefinition>> allGroupsItr = allGroups.entrySet()
+ .iterator();
+ while (allGroupsItr.hasNext() && result.isLeft()) {
+ Entry<String, GroupDefinition> groupAEntry = allGroupsItr.next();
+ // Fetches a group member A
+ String groupAName = groupAEntry.getKey();
+ // Finds all group members in group A
+ Set<String> allGroupAMembersNames = new HashSet<>();
+ fillAllGroupMemebersRecursivly(groupAEntry.getKey(), allGroups, allGroupAMembersNames);
+ // If A is a group member of itself found cyclic dependency
+ if (allGroupAMembersNames.contains(groupAName)) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.GROUP_HAS_CYCLIC_DEPENDENCY, groupAName);
+ result = Either.right(responseFormat);
+ }
+ }
+ } catch (Exception e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ result = Either.right(responseFormat);
+ log.debug("Exception occurred when validateCyclicGroupsDependencies, error is:{}", e.getMessage(), e);
+ }
+ return result;
+ }
- private void handleAndAddExtractedVfcsArtifacts(List<ArtifactDefinition> vfcArtifacts,
- List<ArtifactDefinition> artifactsToAdd) {
- List<String> vfcArtifactNames = vfcArtifacts.stream().map(ArtifactDataDefinition::getArtifactName)
- .collect(toList());
- artifactsToAdd.stream().forEach(a -> {
- if (!vfcArtifactNames.contains(a.getArtifactName())) {
- vfcArtifacts.add(a);
- } else {
- log.debug("Can't upload two artifact with the same name {}. ", a.getArtifactName());
- }
- });
+ /**
+ * This Method fills recursively the set groupMembers with all the members
+ * of the given group which are also of type group.
+ *
+ * @param groupName
+ * @param allGroups
+ * @param allGroupMembers
+ * @return
+ */
+ private void fillAllGroupMemebersRecursivly(String groupName, Map<String, GroupDefinition> allGroups,
+ Set<String> allGroupMembers) {
+
+ // Found Cyclic dependency
+ if (isfillGroupMemebersRecursivlyStopCondition(groupName, allGroups, allGroupMembers)) {
+ return;
+ }
+ GroupDefinition groupDefinition = allGroups.get(groupName);
+ // All Members Of Current Group Resource Instances & Other Groups
+ Set<String> currGroupMembers = groupDefinition.getMembers()
+ .keySet();
+ // Filtered Members Of Current Group containing only members which
+ // are groups
+ List<String> currGroupFilteredMembers = currGroupMembers.stream()
+ .
+ // Keep Only Elements of type group and not Resource Instances
+ filter(allGroups::containsKey)
+ .
+ // Add Filtered Elements to main Set
+ peek(allGroupMembers::add)
+ .
+ // Collect results
+ collect(toList());
+
+ // Recursively call the method for all the filtered group members
+ for (String innerGroupName : currGroupFilteredMembers) {
+ fillAllGroupMemebersRecursivly(innerGroupName, allGroups, allGroupMembers);
+ }
- }
+ }
- @SuppressWarnings("unchecked")
- private void handleNodeTypes(String yamlName, Resource resource,
- String topologyTemplateYaml, boolean needLock,
- Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
- List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo,
- CsarInfo csarInfo, String nodeName) {
- try{
- for (Entry<String, NodeTypeInfo> nodeTypeEntry : nodeTypesInfo.entrySet()) {
- if (nodeTypeEntry.getValue().isNested()) {
-
- handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts,
- nodeTypesInfo, csarInfo, nodeTypeEntry.getKey());
- log.trace("************* finished to create node {}", nodeTypeEntry.getKey());
- }
- }
- Map<String, Object> mappedToscaTemplate = null;
- if (StringUtils.isNotEmpty(nodeName) && isNotEmpty(nodeTypesInfo)
- && nodeTypesInfo.containsKey(nodeName)) {
- mappedToscaTemplate = nodeTypesInfo.get(nodeName).getMappedToscaTemplate();
- }
- if (isEmpty(mappedToscaTemplate)) {
- mappedToscaTemplate = (Map<String, Object>) new Yaml().load(topologyTemplateYaml);
- }
- createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock, nodeTypesArtifactsToHandle,
- nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo);
- } catch(ByActionStatusComponentException e){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
- throw e;
- } catch(ByResponseFormatComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat();
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
- throw e;
- } catch (StorageException e){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
- componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
- throw e;
- }
- }
+ private boolean isfillGroupMemebersRecursivlyStopCondition(String groupName, Map<String, GroupDefinition> allGroups,
+ Set<String> allGroupMembers) {
- private Either<Resource, ResponseFormat> handleVfCsarArtifacts(Resource resource, CsarInfo csarInfo,
- List<ArtifactDefinition> createdArtifacts, ArtifactOperationInfo artifactOperation, boolean shouldLock,
- boolean inTransaction) {
-
- if (csarInfo.getCsar() != null) {
- String vendorLicenseModelId = null;
- String vfLicenseModelId = null;
-
- if (artifactOperation.getArtifactOperationEnum() == ArtifactOperationEnum.UPDATE) {
- Map<String, ArtifactDefinition> deploymentArtifactsMap = resource.getDeploymentArtifacts();
- if (deploymentArtifactsMap != null && !deploymentArtifactsMap.isEmpty()) {
- for (Entry<String, ArtifactDefinition> artifactEntry : deploymentArtifactsMap.entrySet()) {
- if (artifactEntry.getValue().getArtifactName().equalsIgnoreCase(Constants.VENDOR_LICENSE_MODEL)) {
- vendorLicenseModelId = artifactEntry.getValue().getUniqueId();
- }
- if (artifactEntry.getValue().getArtifactName().equalsIgnoreCase(Constants.VF_LICENSE_MODEL)) {
- vfLicenseModelId = artifactEntry.getValue().getUniqueId();
- }
- }
- }
+ boolean stop = false;
+ // In Case Not Group Stop
+ if (!allGroups.containsKey(groupName)) {
+ stop = true;
+ }
+ // In Case Group Has no members stop
+ if (!stop) {
+ GroupDefinition groupDefinition = allGroups.get(groupName);
+ stop = isEmpty(groupDefinition.getMembers());
- }
- // Specific Behavior for license artifacts
- createOrUpdateSingleNonMetaArtifact(resource, csarInfo,
- CsarUtils.ARTIFACTS_PATH + Constants.VENDOR_LICENSE_MODEL, Constants.VENDOR_LICENSE_MODEL,
- ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
- Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME,
- Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId, artifactOperation, null, true, shouldLock,
- inTransaction);
- createOrUpdateSingleNonMetaArtifact(resource, csarInfo,
- CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL,
- ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VF_LICENSE_LABEL,
- Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId,
- artifactOperation, null, true, shouldLock, inTransaction);
-
- Either<Resource, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, resource,
- createdArtifacts, shouldLock, inTransaction, artifactOperation);
- if (eitherCreateResult.isRight()) {
- return Either.right(eitherCreateResult.right().value());
- }
- Either<Resource, StorageOperationStatus> eitherGerResource = toscaOperationFacade
- .getToscaElement(resource.getUniqueId());
- if (eitherGerResource.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource);
+ }
+ // In Case all group members already contained stop
+ if (!stop) {
+ final Set<String> allMembers = allGroups.get(groupName)
+ .getMembers()
+ .keySet();
+ Set<String> membersOfTypeGroup = allMembers.stream()
+ .
+ // Filter In Only Group members
+ filter(allGroups::containsKey)
+ .
+ // Collect
+ collect(toSet());
+ stop = allGroupMembers.containsAll(membersOfTypeGroup);
+ }
+ return stop;
+ }
- return Either.right(responseFormat);
+ private Resource createRIAndRelationsFromYaml(String yamlName, Resource resource,
+ Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap, String topologyTemplateYaml,
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo,
+ CsarInfo csarInfo,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
+ String nodeName) {
+
+ log.debug("************* Going to create all nodes {}", yamlName);
+ handleNodeTypes(yamlName, resource, topologyTemplateYaml, false, nodeTypesArtifactsToCreate,
+ nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeName);
+ log.debug("************* Finished to create all nodes {}", yamlName);
+ log.debug("************* Going to create all resource instances {}", yamlName);
+ Map<String, Resource> existingNodeTypesByResourceNames = new HashMap<>();
+ resource = createResourceInstances(yamlName, resource, null, uploadComponentInstanceInfoMap,
+ csarInfo.getCreatedNodes(), existingNodeTypesByResourceNames);
+ log.debug("************* Finished to create all resource instances {}", yamlName);
+ log.debug("************* Going to create all relations {}", yamlName);
+ resource = createResourceInstancesRelations(csarInfo.getModifier(), yamlName, resource, null, uploadComponentInstanceInfoMap, existingNodeTypesByResourceNames);
+ log.debug("************* Finished to create all relations {}", yamlName);
+ log.debug("************* Going to create positions {}", yamlName);
+ compositionBusinessLogic.setPositionsForComponentInstances(resource, csarInfo.getModifier()
+ .getUserId());
+ log.debug("************* Finished to set positions {}", yamlName);
+ return resource;
+ }
- }
- resource = eitherGerResource.left().value();
-
- Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils.getArtifactsMeta(csarInfo.getCsar(), csarInfo.getCsarUUID(), componentsUtils);
-
- if (artifacsMetaCsarStatus.isLeft()) {
- String artifactsFileName = artifacsMetaCsarStatus.left().value().getKey();
- String artifactsContents = artifacsMetaCsarStatus.left().value().getValue();
- Either<Resource, ResponseFormat> createArtifactsFromCsar;
- if (ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum())) {
- createArtifactsFromCsar = csarArtifactsAndGroupsBusinessLogic.createResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
- } else {
- createArtifactsFromCsar = csarArtifactsAndGroupsBusinessLogic.updateResourceArtifactsFromCsar(csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock, inTransaction);
- }
+ private void handleAndAddExtractedVfcsArtifacts(List<ArtifactDefinition> vfcArtifacts,
+ List<ArtifactDefinition> artifactsToAdd) {
+ List<String> vfcArtifactNames = vfcArtifacts.stream()
+ .map(ArtifactDataDefinition::getArtifactName)
+ .collect(toList());
+ artifactsToAdd.stream()
+ .forEach(a -> {
+ if (!vfcArtifactNames.contains(a.getArtifactName())) {
+ vfcArtifacts.add(a);
+ } else {
+ log.debug("Can't upload two artifact with the same name {}. ", a.getArtifactName());
+ }
+ });
- if (createArtifactsFromCsar.isRight()) {
- log.debug("Couldn't create artifacts from artifacts.meta");
- return Either.right(createArtifactsFromCsar.right().value());
- }
+ }
- return Either.left(createArtifactsFromCsar.left().value());
- } else {
+ @SuppressWarnings("unchecked")
+ private void handleNodeTypes(String yamlName, Resource resource, String topologyTemplateYaml, boolean needLock,
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo,
+ CsarInfo csarInfo, String nodeName) {
+ try {
+ for (Entry<String, NodeTypeInfo> nodeTypeEntry : nodeTypesInfo.entrySet()) {
+ if (nodeTypeEntry.getValue()
+ .isNested()) {
+
+ handleNestedVfc(resource, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
+ csarInfo, nodeTypeEntry.getKey());
+ log.trace("************* finished to create node {}", nodeTypeEntry.getKey());
+ }
+ }
+ Map<String, Object> mappedToscaTemplate = null;
+ if (StringUtils.isNotEmpty(nodeName) && isNotEmpty(nodeTypesInfo) && nodeTypesInfo.containsKey(nodeName)) {
+ mappedToscaTemplate = nodeTypesInfo.get(nodeName)
+ .getMappedToscaTemplate();
+ }
+ if (isEmpty(mappedToscaTemplate)) {
+ mappedToscaTemplate = (Map<String, Object>) new Yaml().load(topologyTemplateYaml);
+ }
+ createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock,
+ nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo);
+ } catch (ComponentException e) {
+ ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
+ : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource,
+ AuditingActionEnum.IMPORT_RESOURCE);
+ throw e;
+ } catch (StorageException e) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource,
+ AuditingActionEnum.IMPORT_RESOURCE);
+ throw e;
+ }
+ }
- return csarArtifactsAndGroupsBusinessLogic.deleteVFModules(resource, csarInfo, shouldLock, inTransaction);
+ private Either<Resource, ResponseFormat> handleVfCsarArtifacts(Resource resource, CsarInfo csarInfo,
+ List<ArtifactDefinition> createdArtifacts, ArtifactOperationInfo artifactOperation, boolean shouldLock,
+ boolean inTransaction) {
+
+ if (csarInfo.getCsar() != null) {
+ String vendorLicenseModelId = null;
+ String vfLicenseModelId = null;
+
+ if (artifactOperation.getArtifactOperationEnum() == ArtifactOperationEnum.UPDATE) {
+ Map<String, ArtifactDefinition> deploymentArtifactsMap = resource.getDeploymentArtifacts();
+ if (deploymentArtifactsMap != null && !deploymentArtifactsMap.isEmpty()) {
+ for (Entry<String, ArtifactDefinition> artifactEntry : deploymentArtifactsMap.entrySet()) {
+ if (artifactEntry.getValue()
+ .getArtifactName()
+ .equalsIgnoreCase(Constants.VENDOR_LICENSE_MODEL)) {
+ vendorLicenseModelId = artifactEntry.getValue()
+ .getUniqueId();
+ }
+ if (artifactEntry.getValue()
+ .getArtifactName()
+ .equalsIgnoreCase(Constants.VF_LICENSE_MODEL)) {
+ vfLicenseModelId = artifactEntry.getValue()
+ .getUniqueId();
+ }
+ }
+ }
- }
- }
- return Either.left(resource);
- }
+ }
+ // Specific Behavior for license artifacts
+ createOrUpdateSingleNonMetaArtifact(resource, csarInfo,
+ CsarUtils.ARTIFACTS_PATH + Constants.VENDOR_LICENSE_MODEL, Constants.VENDOR_LICENSE_MODEL,
+ ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
+ Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME,
+ Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId, artifactOperation, null, true,
+ shouldLock, inTransaction);
+ createOrUpdateSingleNonMetaArtifact(resource, csarInfo,
+ CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL,
+ ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VF_LICENSE_LABEL,
+ Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId,
+ artifactOperation, null, true, shouldLock, inTransaction);
+
+ Either<Resource, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, resource,
+ createdArtifacts, shouldLock, inTransaction, artifactOperation);
+ if (eitherCreateResult.isRight()) {
+ return Either.right(eitherCreateResult.right()
+ .value());
+ }
+ Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils
+ .getArtifactsMeta(csarInfo.getCsar(), csarInfo.getCsarUUID(), componentsUtils);
+
+ if (artifacsMetaCsarStatus.isLeft()) {
+ String artifactsFileName = artifacsMetaCsarStatus.left()
+ .value()
+ .getKey();
+ String artifactsContents = artifacsMetaCsarStatus.left()
+ .value()
+ .getValue();
+ Either<Resource, ResponseFormat> createArtifactsFromCsar;
+ if (ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum())) {
+ createArtifactsFromCsar = csarArtifactsAndGroupsBusinessLogic.createResourceArtifactsFromCsar(
+ csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts);
+ } else {
+ createArtifactsFromCsar = csarArtifactsAndGroupsBusinessLogic.updateResourceArtifactsFromCsar(
+ csarInfo, resource, artifactsContents, artifactsFileName, createdArtifacts, shouldLock,
+ inTransaction);
+ }
+
+ if (createArtifactsFromCsar.isRight()) {
+ log.debug("Couldn't create artifacts from artifacts.meta");
+ return Either.right(createArtifactsFromCsar.right()
+ .value());
+ }
+
+ return Either.left(createArtifactsFromCsar.left()
+ .value());
+ } else {
+
+ return csarArtifactsAndGroupsBusinessLogic.deleteVFModules(resource, csarInfo, shouldLock,
+ inTransaction);
- private Either<Boolean, ResponseFormat> createOrUpdateSingleNonMetaArtifact(Resource resource, CsarInfo csarInfo,
- String artifactPath, String artifactFileName, String artifactType, ArtifactGroupTypeEnum artifactGroupType,
- String artifactLabel, String artifactDisplayName, String artifactDescription, String artifactId,
- ArtifactOperationInfo operation, List<ArtifactDefinition> createdArtifacts, boolean isFromCsar, boolean shouldLock,
- boolean inTransaction) {
- byte[] artifactFileBytes = null;
+ }
+ }
+ return Either.left(resource);
+ }
- if (csarInfo.getCsar().containsKey(artifactPath)) {
- artifactFileBytes = csarInfo.getCsar().get(artifactPath);
- }
- Either<Boolean, ResponseFormat> result = Either.left(true);
- if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.UPDATE || operation.getArtifactOperationEnum() == ArtifactOperationEnum.DELETE) {
- if (isArtifactDeletionRequired(artifactId, artifactFileBytes, isFromCsar)) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic.handleDelete(resource.getUniqueId(), artifactId, csarInfo.getModifier(), AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource,
- shouldLock, inTransaction);
- if (handleDelete.isRight()) {
- result = Either.right(handleDelete.right().value());
- }
- return result;
- }
+ private Either<Boolean, ResponseFormat> createOrUpdateSingleNonMetaArtifact(Resource resource, CsarInfo csarInfo,
+ String artifactPath, String artifactFileName, String artifactType, ArtifactGroupTypeEnum artifactGroupType,
+ String artifactLabel, String artifactDisplayName, String artifactDescription, String artifactId,
+ ArtifactOperationInfo operation, List<ArtifactDefinition> createdArtifacts, boolean isFromCsar,
+ boolean shouldLock, boolean inTransaction) {
+ byte[] artifactFileBytes = null;
+
+ if (csarInfo.getCsar()
+ .containsKey(artifactPath)) {
+ artifactFileBytes = csarInfo.getCsar()
+ .get(artifactPath);
+ }
+ Either<Boolean, ResponseFormat> result = Either.left(true);
+ if (operation.getArtifactOperationEnum() == ArtifactOperationEnum.UPDATE
+ || operation.getArtifactOperationEnum() == ArtifactOperationEnum.DELETE) {
+ if (isArtifactDeletionRequired(artifactId, artifactFileBytes, isFromCsar)) {
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> handleDelete = artifactsBusinessLogic
+ .handleDelete(resource.getUniqueId(), artifactId, csarInfo.getModifier(),
+ AuditingActionEnum.ARTIFACT_DELETE, ComponentTypeEnum.RESOURCE, resource, shouldLock,
+ inTransaction);
+ if (handleDelete.isRight()) {
+ result = Either.right(handleDelete.right()
+ .value());
+ } else {
+ Either<ArtifactDefinition, Operation> value = handleDelete.left().value();
+ if (value.isLeft()) {
+ String updatedArtifactId = value.left().value().getUniqueId();
+ if (artifactGroupType == ArtifactGroupTypeEnum.DEPLOYMENT) {
+ resource.getDeploymentArtifacts().remove(updatedArtifactId);
+ } else {
+ resource.getArtifacts().remove(updatedArtifactId);
+ }
+ }
+ }
+ return result;
+ }
+ if (StringUtils.isEmpty(artifactId) && artifactFileBytes != null) {
+ operation = artifactsBusinessLogic.new ArtifactOperationInfo(false, false,
+ ArtifactOperationEnum.CREATE);
+ }
- if (StringUtils.isEmpty(artifactId) && artifactFileBytes != null) {
- operation = artifactsBusinessLogic.new ArtifactOperationInfo(false, false,
- ArtifactOperationEnum.CREATE);
- }
+ }
+ if (artifactFileBytes != null) {
+ Map<String, Object> vendorLicenseModelJson = ArtifactUtils.buildJsonForUpdateArtifact(artifactId,
+ artifactFileName, artifactType, artifactGroupType, artifactLabel, artifactDisplayName,
+ artifactDescription, artifactFileBytes, null, isFromCsar);
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherNonMetaArtifacts = csarArtifactsAndGroupsBusinessLogic
+ .createOrUpdateCsarArtifactFromJson(resource, csarInfo.getModifier(), vendorLicenseModelJson,
+ operation);
+ addNonMetaCreatedArtifactsToSupportRollback(operation, createdArtifacts, eitherNonMetaArtifacts);
+ if (eitherNonMetaArtifacts.isRight()) {
+ BeEcompErrorManager.getInstance()
+ .logInternalFlowError("UploadLicenseArtifact", "Failed to upload license artifact: "
+ + artifactFileName + "With csar uuid: " + csarInfo.getCsarUUID(),
+ ErrorSeverity.WARNING);
+ return Either.right(eitherNonMetaArtifacts.right()
+ .value());
+ }
+ ArtifactDefinition artifactDefinition = eitherNonMetaArtifacts.left().value().left().value();
+ createOrUpdateResourceWithUpdatedArtifact(artifactDefinition,resource, artifactGroupType);
+ }
- }
- if (artifactFileBytes != null) {
- Map<String, Object> vendorLicenseModelJson = ArtifactUtils.buildJsonForUpdateArtifact(artifactId, artifactFileName,
- artifactType, artifactGroupType, artifactLabel, artifactDisplayName, artifactDescription,
- artifactFileBytes, null, isFromCsar);
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherNonMetaArtifacts = csarArtifactsAndGroupsBusinessLogic.createOrUpdateCsarArtifactFromJson(
- resource, csarInfo.getModifier(), vendorLicenseModelJson, operation);
- addNonMetaCreatedArtifactsToSupportRollback(operation, createdArtifacts, eitherNonMetaArtifacts);
- if (eitherNonMetaArtifacts.isRight()) {
- BeEcompErrorManager.getInstance()
- .logInternalFlowError("UploadLicenseArtifact", "Failed to upload license artifact: "
- + artifactFileName + "With csar uuid: " + csarInfo.getCsarUUID(),
- ErrorSeverity.WARNING);
- return Either.right(eitherNonMetaArtifacts.right().value());
- }
- }
- return result;
- }
+ return result;
+ }
- private boolean isArtifactDeletionRequired(String artifactId, byte[] artifactFileBytes, boolean isFromCsar) {
- return !StringUtils.isEmpty(artifactId) && artifactFileBytes == null && isFromCsar;
- }
+ private void createOrUpdateResourceWithUpdatedArtifact(ArtifactDefinition artifact, Resource resource, ArtifactGroupTypeEnum groupTypeEnum) {
+ if (groupTypeEnum == ArtifactGroupTypeEnum.DEPLOYMENT) {
+ resource.getDeploymentArtifacts().put(artifact.getArtifactLabel(), artifact);
+ } else {
+ resource.getArtifacts().put(artifact.getArtifactLabel(), artifact);
+ }
+ }
+ private boolean isArtifactDeletionRequired(String artifactId, byte[] artifactFileBytes, boolean isFromCsar) {
+ return !StringUtils.isEmpty(artifactId) && artifactFileBytes == null && isFromCsar;
+ }
- private void addNonMetaCreatedArtifactsToSupportRollback(ArtifactOperationInfo operation,
- List<ArtifactDefinition> createdArtifacts,
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherNonMetaArtifacts) {
- if (ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum()) && createdArtifacts != null
- && eitherNonMetaArtifacts.isLeft()) {
- Either<ArtifactDefinition, Operation> eitherResult = eitherNonMetaArtifacts.left().value();
- if (eitherResult.isLeft()) {
- createdArtifacts.add(eitherResult.left().value());
- }
- }
- }
+ private void addNonMetaCreatedArtifactsToSupportRollback(ArtifactOperationInfo operation,
+ List<ArtifactDefinition> createdArtifacts,
+ Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherNonMetaArtifacts) {
+ if (ArtifactOperationEnum.isCreateOrLink(operation.getArtifactOperationEnum()) && createdArtifacts != null
+ && eitherNonMetaArtifacts.isLeft()) {
+ Either<ArtifactDefinition, Operation> eitherResult = eitherNonMetaArtifacts.left()
+ .value();
+ if (eitherResult.isLeft()) {
+ createdArtifacts.add(eitherResult.left()
+ .value());
+ }
+ }
+ }
+ private Either<Resource, ResponseFormat> createOrUpdateNonMetaArtifacts(CsarInfo csarInfo, Resource resource,
+ List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction,
+ ArtifactOperationInfo artifactOperation) {
- private Either<Resource, ResponseFormat> createOrUpdateNonMetaArtifacts(CsarInfo csarInfo, Resource resource,
- List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction,
- ArtifactOperationInfo artifactOperation) {
+ Either<Resource, ResponseFormat> resStatus = null;
+ Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
- Either<Resource, ResponseFormat> resStatus = null;
- Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
+ try {
+ Either<List<NonMetaArtifactInfo>, String> artifactPathAndNameList = getValidArtifactNames(csarInfo,
+ collectedWarningMessages);
+ if (artifactPathAndNameList.isRight()) {
+ return Either.right(getComponentsUtils().getResponseFormatByArtifactId(
+ ActionStatus.ARTIFACT_NAME_INVALID, artifactPathAndNameList.right()
+ .value()));
+ }
+ EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> vfCsarArtifactsToHandle = null;
+
+ if (ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum())) {
+ vfCsarArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
+ vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList.left()
+ .value());
+ } else {
+ Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(
+ resource, artifactPathAndNameList.left()
+ .value(),
+ csarInfo.getModifier());
+
+ if (findVfCsarArtifactsToHandleRes.isRight()) {
+ resStatus = Either.right(findVfCsarArtifactsToHandleRes.right()
+ .value());
+ }
+ if (resStatus == null) {
+ vfCsarArtifactsToHandle = findVfCsarArtifactsToHandleRes.left()
+ .value();
+ }
+ }
+ if (resStatus == null && vfCsarArtifactsToHandle != null) {
+ resStatus = processCsarArtifacts(csarInfo, resource, createdArtifacts, shouldLock, inTransaction,
+ resStatus, vfCsarArtifactsToHandle);
+ }
+ if (resStatus == null) {
+ resStatus = Either.left(resource);
+ }
+ } catch (Exception e) {
+ resStatus = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ log.debug("Exception occurred in createNonMetaArtifacts, message:{}", e.getMessage(), e);
+ } finally {
+ CsarUtils.handleWarningMessages(collectedWarningMessages);
+ }
+ return resStatus;
+ }
- try {
- Either<List<NonMetaArtifactInfo>, String> artifactPathAndNameList = getValidArtifactNames(csarInfo, collectedWarningMessages);
- if (artifactPathAndNameList.isRight()) {
- return Either.right(getComponentsUtils().getResponseFormatByArtifactId(
- ActionStatus.ARTIFACT_NAME_INVALID, artifactPathAndNameList.right().value()));
- }
- EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> vfCsarArtifactsToHandle = null;
+ private Either<Resource, ResponseFormat> processCsarArtifacts(CsarInfo csarInfo, Resource resource,
+ List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction,
+ Either<Resource, ResponseFormat> resStatus,
+ EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> vfCsarArtifactsToHandle) {
+ for (Entry<ArtifactOperationEnum, List<NonMetaArtifactInfo>> currArtifactOperationPair : vfCsarArtifactsToHandle
+ .entrySet()) {
+
+ Optional<ResponseFormat> optionalCreateInDBError =
+ // Stream of artifacts to be created
+ currArtifactOperationPair.getValue()
+ .stream()
+ // create each artifact
+ .map(e -> createOrUpdateSingleNonMetaArtifact(resource, csarInfo, e.getPath(),
+ e.getArtifactName(), e.getArtifactType()
+ .getType(),
+ e.getArtifactGroupType(), e.getArtifactLabel(), e.getDisplayName(),
+ CsarUtils.ARTIFACT_CREATED_FROM_CSAR, e.getArtifactUniqueId(),
+ artifactsBusinessLogic.new ArtifactOperationInfo(false, false,
+ currArtifactOperationPair.getKey()),
+ createdArtifacts, e.isFromCsar(), shouldLock, inTransaction))
+ // filter in only error
+ .filter(Either::isRight)
+ .
+ // Convert the error from either to
+ // ResponseFormat
+ map(e -> e.right()
+ .value())
+ .
+ // Check if an error occurred
+ findAny();
+ // Error found on artifact Creation
+ if (optionalCreateInDBError.isPresent()) {
+ resStatus = Either.right(optionalCreateInDBError.get());
+ break;
+ }
+ }
+ return resStatus;
+ }
- if (ArtifactOperationEnum.isCreateOrLink(artifactOperation.getArtifactOperationEnum())) {
- vfCsarArtifactsToHandle = new EnumMap<>(ArtifactOperationEnum.class);
- vfCsarArtifactsToHandle.put(artifactOperation.getArtifactOperationEnum(), artifactPathAndNameList.left().value());
- } else {
- Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandleRes = findVfCsarArtifactsToHandle(
- resource, artifactPathAndNameList.left().value(), csarInfo.getModifier());
+ private Either<List<NonMetaArtifactInfo>, String> getValidArtifactNames(CsarInfo csarInfo,
+ Map<String, Set<List<String>>> collectedWarningMessages) {
+ List<NonMetaArtifactInfo> artifactPathAndNameList =
+ // Stream of file paths contained in csar
+ csarInfo.getCsar()
+ .entrySet()
+ .stream()
+ // Filter in only VF artifact path location
+ .filter(e -> Pattern.compile(VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN)
+ .matcher(e.getKey())
+ .matches())
+ // Validate and add warnings
+ .map(e -> CsarUtils.validateNonMetaArtifact(e.getKey(), e.getValue(), collectedWarningMessages))
+ // Filter in Non Warnings
+ .filter(Either::isLeft)
+ // Convert from Either to NonMetaArtifactInfo
+ .map(e -> e.left()
+ .value())
+ // collect to List
+ .collect(toList());
+ Pattern englishNumbersAndUnderScoresOnly = Pattern.compile(CsarUtils.VALID_ENGLISH_ARTIFACT_NAME);
+ for (NonMetaArtifactInfo nonMetaArtifactInfo : artifactPathAndNameList) {
+ if (!englishNumbersAndUnderScoresOnly.matcher(nonMetaArtifactInfo.getDisplayName())
+ .matches()) {
+ return Either.right(nonMetaArtifactInfo.getArtifactName());
+ }
+ }
+ return Either.left(artifactPathAndNameList);
+ }
- if (findVfCsarArtifactsToHandleRes.isRight()) {
- resStatus = Either.right(findVfCsarArtifactsToHandleRes.right().value());
- }
- if (resStatus == null) {
- vfCsarArtifactsToHandle = findVfCsarArtifactsToHandleRes.left().value();
- }
- }
- if (resStatus == null && vfCsarArtifactsToHandle != null) {
- resStatus = processCsarArtifacts(csarInfo, resource, createdArtifacts, shouldLock, inTransaction, resStatus, vfCsarArtifactsToHandle);
- }
- if (resStatus == null) {
- resStatus = Either.left(resource);
- }
- } catch (Exception e) {
- resStatus = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- log.debug("Exception occured in createNonMetaArtifacts, message:{}", e.getMessage(), e);
- } finally {
- CsarUtils.handleWarningMessages(collectedWarningMessages);
- }
- return resStatus;
- }
+ private Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandle(
+ Resource resource, List<NonMetaArtifactInfo> artifactPathAndNameList, User user) {
- private Either<Resource, ResponseFormat> processCsarArtifacts(CsarInfo csarInfo, Resource resource, List<ArtifactDefinition> createdArtifacts, boolean shouldLock, boolean inTransaction, Either<Resource, ResponseFormat> resStatus, EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> vfCsarArtifactsToHandle) {
- for (Entry<ArtifactOperationEnum, List<NonMetaArtifactInfo>> currArtifactOperationPair : vfCsarArtifactsToHandle
- .entrySet()) {
-
- Optional<ResponseFormat> optionalCreateInDBError =
- // Stream of artifacts to be created
- currArtifactOperationPair.getValue().stream()
- // create each artifact
- .map(e -> createOrUpdateSingleNonMetaArtifact(resource, csarInfo, e.getPath(),
- e.getArtifactName(), e.getArtifactType().getType(),
- e.getArtifactGroupType(), e.getArtifactLabel(), e.getDisplayName(),
- CsarUtils.ARTIFACT_CREATED_FROM_CSAR, e.getArtifactUniqueId(),
- artifactsBusinessLogic.new ArtifactOperationInfo(false, false,
- currArtifactOperationPair.getKey()),
- createdArtifacts, e.isFromCsar(), shouldLock, inTransaction))
- // filter in only error
- .filter(Either::isRight).
- // Convert the error from either to
- // ResponseFormat
- map(e -> e.right().value()).
- // Check if an error occurred
- findAny();
- // Error found on artifact Creation
- if (optionalCreateInDBError.isPresent()) {
- resStatus = Either.right(optionalCreateInDBError.get());
- break;
- }
- }
- return resStatus;
- }
+ List<ArtifactDefinition> existingArtifacts = new ArrayList<>();
+ // collect all Deployment and Informational artifacts of VF
+ if (resource.getDeploymentArtifacts() != null && !resource.getDeploymentArtifacts()
+ .isEmpty()) {
+ existingArtifacts.addAll(resource.getDeploymentArtifacts()
+ .values());
+ }
+ if (resource.getArtifacts() != null && !resource.getArtifacts()
+ .isEmpty()) {
+ existingArtifacts.addAll(resource.getArtifacts()
+ .values());
+ }
+ existingArtifacts = existingArtifacts.stream()
+ // filter MANDATORY artifacts, LICENSE artifacts and artifacts
+ // was created from HEAT.meta
+ .filter(this::isNonMetaArtifact)
+ .collect(toList());
+
+ List<String> artifactsToIgnore = new ArrayList<>();
+ // collect IDs of Artifacts of VF which belongs to any group
+ if (resource.getGroups() != null) {
+ resource.getGroups()
+ .stream()
+ .forEach(g -> {
+ if (g.getArtifacts() != null && !g.getArtifacts()
+ .isEmpty()) {
+ artifactsToIgnore.addAll(g.getArtifacts());
+ }
+ });
+ }
+ existingArtifacts = existingArtifacts.stream()
+ // filter artifacts which belongs to any group
+ .filter(a -> !artifactsToIgnore.contains(a.getUniqueId()))
+ .collect(toList());
+ return organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifacts, resource, user);
+ }
- private Either<List<NonMetaArtifactInfo>, String> getValidArtifactNames(CsarInfo csarInfo, Map<String, Set<List<String>>> collectedWarningMessages) {
- List<NonMetaArtifactInfo> artifactPathAndNameList =
- // Stream of file paths contained in csar
- csarInfo.getCsar().entrySet().stream()
- // Filter in only VF artifact path location
- .filter(e -> Pattern.compile(VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN).matcher(e.getKey())
- .matches())
- // Validate and add warnings
- .map(e -> CsarUtils.validateNonMetaArtifact(e.getKey(), e.getValue(),
- collectedWarningMessages))
- // Filter in Non Warnings
- .filter(Either::isLeft)
- // Convert from Either to NonMetaArtifactInfo
- .map(e -> e.left().value())
- // collect to List
- .collect(toList());
- Pattern englishNumbersAndUnderScoresOnly = Pattern.compile(CsarUtils.VALID_ENGLISH_ARTIFACT_NAME);
- for (NonMetaArtifactInfo nonMetaArtifactInfo : artifactPathAndNameList) {
- if (!englishNumbersAndUnderScoresOnly.matcher(nonMetaArtifactInfo.getDisplayName()).matches()) {
- return Either.right(nonMetaArtifactInfo.getArtifactName());
- }
- }
- return Either.left(artifactPathAndNameList);
- }
+ private boolean isNonMetaArtifact(ArtifactDefinition artifact) {
+ boolean result = true;
+ if (artifact.getMandatory() || artifact.getArtifactName() == null || !isValidArtifactType(artifact)) {
+ result = false;
+ }
+ return result;
+ }
- private Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> findVfCsarArtifactsToHandle(
- Resource resource, List<NonMetaArtifactInfo> artifactPathAndNameList, User user) {
+ private boolean isValidArtifactType(ArtifactDefinition artifact) {
+ boolean result = true;
+ if (artifact.getArtifactType() == null
+ || ArtifactTypeEnum.findType(artifact.getArtifactType()) == ArtifactTypeEnum.VENDOR_LICENSE
+ || ArtifactTypeEnum.findType(artifact.getArtifactType()) == ArtifactTypeEnum.VF_LICENSE) {
+ result = false;
+ }
+ return result;
+ }
- List<ArtifactDefinition> existingArtifacts = new ArrayList<>();
- // collect all Deployment and Informational artifacts of VF
- if (resource.getDeploymentArtifacts() != null && !resource.getDeploymentArtifacts().isEmpty()) {
- existingArtifacts.addAll(resource.getDeploymentArtifacts().values());
- }
- if (resource.getArtifacts() != null && !resource.getArtifacts().isEmpty()) {
- existingArtifacts.addAll(resource.getArtifacts().values());
- }
- existingArtifacts = existingArtifacts.stream()
- // filter MANDATORY artifacts, LICENSE artifacts and artifacts
- // was created from HEAT.meta
- .filter(this::isNonMetaArtifact).collect(toList());
-
- List<String> artifactsToIgnore = new ArrayList<>();
- // collect IDs of Artifacts of VF which belongs to any group
- if (resource.getGroups() != null) {
- resource.getGroups().stream().forEach(g -> {
- if (g.getArtifacts() != null && !g.getArtifacts().isEmpty()) {
- artifactsToIgnore.addAll(g.getArtifacts());
- }
- });
- }
- existingArtifacts = existingArtifacts.stream()
- // filter artifacts which belongs to any group
- .filter(a -> !artifactsToIgnore.contains(a.getUniqueId())).collect(toList());
- return organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifacts, resource, user);
- }
+ private Resource createResourceInstancesRelations(User user, String yamlName, Resource resource, Resource oldResource,
+ Map<String, UploadComponentInstanceInfo> uploadResInstancesMap, Map<String, Resource> existingNodeTypesByResourceNames) {
+ log.debug("#createResourceInstancesRelations - Going to create relations ");
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,"Start to create relations");
+ List<ComponentInstance> componentInstancesList = resource.getComponentInstances();
+ if (isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList) &&
+ resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances {
+ log.debug(
+ "#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ",
+ resource.getUniqueId(), yamlName);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.ERROR,"No instances found in the resource: {}, is empty, yaml template file name: {}",resource.getName(),yamlName);
+ BeEcompErrorManager.getInstance()
+ .logInternalDataError("createResourceInstancesRelations",
+ "No instances found in a resource or nn yaml template. ", ErrorSeverity.ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ }
+ Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>();
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>();
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>();
+ Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>();
+ Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>();
+ Map<String, List<PropertyDefinition>> instAttributes = new HashMap<>();
+ List<RequirementCapabilityRelDef> relations = new ArrayList<>();
+ Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
+
+ log.debug("#createResourceInstancesRelations - Before get all datatypes. ");
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll();
+ if (allDataTypes.isRight()) {
+ JanusGraphOperationStatus status = allDataTypes.right()
+ .value();
+ BeEcompErrorManager.getInstance()
+ .logInternalFlowError("UpdatePropertyValueOnComponentInstance",
+ "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR while update property value on instance. Status is: "+status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), yamlName);
- private boolean isNonMetaArtifact(ArtifactDefinition artifact) {
- boolean result = true;
- if (artifact.getMandatory() || artifact.getArtifactName() == null || !isValidArtifactType(artifact)) {
- result = false;
- }
- return result;
- }
+ }
+ Resource finalResource = resource;
+ uploadResInstancesMap.values()
+ .forEach(i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes,
+ instProperties, instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts,
+ instAttributes, existingNodeTypesByResourceNames, instInputs, i));
+ resource.getComponentInstances()
+ .stream()
+ .filter(i -> !i.isCreatedFromCsar())
+ .forEach(i->processUiComponentInstance(oldResource, i, instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instProperties, instInputs, instAttributes));
+
+ associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties);
+ associateComponentInstanceInputsToComponent(yamlName, resource, instInputs);
+ associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts);
+ associateArtifactsToInstances(yamlName, resource, instArtifacts);
+ associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements);
+ associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes);
+ addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, relations);
+ associateResourceInstances(yamlName, resource, relations);
+ handleSubstitutionMappings(resource, uploadResInstancesMap);
+ log.debug("************* in create relations, getResource start");
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.COMPLETE,"create relations");
+ Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade
+ .getToscaFullElement(resource.getUniqueId());
+ log.debug("************* in create relations, getResource end");
+ if (eitherGetResource.isRight()) {
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR while create relations");
+ throw new ByResponseFormatComponentException(componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right()
+ .value()), resource));
+ }
+ return eitherGetResource.left()
+ .value();
+ }
- private boolean isValidArtifactType(ArtifactDefinition artifact) {
- boolean result = true;
- if (artifact.getArtifactType() == null
- || ArtifactTypeEnum.findType(artifact.getArtifactType()) == ArtifactTypeEnum.VENDOR_LICENSE
- || ArtifactTypeEnum.findType(artifact.getArtifactType()) == ArtifactTypeEnum.VF_LICENSE) {
- result = false;
- }
- return result;
- }
+ private void processUiComponentInstance(Resource oldResource, ComponentInstance instance,
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities,
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements,
+ Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts,
+ Map<String, Map<String, ArtifactDefinition>> instArtifacts, Map<String, List<ComponentInstanceProperty>> instProperties, Map<String, List<ComponentInstanceInput>> instInputs, Map<String, List<PropertyDefinition>> instAttributes) {
+ Optional<ComponentInstance> foundInstance = findInstance(oldResource, instance);
+ if(foundInstance.isPresent()){
+ if(MapUtils.isNotEmpty(foundInstance.get().getCapabilities())){
+ instCapabilities.put(instance, foundInstance.get().getCapabilities());
+ }
+ if(MapUtils.isNotEmpty(foundInstance.get().getRequirements())){
+ instRequirements.put(instance, foundInstance.get().getRequirements());
+ }
+ if(MapUtils.isNotEmpty(foundInstance.get().getDeploymentArtifacts())){
+ instDeploymentArtifacts.put(instance.getUniqueId(), foundInstance.get().getDeploymentArtifacts());
+ }
+ if(MapUtils.isNotEmpty(foundInstance.get().getArtifacts())){
+ instArtifacts.put(instance.getUniqueId(), foundInstance.get().getArtifacts());
+ }
+ if(MapUtils.isNotEmpty(oldResource.getComponentInstancesProperties()) &&
+ CollectionUtils.isNotEmpty(oldResource.getComponentInstancesProperties().get(foundInstance.get().getUniqueId()))){
+ instProperties.put(instance.getUniqueId(), oldResource.getComponentInstancesProperties().get(foundInstance.get().getUniqueId()));
+ }
+ if(MapUtils.isNotEmpty(oldResource.getComponentInstancesInputs()) &&
+ CollectionUtils.isNotEmpty(oldResource.getComponentInstancesInputs().get(foundInstance.get().getUniqueId()))){
+ instInputs.put(instance.getUniqueId(), oldResource.getComponentInstancesInputs().get(foundInstance.get().getUniqueId()));
+ }
+ if(MapUtils.isNotEmpty(oldResource.getComponentInstancesAttributes()) &&
+ CollectionUtils.isNotEmpty(oldResource.getComponentInstancesAttributes().get(foundInstance.get().getUniqueId()))){
+ instAttributes.put(instance.getUniqueId(), oldResource.getComponentInstancesAttributes().get(foundInstance.get().getUniqueId()).stream().map(PropertyDefinition::new).collect(toList()));
+ }
+ }
+ }
- private Resource createResourceInstancesRelations(User user, String yamlName, Resource resource,
- Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
- log.debug("#createResourceInstancesRelations - Going to create relations ");
- List<ComponentInstance> componentInstancesList = resource.getComponentInstances();
- if (((isEmpty(uploadResInstancesMap) || CollectionUtils.isEmpty(componentInstancesList)) &&
- resource.getResourceType() != ResourceTypeEnum.PNF)) { // PNF can have no resource instances
- log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ", resource.getUniqueId(), yamlName);
- BeEcompErrorManager.getInstance().logInternalDataError("createResourceInstancesRelations", "No instances found in a resource or nn yaml template. ", ErrorSeverity.ERROR);
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName));
- }
- Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>();
- Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>();
- Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>();
- Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>();
- Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>();
- Map<String, List<PropertyDefinition>> instAttributes = new HashMap<>();
- Map<String, Resource> originCompMap = new HashMap<>();
- List<RequirementCapabilityRelDef> relations = new ArrayList<>();
- Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
-
- log.debug("#createResourceInstancesRelations - Before get all datatypes. ");
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll();
- if (allDataTypes.isRight()) {
- JanusGraphOperationStatus status = allDataTypes.right().value();
- BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance",
- "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
- DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), yamlName));
+ private Optional<ComponentInstance> findInstance(Resource oldResource, ComponentInstance instance) {
+ if(oldResource != null && CollectionUtils.isNotEmpty(oldResource.getComponentInstances())) {
+ return oldResource.getComponentInstances().stream().filter(i -> i.getName().equals(instance.getName())).findFirst();
+ }
+ return Optional.empty();
+ }
- }
- Resource finalResource = resource;
- uploadResInstancesMap
- .values()
- .forEach(i ->processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes,
- instProperties, instCapabilities, instRequirements, instDeploymentArtifacts,
- instArtifacts, instAttributes, originCompMap, instInputs, i));
-
- associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties);
- associateComponentInstanceInputsToComponent(yamlName, resource, instInputs);
- associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts);
- associateArtifactsToInstances(yamlName, resource, instArtifacts);
- associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements);
- associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes);
-
- resource = getResourceAfterCreateRelations(resource);
-
- addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, relations);
- associateResourceInstances(yamlName, resource, relations);
- handleSubstitutionMappings(resource, uploadResInstancesMap);
- log.debug("************* in create relations, getResource start");
- Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId());
- log.debug("************* in create relations, getResource end");
- if (eitherGetResource.isRight()) {
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource));
- }
- return eitherGetResource.left().value();
- }
+ private void associateResourceInstances(String yamlName, Resource resource,
+ List<RequirementCapabilityRelDef> relations) {
+ Either<List<RequirementCapabilityRelDef>, StorageOperationStatus> relationsEither = toscaOperationFacade.associateResourceInstances(resource, resource.getUniqueId(), relations);
+
+ if (relationsEither.isRight() && relationsEither.right().value() != StorageOperationStatus.NOT_FOUND) {
+ StorageOperationStatus status = relationsEither.right().value();
+ log.debug("failed to associate instances of resource {} status is {}", resource.getUniqueId(),
+ status);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), yamlName);
+ } else {
+ setResourceInstanceRelationsOnComponent(resource, relationsEither.left().value());
+ }
+ }
- private Resource getResourceAfterCreateRelations(Resource resource) {
- ComponentParametersView parametersView = getComponentFilterAfterCreateRelations();
- Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade
- .getToscaElement(resource.getUniqueId(), parametersView);
+ private void associateInstAttributeToComponentToInstances(String yamlName, Resource resource,
+ Map<String, List<PropertyDefinition>> instAttributes) {
+ StorageOperationStatus addArtToInst;
+ addArtToInst = toscaOperationFacade.associateInstAttributeToComponentToInstances(instAttributes,
+ resource);
+ if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
+ log.debug("failed to associate attributes of resource {} status is {}", resource.getUniqueId(),
+ addArtToInst);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName);
+ }
+ }
- if (eitherGetResource.isRight()) {
- throwComponentExceptionByResource(eitherGetResource.right().value(),resource);
- }
- return eitherGetResource.left().value();
- }
+ private void associateOrAddCalculatedCapReq(String yamlName, Resource resource,
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities,
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements) {
+ StorageOperationStatus addArtToInst;
+ addArtToInst = toscaOperationFacade.associateOrAddCalculatedCapReq(instCapabilities, instRequirements,
+ resource);
+ if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
+ log.debug("failed to associate cap and req of resource {} status is {}", resource.getUniqueId(),
+ addArtToInst);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName);
+ }
+ }
- private void associateResourceInstances(String yamlName, Resource resource, List<RequirementCapabilityRelDef> relations) {
- StorageOperationStatus addArtToInst;
- addArtToInst = toscaOperationFacade.associateResourceInstances(resource.getUniqueId(), relations);
- if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
- log.debug("failed to associate instances of resource {} status is {}", resource.getUniqueId(),
- addArtToInst);
- throw new ByResponseFormatComponentException(componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
- }
- }
+ private void associateArtifactsToInstances(String yamlName, Resource resource,
+ Map<String, Map<String, ArtifactDefinition>> instArtifacts) {
+ StorageOperationStatus addArtToInst;
- private ComponentParametersView getComponentFilterAfterCreateRelations() {
- ComponentParametersView parametersView = new ComponentParametersView();
- parametersView.disableAll();
- parametersView.setIgnoreComponentInstances(false);
- parametersView.setIgnoreComponentInstancesProperties(false);
- parametersView.setIgnoreCapabilities(false);
- parametersView.setIgnoreRequirements(false);
- parametersView.setIgnoreGroups(false);
- return parametersView;
- }
+ addArtToInst = toscaOperationFacade.associateArtifactsToInstances(instArtifacts, resource);
+ if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
+ log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName);
+ }
+ }
- private void associateInstAttributeToComponentToInstances(String yamlName, Resource resource, Map<String, List<PropertyDefinition>> instAttributes) {
- StorageOperationStatus addArtToInst;
- addArtToInst = toscaOperationFacade.associateInstAttributeToComponentToInstances(instAttributes,
- resource.getUniqueId());
- if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
- log.debug("failed to associate attributes of resource {} status is {}", resource.getUniqueId(),
- addArtToInst);
- throw new ByResponseFormatComponentException(componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
- }
- }
+ private void associateDeploymentArtifactsToInstances(User user, String yamlName, Resource resource,
+ Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts) {
+ StorageOperationStatus addArtToInst = toscaOperationFacade
+ .associateDeploymentArtifactsToInstances(instDeploymentArtifacts, resource, user);
+ if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
+ log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName);
+ }
+ }
- private void associateOrAddCalculatedCapReq(String yamlName, Resource resource, Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities, Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements) {
- StorageOperationStatus addArtToInst;
- addArtToInst = toscaOperationFacade.associateOrAddCalculatedCapReq(instCapabilities, instRequirements,
- resource.getUniqueId());
- if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
- log.debug("failed to associate cap and req of resource {} status is {}", resource.getUniqueId(),
- addArtToInst);
- throw new ByResponseFormatComponentException(componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
- }
- }
+ private void associateComponentInstanceInputsToComponent(String yamlName, Resource resource,
+ Map<String, List<ComponentInstanceInput>> instInputs) {
+ if (MapUtils.isNotEmpty(instInputs)) {
+ Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addInputToInst = toscaOperationFacade
+ .associateComponentInstanceInputsToComponent(instInputs, resource.getUniqueId());
+ if (addInputToInst.isRight()) {
+
+ StorageOperationStatus addInputToInstError = addInputToInst.right().value();
+ log.debug("failed to associate inputs value of resource {} status is {}", resource.getUniqueId(),
+ addInputToInstError);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(addInputToInstError), yamlName);
+ }
+ setComponentInstanceInputsOnComponent(resource, instInputs);
+ }
+ }
- private void associateArtifactsToInstances(String yamlName, Resource resource, Map<String, Map<String, ArtifactDefinition>> instArtifacts) {
- StorageOperationStatus addArtToInst;
+ private void setComponentInstanceInputsOnComponent(Resource resource, Map<String, List<ComponentInstanceInput>> instInputs) {
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs = resource.getComponentInstancesInputs();
+ if (componentInstancesInputs == null)
+ componentInstancesInputs = new HashMap<>();
+ componentInstancesInputs.putAll(instInputs);
+ resource.setComponentInstancesInputs(componentInstancesInputs);
+ }
- addArtToInst = toscaOperationFacade.associateArtifactsToInstances(instArtifacts, resource.getUniqueId());
- if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
- log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst);
- throw new ByResponseFormatComponentException(componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
- }
- }
+ private void associateComponentInstancePropertiesToComponent(String yamlName, Resource resource,
+ Map<String, List<ComponentInstanceProperty>> instProperties) {
+ Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addPropToInst = toscaOperationFacade
+ .associateComponentInstancePropertiesToComponent(instProperties, resource.getUniqueId());
+ if (addPropToInst.isRight()) {
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR while associate compnent insatnce properties of resource: {} status is: {}",resource.getName(),addPropToInst.right().value());
+ StorageOperationStatus storageOperationStatus = addPropToInst.right().value();
+ log.debug("failed to associate properties of resource {} status is {}", resource.getUniqueId(),
+ storageOperationStatus);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageOperationStatus), yamlName);
+ }
+ setComponentInstancePropertiesOnComponent(resource, instProperties);
+ }
- private void associateDeploymentArtifactsToInstances(User user, String yamlName, Resource resource, Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts) {
- StorageOperationStatus addArtToInst = toscaOperationFacade
- .associateDeploymentArtifactsToInstances(instDeploymentArtifacts, resource.getUniqueId(), user);
- if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
- log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst);
- throw new ByResponseFormatComponentException(componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
- }
- }
+ private void setComponentInstancePropertiesOnComponent(Resource resource, Map<String, List<ComponentInstanceProperty>> instProperties) {
+ Map<String, List<ComponentInstanceProperty>> componentInstanceProps = resource.getComponentInstancesProperties();
+ if (componentInstanceProps == null )
+ componentInstanceProps = new HashMap<>();
+ componentInstanceProps.putAll(instProperties);
+ resource.setComponentInstancesProperties(componentInstanceProps);
+ }
- private void associateComponentInstanceInputsToComponent(String yamlName, Resource resource, Map<String, List<ComponentInstanceInput>> instInputs) {
- if (MapUtils.isNotEmpty(instInputs)) {
- Either<Map<String, List<ComponentInstanceInput>>, StorageOperationStatus> addInputToInst = toscaOperationFacade
- .associateComponentInstanceInputsToComponent(instInputs, resource.getUniqueId());
- if (addInputToInst.isRight()) {
- log.debug("failed to associate inputs value of resource {} status is {}", resource.getUniqueId(),
- addInputToInst.right().value());
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(addInputToInst.right().value()), yamlName));
- }
- }
- }
+ private void handleSubstitutionMappings(Resource resource,
+ Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
+ if (resource.getResourceType() == ResourceTypeEnum.CVFC) {
+ Either<Resource, StorageOperationStatus> getResourceRes =
+ updateCalculatedCapReqWithSubstitutionMappings(resource, uploadResInstancesMap);
+ if (getResourceRes.isRight()) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(getResourceRes.right()
+ .value()), resource);
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+ }
+ }
- private void associateComponentInstancePropertiesToComponent(String yamlName, Resource resource, Map<String, List<ComponentInstanceProperty>> instProperties) {
- Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addPropToInst = toscaOperationFacade
- .associateComponentInstancePropertiesToComponent(instProperties, resource.getUniqueId());
- if (addPropToInst.isRight()) {
- log.debug("failed to associate properties of resource {} status is {}", resource.getUniqueId(),
- addPropToInst.right().value());
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(addPropToInst.right().value()), yamlName));
- }
- }
+ private void addRelationsToRI(String yamlName, Resource resource,
+ Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
+ List<ComponentInstance> componentInstancesList, List<RequirementCapabilityRelDef> relations) {
+ for (Entry<String, UploadComponentInstanceInfo> entry : uploadResInstancesMap.entrySet()) {
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = entry.getValue();
+ ComponentInstance currentCompInstance = null;
+ for (ComponentInstance compInstance : componentInstancesList) {
- private void handleSubstitutionMappings(Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
- if (resource.getResourceType() == ResourceTypeEnum.CVFC) {
- Either<Resource, StorageOperationStatus> getResourceRes = toscaOperationFacade.getToscaFullElement(resource.getUniqueId());
- if (getResourceRes.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), resource);
- throw new ByResponseFormatComponentException(responseFormat);
- }
- getResourceRes = updateCalculatedCapReqWithSubstitutionMappings(getResourceRes.left().value(),
- uploadResInstancesMap);
- if (getResourceRes.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), resource);
- throw new ByResponseFormatComponentException(responseFormat);
- }
- }
- }
+ if (compInstance.getName()
+ .equals(uploadComponentInstanceInfo.getName())) {
+ currentCompInstance = compInstance;
+ break;
+ }
- private void addRelationsToRI(String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap, List<ComponentInstance> componentInstancesList, List<RequirementCapabilityRelDef> relations) {
- for (Entry<String, UploadComponentInstanceInfo> entry : uploadResInstancesMap.entrySet()) {
- UploadComponentInstanceInfo uploadComponentInstanceInfo = entry.getValue();
- ComponentInstance currentCompInstance = null;
- for (ComponentInstance compInstance : componentInstancesList) {
+ }
+ if (currentCompInstance == null) {
+ log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, uploadComponentInstanceInfo.getName(),
+ resource.getUniqueId());
+ BeEcompErrorManager.getInstance()
+ .logInternalDataError(
+ COMPONENT_INSTANCE_WITH_NAME + uploadComponentInstanceInfo.getName() + IN_RESOURCE,
+ resource.getUniqueId(), ErrorSeverity.ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ }
- if (compInstance.getName().equals(uploadComponentInstanceInfo.getName())) {
- currentCompInstance = compInstance;
- break;
- }
+ ResponseFormat addRelationToRiRes = addRelationToRI(yamlName, resource, entry.getValue(), relations);
+ if (addRelationToRiRes.getStatus() != 200) {
+ throw new ByResponseFormatComponentException(addRelationToRiRes);
+ }
+ }
- }
- if (currentCompInstance == null) {
- log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, uploadComponentInstanceInfo.getName(),
- resource.getUniqueId());
- BeEcompErrorManager.getInstance().logInternalDataError(
- COMPONENT_INSTANCE_WITH_NAME + uploadComponentInstanceInfo.getName() + IN_RESOURCE,
- resource.getUniqueId(), ErrorSeverity.ERROR);
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
- throw new ByResponseFormatComponentException(responseFormat);
- }
+ }
- ResponseFormat addRelationToRiRes = addRelationToRI(yamlName, resource, entry.getValue(), relations);
- if (addRelationToRiRes.getStatus() != 200) {
- throw new ByResponseFormatComponentException(addRelationToRiRes);
- }
- }
- }
+ private void setResourceInstanceRelationsOnComponent(Resource resource, List<RequirementCapabilityRelDef> relations) {
+ if (resource.getComponentInstancesRelations() != null) {
+ /*Map<String, RequirementCapabilityRelDef> relationsMapByUid = resource.getComponentInstancesRelations().stream().collect(Collectors.toMap(r -> r.getUid(), r -> r));
+ Map<String, RequirementCapabilityRelDef> updatedRelationsByUid = relations.stream().collect(Collectors.toMap(r -> r.getUid(), r -> r));
+ relationsMapByUid.putAll(updatedRelationsByUid);
+ resource.setComponentInstancesRelations(new ArrayList<>(relationsMapByUid.values()));*/
+ resource.getComponentInstancesRelations().addAll(relations);
+ } else {
+ resource.setComponentInstancesRelations(relations);
+ }
+ }
- private void processComponentInstance(String yamlName, Resource resource, List<ComponentInstance> componentInstancesList, Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes, Map<String, List<ComponentInstanceProperty>> instProperties, Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties, Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements, Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, Map<String, Map<String, ArtifactDefinition>> instArtifacts, Map<String, List<PropertyDefinition>> instAttributes, Map<String, Resource> originCompMap, Map<String, List<ComponentInstanceInput>> instInputs, UploadComponentInstanceInfo uploadComponentInstanceInfo) {
- Optional<ComponentInstance> currentCompInstanceOpt = componentInstancesList.stream()
- .filter(i->i.getName().equals(uploadComponentInstanceInfo.getName()))
- .findFirst();
- if (!currentCompInstanceOpt.isPresent()) {
- log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, uploadComponentInstanceInfo.getName(),
- resource.getUniqueId());
- BeEcompErrorManager.getInstance().logInternalDataError(
- COMPONENT_INSTANCE_WITH_NAME + uploadComponentInstanceInfo.getName() + IN_RESOURCE,
- resource.getUniqueId(), ErrorSeverity.ERROR);
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
- throw new ByResponseFormatComponentException(responseFormat);
- }
- ComponentInstance currentCompInstance = currentCompInstanceOpt.get();
- String resourceInstanceId = currentCompInstance.getUniqueId();
- Resource originResource = getOriginResource(yamlName, originCompMap, currentCompInstance);
- if (isNotEmpty(originResource.getRequirements())) {
- instRequirements.put(currentCompInstance, originResource.getRequirements());
- }
- if (isNotEmpty(originResource.getCapabilities())) {
- processComponentInstanceCapabilities(allDataTypes, instCapabilties, uploadComponentInstanceInfo,
- currentCompInstance, originResource);
- }
- if (originResource.getDeploymentArtifacts() != null && !originResource.getDeploymentArtifacts().isEmpty()) {
- instDeploymentArtifacts.put(resourceInstanceId, originResource.getDeploymentArtifacts());
- }
- if (originResource.getArtifacts() != null && !originResource.getArtifacts().isEmpty()) {
- instArtifacts.put(resourceInstanceId, originResource.getArtifacts());
- }
- if (originResource.getAttributes() != null && !originResource.getAttributes().isEmpty()) {
- instAttributes.put(resourceInstanceId, originResource.getAttributes());
- }
- if (originResource.getResourceType() != ResourceTypeEnum.CVFC) {
- ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource,
- originResource, currentCompInstance, instProperties, allDataTypes.left().value());
- if (addPropertiesValueToRiRes.getStatus() != 200) {
- throw new ByResponseFormatComponentException(addPropertiesValueToRiRes);
- }
- } else {
- addInputsValuesToRi(uploadComponentInstanceInfo, resource,
- originResource, currentCompInstance, instInputs, allDataTypes.left().value());
- }
- }
+ private void processComponentInstance(String yamlName, Resource resource,
+ List<ComponentInstance> componentInstancesList,
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes,
+ Map<String, List<ComponentInstanceProperty>> instProperties,
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties,
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements,
+ Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts,
+ Map<String, Map<String, ArtifactDefinition>> instArtifacts,
+ Map<String, List<PropertyDefinition>> instAttributes, Map<String, Resource> originCompMap,
+ Map<String, List<ComponentInstanceInput>> instInputs,
+ UploadComponentInstanceInfo uploadComponentInstanceInfo) {
+ Optional<ComponentInstance> currentCompInstanceOpt = componentInstancesList.stream()
+ .filter(i -> i.getName()
+ .equals(uploadComponentInstanceInfo.getName()))
+ .findFirst();
+ if (!currentCompInstanceOpt.isPresent()) {
+ log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, uploadComponentInstanceInfo.getName(),
+ resource.getUniqueId());
+ BeEcompErrorManager.getInstance()
+ .logInternalDataError(
+ COMPONENT_INSTANCE_WITH_NAME + uploadComponentInstanceInfo.getName() + IN_RESOURCE,
+ resource.getUniqueId(), ErrorSeverity.ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ }
+ ComponentInstance currentCompInstance = currentCompInstanceOpt.get();
+ String resourceInstanceId = currentCompInstance.getUniqueId();
+ Resource originResource = getOriginResource(originCompMap, currentCompInstance);
+ if (isNotEmpty(originResource.getRequirements())) {
+ instRequirements.put(currentCompInstance, originResource.getRequirements());
+ }
+ if (isNotEmpty(originResource.getCapabilities())) {
+ processComponentInstanceCapabilities(allDataTypes, instCapabilties, uploadComponentInstanceInfo,
+ currentCompInstance, originResource);
+ }
+ if (originResource.getDeploymentArtifacts() != null && !originResource.getDeploymentArtifacts()
+ .isEmpty()) {
+ instDeploymentArtifacts.put(resourceInstanceId, originResource.getDeploymentArtifacts());
+ }
+ if (originResource.getArtifacts() != null && !originResource.getArtifacts()
+ .isEmpty()) {
+ instArtifacts.put(resourceInstanceId, originResource.getArtifacts());
+ }
+ if (originResource.getAttributes() != null && !originResource.getAttributes()
+ .isEmpty()) {
+ instAttributes.put(resourceInstanceId, originResource.getAttributes());
+ }
+ if (originResource.getResourceType() != ResourceTypeEnum.CVFC) {
+ ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource,
+ originResource, currentCompInstance, instProperties, allDataTypes.left()
+ .value());
+ if (addPropertiesValueToRiRes.getStatus() != 200) {
+ throw new ByResponseFormatComponentException(addPropertiesValueToRiRes);
+ }
+ } else {
+ addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, instInputs,
+ allDataTypes.left()
+ .value());
+ }
+ }
- private Resource getOriginResource(String yamlName, Map<String, Resource> originCompMap, ComponentInstance currentCompInstance) {
- Resource originResource;
- if (!originCompMap.containsKey(currentCompInstance.getComponentUid())) {
- Either<Resource, StorageOperationStatus> getOriginResourceRes = toscaOperationFacade
- .getToscaFullElement(currentCompInstance.getComponentUid());
- if (getOriginResourceRes.isRight()) {
- log.debug("failed to fetch resource with uniqueId {} and tosca component name {} status is {}",
- currentCompInstance.getComponentUid(), currentCompInstance.getToscaComponentName(),
- getOriginResourceRes);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(getOriginResourceRes.right().value()), yamlName);
- throw new ByResponseFormatComponentException(responseFormat);
- }
- originResource = getOriginResourceRes.left().value();
- originCompMap.put(originResource.getUniqueId(), originResource);
- } else {
- originResource = originCompMap.get(currentCompInstance.getComponentUid());
- }
- return originResource;
- }
+ private Resource getOriginResource(Map<String, Resource> originCompMap, ComponentInstance currentCompInstance) {
+ Resource originResource;
+ if (!originCompMap.containsKey(currentCompInstance.getComponentUid())) {
+ Either<Resource, StorageOperationStatus> getOriginResourceRes = toscaOperationFacade
+ .getToscaFullElement(currentCompInstance.getComponentUid());
+ if (getOriginResourceRes.isRight()) {
+ log.debug("failed to fetch resource with uniqueId {} and tosca component name {} status is {}",
+ currentCompInstance.getComponentUid(), currentCompInstance.getToscaComponentName(),
+ getOriginResourceRes);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(getOriginResourceRes.right()
+ .value()), currentCompInstance.getComponentUid());
+ }
+ originResource = getOriginResourceRes.left()
+ .value();
+ originCompMap.put(originResource.getUniqueId(), originResource);
+ } else {
+ originResource = originCompMap.get(currentCompInstance.getComponentUid());
+ }
+ return originResource;
+ }
- private void processComponentInstanceCapabilities(Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes, Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties, UploadComponentInstanceInfo uploadComponentInstanceInfo, ComponentInstance currentCompInstance, Resource originResource) {
- Map<String, List<CapabilityDefinition>> originCapabilities;
- if (isNotEmpty(uploadComponentInstanceInfo.getCapabilities())) {
- originCapabilities = new HashMap<>();
- Map<String, Map<String, UploadPropInfo>> newPropertiesMap = new HashMap<>();
- originResource.getCapabilities().forEach((k,v) -> addCapabilities(originCapabilities, k, v));
- uploadComponentInstanceInfo.getCapabilities().values().forEach(l-> addCapabilitiesProperties(newPropertiesMap, l));
- updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap);
- } else {
- originCapabilities = originResource.getCapabilities();
- }
- instCapabilties.put(currentCompInstance, originCapabilities);
- }
+ private void processComponentInstanceCapabilities(
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes,
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties,
+ UploadComponentInstanceInfo uploadComponentInstanceInfo, ComponentInstance currentCompInstance,
+ Resource originResource) {
+ Map<String, List<CapabilityDefinition>> originCapabilities;
+ if (isNotEmpty(uploadComponentInstanceInfo.getCapabilities())) {
+ originCapabilities = new HashMap<>();
+ Map<String, Map<String, UploadPropInfo>> newPropertiesMap = new HashMap<>();
+ originResource.getCapabilities()
+ .forEach((k, v) -> addCapabilities(originCapabilities, k, v));
+ uploadComponentInstanceInfo.getCapabilities()
+ .values()
+ .forEach(l -> addCapabilitiesProperties(newPropertiesMap, l));
+ updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap);
+ } else {
+ originCapabilities = originResource.getCapabilities();
+ }
+ instCapabilties.put(currentCompInstance, originCapabilities);
+ }
- private void updateCapabilityPropertiesValues(Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes, Map<String, List<CapabilityDefinition>> originCapabilities, Map<String, Map<String, UploadPropInfo>> newPropertiesMap) {
- originCapabilities.values().stream()
- .flatMap(Collection::stream)
- .filter(c -> newPropertiesMap.containsKey(c.getName()))
- .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()), allDataTypes.left().value()));
- }
+ private void updateCapabilityPropertiesValues(
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes,
+ Map<String, List<CapabilityDefinition>> originCapabilities,
+ Map<String, Map<String, UploadPropInfo>> newPropertiesMap) {
+ originCapabilities.values()
+ .stream()
+ .flatMap(Collection::stream)
+ .filter(c -> newPropertiesMap.containsKey(c.getName()))
+ .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()),
+ allDataTypes.left()
+ .value()));
+ }
- private void addCapabilitiesProperties(Map<String, Map<String, UploadPropInfo>> newPropertiesMap, List<UploadCapInfo> capabilities) {
- for (UploadCapInfo capability : capabilities) {
- if (isNotEmpty(capability.getProperties())) {
- newPropertiesMap.put(capability.getName(), capability.getProperties().stream()
- .collect(toMap(UploadInfo::getName, p -> p)));
- }
- }
- }
+ private void addCapabilitiesProperties(Map<String, Map<String, UploadPropInfo>> newPropertiesMap,
+ List<UploadCapInfo> capabilities) {
+ for (UploadCapInfo capability : capabilities) {
+ if (isNotEmpty(capability.getProperties())) {
+ newPropertiesMap.put(capability.getName(), capability.getProperties()
+ .stream()
+ .collect(toMap(UploadInfo::getName, p -> p)));
+ }
+ }
+ }
- private void addCapabilities(Map<String, List<CapabilityDefinition>> originCapabilities, String type, List<CapabilityDefinition> capabilities) {
- List<CapabilityDefinition> list = capabilities.stream().map(CapabilityDefinition::new)
- .collect(toList());
- originCapabilities.put(type, list);
- }
+ private void addCapabilities(Map<String, List<CapabilityDefinition>> originCapabilities, String type,
+ List<CapabilityDefinition> capabilities) {
+ List<CapabilityDefinition> list = capabilities.stream()
+ .map(CapabilityDefinition::new)
+ .collect(toList());
+ originCapabilities.put(type, list);
+ }
- private void updatePropertyValues(List<ComponentInstanceProperty> properties, Map<String, UploadPropInfo> newProperties,
- Map<String, DataTypeDefinition> allDataTypes) {
- properties.forEach(p->updatePropertyValue(p, newProperties.get(p.getName()), allDataTypes));
- }
+ private void updatePropertyValues(List<ComponentInstanceProperty> properties,
+ Map<String, UploadPropInfo> newProperties, Map<String, DataTypeDefinition> allDataTypes) {
+ properties.forEach(p -> updatePropertyValue(p, newProperties.get(p.getName()), allDataTypes));
+ }
- private String updatePropertyValue(ComponentInstanceProperty property, UploadPropInfo propertyInfo,
- Map<String, DataTypeDefinition> allDataTypes) {
- String value = null;
- List<GetInputValueDataDefinition> getInputs = null;
- boolean isValidate = true;
- if (null != propertyInfo && propertyInfo.getValue() != null) {
- getInputs = propertyInfo.getGet_input();
- isValidate = getInputs == null || getInputs.isEmpty();
- if (isValidate) {
- value = getPropertyJsonStringValue(propertyInfo.getValue(), property.getType());
- } else {
- value = getPropertyJsonStringValue(propertyInfo.getValue(),
- TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
- }
- }
- property.setValue(value);
+ private String updatePropertyValue(ComponentInstanceProperty property, UploadPropInfo propertyInfo,
+ Map<String, DataTypeDefinition> allDataTypes) {
+ String value = null;
+ List<GetInputValueDataDefinition> getInputs = null;
+ boolean isValidate = true;
+ if (null != propertyInfo && propertyInfo.getValue() != null) {
+ getInputs = propertyInfo.getGet_input();
+ isValidate = getInputs == null || getInputs.isEmpty();
+ if (isValidate) {
+ value = getPropertyJsonStringValue(propertyInfo.getValue(), property.getType());
+ } else {
+ value = getPropertyJsonStringValue(propertyInfo.getValue(),
+ TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
+ }
+ }
+ property.setValue(value);
return validatePropValueBeforeCreate(property, value, isValidate, allDataTypes);
- }
+ }
- private Either<Resource, StorageOperationStatus> updateCalculatedCapReqWithSubstitutionMappings(Resource resource,
- Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
- Either<Resource, StorageOperationStatus> updateRes = null;
- Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities = new HashMap<>();
- Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements = new HashMap<>();
- StorageOperationStatus status = toscaOperationFacade
- .deleteAllCalculatedCapabilitiesRequirements(resource.getUniqueId());
- if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
- log.debug(
- "Failed to delete all calculated capabilities and requirements of resource {} upon update. Status is {}",
- resource.getUniqueId(), status);
- updateRes = Either.right(status);
- }
- if (updateRes == null) {
- fillUpdatedInstCapabilitiesRequirements(resource.getComponentInstances(), uploadResInstancesMap,
- updatedInstCapabilities, updatedInstRequirements);
- status = toscaOperationFacade.associateOrAddCalculatedCapReq(updatedInstCapabilities, updatedInstRequirements,
- resource.getUniqueId());
- if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
- log.debug(
- "Failed to associate capabilities and requirementss of resource {}, updated according to a substitution mapping. Status is {}",
- resource.getUniqueId(), status);
- updateRes = Either.right(status);
- }
- }
- if (updateRes == null) {
- updateRes = Either.left(resource);
- }
- return updateRes;
- }
+ private Either<Resource, StorageOperationStatus> updateCalculatedCapReqWithSubstitutionMappings(Resource resource,
+ Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
+ Either<Resource, StorageOperationStatus> updateRes = null;
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities = new HashMap<>();
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements = new HashMap<>();
+ StorageOperationStatus status = toscaOperationFacade
+ .deleteAllCalculatedCapabilitiesRequirements(resource.getUniqueId());
+ if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
+ log.debug(
+ "Failed to delete all calculated capabilities and requirements of resource {} upon update. Status is {}",
+ resource.getUniqueId(), status);
+ updateRes = Either.right(status);
+ }
+ if (updateRes == null) {
+ fillUpdatedInstCapabilitiesRequirements(resource.getComponentInstances(), uploadResInstancesMap,
+ updatedInstCapabilities, updatedInstRequirements);
+ status = toscaOperationFacade.associateOrAddCalculatedCapReq(updatedInstCapabilities,
+ updatedInstRequirements, resource);
+ if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) {
+ log.debug(
+ "Failed to associate capabilities and requirementss of resource {}, updated according to a substitution mapping. Status is {}",
+ resource.getUniqueId(), status);
+ updateRes = Either.right(status);
+ }
+ }
+ if (updateRes == null) {
+ updateRes = Either.left(resource);
+ }
+ return updateRes;
+ }
- private void fillUpdatedInstCapabilitiesRequirements(List<ComponentInstance> componentInstances,
- Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
- Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities,
- Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements) {
-
- componentInstances.stream().forEach(i -> {
- fillUpdatedInstCapabilities(updatedInstCapabilities, i,
- uploadResInstancesMap.get(i.getName()).getCapabilitiesNamesToUpdate());
- fillUpdatedInstRequirements(updatedInstRequirements, i,
- uploadResInstancesMap.get(i.getName()).getRequirementsNamesToUpdate());
- });
- }
+ private void fillUpdatedInstCapabilitiesRequirements(List<ComponentInstance> componentInstances,
+ Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities,
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements) {
+
+ componentInstances.stream()
+ .forEach(i -> {
+ fillUpdatedInstCapabilities(updatedInstCapabilities, i, uploadResInstancesMap.get(i.getName())
+ .getCapabilitiesNamesToUpdate());
+ fillUpdatedInstRequirements(updatedInstRequirements, i, uploadResInstancesMap.get(i.getName())
+ .getRequirementsNamesToUpdate());
+ });
+ }
- private void fillUpdatedInstRequirements(
- Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements,
- ComponentInstance instance, Map<String, String> requirementsNamesToUpdate) {
- Map<String, List<RequirementDefinition>> updatedRequirements = new HashMap<>();
- Set<String> updatedReqNames = new HashSet<>();
- if (isNotEmpty(requirementsNamesToUpdate)) {
- for (Map.Entry<String, List<RequirementDefinition>> requirements : instance.getRequirements().entrySet()) {
- updatedRequirements.put(requirements.getKey(),
- requirements.getValue().stream()
- .filter(r -> requirementsNamesToUpdate.containsKey(r.getName())
- && !updatedReqNames.contains(requirementsNamesToUpdate.get(r.getName())))
- .map(r -> {
- r.setParentName(r.getName());
- r.setName(requirementsNamesToUpdate.get(r.getName()));
- updatedReqNames.add(r.getName());
- return r;
- }).collect(toList()));
- }
- }
- if (isNotEmpty(updatedRequirements)) {
- updatedInstRequirements.put(instance, updatedRequirements);
- }
- }
+ private void fillUpdatedInstRequirements(
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements,
+ ComponentInstance instance, Map<String, String> requirementsNamesToUpdate) {
+ Map<String, List<RequirementDefinition>> updatedRequirements = new HashMap<>();
+ Set<String> updatedReqNames = new HashSet<>();
+ if (isNotEmpty(requirementsNamesToUpdate)) {
+ for (Map.Entry<String, List<RequirementDefinition>> requirements : instance.getRequirements()
+ .entrySet()) {
+ updatedRequirements.put(requirements.getKey(), requirements.getValue()
+ .stream()
+ .filter(r -> requirementsNamesToUpdate.containsKey(r.getName())
+ && !updatedReqNames.contains(requirementsNamesToUpdate.get(r.getName())))
+ .map(r -> {
+ r.setParentName(r.getName());
+ r.setName(requirementsNamesToUpdate.get(r.getName()));
+ updatedReqNames.add(r.getName());
+ return r;
+ })
+ .collect(toList()));
+ }
+ }
+ if (isNotEmpty(updatedRequirements)) {
+ updatedInstRequirements.put(instance, updatedRequirements);
+ }
+ }
- private void fillUpdatedInstCapabilities(
- Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilties,
- ComponentInstance instance, Map<String, String> capabilitiesNamesToUpdate) {
- Map<String, List<CapabilityDefinition>> updatedCapabilities = new HashMap<>();
- Set<String> updatedCapNames = new HashSet<>();
- if (isNotEmpty(capabilitiesNamesToUpdate)) {
- for (Map.Entry<String, List<CapabilityDefinition>> requirements : instance.getCapabilities().entrySet()) {
- updatedCapabilities.put(requirements.getKey(),
- requirements.getValue().stream()
- .filter(c -> capabilitiesNamesToUpdate.containsKey(c.getName())
- && !updatedCapNames.contains(capabilitiesNamesToUpdate.get(c.getName())))
- .map(c -> {
- c.setParentName(c.getName());
- c.setName(capabilitiesNamesToUpdate.get(c.getName()));
- updatedCapNames.add(c.getName());
- return c;
- }).collect(toList()));
- }
- }
- if (isNotEmpty(updatedCapabilities)) {
- updatedInstCapabilties.put(instance, updatedCapabilities);
- }
- }
+ private void fillUpdatedInstCapabilities(
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilties,
+ ComponentInstance instance, Map<String, String> capabilitiesNamesToUpdate) {
+ Map<String, List<CapabilityDefinition>> updatedCapabilities = new HashMap<>();
+ Set<String> updatedCapNames = new HashSet<>();
+ if (isNotEmpty(capabilitiesNamesToUpdate)) {
+ for (Map.Entry<String, List<CapabilityDefinition>> requirements : instance.getCapabilities()
+ .entrySet()) {
+ updatedCapabilities.put(requirements.getKey(), requirements.getValue()
+ .stream()
+ .filter(c -> capabilitiesNamesToUpdate.containsKey(c.getName())
+ && !updatedCapNames.contains(capabilitiesNamesToUpdate.get(c.getName())))
+ .map(c -> {
+ c.setParentName(c.getName());
+ c.setName(capabilitiesNamesToUpdate.get(c.getName()));
+ updatedCapNames.add(c.getName());
+ return c;
+ })
+ .collect(toList()));
+ }
+ }
+ if (isNotEmpty(updatedCapabilities)) {
+ updatedInstCapabilties.put(instance, updatedCapabilities);
+ }
+ }
- private ResponseFormat addRelationToRI(String yamlName, Resource resource,
- UploadComponentInstanceInfo nodesInfoValue, List<RequirementCapabilityRelDef> relations) {
- List<ComponentInstance> componentInstancesList = resource.getComponentInstances();
+ private ResponseFormat addRelationToRI(String yamlName, Resource resource,
+ UploadComponentInstanceInfo nodesInfoValue, List<RequirementCapabilityRelDef> relations) {
+ List<ComponentInstance> componentInstancesList = resource.getComponentInstances();
- ComponentInstance currentCompInstance = null;
+ ComponentInstance currentCompInstance = null;
- for (ComponentInstance compInstance : componentInstancesList) {
+ for (ComponentInstance compInstance : componentInstancesList) {
- if (compInstance.getName().equals(nodesInfoValue.getName())) {
- currentCompInstance = compInstance;
- break;
- }
+ if (compInstance.getName()
+ .equals(nodesInfoValue.getName())) {
+ currentCompInstance = compInstance;
+ break;
+ }
- }
+ }
- if (currentCompInstance == null) {
- log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, nodesInfoValue.getName(),
- resource.getUniqueId());
- BeEcompErrorManager.getInstance().logInternalDataError(
- COMPONENT_INSTANCE_WITH_NAME + nodesInfoValue.getName() + IN_RESOURCE,
- resource.getUniqueId(), ErrorSeverity.ERROR);
- return componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE,
- yamlName);
- }
- String resourceInstanceId = currentCompInstance.getUniqueId();
-
- Map<String, List<UploadReqInfo>> regMap = nodesInfoValue.getRequirements();
-
- if (regMap != null) {
- Iterator<Entry<String, List<UploadReqInfo>>> nodesRegValue = regMap.entrySet().iterator();
-
- while (nodesRegValue.hasNext()) {
- Entry<String, List<UploadReqInfo>> nodesRegInfoEntry = nodesRegValue.next();
-
- List<UploadReqInfo> uploadRegInfoList = nodesRegInfoEntry.getValue();
- for (UploadReqInfo uploadRegInfo : uploadRegInfoList) {
- log.debug("Going to create relation {}", uploadRegInfo.getName());
- String regName = uploadRegInfo.getName();
- RequirementCapabilityRelDef regCapRelDef = new RequirementCapabilityRelDef();
- regCapRelDef.setFromNode(resourceInstanceId);
- log.debug("try to find available requirement {} ", regName);
- Either<RequirementDefinition, ResponseFormat> eitherReqStatus = findAviableRequiremen(regName,
- yamlName, nodesInfoValue, currentCompInstance,
- uploadRegInfo.getCapabilityName());
- if (eitherReqStatus.isRight()) {
- log.debug("failed to find available requirement {} status is {}", regName,
- eitherReqStatus.right().value());
- return eitherReqStatus.right().value();
- }
-
- RequirementDefinition validReq = eitherReqStatus.left().value();
- List<CapabilityRequirementRelationship> reqAndRelationshipPairList = regCapRelDef
- .getRelationships();
- if (reqAndRelationshipPairList == null) {
- reqAndRelationshipPairList = new ArrayList<>();
- }
- RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
- reqAndRelationshipPair.setRequirement(regName);
- reqAndRelationshipPair.setRequirementOwnerId(validReq.getOwnerId());
- reqAndRelationshipPair.setRequirementUid(validReq.getUniqueId());
- RelationshipImpl relationship = new RelationshipImpl();
- relationship.setType(validReq.getCapability());
- reqAndRelationshipPair.setRelationships(relationship);
-
- ComponentInstance currentCapCompInstance = null;
- for (ComponentInstance compInstance : componentInstancesList) {
- if (compInstance.getName().equals(uploadRegInfo.getNode())) {
- currentCapCompInstance = compInstance;
- break;
- }
- }
-
- if (currentCapCompInstance == null) {
- log.debug("The component instance with name {} not found on resource {} ",
- uploadRegInfo.getNode(), resource.getUniqueId());
- BeEcompErrorManager.getInstance().logInternalDataError(
- COMPONENT_INSTANCE_WITH_NAME + uploadRegInfo.getNode() + IN_RESOURCE,
- resource.getUniqueId(), ErrorSeverity.ERROR);
- return componentsUtils
- .getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
- }
- regCapRelDef.setToNode(currentCapCompInstance.getUniqueId());
- log.debug("try to find aviable Capability req name is {} ", validReq.getName());
- CapabilityDefinition aviableCapForRel = findAvailableCapabilityByTypeOrName(validReq,
- currentCapCompInstance, uploadRegInfo);
- reqAndRelationshipPair.setCapability(aviableCapForRel.getName());
- reqAndRelationshipPair.setCapabilityUid(aviableCapForRel.getUniqueId());
- reqAndRelationshipPair.setCapabilityOwnerId(aviableCapForRel.getOwnerId());
- if (aviableCapForRel == null) {
- log.debug("aviable capability was not found. req name is {} component instance is {}",
- validReq.getName(), currentCapCompInstance.getUniqueId());
- BeEcompErrorManager.getInstance().logInternalDataError(
- "aviable capability was not found. req name is " + validReq.getName()
- + " component instance is " + currentCapCompInstance.getUniqueId(),
- resource.getUniqueId(), ErrorSeverity.ERROR);
- return componentsUtils
- .getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
- }
- CapabilityRequirementRelationship capReqRel = new CapabilityRequirementRelationship();
- capReqRel.setRelation(reqAndRelationshipPair);
- reqAndRelationshipPairList.add(capReqRel);
- regCapRelDef.setRelationships(reqAndRelationshipPairList);
- relations.add(regCapRelDef);
- }
- }
- } else if (resource.getResourceType() != ResourceTypeEnum.CVFC) {
- return componentsUtils.getResponseFormat(ActionStatus.OK, yamlName);
- }
- return componentsUtils.getResponseFormat(ActionStatus.OK);
- }
+ if (currentCompInstance == null) {
+ log.debug(COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE, nodesInfoValue.getName(), resource.getUniqueId());
+ BeEcompErrorManager.getInstance()
+ .logInternalDataError(COMPONENT_INSTANCE_WITH_NAME + nodesInfoValue.getName() + IN_RESOURCE,
+ resource.getUniqueId(), ErrorSeverity.ERROR);
+ return componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ }
+ String resourceInstanceId = currentCompInstance.getUniqueId();
+
+ Map<String, List<UploadReqInfo>> regMap = nodesInfoValue.getRequirements();
+
+ if (regMap != null) {
+ Iterator<Entry<String, List<UploadReqInfo>>> nodesRegValue = regMap.entrySet()
+ .iterator();
+
+ while (nodesRegValue.hasNext()) {
+ Entry<String, List<UploadReqInfo>> nodesRegInfoEntry = nodesRegValue.next();
+
+ List<UploadReqInfo> uploadRegInfoList = nodesRegInfoEntry.getValue();
+ for (UploadReqInfo uploadRegInfo : uploadRegInfoList) {
+ log.debug("Going to create relation {}", uploadRegInfo.getName());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,"Started to create relations on instance: {}",uploadRegInfo.getName());
+ String regName = uploadRegInfo.getName();
+ RequirementCapabilityRelDef regCapRelDef = new RequirementCapabilityRelDef();
+ regCapRelDef.setFromNode(resourceInstanceId);
+ log.debug("try to find available requirement {} ", regName);
+ Either<RequirementDefinition, ResponseFormat> eitherReqStatus = findAviableRequiremen(regName,
+ yamlName, nodesInfoValue, currentCompInstance, uploadRegInfo.getCapabilityName());
+ if (eitherReqStatus.isRight()) {
+ log.debug("failed to find available requirement {} status is {}", regName,
+ eitherReqStatus.right()
+ .value());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.ERROR,"ERROR while search available requirement {} status is: {}",regName,eitherReqStatus.right().value());
+ return eitherReqStatus.right()
+ .value();
+ }
+
+ RequirementDefinition validReq = eitherReqStatus.left()
+ .value();
+ List<CapabilityRequirementRelationship> reqAndRelationshipPairList = regCapRelDef
+ .getRelationships();
+ if (reqAndRelationshipPairList == null) {
+ reqAndRelationshipPairList = new ArrayList<>();
+ }
+ RelationshipInfo reqAndRelationshipPair = new RelationshipInfo();
+ reqAndRelationshipPair.setRequirement(regName);
+ reqAndRelationshipPair.setRequirementOwnerId(validReq.getOwnerId());
+ reqAndRelationshipPair.setRequirementUid(validReq.getUniqueId());
+ RelationshipImpl relationship = new RelationshipImpl();
+ relationship.setType(validReq.getCapability());
+ reqAndRelationshipPair.setRelationships(relationship);
+
+ ComponentInstance currentCapCompInstance = null;
+ for (ComponentInstance compInstance : componentInstancesList) {
+ if (compInstance.getName()
+ .equals(uploadRegInfo.getNode())) {
+ currentCapCompInstance = compInstance;
+ break;
+ }
+ }
+
+ if (currentCapCompInstance == null) {
+ log.debug("The component instance with name {} not found on resource {} ",
+ uploadRegInfo.getNode(), resource.getUniqueId());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.ERROR,"ERROR component instance with name: {} not found on resource: {}",uploadRegInfo.getNode(),resource.getUniqueId());
+ BeEcompErrorManager.getInstance()
+ .logInternalDataError(
+ COMPONENT_INSTANCE_WITH_NAME + uploadRegInfo.getNode() + IN_RESOURCE,
+ resource.getUniqueId(), ErrorSeverity.ERROR);
+ return componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ }
+ regCapRelDef.setToNode(currentCapCompInstance.getUniqueId());
+ log.debug("try to find aviable Capability req name is {} ", validReq.getName());
+ CapabilityDefinition aviableCapForRel = findAvailableCapabilityByTypeOrName(validReq,
+ currentCapCompInstance, uploadRegInfo);
+ reqAndRelationshipPair.setCapability(aviableCapForRel.getName());
+ reqAndRelationshipPair.setCapabilityUid(aviableCapForRel.getUniqueId());
+ reqAndRelationshipPair.setCapabilityOwnerId(aviableCapForRel.getOwnerId());
+ if (aviableCapForRel == null) {
+ log.debug("aviable capability was not found. req name is {} component instance is {}",
+ validReq.getName(), currentCapCompInstance.getUniqueId());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.ERROR,"ERROR available capability was not found. req name is: {} component instance is: {}",validReq.getName(),currentCapCompInstance.getUniqueId());
+ BeEcompErrorManager.getInstance()
+ .logInternalDataError(
+ "aviable capability was not found. req name is " + validReq.getName()
+ + " component instance is " + currentCapCompInstance.getUniqueId(),
+ resource.getUniqueId(), ErrorSeverity.ERROR);
+ return componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ }
+ CapabilityRequirementRelationship capReqRel = new CapabilityRequirementRelationship();
+ capReqRel.setRelation(reqAndRelationshipPair);
+ reqAndRelationshipPairList.add(capReqRel);
+ regCapRelDef.setRelationships(reqAndRelationshipPairList);
+ relations.add(regCapRelDef);
+ }
+ }
+ } else if (resource.getResourceType() != ResourceTypeEnum.CVFC) {
+ return componentsUtils.getResponseFormat(ActionStatus.OK, yamlName);
+ }
+ return componentsUtils.getResponseFormat(ActionStatus.OK);
+ }
- private void addInputsValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo,
- Resource resource, Resource originResource, ComponentInstance currentCompInstance,
- Map<String, List<ComponentInstanceInput>> instInputs, Map<String, DataTypeDefinition> allDataTypes) {
- Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
- if (MapUtils.isNotEmpty(propMap)) {
- Map<String, InputDefinition> currPropertiesMap = new HashMap<>();
- List<ComponentInstanceInput> instPropList = new ArrayList<>();
-
- if (CollectionUtils.isEmpty( originResource.getInputs())) {
- log.debug("failed to find properties ");
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
- }
- originResource.getInputs().forEach(p->addInput(currPropertiesMap, p));
- for (List<UploadPropInfo> propertyList : propMap.values()) {
- processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList);
- }
- currPropertiesMap.values().forEach(p->instPropList.add(new ComponentInstanceInput(p)));
- instInputs.put(currentCompInstance.getUniqueId(), instPropList);
- }
- }
+ private void addInputsValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo, Resource resource,
+ Resource originResource, ComponentInstance currentCompInstance,
+ Map<String, List<ComponentInstanceInput>> instInputs, Map<String, DataTypeDefinition> allDataTypes) {
+ Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
+ if (MapUtils.isNotEmpty(propMap)) {
+ Map<String, InputDefinition> currPropertiesMap = new HashMap<>();
+ List<ComponentInstanceInput> instPropList = new ArrayList<>();
+
+ if (CollectionUtils.isEmpty(originResource.getInputs())) {
+ log.debug("failed to find properties ");
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS,resource.getComponentMetadataForSupportLog(),StatusCode.ERROR,"ERROR while try to find properties");
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND);
+ }
+ originResource.getInputs()
+ .forEach(p -> addInput(currPropertiesMap, p));
+ for (List<UploadPropInfo> propertyList : propMap.values()) {
+ processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList,
+ propertyList);
+ }
+ currPropertiesMap.values()
+ .forEach(p -> instPropList.add(new ComponentInstanceInput(p)));
+ instInputs.put(currentCompInstance.getUniqueId(), instPropList);
+ }
+ }
- private void processProperty(Resource resource, ComponentInstance currentCompInstance, Map<String, DataTypeDefinition> allDataTypes, Map<String, InputDefinition> currPropertiesMap, List<ComponentInstanceInput> instPropList, List<UploadPropInfo> propertyList) {
- UploadPropInfo propertyInfo = propertyList.get(0);
- String propName = propertyInfo.getName();
- if (!currPropertiesMap.containsKey(propName)) {
- log.debug("failed to find property {} ", propName);
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND,
- propName));
- }
- InputDefinition curPropertyDef = currPropertiesMap.get(propName);
- ComponentInstanceInput property = null;
-
- String value = null;
- List<GetInputValueDataDefinition> getInputs = null;
- boolean isValidate = true;
- if (propertyInfo.getValue() != null) {
- getInputs = propertyInfo.getGet_input();
- isValidate = getInputs == null || getInputs.isEmpty();
- if (isValidate) {
- value = getPropertyJsonStringValue(propertyInfo.getValue(),
- curPropertyDef.getType());
- } else {
- value = getPropertyJsonStringValue(propertyInfo.getValue(),
- TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
- }
- }
- String innerType = null;
- property = new ComponentInstanceInput(curPropertyDef, value, null);
+ private void processProperty(Resource resource, ComponentInstance currentCompInstance,
+ Map<String, DataTypeDefinition> allDataTypes, Map<String, InputDefinition> currPropertiesMap,
+ List<ComponentInstanceInput> instPropList, List<UploadPropInfo> propertyList) {
+ UploadPropInfo propertyInfo = propertyList.get(0);
+ String propName = propertyInfo.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ loggerSupportability.log(LoggerSupportabilityActions.PROPERTY,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR failed to find property: {}",propName);
+ log.debug("failed to find property {} ", propName);
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, propName);
+ }
+ InputDefinition curPropertyDef = currPropertiesMap.get(propName);
+ ComponentInstanceInput property = null;
+
+ String value = null;
+ List<GetInputValueDataDefinition> getInputs = null;
+ boolean isValidate = true;
+ if (propertyInfo.getValue() != null) {
+ getInputs = propertyInfo.getGet_input();
+ isValidate = getInputs == null || getInputs.isEmpty();
+ if (isValidate) {
+ value = getPropertyJsonStringValue(propertyInfo.getValue(), curPropertyDef.getType());
+ } else {
+ value = getPropertyJsonStringValue(propertyInfo.getValue(),
+ TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
+ }
+ }
+ String innerType = null;
+ property = new ComponentInstanceInput(curPropertyDef, value, null);
String validPropertyVAlue = validatePropValueBeforeCreate(property, value, isValidate, allDataTypes);
- property.setValue(validPropertyVAlue);
-
- if (isNotEmpty(getInputs)) {
- List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
- for (GetInputValueDataDefinition getInput : getInputs) {
- List<InputDefinition> inputs = resource.getInputs();
- if (CollectionUtils.isEmpty(inputs)) {
- log.debug("Failed to add property {} to resource instance {}. Inputs list is empty ",
- property, currentCompInstance.getUniqueId());
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- Optional<InputDefinition> optional = inputs.stream()
- .filter(p -> p.getName().equals(getInput.getInputName())).findAny();
- if (!optional.isPresent()) {
- log.debug("Failed to find input {} ", getInput.getInputName());
- // @@TODO error message
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- InputDefinition input = optional.get();
- getInput.setInputId(input.getUniqueId());
- getInputValues.add(getInput);
-
- GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
- processGetInput(getInputValues, inputs, getInputIndex);
- }
- property.setGetInputValues(getInputValues);
- }
- instPropList.add(property);
- // delete overriden property
- currPropertiesMap.remove(property.getName());
- }
+ property.setValue(validPropertyVAlue);
+
+ if (isNotEmpty(getInputs)) {
+ List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
+ for (GetInputValueDataDefinition getInput : getInputs) {
+ List<InputDefinition> inputs = resource.getInputs();
+ if (CollectionUtils.isEmpty(inputs)) {
+ loggerSupportability.log(LoggerSupportabilityActions.PROPERTY,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR Failed to add property: "+propName+" to resource instance: {}. Inputs list is empty ",currentCompInstance.getUniqueId());
+ log.debug("Failed to add property {} to resource instance {}. Inputs list is empty ", property,
+ currentCompInstance.getUniqueId());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
+ }
+
+ Optional<InputDefinition> optional = inputs.stream()
+ .filter(p -> p.getName()
+ .equals(getInput.getInputName()))
+ .findAny();
+ if (!optional.isPresent()) {
+ loggerSupportability.log(LoggerSupportabilityActions.PROPERTY,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR Failed to find input: "+getInput.getInputName());
+ log.debug("Failed to find input {} ", getInput.getInputName());
+ // @@TODO error message
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
+ }
+ InputDefinition input = optional.get();
+ getInput.setInputId(input.getUniqueId());
+ getInputValues.add(getInput);
+
+ GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
+ processGetInput(getInputValues, inputs, getInputIndex);
+ }
+ property.setGetInputValues(getInputValues);
+ }
+ instPropList.add(property);
+ // delete overriden property
+ currPropertiesMap.remove(property.getName());
+ }
- private void processGetInput(List<GetInputValueDataDefinition> getInputValues, List<InputDefinition> inputs, GetInputValueDataDefinition getInputIndex) {
- Optional<InputDefinition> optional;
- if (getInputIndex != null) {
- optional = inputs.stream().filter(p -> p.getName().equals(getInputIndex.getInputName()))
- .findAny();
- if (!optional.isPresent()) {
- log.debug("Failed to find input {} ", getInputIndex.getInputName());
- // @@TODO error message
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- InputDefinition inputIndex = optional.get();
- getInputIndex.setInputId(inputIndex.getUniqueId());
- getInputValues.add(getInputIndex);
- }
- }
+ private void processGetInput(List<GetInputValueDataDefinition> getInputValues, List<InputDefinition> inputs,
+ GetInputValueDataDefinition getInputIndex) {
+ Optional<InputDefinition> optional;
+ if (getInputIndex != null) {
+ optional = inputs.stream()
+ .filter(p -> p.getName()
+ .equals(getInputIndex.getInputName()))
+ .findAny();
+ if (!optional.isPresent()) {
+ log.debug("Failed to find input {} ", getInputIndex.getInputName());
+ // @@TODO error message
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
+ }
+ InputDefinition inputIndex = optional.get();
+ getInputIndex.setInputId(inputIndex.getUniqueId());
+ getInputValues.add(getInputIndex);
+ }
+ }
- private void addInput(Map<String, InputDefinition> currPropertiesMap, InputDefinition prop) {
- String propName = prop.getName();
- if (!currPropertiesMap.containsKey(propName)) {
- currPropertiesMap.put(propName, prop);
- }
- }
+ private void addInput(Map<String, InputDefinition> currPropertiesMap, InputDefinition prop) {
+ String propName = prop.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ currPropertiesMap.put(propName, prop);
+ }
+ }
- private ResponseFormat addPropertyValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo,
- Resource resource, Resource originResource, ComponentInstance currentCompInstance,
- Map<String, List<ComponentInstanceProperty>> instProperties, Map<String, DataTypeDefinition> allDataTypes) {
+ private ResponseFormat addPropertyValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo,
+ Resource resource, Resource originResource, ComponentInstance currentCompInstance,
+ Map<String, List<ComponentInstanceProperty>> instProperties, Map<String, DataTypeDefinition> allDataTypes) {
- Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
- Map<String, PropertyDefinition> currPropertiesMap = new HashMap<>();
+ Map<String, List<UploadPropInfo>> propMap = uploadComponentInstanceInfo.getProperties();
+ Map<String, PropertyDefinition> currPropertiesMap = new HashMap<>();
- List<PropertyDefinition> listFromMap = originResource.getProperties();
- if ((propMap != null && !propMap.isEmpty()) && (listFromMap == null || listFromMap.isEmpty())) {
- log.debug("failed to find properties ");
- return componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND);
- }
- if (listFromMap == null || listFromMap.isEmpty()) {
- return componentsUtils.getResponseFormat(ActionStatus.OK);
- }
- for (PropertyDefinition prop : listFromMap) {
- String propName = prop.getName();
- if (!currPropertiesMap.containsKey(propName)) {
- currPropertiesMap.put(propName, prop);
- }
- }
- List<ComponentInstanceProperty> instPropList = new ArrayList<>();
- if (propMap != null && propMap.size() > 0) {
- for (List<UploadPropInfo> propertyList : propMap.values()) {
-
- UploadPropInfo propertyInfo = propertyList.get(0);
- String propName = propertyInfo.getName();
- if (!currPropertiesMap.containsKey(propName)) {
- log.debug("failed to find property {} ", propName);
- return componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND,
- propName);
- }
- PropertyDefinition curPropertyDef = currPropertiesMap.get(propName);
- ComponentInstanceProperty property = null;
-
- String value = null;
- List<GetInputValueDataDefinition> getInputs = null;
- boolean isValidate = true;
- if (propertyInfo.getValue() != null) {
- getInputs = propertyInfo.getGet_input();
- isValidate = getInputs == null || getInputs.isEmpty();
- if (isValidate) {
- value = getPropertyJsonStringValue(propertyInfo.getValue(),
- curPropertyDef.getType());
- } else {
- value = getPropertyJsonStringValue(propertyInfo.getValue(),
- TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
- }
- }
- String innerType = null;
- property = new ComponentInstanceProperty(curPropertyDef, value, null);
+ List<PropertyDefinition> listFromMap = originResource.getProperties();
+ if ((propMap != null && !propMap.isEmpty()) && (listFromMap == null || listFromMap.isEmpty())) {
+ loggerSupportability.log(LoggerSupportabilityActions.PROPERTY,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR Failed to find properties");
+ log.debug("failed to find properties");
+ return componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND);
+ }
+ if (listFromMap == null || listFromMap.isEmpty()) {
+ return componentsUtils.getResponseFormat(ActionStatus.OK);
+ }
+ for (PropertyDefinition prop : listFromMap) {
+ String propName = prop.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ currPropertiesMap.put(propName, prop);
+ }
+ }
+ List<ComponentInstanceProperty> instPropList = new ArrayList<>();
+ if (propMap != null && propMap.size() > 0) {
+ for (List<UploadPropInfo> propertyList : propMap.values()) {
+
+ UploadPropInfo propertyInfo = propertyList.get(0);
+ String propName = propertyInfo.getName();
+ if (!currPropertiesMap.containsKey(propName)) {
+ log.debug("failed to find property {} ", propName);
+ loggerSupportability.log(LoggerSupportabilityActions.PROPERTY,resource.getComponentMetadataForSupportLog(), StatusCode.ERROR,"ERROR Failed to find property: {}",propName);
+ return componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, propName);
+ }
+ PropertyDefinition curPropertyDef = currPropertiesMap.get(propName);
+ ComponentInstanceProperty property = null;
+
+ String value = null;
+ List<GetInputValueDataDefinition> getInputs = null;
+ boolean isValidate = true;
+ if (propertyInfo.getValue() != null) {
+ getInputs = propertyInfo.getGet_input();
+ isValidate = getInputs == null || getInputs.isEmpty();
+ if (isValidate) {
+ value = getPropertyJsonStringValue(propertyInfo.getValue(), curPropertyDef.getType());
+ } else {
+ value = getPropertyJsonStringValue(propertyInfo.getValue(),
+ TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName());
+ }
+ }
+ String innerType = null;
+ property = new ComponentInstanceProperty(curPropertyDef, value, null);
String validatePropValue = validatePropValueBeforeCreate(property, value, isValidate, allDataTypes);
- property.setValue(validatePropValue);
-
- if (getInputs != null && !getInputs.isEmpty()) {
- List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
- for (GetInputValueDataDefinition getInput : getInputs) {
- List<InputDefinition> inputs = resource.getInputs();
- if (inputs == null || inputs.isEmpty()) {
- log.debug("Failed to add property {} to instance. Inputs list is empty ", property);
- rollbackWithException(ActionStatus.INPUTS_NOT_FOUND, property.getGetInputValues()
- .stream()
- .map(GetInputValueDataDefinition::getInputName)
- .collect(toList()).toString());
- }
- InputDefinition input = findInputByName(inputs, getInput);
- getInput.setInputId(input.getUniqueId());
- getInputValues.add(getInput);
-
- GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
- if (getInputIndex != null) {
- input = findInputByName(inputs, getInputIndex);
- getInputIndex.setInputId(input.getUniqueId());
- getInputValues.add(getInputIndex);
-
- }
-
- }
- property.setGetInputValues(getInputValues);
- }
- instPropList.add(property);
- // delete overriden property
- currPropertiesMap.remove(property.getName());
- }
- }
- // add rest of properties
- if (!currPropertiesMap.isEmpty()) {
- for (PropertyDefinition value : currPropertiesMap.values()) {
- instPropList.add(new ComponentInstanceProperty(value));
- }
- }
- instProperties.put(currentCompInstance.getUniqueId(), instPropList);
- return componentsUtils.getResponseFormat(ActionStatus.OK);
- }
+ property.setValue(validatePropValue);
+
+ if (getInputs != null && !getInputs.isEmpty()) {
+ List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
+ for (GetInputValueDataDefinition getInput : getInputs) {
+ List<InputDefinition> inputs = resource.getInputs();
+ if (inputs == null || inputs.isEmpty()) {
+ log.debug("Failed to add property {} to instance. Inputs list is empty ", property);
+ loggerSupportability.log(LoggerSupportabilityActions.PROPERTY,resource.getComponentMetadataForSupportLog(), StatusCode.ERROR,"Failed to add property: {} to instance. Inputs list is empty",propName);
+ rollbackWithException(ActionStatus.INPUTS_NOT_FOUND, property.getGetInputValues()
+ .stream()
+ .map(GetInputValueDataDefinition::getInputName)
+ .collect(toList())
+ .toString());
+ }
+ InputDefinition input = findInputByName(inputs, getInput);
+ getInput.setInputId(input.getUniqueId());
+ getInputValues.add(getInput);
+
+ GetInputValueDataDefinition getInputIndex = getInput.getGetInputIndex();
+ if (getInputIndex != null) {
+ input = findInputByName(inputs, getInputIndex);
+ getInputIndex.setInputId(input.getUniqueId());
+ getInputValues.add(getInputIndex);
+
+ }
+
+ }
+ property.setGetInputValues(getInputValues);
+ }
+ instPropList.add(property);
+ // delete overriden property
+ currPropertiesMap.remove(property.getName());
+ }
+ }
+ // add rest of properties
+ if (!currPropertiesMap.isEmpty()) {
+ for (PropertyDefinition value : currPropertiesMap.values()) {
+ instPropList.add(new ComponentInstanceProperty(value));
+ }
+ }
+ instProperties.put(currentCompInstance.getUniqueId(), instPropList);
+ return componentsUtils.getResponseFormat(ActionStatus.OK);
+ }
- // US740820 Relate RIs according to capability name
- private CapabilityDefinition findAvailableCapabilityByTypeOrName(RequirementDefinition validReq,
- ComponentInstance currentCapCompInstance, UploadReqInfo uploadReqInfo) {
- if (null == uploadReqInfo.getCapabilityName()
- || validReq.getCapability().equals(uploadReqInfo.getCapabilityName())) {// get
- // by
- // capability
- // type
- return findAvailableCapability(validReq, currentCapCompInstance);
- }
- return findAvailableCapability(validReq, currentCapCompInstance, uploadReqInfo);
- }
+ // US740820 Relate RIs according to capability name
+ private CapabilityDefinition findAvailableCapabilityByTypeOrName(RequirementDefinition validReq,
+ ComponentInstance currentCapCompInstance, UploadReqInfo uploadReqInfo) {
+ if (null == uploadReqInfo.getCapabilityName() || validReq.getCapability()
+ .equals(uploadReqInfo.getCapabilityName())) {// get
+ // by
+ // capability
+ // type
+ return findAvailableCapability(validReq, currentCapCompInstance);
+ }
+ return findAvailableCapability(validReq, currentCapCompInstance, uploadReqInfo);
+ }
- private CapabilityDefinition findAvailableCapability(RequirementDefinition validReq,
- ComponentInstance currentCapCompInstance, UploadReqInfo uploadReqInfo) {
- CapabilityDefinition cap = null;
- Map<String, List<CapabilityDefinition>> capMap = currentCapCompInstance.getCapabilities();
- if (!capMap.containsKey(validReq.getCapability())) {
- return null;
- }
- Optional<CapabilityDefinition> capByName = capMap.get(validReq.getCapability()).stream()
- .filter(p -> p.getName().equals(uploadReqInfo.getCapabilityName())).findAny();
- if (!capByName.isPresent()) {
- return null;
- }
- cap = capByName.get();
+ private CapabilityDefinition findAvailableCapability(RequirementDefinition validReq,
+ ComponentInstance currentCapCompInstance, UploadReqInfo uploadReqInfo) {
+ CapabilityDefinition cap = null;
+ Map<String, List<CapabilityDefinition>> capMap = currentCapCompInstance.getCapabilities();
+ if (!capMap.containsKey(validReq.getCapability())) {
+ return null;
+ }
+ Optional<CapabilityDefinition> capByName = capMap.get(validReq.getCapability())
+ .stream()
+ .filter(p -> p.getName()
+ .equals(uploadReqInfo.getCapabilityName()))
+ .findAny();
+ if (!capByName.isPresent()) {
+ return null;
+ }
+ cap = capByName.get();
- if (isBoundedByOccurrences(cap)) {
- String leftOccurrences = cap.getLeftOccurrences();
- int left = Integer.parseInt(leftOccurrences);
- if (left > 0) {
- --left;
- cap.setLeftOccurrences(String.valueOf(left));
+ if (isBoundedByOccurrences(cap)) {
+ String leftOccurrences = cap.getLeftOccurrences();
+ int left = Integer.parseInt(leftOccurrences);
+ if (left > 0) {
+ --left;
+ cap.setLeftOccurrences(String.valueOf(left));
- }
+ }
- }
- return cap;
- }
+ }
+ return cap;
+ }
- private CapabilityDefinition findAvailableCapability(RequirementDefinition validReq, ComponentInstance instance) {
- Map<String, List<CapabilityDefinition>> capMap = instance.getCapabilities();
- if (capMap.containsKey(validReq.getCapability())) {
- List<CapabilityDefinition> capList = capMap.get(validReq.getCapability());
-
- for (CapabilityDefinition cap : capList) {
- if (isBoundedByOccurrences(cap)) {
- String leftOccurrences = cap.getLeftOccurrences() != null ?
- cap.getLeftOccurrences() : cap.getMaxOccurrences();
- int left = Integer.parseInt(leftOccurrences);
- if (left > 0) {
- --left;
- cap.setLeftOccurrences(String.valueOf(left));
- return cap;
- }
- } else {
- return cap;
- }
- }
- }
- return null;
- }
+ private CapabilityDefinition findAvailableCapability(RequirementDefinition validReq, ComponentInstance instance) {
+ Map<String, List<CapabilityDefinition>> capMap = instance.getCapabilities();
+ if (capMap.containsKey(validReq.getCapability())) {
+ List<CapabilityDefinition> capList = capMap.get(validReq.getCapability());
+
+ for (CapabilityDefinition cap : capList) {
+ if (isBoundedByOccurrences(cap)) {
+ String leftOccurrences = cap.getLeftOccurrences() != null ? cap.getLeftOccurrences()
+ : cap.getMaxOccurrences();
+ int left = Integer.parseInt(leftOccurrences);
+ if (left > 0) {
+ --left;
+ cap.setLeftOccurrences(String.valueOf(left));
+ return cap;
+ }
+ } else {
+ return cap;
+ }
+ }
+ }
+ return null;
+ }
- private boolean isBoundedByOccurrences(CapabilityDefinition cap) {
- return cap.getMaxOccurrences() != null && !cap.getMaxOccurrences().equals(CapabilityDataDefinition.MAX_OCCURRENCES);
- }
+ private boolean isBoundedByOccurrences(CapabilityDefinition cap) {
+ return cap.getMaxOccurrences() != null && !cap.getMaxOccurrences()
+ .equals(CapabilityDataDefinition.MAX_OCCURRENCES);
+ }
- private Either<RequirementDefinition, ResponseFormat> findAviableRequiremen(String regName, String yamlName,
- UploadComponentInstanceInfo uploadComponentInstanceInfo, ComponentInstance currentCompInstance,
- String capName) {
- Map<String, List<RequirementDefinition>> comInstRegDefMap = currentCompInstance.getRequirements();
- List<RequirementDefinition> list = comInstRegDefMap.get(capName);
- RequirementDefinition validRegDef = null;
- if (list == null) {
- for (Entry<String, List<RequirementDefinition>> entry : comInstRegDefMap.entrySet()) {
- for (RequirementDefinition reqDef : entry.getValue()) {
- if (reqDef.getName().equals(regName)) {
- if (reqDef.getMaxOccurrences() != null
- && !reqDef.getMaxOccurrences().equals(RequirementDataDefinition.MAX_OCCURRENCES)) {
- String leftOccurrences = reqDef.getLeftOccurrences();
- if (leftOccurrences == null) {
- leftOccurrences = reqDef.getMaxOccurrences();
- }
- int left = Integer.parseInt(leftOccurrences);
- if (left > 0) {
- --left;
- reqDef.setLeftOccurrences(String.valueOf(left));
- validRegDef = reqDef;
- break;
- } else {
- continue;
- }
- } else {
- validRegDef = reqDef;
- break;
- }
-
- }
- }
- if (validRegDef != null) {
- break;
- }
- }
- } else {
- for (RequirementDefinition reqDef : list) {
- if (reqDef.getName().equals(regName)) {
- if (reqDef.getMaxOccurrences() != null
- && !reqDef.getMaxOccurrences().equals(RequirementDataDefinition.MAX_OCCURRENCES)) {
- String leftOccurrences = reqDef.getLeftOccurrences();
- if (leftOccurrences == null) {
- leftOccurrences = reqDef.getMaxOccurrences();
- }
- int left = Integer.parseInt(leftOccurrences);
- if (left > 0) {
- --left;
- reqDef.setLeftOccurrences(String.valueOf(left));
- validRegDef = reqDef;
- break;
- } else {
- continue;
- }
- } else {
- validRegDef = reqDef;
- break;
- }
- }
- }
- }
- if (validRegDef == null) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE,
- yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
- return Either.right(responseFormat);
- }
- return Either.left(validRegDef);
- }
+ private Either<RequirementDefinition, ResponseFormat> findAviableRequiremen(String regName, String yamlName,
+ UploadComponentInstanceInfo uploadComponentInstanceInfo, ComponentInstance currentCompInstance,
+ String capName) {
+ Map<String, List<RequirementDefinition>> comInstRegDefMap = currentCompInstance.getRequirements();
+ List<RequirementDefinition> list = comInstRegDefMap.get(capName);
+ RequirementDefinition validRegDef = null;
+ if (list == null) {
+ for (Entry<String, List<RequirementDefinition>> entry : comInstRegDefMap.entrySet()) {
+ for (RequirementDefinition reqDef : entry.getValue()) {
+ if (reqDef.getName()
+ .equals(regName)) {
+ if (reqDef.getMaxOccurrences() != null && !reqDef.getMaxOccurrences()
+ .equals(RequirementDataDefinition.MAX_OCCURRENCES)) {
+ String leftOccurrences = reqDef.getLeftOccurrences();
+ if (leftOccurrences == null) {
+ leftOccurrences = reqDef.getMaxOccurrences();
+ }
+ int left = Integer.parseInt(leftOccurrences);
+ if (left > 0) {
+ --left;
+ reqDef.setLeftOccurrences(String.valueOf(left));
+ validRegDef = reqDef;
+ break;
+ } else {
+ continue;
+ }
+ } else {
+ validRegDef = reqDef;
+ break;
+ }
+
+ }
+ }
+ if (validRegDef != null) {
+ break;
+ }
+ }
+ } else {
+ for (RequirementDefinition reqDef : list) {
+ if (reqDef.getName()
+ .equals(regName)) {
+ if (reqDef.getMaxOccurrences() != null && !reqDef.getMaxOccurrences()
+ .equals(RequirementDataDefinition.MAX_OCCURRENCES)) {
+ String leftOccurrences = reqDef.getLeftOccurrences();
+ if (leftOccurrences == null) {
+ leftOccurrences = reqDef.getMaxOccurrences();
+ }
+ int left = Integer.parseInt(leftOccurrences);
+ if (left > 0) {
+ --left;
+ reqDef.setLeftOccurrences(String.valueOf(left));
+ validRegDef = reqDef;
+ break;
+ } else {
+ continue;
+ }
+ } else {
+ validRegDef = reqDef;
+ break;
+ }
+ }
+ }
+ }
+ if (validRegDef == null) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE,
+ yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ return Either.right(responseFormat);
+ }
+ return Either.left(validRegDef);
+ }
- private Resource createResourceInstances(String yamlName, Resource resource,
- Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
- Map<String, Resource> nodeNamespaceMap) {
+ private Resource createResourceInstances(String yamlName, Resource resource, Resource oldResource,
+ Map<String, UploadComponentInstanceInfo> uploadResInstancesMap, Map<String, Resource> nodeNamespaceMap, Map<String, Resource> existingNodeTypesByResourceNames) {
- Either<Resource, ResponseFormat> eitherResource = null;
- log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName);
+ Either<Resource, ResponseFormat> eitherResource;
+ log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName);
if (isEmpty(uploadResInstancesMap) && resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
throw new ByResponseFormatComponentException(responseFormat);
- }
- Map<String, Resource> existingNodeTypeMap = new HashMap<>();
- if (MapUtils.isNotEmpty(nodeNamespaceMap)) {
- nodeNamespaceMap.forEach((k, v) -> existingNodeTypeMap.put(v.getToscaResourceName(), v));
- }
- Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
- uploadResInstancesMap
- .values()
- .forEach(i->createAndAddResourceInstance(i, yamlName, resource, nodeNamespaceMap, existingNodeTypeMap, resourcesInstancesMap));
-
- if (isNotEmpty(resourcesInstancesMap)) {
- StorageOperationStatus status = toscaOperationFacade.associateComponentInstancesToComponent(resource,
- resourcesInstancesMap, false);
- if (status != null && status != StorageOperationStatus.OK) {
- log.debug("Failed to add component instances to container component {}", resource.getName());
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(status));
- eitherResource = Either.right(responseFormat);
- throw new ByResponseFormatComponentException(eitherResource.right().value());
- }
- }
- log.debug("*************Going to get resource {}", resource.getUniqueId());
- Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade
- .getToscaElement(resource.getUniqueId(), getComponentWithInstancesFilter());
- log.debug("*************finished to get resource {}", resource.getUniqueId());
- if (eitherGetResource.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource);
- throw new ByResponseFormatComponentException(responseFormat);
- }
- if (CollectionUtils.isEmpty(eitherGetResource.left().value().getComponentInstances()) &&
- resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances
- log.debug("Error when create resource instance from csar. ComponentInstances list empty");
- BeEcompErrorManager.getInstance().logBeDaoSystemError(
- "Error when create resource instance from csar. ComponentInstances list empty");
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
- }
- return eitherGetResource.left().value();
- }
+ }
+ if (MapUtils.isNotEmpty(nodeNamespaceMap)) {
+ nodeNamespaceMap.forEach((k, v) -> existingNodeTypesByResourceNames.put(v.getToscaResourceName(), v));
+ }
+ Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>();
+ uploadResInstancesMap.values()
+ .forEach(i -> createAndAddResourceInstance(i, yamlName, resource, nodeNamespaceMap,
+ existingNodeTypesByResourceNames, resourcesInstancesMap));
+ if (oldResource != null && oldResource.getResourceType() != ResourceTypeEnum.CVFC && oldResource.getComponentInstances() != null) {
+ Map<String, Resource> existingNodeTypesByUids = existingNodeTypesByResourceNames.values()
+ .stream()
+ .collect(toMap(Resource::getUniqueId, r -> r));
+ oldResource.getComponentInstances()
+ .stream()
+ .filter(i -> !i.isCreatedFromCsar())
+ .forEach(uiInst -> resourcesInstancesMap.put(uiInst,
+ getOriginResource(existingNodeTypesByUids, uiInst)));
+ }
- private void createAndAddResourceInstance(UploadComponentInstanceInfo uploadComponentInstanceInfo, String yamlName,
- Resource resource, Map<String, Resource> nodeNamespaceMap, Map<String, Resource> existingnodeTypeMap, Map<ComponentInstance, Resource> resourcesInstancesMap) {
- Either<Resource, ResponseFormat> eitherResource;
- log.debug("*************Going to create resource instances {}", yamlName);
- // updating type if the type is node type name - we need to take the
- // updated name
- log.debug("*************Going to create resource instances {}", uploadComponentInstanceInfo.getName());
- if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
- uploadComponentInstanceInfo
- .setType(nodeNamespaceMap.get(uploadComponentInstanceInfo.getType()).getToscaResourceName());
- }
- Resource refResource = validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo,
- existingnodeTypeMap);
+ if (isNotEmpty(resourcesInstancesMap)) {
+ try {
+ toscaOperationFacade.associateComponentInstancesToComponent(resource,
+ resourcesInstancesMap, false, oldResource != null);
+ } catch (StorageException exp) {
+ if (exp.getStorageOperationStatus() != null && exp.getStorageOperationStatus() != StorageOperationStatus.OK) {
+ log.debug("Failed to add component instances to container component {}", resource.getName());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(exp.getStorageOperationStatus()));
+ eitherResource = Either.right(responseFormat);
+ throw new ByResponseFormatComponentException(eitherResource.right().value());
+ }
+ }
+ }
+ if (CollectionUtils.isEmpty(resource.getComponentInstances()) &&
+ resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances
+ log.debug("Error when create resource instance from csar. ComponentInstances list empty");
+ BeEcompErrorManager.getInstance()
+ .logBeDaoSystemError(
+ "Error when create resource instance from csar. ComponentInstances list empty");
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
+ }
+ return resource;
+ }
- ComponentInstance componentInstance = new ComponentInstance();
- componentInstance.setComponentUid(refResource.getUniqueId());
+ private void createAndAddResourceInstance(UploadComponentInstanceInfo uploadComponentInstanceInfo, String yamlName,
+ Resource resource, Map<String, Resource> nodeNamespaceMap, Map<String, Resource> existingnodeTypeMap,
+ Map<ComponentInstance, Resource> resourcesInstancesMap) {
+ Either<Resource, ResponseFormat> eitherResource;
+ log.debug("*************Going to create resource instances {}", yamlName);
+ // updating type if the type is node type name - we need to take the
+ // updated name
+ log.debug("*************Going to create resource instances {}", uploadComponentInstanceInfo.getName());
+ if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
+ uploadComponentInstanceInfo.setType(nodeNamespaceMap.get(uploadComponentInstanceInfo.getType())
+ .getToscaResourceName());
+ }
+ Resource refResource = validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo,
+ existingnodeTypeMap);
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setComponentUid(refResource.getUniqueId());
Collection<String> directives = uploadComponentInstanceInfo.getDirectives();
if(directives != null && !directives.isEmpty()) {
componentInstance.setDirectives(new ArrayList<>(directives));
@@ -3135,18 +3606,16 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
componentInstance.setNodeFilter(new CINodeFilterUtils().getNodeFilterDataDefinition(uploadNodeFilterInfo,
componentInstance.getUniqueId()));
}
-
ComponentTypeEnum containerComponentType = resource.getComponentType();
- NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
- if (containerNodeType.equals(NodeTypeEnum.Resource)
- && isNotEmpty(uploadComponentInstanceInfo.getCapabilities())
- && isNotEmpty(refResource.getCapabilities())) {
- setCapabilityNamesTypes(refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities());
- Map<String, List<CapabilityDefinition>> validComponentInstanceCapabilities = getValidComponentInstanceCapabilities(
- refResource.getUniqueId(), refResource.getCapabilities(),
- uploadComponentInstanceInfo.getCapabilities());
- componentInstance.setCapabilities(validComponentInstanceCapabilities);
- }
+ NodeTypeEnum containerNodeType = containerComponentType.getNodeType();
+ if (containerNodeType == NodeTypeEnum.Resource && isNotEmpty(uploadComponentInstanceInfo.getCapabilities())
+ && isNotEmpty(refResource.getCapabilities())) {
+ setCapabilityNamesTypes(refResource.getCapabilities(), uploadComponentInstanceInfo.getCapabilities());
+ Map<String, List<CapabilityDefinition>> validComponentInstanceCapabilities = getValidComponentInstanceCapabilities(
+ refResource.getUniqueId(), refResource.getCapabilities(),
+ uploadComponentInstanceInfo.getCapabilities());
+ componentInstance.setCapabilities(validComponentInstanceCapabilities);
+ }
if (isNotEmpty(uploadComponentInstanceInfo.getArtifacts())) {
Map<String, Map<String, UploadArtifactInfo>> artifacts = uploadComponentInstanceInfo.getArtifacts();
@@ -3164,1588 +3633,1720 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
componentInstance.setToscaArtifacts(toscaArtifacts);
}
- if (!existingnodeTypeMap.containsKey(uploadComponentInstanceInfo.getType())) {
- log.debug(
- "createResourceInstances - not found lates version for resource instance with name {} and type ",
- uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE,
- yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
- throw new ByResponseFormatComponentException(responseFormat);
- }
- Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType());
- componentInstance.setName(uploadComponentInstanceInfo.getName());
- componentInstance.setIcon(origResource.getIcon());
- resourcesInstancesMap.put(componentInstance, origResource);
- }
-
- private ComponentParametersView getComponentWithInstancesFilter() {
- ComponentParametersView parametersView = new ComponentParametersView();
- parametersView.disableAll();
- parametersView.setIgnoreComponentInstances(false);
- parametersView.setIgnoreInputs(false);
- // inputs are read when creating
- // property values on instances
- parametersView.setIgnoreUsers(false);
- return parametersView;
- }
-
- private void setCapabilityNamesTypes(Map<String, List<CapabilityDefinition>> originCapabilities,
- Map<String, List<UploadCapInfo>> uploadedCapabilities) {
- for (Entry<String, List<UploadCapInfo>> currEntry : uploadedCapabilities.entrySet()) {
- if (originCapabilities.containsKey(currEntry.getKey())) {
- currEntry.getValue().stream().forEach(cap -> cap.setType(currEntry.getKey()));
- }
- }
- for (Map.Entry<String, List<CapabilityDefinition>> capabilities : originCapabilities.entrySet()) {
- capabilities.getValue().stream().forEach(cap -> {
- if (uploadedCapabilities.containsKey(cap.getName())) {
- uploadedCapabilities.get(cap.getName()).stream().forEach(c -> {
- c.setName(cap.getName());
- c.setType(cap.getType());
- });
- }
- });
- }
+ if (!existingnodeTypeMap.containsKey(uploadComponentInstanceInfo.getType())) {
+ log.debug("createResourceInstances - not found lates version for resource instance with name {} and type ",
+ uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE,
+ yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ }
+ Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType());
+ componentInstance.setName(uploadComponentInstanceInfo.getName());
+ componentInstance.setIcon(origResource.getIcon());
+ componentInstance.setCreatedFrom(CreatedFrom.CSAR);
+ resourcesInstancesMap.put(componentInstance, origResource);
+ }
- }
+ private ComponentParametersView getComponentWithInstancesFilter() {
+ ComponentParametersView parametersView = new ComponentParametersView();
+ parametersView.disableAll();
+ parametersView.setIgnoreComponentInstances(false);
+ parametersView.setIgnoreInputs(false);
+ // inputs are read when creating
+ // property values on instances
+ parametersView.setIgnoreUsers(false);
+ return parametersView;
+ }
- private Resource validateResourceInstanceBeforeCreate(String yamlName, UploadComponentInstanceInfo uploadComponentInstanceInfo,
- Map<String, Resource> nodeNamespaceMap) {
-
- log.debug("validateResourceInstanceBeforeCreate - going to validate resource instance with name {} and type before create",
- uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
- Resource refResource;
- if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
- refResource = nodeNamespaceMap.get(uploadComponentInstanceInfo.getType());
- } else {
- Either<Resource, StorageOperationStatus> findResourceEither = toscaOperationFacade
- .getLatestCertifiedNodeTypeByToscaResourceName(uploadComponentInstanceInfo.getType());
- if (findResourceEither.isRight()) {
- log.debug(
- "validateResourceInstanceBeforeCreate - not found lates version for resource instance with name {} and type ",
- uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(findResourceEither.right().value()));
- throw new ByResponseFormatComponentException(responseFormat);
- }
- refResource = findResourceEither.left().value();
- nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
- }
- String componentState = refResource.getComponentMetadataDefinition().getMetadataDataDefinition().getState();
- if (componentState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
- log.debug(
- "validateResourceInstanceBeforeCreate - component instance of component {} can not be created because the component is in an illegal state {}.",
- refResource.getName(), componentState);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ILLEGAL_COMPONENT_STATE,
- refResource.getComponentType().getValue(), refResource.getName(), componentState);
- throw new ByResponseFormatComponentException(responseFormat);
- }
+ private void setCapabilityNamesTypes(Map<String, List<CapabilityDefinition>> originCapabilities,
+ Map<String, List<UploadCapInfo>> uploadedCapabilities) {
+ for (Entry<String, List<UploadCapInfo>> currEntry : uploadedCapabilities.entrySet()) {
+ if (originCapabilities.containsKey(currEntry.getKey())) {
+ currEntry.getValue()
+ .stream()
+ .forEach(cap -> cap.setType(currEntry.getKey()));
+ }
+ }
+ for (Map.Entry<String, List<CapabilityDefinition>> capabilities : originCapabilities.entrySet()) {
+ capabilities.getValue()
+ .stream()
+ .forEach(cap -> {
+ if (uploadedCapabilities.containsKey(cap.getName())) {
+ uploadedCapabilities.get(cap.getName())
+ .stream()
+ .forEach(c -> {
+ c.setName(cap.getName());
+ c.setType(cap.getType());
+ });
+ }
+ });
+ }
+ }
- if (!ModelConverter.isAtomicComponent(refResource) && refResource.getResourceType() != ResourceTypeEnum.CVFC) {
- log.debug("validateResourceInstanceBeforeCreate - ref resource type is ", refResource.getResourceType());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE,
- yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
- throw new ByResponseFormatComponentException(responseFormat);
- }
- return refResource;
- }
+ private Resource validateResourceInstanceBeforeCreate(String yamlName,
+ UploadComponentInstanceInfo uploadComponentInstanceInfo, Map<String, Resource> nodeNamespaceMap) {
+
+ log.debug(
+ "validateResourceInstanceBeforeCreate - going to validate resource instance with name {} and type {} before create",
+ uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ Resource refResource;
+ if (nodeNamespaceMap.containsKey(uploadComponentInstanceInfo.getType())) {
+ refResource = nodeNamespaceMap.get(uploadComponentInstanceInfo.getType());
+ } else {
+ Either<Resource, StorageOperationStatus> findResourceEither = toscaOperationFacade
+ .getLatestCertifiedNodeTypeByToscaResourceName(uploadComponentInstanceInfo.getType());
+ if (findResourceEither.isRight()) {
+ log.debug(
+ "validateResourceInstanceBeforeCreate - not found lates version for resource instance with name {} and type {}",
+ uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(findResourceEither.right().value()));
+ }
+ refResource = findResourceEither.left().value();
+ nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
+ }
+ String componentState = refResource.getComponentMetadataDefinition()
+ .getMetadataDataDefinition()
+ .getState();
+ if (componentState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())) {
+ log.debug(
+ "validateResourceInstanceBeforeCreate - component instance of component {} can not be created because the component is in an illegal state {}.",
+ refResource.getName(), componentState);
+ throw new ByActionStatusComponentException(ActionStatus.ILLEGAL_COMPONENT_STATE,
+ refResource.getComponentType().getValue(),refResource.getName(), componentState);
+ }
+ if (!ModelConverter.isAtomicComponent(refResource) && refResource.getResourceType() != ResourceTypeEnum.CVFC) {
+ log.debug("validateResourceInstanceBeforeCreate - ref resource type is ", refResource.getResourceType());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE,
+ yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
+ }
+ return refResource;
+ }
- public Either<Resource, ResponseFormat> propagateStateToCertified(User user, Resource resource,
- LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock,
- boolean forceCertificationAllowed) {
+ public Resource propagateStateToCertified(User user, Resource resource,
+ LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock,
+ boolean forceCertificationAllowed) {
- Either<Resource, ResponseFormat> result = null;
- try {
- if (resource.getLifecycleState() != LifecycleStateEnum.CERTIFIED && forceCertificationAllowed
- && lifecycleBusinessLogic.isFirstCertification(resource.getVersion())) {
- result = nodeForceCertification(resource, user, lifecycleChangeInfo, inTransaction, needLock);
- if (result.isRight()) {
- return result;
- }
- resource = result.left().value();
- }
- if (resource.getLifecycleState() == LifecycleStateEnum.CERTIFIED) {
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherPopulated = populateToscaArtifacts(
- resource, user, false, inTransaction, needLock);
- result = eitherPopulated.isLeft() ? Either.left(resource)
- : Either.right(eitherPopulated.right().value());
- return result;
- }
- return nodeFullCertification(resource.getUniqueId(), user, lifecycleChangeInfo, inTransaction, needLock);
- } catch (Exception e) {
- log.debug("The exception has occurred upon certification of resource {}. ", resource.getName(), e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- } finally {
- if (result == null || result.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError("Change LifecycleState - Certify");
- if (!inTransaction) {
+ boolean failed = false;
+ try {
+ if (resource.getLifecycleState() != LifecycleStateEnum.CERTIFIED && forceCertificationAllowed
+ && lifecycleBusinessLogic.isFirstCertification(resource.getVersion())) {
+ nodeForceCertification(resource, user, lifecycleChangeInfo, inTransaction, needLock);
+ }
+ if (resource.getLifecycleState() == LifecycleStateEnum.CERTIFIED) {
+ Either<ArtifactDefinition, Operation> eitherPopulated = populateToscaArtifacts(
+ resource, user, false, inTransaction, needLock, false);
+ return resource;
+ }
+ return nodeFullCertification(resource.getUniqueId(), user, lifecycleChangeInfo, inTransaction, needLock);
+ } catch (ComponentException e) {
+ failed = true;
+ log.debug("The exception has occurred upon certification of resource {}. ", resource.getName(), e);
+ throw e;
+ } finally {
+ if (failed) {
+ BeEcompErrorManager.getInstance()
+ .logBeSystemError("Change LifecycleState - Certify");
+ if (!inTransaction) {
janusGraphDao.rollback();
- }
- } else if (!inTransaction) {
+ }
+ } else if (!inTransaction) {
janusGraphDao.commit();
- }
- }
- }
+ }
+ }
+ }
- private Either<Resource, ResponseFormat> nodeFullCertification(String uniqueId, User user,
- LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
- return lifecycleBusinessLogic.changeState(uniqueId, user, LifeCycleTransitionEnum.CERTIFY,
- lifecycleChangeInfo, inTransaction, needLock);
- }
+ private Resource nodeFullCertification(String uniqueId, User user,
+ LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+ Either<Resource, ResponseFormat> resourceResponse = lifecycleBusinessLogic.changeState(uniqueId, user, LifeCycleTransitionEnum.CERTIFY, lifecycleChangeInfo,
+ inTransaction, needLock);
+ if(resourceResponse.isRight()){
+ throw new ByResponseFormatComponentException(resourceResponse.right().value());
+ }
+ return resourceResponse.left().value();
+ }
- private Either<Resource, ResponseFormat> nodeForceCertification(Resource resource, User user,
- LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
- return lifecycleBusinessLogic.forceResourceCertification(resource, user, lifecycleChangeInfo, inTransaction,
- needLock);
- }
+ private Resource nodeForceCertification(Resource resource, User user,
+ LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+ return lifecycleBusinessLogic.forceResourceCertification(resource, user, lifecycleChangeInfo, inTransaction,
+ needLock);
+ }
- public ImmutablePair<Resource, ActionStatus> createOrUpdateResourceByImport(
- Resource resource, User user, boolean isNormative, boolean isInTransaction, boolean needLock,
- CsarInfo csarInfo, String nodeName, boolean isNested) {
-
- ImmutablePair<Resource, ActionStatus> result = null;
- // check if resource already exists (search by tosca name = type)
- boolean isNestedResource = isNestedResourceUpdate(csarInfo, nodeName);
- Either<Resource, StorageOperationStatus> latestByToscaName = toscaOperationFacade
- .getLatestByToscaResourceName(resource.getToscaResourceName());
-
- if (latestByToscaName.isLeft()) {
- Resource foundResource = latestByToscaName.left().value();
- // we don't allow updating names of top level types
- if (!isNestedResource &&
- !StringUtils.equals(resource.getName(), foundResource.getName())) {
- BeEcompErrorManager.getInstance().logBeComponentMissingError("Create / Update resource by import",
- ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
- log.debug("resource already exist new name={} old name={} same type={}", resource.getName(),
- foundResource.getName(), resource.getToscaResourceName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_ALREADY_EXISTS);
- componentsUtils.auditResource(responseFormat, user, resource, AuditingActionEnum.IMPORT_RESOURCE);
- throwComponentException(responseFormat);
- }
- result = updateExistingResourceByImport(resource, foundResource, user, isNormative, needLock, isNested);
- } else if (isNotFound(latestByToscaName)) {
- if (isNestedResource) {
- result = createOrUpdateNestedResource(resource, user, isNormative, isInTransaction, needLock, csarInfo, isNested, nodeName);
- } else {
- result = createResourceByImport(resource, user, isNormative, isInTransaction, csarInfo);
- }
- } else {
- StorageOperationStatus status = latestByToscaName.right().value();
- log.debug("failed to get latest version of resource {}. status={}", resource.getName(), status);
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(latestByToscaName.right().value()), resource);
- componentsUtils.auditResource(responseFormat, user, resource, AuditingActionEnum.IMPORT_RESOURCE);
- throwComponentException(responseFormat);
- }
- return result;
- }
+ public ImmutablePair<Resource, ActionStatus> createOrUpdateResourceByImport(Resource resource, User user,
+ boolean isNormative, boolean isInTransaction, boolean needLock, CsarInfo csarInfo, String nodeName,
+ boolean isNested) {
+
+ ImmutablePair<Resource, ActionStatus> result = null;
+ // check if resource already exists (search by tosca name = type)
+ boolean isNestedResource = isNestedResourceUpdate(csarInfo, nodeName);
+ Either<Resource, StorageOperationStatus> latestByToscaName = toscaOperationFacade
+ .getLatestByToscaResourceName(resource.getToscaResourceName());
+
+ if (latestByToscaName.isLeft()) {
+ Resource foundResource = latestByToscaName.left()
+ .value();
+ // we don't allow updating names of top level types
+ if (!isNestedResource && !StringUtils.equals(resource.getName(), foundResource.getName())) {
+ BeEcompErrorManager.getInstance()
+ .logBeComponentMissingError("Create / Update resource by import",
+ ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
+ log.debug("resource already exist new name={} old name={} same type={}", resource.getName(),
+ foundResource.getName(), resource.getToscaResourceName());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_ALREADY_EXISTS);
+ componentsUtils.auditResource(responseFormat, user, resource, AuditingActionEnum.IMPORT_RESOURCE);
+ throwComponentException(responseFormat);
+ }
+ result = updateExistingResourceByImport(resource, foundResource, user, isNormative, needLock, isNested);
+ } else if (isNotFound(latestByToscaName)) {
+ if (isNestedResource) {
+ result = createOrUpdateNestedResource(resource, user, isNormative, isInTransaction, needLock, csarInfo,
+ isNested, nodeName);
+ } else {
+ result = createResourceByImport(resource, user, isNormative, isInTransaction, csarInfo);
+ }
+ } else {
+ StorageOperationStatus status = latestByToscaName.right()
+ .value();
+ log.debug("failed to get latest version of resource {}. status={}", resource.getName(), status);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(latestByToscaName.right()
+ .value()), resource);
+ componentsUtils.auditResource(responseFormat, user, resource, AuditingActionEnum.IMPORT_RESOURCE);
+ throwComponentException(responseFormat);
+ }
+ return result;
+ }
- private boolean isNestedResourceUpdate(CsarInfo csarInfo, String nodeName) {
- return csarInfo != null && csarInfo.isUpdate() && nodeName != null;
- }
+ private boolean isNestedResourceUpdate(CsarInfo csarInfo, String nodeName) {
+ return csarInfo != null && csarInfo.isUpdate() && nodeName != null;
+ }
- private ImmutablePair<Resource, ActionStatus> createOrUpdateNestedResource(Resource resource, User user, boolean isNormative, boolean isInTransaction, boolean needLock, CsarInfo csarInfo, boolean isNested, String nodeName) {
- Either<Component, StorageOperationStatus> latestByToscaName = toscaOperationFacade.getLatestByToscaResourceName(buildNestedToscaResourceName(
- resource.getResourceType().name(), csarInfo.getVfResourceName(), nodeName).getRight());
- if (latestByToscaName.isLeft()) {
- Resource nestedResource = (Resource) latestByToscaName.left().value();
- log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
- Either<Boolean, ResponseFormat> eitherValidation = validateNestedDerivedFromDuringUpdate(nestedResource, resource,
- ValidationUtils.hasBeenCertified(nestedResource.getVersion()));
- if (eitherValidation.isRight()) {
- return createResourceByImport(resource, user, isNormative, isInTransaction, csarInfo);
- }
- return updateExistingResourceByImport(resource, nestedResource, user, isNormative, needLock, isNested);
- } else {
- return createResourceByImport(resource, user, isNormative, isInTransaction, csarInfo);
- }
- }
+ private ImmutablePair<Resource, ActionStatus> createOrUpdateNestedResource(Resource resource, User user,
+ boolean isNormative, boolean isInTransaction, boolean needLock, CsarInfo csarInfo, boolean isNested,
+ String nodeName) {
+ Either<Component, StorageOperationStatus> latestByToscaName = toscaOperationFacade
+ .getLatestByToscaResourceName(buildNestedToscaResourceName(resource.getResourceType()
+ .name(), csarInfo.getVfResourceName(), nodeName).getRight());
+ if (latestByToscaName.isLeft()) {
+ Resource nestedResource = (Resource) latestByToscaName.left()
+ .value();
+ log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
+ Either<Boolean, ResponseFormat> eitherValidation = validateNestedDerivedFromDuringUpdate(nestedResource,
+ resource, ValidationUtils.hasBeenCertified(nestedResource.getVersion()));
+ if (eitherValidation.isRight()) {
+ return createResourceByImport(resource, user, isNormative, isInTransaction, csarInfo);
+ }
+ return updateExistingResourceByImport(resource, nestedResource, user, isNormative, needLock, isNested);
+ } else {
+ return createResourceByImport(resource, user, isNormative, isInTransaction, csarInfo);
+ }
+ }
- private boolean isNotFound(Either<Resource, StorageOperationStatus> getResourceEither) {
- return getResourceEither.isRight() && getResourceEither.right().value() == StorageOperationStatus.NOT_FOUND;
- }
+ private boolean isNotFound(Either<Resource, StorageOperationStatus> getResourceEither) {
+ return getResourceEither.isRight() && getResourceEither.right()
+ .value() == StorageOperationStatus.NOT_FOUND;
+ }
- private ImmutablePair<Resource, ActionStatus> createResourceByImport(Resource resource,
- User user, boolean isNormative, boolean isInTransaction, CsarInfo csarInfo) {
- log.debug("resource with name {} does not exist. create new resource", resource.getName());
- validateResourceBeforeCreate(resource, user,
- AuditingActionEnum.IMPORT_RESOURCE, isInTransaction, csarInfo);
- Resource createdResource = createResourceByDao(resource, user,
- AuditingActionEnum.IMPORT_RESOURCE, isNormative, isInTransaction);
- ImmutablePair<Resource, ActionStatus> resourcePair = new ImmutablePair<>(createdResource,
- ActionStatus.CREATED);
- ASDCKpiApi.countImportResourcesKPI();
- return resourcePair;
- }
+ private ImmutablePair<Resource, ActionStatus> createResourceByImport(Resource resource, User user,
+ boolean isNormative, boolean isInTransaction, CsarInfo csarInfo) {
+ log.debug("resource with name {} does not exist. create new resource", resource.getName());
+ validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isInTransaction, csarInfo);
+ final Resource createResourceByDao = createResourceByDao(resource, user, AuditingActionEnum.IMPORT_RESOURCE, isNormative,
+ isInTransaction);
+ Resource createdResource = updateCatalog(createResourceByDao, ChangeTypeEnum.LIFECYCLE).left().map(r -> (Resource)r).left().value();
+ ImmutablePair<Resource, ActionStatus> resourcePair = new ImmutablePair<>(createdResource, ActionStatus.CREATED);
+ ASDCKpiApi.countImportResourcesKPI();
+ return resourcePair;
+ }
- public boolean isResourceExist(String resourceName) {
- Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resourceName);
- return latestByName.isLeft();
- }
+ public boolean isResourceExist(String resourceName) {
+ Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resourceName);
+ return latestByName.isLeft();
+ }
- private ImmutablePair<Resource, ActionStatus> updateExistingResourceByImport(
- Resource newResource, Resource oldResource, User user, boolean inTransaction, boolean needLock,
- boolean isNested) {
- String lockedResourceId = oldResource.getUniqueId();
- log.debug("found resource: name={}, id={}, version={}, state={}", oldResource.getName(), lockedResourceId,
- oldResource.getVersion(), oldResource.getLifecycleState());
- ImmutablePair<Resource, ActionStatus> resourcePair = null;
- try {
- lockComponent(lockedResourceId, oldResource, needLock, "Update Resource by Import");
- oldResource = prepareResourceForUpdate(oldResource, newResource, user, inTransaction, false);
- mergeOldResourceMetadataWithNew(oldResource, newResource);
-
- validateResourceFieldsBeforeUpdate(oldResource, newResource, inTransaction, isNested);
- validateCapabilityTypesCreate(user, getCapabilityTypeOperation(), newResource, AuditingActionEnum.IMPORT_RESOURCE, inTransaction);
- // contact info normalization
- newResource.setContactId(newResource.getContactId().toLowerCase());
- // non-updatable fields
- newResource.setCreatorUserId(user.getUserId());
- newResource.setCreatorFullName(user.getFullName());
- newResource.setLastUpdaterUserId(user.getUserId());
- newResource.setLastUpdaterFullName(user.getFullName());
- newResource.setUniqueId(oldResource.getUniqueId());
- newResource.setVersion(oldResource.getVersion());
- newResource.setInvariantUUID(oldResource.getInvariantUUID());
- newResource.setLifecycleState(oldResource.getLifecycleState());
- newResource.setUUID(oldResource.getUUID());
- newResource.setNormalizedName(oldResource.getNormalizedName());
- newResource.setSystemName(oldResource.getSystemName());
- if (oldResource.getCsarUUID() != null) {
- newResource.setCsarUUID(oldResource.getCsarUUID());
- }
- if (oldResource.getImportedToscaChecksum() != null) {
- newResource.setImportedToscaChecksum(oldResource.getImportedToscaChecksum());
- }
- newResource.setAbstract(oldResource.isAbstract());
+ private ImmutablePair<Resource, ActionStatus> updateExistingResourceByImport(Resource newResource,
+ Resource oldResource, User user, boolean inTransaction, boolean needLock, boolean isNested) {
+ String lockedResourceId = oldResource.getUniqueId();
+ log.debug("found resource: name={}, id={}, version={}, state={}", oldResource.getName(), lockedResourceId,
+ oldResource.getVersion(), oldResource.getLifecycleState());
+ ImmutablePair<Resource, ActionStatus> resourcePair = null;
+ try {
+ lockComponent(lockedResourceId, oldResource, needLock, "Update Resource by Import");
+ oldResource = prepareResourceForUpdate(oldResource, newResource, user, inTransaction, false);
+ mergeOldResourceMetadataWithNew(oldResource, newResource);
+
+ validateResourceFieldsBeforeUpdate(oldResource, newResource, inTransaction, isNested);
+ validateCapabilityTypesCreate(user, getCapabilityTypeOperation(), newResource,
+ AuditingActionEnum.IMPORT_RESOURCE, inTransaction);
+ // contact info normalization
+ newResource.setContactId(newResource.getContactId()
+ .toLowerCase());
+ PropertyConstraintsUtils.validatePropertiesConstraints(newResource, oldResource);
+ // non-updatable fields
+ newResource.setCreatorUserId(user.getUserId());
+ newResource.setCreatorFullName(user.getFullName());
+ newResource.setLastUpdaterUserId(user.getUserId());
+ newResource.setLastUpdaterFullName(user.getFullName());
+ newResource.setUniqueId(oldResource.getUniqueId());
+ newResource.setVersion(oldResource.getVersion());
+ newResource.setInvariantUUID(oldResource.getInvariantUUID());
+ newResource.setLifecycleState(oldResource.getLifecycleState());
+ newResource.setUUID(oldResource.getUUID());
+ newResource.setNormalizedName(oldResource.getNormalizedName());
+ newResource.setSystemName(oldResource.getSystemName());
+ if (oldResource.getCsarUUID() != null) {
+ newResource.setCsarUUID(oldResource.getCsarUUID());
+ }
+ if (oldResource.getImportedToscaChecksum() != null) {
+ newResource.setImportedToscaChecksum(oldResource.getImportedToscaChecksum());
+ }
+ newResource.setAbstract(oldResource.isAbstract());
- if (newResource.getDerivedFrom() == null || newResource.getDerivedFrom().isEmpty()) {
- newResource.setDerivedFrom(oldResource.getDerivedFrom());
- }
- if (newResource.getDerivedFromGenericType() == null || newResource.getDerivedFromGenericType().isEmpty()) {
- newResource.setDerivedFromGenericType(oldResource.getDerivedFromGenericType());
- }
- if (newResource.getDerivedFromGenericVersion() == null || newResource.getDerivedFromGenericVersion().isEmpty()) {
- newResource.setDerivedFromGenericVersion(oldResource.getDerivedFromGenericVersion());
- }
- // add for new)
- // created without tosca artifacts - add the placeholders
- if (newResource.getToscaArtifacts() == null || newResource.getToscaArtifacts().isEmpty()) {
- setToscaArtifactsPlaceHolders(newResource, user);
- }
+ if (newResource.getDerivedFrom() == null || newResource.getDerivedFrom()
+ .isEmpty()) {
+ newResource.setDerivedFrom(oldResource.getDerivedFrom());
+ }
+ if (newResource.getDerivedFromGenericType() == null || newResource.getDerivedFromGenericType()
+ .isEmpty()) {
+ newResource.setDerivedFromGenericType(oldResource.getDerivedFromGenericType());
+ }
+ if (newResource.getDerivedFromGenericVersion() == null || newResource.getDerivedFromGenericVersion()
+ .isEmpty()) {
+ newResource.setDerivedFromGenericVersion(oldResource.getDerivedFromGenericVersion());
+ }
+ // add for new)
+ // created without tosca artifacts - add the placeholders
+ if (newResource.getToscaArtifacts() == null || newResource.getToscaArtifacts()
+ .isEmpty()) {
+ setToscaArtifactsPlaceHolders(newResource, user);
+ }
- if (newResource.getInterfaces() == null || newResource.getInterfaces().isEmpty()) {
- newResource.setInterfaces(oldResource.getInterfaces());
- }
+ if (newResource.getInterfaces() == null || newResource.getInterfaces().isEmpty()) {
+ newResource.setInterfaces(oldResource.getInterfaces());
+ }
if (CollectionUtils.isEmpty(newResource.getProperties())) {
newResource.setProperties(oldResource.getProperties());
}
- Either<Resource, StorageOperationStatus> overrideResource = toscaOperationFacade
- .overrideComponent(newResource, oldResource);
-
- if (overrideResource.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(overrideResource.right().value()), newResource);
- componentsUtils.auditResource(responseFormat, user, newResource, AuditingActionEnum.IMPORT_RESOURCE);
+ Either<Resource, StorageOperationStatus> overrideResource = toscaOperationFacade
+ .overrideComponent(newResource, oldResource);
- throwComponentException(responseFormat);
- }
+ if (overrideResource.isRight()) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(overrideResource.right()
+ .value()), newResource);
+ componentsUtils.auditResource(responseFormat, user, newResource, AuditingActionEnum.IMPORT_RESOURCE);
- log.debug("Resource updated successfully!!!");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- componentsUtils.auditResource(responseFormat, user, newResource, AuditingActionEnum.IMPORT_RESOURCE,
- ResourceVersionInfo.newBuilder()
- .state(oldResource.getLifecycleState()
- .name())
- .version(oldResource.getVersion())
- .build());
-
- resourcePair = new ImmutablePair<>(overrideResource.left().value(),
- ActionStatus.OK);
- return resourcePair;
- } finally {
- if (resourcePair == null) {
- BeEcompErrorManager.getInstance().logBeSystemError("Change LifecycleState - Certify");
- janusGraphDao.rollback();
- } else if (!inTransaction) {
+ throwComponentException(responseFormat);
+ }
+ updateCatalog(overrideResource.left()
+ .value(), ChangeTypeEnum.LIFECYCLE);
+
+ log.debug("Resource updated successfully!!!");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
+ componentsUtils.auditResource(responseFormat, user, newResource, AuditingActionEnum.IMPORT_RESOURCE,
+ ResourceVersionInfo.newBuilder()
+ .state(oldResource.getLifecycleState()
+ .name())
+ .version(oldResource.getVersion())
+ .build());
+
+ resourcePair = new ImmutablePair<>(overrideResource.left()
+ .value(), ActionStatus.OK);
+ return resourcePair;
+ } finally {
+ if (resourcePair == null) {
+ BeEcompErrorManager.getInstance()
+ .logBeSystemError("Change LifecycleState - Certify");
+ janusGraphDao.rollback();
+ } else if (!inTransaction) {
janusGraphDao.commit();
- }
- if (needLock) {
- log.debug("unlock resource {}", lockedResourceId);
- graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
- }
- }
-
- }
+ }
+ if (needLock) {
+ log.debug("unlock resource {}", lockedResourceId);
+ graphLockOperation.unlockComponent(lockedResourceId, NodeTypeEnum.Resource);
+ }
+ }
- /**
- * Merge old resource with new. Keep old category and vendor name without
- * change
- *
- * @param oldResource
- * @param newResource
- */
- private void mergeOldResourceMetadataWithNew(Resource oldResource, Resource newResource) {
-
- // keep old category and vendor name without change
- // merge the rest of the resource metadata
- if (newResource.getTags() == null || newResource.getTags().isEmpty()) {
- newResource.setTags(oldResource.getTags());
- }
+ }
- if (newResource.getDescription() == null) {
- newResource.setDescription(oldResource.getDescription());
- }
+ /**
+ * Merge old resource with new. Keep old category and vendor name without
+ * change
+ *
+ * @param oldResource
+ * @param newResource
+ */
+ private void mergeOldResourceMetadataWithNew(Resource oldResource, Resource newResource) {
+
+ // keep old category and vendor name without change
+ // merge the rest of the resource metadata
+ if (newResource.getTags() == null || newResource.getTags().isEmpty()) {
+ newResource.setTags(oldResource.getTags());
+ }
- if (newResource.getVendorRelease() == null) {
- newResource.setVendorRelease(oldResource.getVendorRelease());
- }
+ if (newResource.getDescription() == null) {
+ newResource.setDescription(oldResource.getDescription());
+ }
- if (newResource.getResourceVendorModelNumber() == null) {
- newResource.setResourceVendorModelNumber(oldResource.getResourceVendorModelNumber());
- }
+ if (newResource.getVendorRelease() == null) {
+ newResource.setVendorRelease(oldResource.getVendorRelease());
+ }
- if (newResource.getContactId() == null) {
- newResource.setContactId(oldResource.getContactId());
- }
+ if (newResource.getResourceVendorModelNumber() == null) {
+ newResource.setResourceVendorModelNumber(oldResource.getResourceVendorModelNumber());
+ }
- newResource.setCategories(oldResource.getCategories());
- if (newResource.getVendorName() == null) {
- newResource.setVendorName(oldResource.getVendorName());
- }
- }
+ if (newResource.getContactId() == null) {
+ newResource.setContactId(oldResource.getContactId());
+ }
- private Resource prepareResourceForUpdate(Resource oldResource, Resource newResource, User user,
- boolean inTransaction, boolean needLock) {
+ newResource.setCategories(oldResource.getCategories());
+ if (newResource.getVendorName() == null) {
+ newResource.setVendorName(oldResource.getVendorName());
+ }
+ List<GroupDefinition>oldForUpdate = oldResource.getGroups();
+ if(CollectionUtils.isNotEmpty(oldForUpdate)){
+ List<GroupDefinition>groupForUpdate = oldForUpdate.stream().map(group -> new GroupDefinition(group)).collect(Collectors.toList());
- if (!ComponentValidationUtils.canWorkOnResource(oldResource, user.getUserId())) {
- // checkout
- return lifecycleBusinessLogic.changeState(
- oldResource.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT,
- new LifecycleChangeInfoWithAction("update by import"), inTransaction, needLock)
- .left()
- .on(response -> failOnChangeState(response, user, oldResource, newResource));
- }
- return oldResource;
- }
+ groupForUpdate.stream().filter(group -> group.isVspOriginated())
+ .forEach(group -> group.setName(group.getInvariantName()));
- private Resource failOnChangeState(ResponseFormat response, User user, Resource oldResource, Resource newResource) {
- log.info("resource {} cannot be updated. reason={}", oldResource.getUniqueId(),
- response.getFormattedMessage());
- componentsUtils.auditResource(response, user, newResource, AuditingActionEnum.IMPORT_RESOURCE,
- ResourceVersionInfo.newBuilder()
- .state(oldResource.getLifecycleState().name())
- .version(oldResource.getVersion())
- .build());
- throw new ByResponseFormatComponentException(response);
- }
+ newResource.setGroups(groupForUpdate);
+ }
- public Resource validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum, boolean inTransaction, CsarInfo csarInfo) {
-
- validateResourceFieldsBeforeCreate(user, resource, actionEnum, inTransaction);
- validateCapabilityTypesCreate(user, getCapabilityTypeOperation(), resource, actionEnum, inTransaction);
- validateLifecycleTypesCreate(user, resource, actionEnum);
- validateResourceType(user, resource, actionEnum);
- resource.setCreatorUserId(user.getUserId());
- resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
- resource.setContactId(resource.getContactId().toLowerCase());
- if (StringUtils.isEmpty(resource.getToscaResourceName()) && !ModelConverter.isAtomicComponent(resource)) {
- String resourceSystemName;
- if (csarInfo != null && StringUtils.isNotEmpty(csarInfo.getVfResourceName())) {
- resourceSystemName = ValidationUtils.convertToSystemName(csarInfo.getVfResourceName());
- } else {
- resourceSystemName = resource.getSystemName();
- }
- resource.setToscaResourceName(CommonBeUtils
- .generateToscaResourceName(resource.getResourceType().name().toLowerCase(), resourceSystemName));
- }
- // Generate invariant UUID - must be here and not in operation since it
- // should stay constant during clone
- // TODO
- String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
- resource.setInvariantUUID(invariantUUID);
+ if(newResource.getResourceType().isAtomicType() && !newResource.getName().equals("Root")&& newResource.getResourceType() != ResourceTypeEnum.CVFC) {
+ ResourceTypeEnum updatedResourceType = newResource.getResourceType();
+ Component derivedFromResource = getParentComponent(newResource);
+ if (derivedFromResource.getComponentType() == ComponentTypeEnum.RESOURCE) {
+ Resource parentResource = (Resource) derivedFromResource;
+ if (!(parentResource.isAbstract() && (ResourceTypeEnum.VFC == parentResource.getResourceType() || ResourceTypeEnum.ABSTRACT == parentResource.getResourceType())) &&
+ parentResource.getResourceType() != updatedResourceType) {
+ BeEcompErrorManager.getInstance()
+ .logInternalDataError("mergeOldResourceMetadataWithNew", "resource type of the resource does not match to derived from resource type",
+ ErrorSeverity.ERROR);
+ log.debug("#mergeOldResourceMetadataWithNew - resource type {} of the resource {} does not match to derived from resource type {}",
+ newResource.getResourceType(), newResource.getToscaResourceName(), parentResource.getResourceType());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_RESOURCE_TYPE);
+ }
+ }
+ }
- return resource;
- }
+ }
- private Either<Boolean, ResponseFormat> validateResourceType(User user, Resource resource,
- AuditingActionEnum actionEnum) {
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
- if (resource.getResourceType() == null) {
- log.debug("Invalid resource type for resource");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
- eitherResult = Either.right(errorResponse);
- componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- }
- return eitherResult;
- }
+ private Component getParentComponent(Resource newResource) {
+ String toscaResourceNameDerivedFrom = newResource.getDerivedFrom().get(0);
+ Either<Component, StorageOperationStatus> latestByToscaResourceName = toscaOperationFacade.getLatestByToscaResourceName(toscaResourceNameDerivedFrom);
+ if(latestByToscaResourceName.isRight()){
+ BeEcompErrorManager.getInstance()
+ .logInternalDataError("mergeOldResourceMetadataWithNew", "derived from resource not found", ErrorSeverity.ERROR);
+ log.debug("#mergeOldResourceMetadataWithNew - derived from resource {} not found", toscaResourceNameDerivedFrom);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NOT_FOUND, toscaResourceNameDerivedFrom);
+ }
+ return latestByToscaResourceName.left().value();
+ }
- private Either<Boolean, ResponseFormat> validateLifecycleTypesCreate(User user, Resource resource,
- AuditingActionEnum actionEnum) {
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
- if (resource.getInterfaces() != null && resource.getInterfaces().size() > 0) {
- log.debug("validate interface lifecycle Types Exist");
- Iterator<InterfaceDefinition> intItr = resource.getInterfaces().values().iterator();
- while (intItr.hasNext() && eitherResult.isLeft()) {
- InterfaceDefinition interfaceDefinition = intItr.next();
- String intType = interfaceDefinition.getUniqueId();
- Either<InterfaceDefinition, StorageOperationStatus> eitherCapTypeFound = interfaceTypeOperation
- .getInterface(intType);
- if (eitherCapTypeFound.isRight()) {
- if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().logBeGraphObjectMissingError(
- "Create Resource - validateLifecycleTypesCreate", "Interface", intType);
- log.debug("Lifecycle Type: {} is required by resource: {} but does not exist in the DB",
- intType, resource.getName());
- BeEcompErrorManager.getInstance()
- .logBeDaoSystemError("Create Resource - validateLifecycleTypesCreate");
- log.debug("request to data model failed with error: {}",
- eitherCapTypeFound.right().value().name());
- }
-
- ResponseFormat errorResponse = componentsUtils
- .getResponseFormat(ActionStatus.MISSING_LIFECYCLE_TYPE, intType);
- eitherResult = Either.right(errorResponse);
- componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- }
+ private Resource prepareResourceForUpdate(Resource oldResource, Resource newResource, User user,
+ boolean inTransaction, boolean needLock) {
- }
- }
- return eitherResult;
- }
+ if (!ComponentValidationUtils.canWorkOnResource(oldResource, user.getUserId())) {
+ // checkout
+ return lifecycleBusinessLogic.changeState(oldResource.getUniqueId(), user, LifeCycleTransitionEnum.CHECKOUT,
+ new LifecycleChangeInfoWithAction("update by import"), inTransaction, needLock)
+ .left()
+ .on(response -> failOnChangeState(response, user, oldResource, newResource));
+ }
+ return oldResource;
+ }
- private Either<Boolean, ResponseFormat> validateCapabilityTypesCreate(User user,
- ICapabilityTypeOperation capabilityTypeOperation, Resource resource, AuditingActionEnum actionEnum,
- boolean inTransaction) {
+ private Resource failOnChangeState(ResponseFormat response, User user, Resource oldResource, Resource newResource) {
+ log.info("resource {} cannot be updated. reason={}", oldResource.getUniqueId(), response.getFormattedMessage());
+ componentsUtils.auditResource(response, user, newResource, AuditingActionEnum.IMPORT_RESOURCE,
+ ResourceVersionInfo.newBuilder()
+ .state(oldResource.getLifecycleState()
+ .name())
+ .version(oldResource.getVersion())
+ .build());
+ throw new ByResponseFormatComponentException(response);
+ }
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
- if (resource.getCapabilities() != null && resource.getCapabilities().size() > 0) {
- log.debug("validate capability Types Exist - capabilities section");
+ public Resource validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum,
+ boolean inTransaction, CsarInfo csarInfo) {
+
+ validateResourceFieldsBeforeCreate(user, resource, actionEnum, inTransaction);
+ validateCapabilityTypesCreate(user, getCapabilityTypeOperation(), resource, actionEnum, inTransaction);
+ validateLifecycleTypesCreate(user, resource, actionEnum);
+ validateResourceType(user, resource, actionEnum);
+ resource.setCreatorUserId(user.getUserId());
+ resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
+ resource.setContactId(resource.getContactId()
+ .toLowerCase());
+ if (StringUtils.isEmpty(resource.getToscaResourceName()) && !ModelConverter.isAtomicComponent(resource)) {
+ String resourceSystemName;
+ if (csarInfo != null && StringUtils.isNotEmpty(csarInfo.getVfResourceName())) {
+ resourceSystemName = ValidationUtils.convertToSystemName(csarInfo.getVfResourceName());
+ } else {
+ resourceSystemName = resource.getSystemName();
+ }
+ resource.setToscaResourceName(CommonBeUtils.generateToscaResourceName(resource.getResourceType()
+ .name()
+ .toLowerCase(), resourceSystemName));
+ }
- for (Entry<String, List<CapabilityDefinition>> typeEntry : resource.getCapabilities().entrySet()) {
+ // Generate invariant UUID - must be here and not in operation since it
+ // should stay constant during clone
+ // TODO
+ String invariantUUID = UniqueIdBuilder.buildInvariantUUID();
+ resource.setInvariantUUID(invariantUUID);
- eitherResult = validateCapabilityTypeExists(user, capabilityTypeOperation, resource, actionEnum,
- eitherResult, typeEntry, inTransaction);
- if (eitherResult.isRight()) {
- return Either.right(eitherResult.right().value());
- }
- }
- }
+ return resource;
+ }
- if (resource.getRequirements() != null && resource.getRequirements().size() > 0) {
- log.debug("validate capability Types Exist - requirements section");
- for (String type : resource.getRequirements().keySet()) {
- eitherResult = validateCapabilityTypeExists(user, capabilityTypeOperation, resource,
- resource.getRequirements().get(type), actionEnum, eitherResult, type, inTransaction);
- if (eitherResult.isRight()) {
- return Either.right(eitherResult.right().value());
- }
- }
- }
+ private Either<Boolean, ResponseFormat> validateResourceType(User user, Resource resource,
+ AuditingActionEnum actionEnum) {
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ if (resource.getResourceType() == null) {
+ log.debug("Invalid resource type for resource");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
+ eitherResult = Either.right(errorResponse);
+ componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
+ }
+ return eitherResult;
+ }
- return eitherResult;
- }
+ private Either<Boolean, ResponseFormat> validateLifecycleTypesCreate(User user, Resource resource,
+ AuditingActionEnum actionEnum) {
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ if (resource.getInterfaces() != null && resource.getInterfaces()
+ .size() > 0) {
+ log.debug("validate interface lifecycle Types Exist");
+ Iterator<InterfaceDefinition> intItr = resource.getInterfaces()
+ .values()
+ .iterator();
+ while (intItr.hasNext() && eitherResult.isLeft()) {
+ InterfaceDefinition interfaceDefinition = intItr.next();
+ String intType = interfaceDefinition.getUniqueId();
+ Either<InterfaceDefinition, StorageOperationStatus> eitherCapTypeFound = interfaceTypeOperation
+ .getInterface(intType);
+ if (eitherCapTypeFound.isRight()) {
+ if (eitherCapTypeFound.right()
+ .value() == StorageOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance()
+ .logBeGraphObjectMissingError("Create Resource - validateLifecycleTypesCreate",
+ "Interface", intType);
+ log.debug("Lifecycle Type: {} is required by resource: {} but does not exist in the DB",
+ intType, resource.getName());
+ BeEcompErrorManager.getInstance()
+ .logBeDaoSystemError("Create Resource - validateLifecycleTypesCreate");
+ log.debug("request to data model failed with error: {}", eitherCapTypeFound.right()
+ .value()
+ .name());
+ }
+
+ ResponseFormat errorResponse = componentsUtils
+ .getResponseFormat(ActionStatus.MISSING_LIFECYCLE_TYPE, intType);
+ eitherResult = Either.right(errorResponse);
+ componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
+ }
- // @param typeObject- the object to which the validation is done
- private Either<Boolean, ResponseFormat> validateCapabilityTypeExists(User user,
- ICapabilityTypeOperation capabilityTypeOperation, Resource resource, List<?> validationObjects,
- AuditingActionEnum actionEnum, Either<Boolean, ResponseFormat> eitherResult, String type,
- boolean inTransaction) {
- Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation
- .getCapabilityType(type, inTransaction);
- if (eitherCapTypeFound.isRight()) {
- if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().logBeGraphObjectMissingError(
- CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES, "Capability Type", type);
- log.debug("Capability Type: {} is required by resource: {} but does not exist in the DB", type,
- resource.getName());
- BeEcompErrorManager.getInstance()
- .logBeDaoSystemError(CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES);
- }
- log.debug("Trying to get capability type {} failed with error: {}", type,
- eitherCapTypeFound.right().value().name());
- ResponseFormat errorResponse = null;
- if (type != null) {
- errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, type);
- } else {
- errorResponse = componentsUtils.getResponseFormatByElement(ActionStatus.MISSING_CAPABILITY_TYPE,
- validationObjects);
- }
- eitherResult = Either.right(errorResponse);
- componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- }
- return eitherResult;
- }
+ }
+ }
+ return eitherResult;
+ }
- private Either<Boolean, ResponseFormat> validateCapabilityTypeExists(User user,
- ICapabilityTypeOperation capabilityTypeOperation, Resource resource, AuditingActionEnum actionEnum,
- Either<Boolean, ResponseFormat> eitherResult, Entry<String, List<CapabilityDefinition>> typeEntry,
- boolean inTransaction) {
- Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation
- .getCapabilityType(typeEntry.getKey(), inTransaction);
- if (eitherCapTypeFound.isRight()) {
- if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().logBeGraphObjectMissingError(
- CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES, "Capability Type", typeEntry.getKey());
- log.debug("Capability Type: {} is required by resource: {} but does not exist in the DB",
- typeEntry.getKey(), resource.getName());
- BeEcompErrorManager.getInstance()
- .logBeDaoSystemError(CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES);
- }
- log.debug("Trying to get capability type {} failed with error: {}", typeEntry.getKey(),
- eitherCapTypeFound.right().value().name());
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE,
- typeEntry.getKey());
- eitherResult = Either.right(errorResponse);
- componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- }
- CapabilityTypeDefinition capabilityTypeDefinition = eitherCapTypeFound.left().value();
- if (capabilityTypeDefinition.getProperties() != null) {
- for (CapabilityDefinition capDef : typeEntry.getValue()) {
- List<ComponentInstanceProperty> properties = capDef.getProperties();
- if (properties == null || properties.isEmpty()) {
- properties = new ArrayList<>();
- for (Entry<String, PropertyDefinition> prop : capabilityTypeDefinition.getProperties().entrySet()) {
- ComponentInstanceProperty newProp = new ComponentInstanceProperty(prop.getValue());
- properties.add(newProp);
- }
- } else {
- for (Entry<String, PropertyDefinition> prop : capabilityTypeDefinition.getProperties().entrySet()) {
- PropertyDefinition porpFromDef = prop.getValue();
- List<ComponentInstanceProperty> propsToAdd = new ArrayList<>();
- for (ComponentInstanceProperty cip : properties) {
- if (!cip.getName().equals(porpFromDef.getName())) {
- ComponentInstanceProperty newProp = new ComponentInstanceProperty(porpFromDef);
- propsToAdd.add(newProp);
- }
- }
- if (!propsToAdd.isEmpty()) {
- properties.addAll(propsToAdd);
- }
- }
- }
- capDef.setProperties(properties);
- }
- }
- return eitherResult;
- }
+ private Either<Boolean, ResponseFormat> validateCapabilityTypesCreate(User user,
+ ICapabilityTypeOperation capabilityTypeOperation, Resource resource, AuditingActionEnum actionEnum,
+ boolean inTransaction) {
- public Resource createResourceByDao(Resource resource, User user,
- AuditingActionEnum actionEnum, boolean isNormative, boolean inTransaction) {
- // create resource
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ if (resource.getCapabilities() != null && resource.getCapabilities()
+ .size() > 0) {
+ log.debug("validate capability Types Exist - capabilities section");
- // lock new resource name in order to avoid creation resource with same
- // name
- Resource createdResource = null;
- if (!inTransaction) {
- Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource,
- CREATE_RESOURCE);
- if (lockResult.isRight()) {
- ResponseFormat responseFormat = lockResult.right().value();
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ByResponseFormatComponentException(responseFormat);
- }
+ for (Entry<String, List<CapabilityDefinition>> typeEntry : resource.getCapabilities()
+ .entrySet()) {
- log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
- }
- try {
- if (resource.deriveFromGeneric()) {
- handleResourceGenericType(resource);
- }
- createdResource = createResourceTransaction(resource, user, isNormative
- );
- componentsUtils.auditResource(componentsUtils.getResponseFormat(ActionStatus.CREATED), user,
- createdResource, actionEnum);
- ASDCKpiApi.countCreatedResourcesKPI();
- } catch(ByActionStatusComponentException e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw e;
- } catch(ByResponseFormatComponentException e) {
- ResponseFormat responseFormat = e.getResponseFormat();
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw e;
- } catch (StorageException e){
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw e;
- }
- finally {
- if (!inTransaction) {
- graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(),
- NodeTypeEnum.Resource);
- }
- }
- return createdResource;
- }
+ eitherResult = validateCapabilityTypeExists(user, capabilityTypeOperation, resource, actionEnum,
+ eitherResult, typeEntry, inTransaction);
+ if (eitherResult.isRight()) {
+ return Either.right(eitherResult.right()
+ .value());
+ }
+ }
+ }
- private Resource createResourceTransaction(Resource resource, User user,
- boolean isNormative) {
- // validate resource name uniqueness
- log.debug("validate resource name");
- Either<Boolean, StorageOperationStatus> eitherValidation = toscaOperationFacade.validateComponentNameExists(
- resource.getName(), resource.getResourceType(), resource.getComponentType());
- if (eitherValidation.isRight()) {
- log.debug("Failed to validate component name {}. Status is {}. ", resource.getName(),
- eitherValidation.right().value());
- ResponseFormat errorResponse = componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(eitherValidation.right().value()));
- throw new ByResponseFormatComponentException(errorResponse);
- }
- if (eitherValidation.left().value()) {
- log.debug("resource with name: {}, already exists", resource.getName());
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
- ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
- throw new ByResponseFormatComponentException(errorResponse);
- }
+ if (resource.getRequirements() != null && resource.getRequirements()
+ .size() > 0) {
+ log.debug("validate capability Types Exist - requirements section");
+ for (String type : resource.getRequirements()
+ .keySet()) {
+ eitherResult = validateCapabilityTypeExists(user, capabilityTypeOperation, resource,
+ resource.getRequirements()
+ .get(type),
+ actionEnum, eitherResult, type, inTransaction);
+ if (eitherResult.isRight()) {
+ return Either.right(eitherResult.right()
+ .value());
+ }
+ }
+ }
- log.debug("send resource {} to dao for create", resource.getName());
-
- createArtifactsPlaceHolderData(resource, user);
- // enrich object
- if (!isNormative) {
- log.debug("enrich resource with creator, version and state");
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- resource.setVersion(INITIAL_VERSION);
- resource.setHighestVersion(true);
- if (resource.getResourceType() != null && resource.getResourceType() != ResourceTypeEnum.CVFC) {
- resource.setAbstract(false);
- }
- }
- return toscaOperationFacade.createToscaComponent(resource)
- .left()
- .on(r->throwComponentExceptionByResource(r, resource));
- }
+ return eitherResult;
+ }
- private Resource throwComponentExceptionByResource(StorageOperationStatus status, Resource resource) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(status), resource);
- throw new ByResponseFormatComponentException(responseFormat);
- }
+ // @param typeObject- the object to which the validation is done
+ private Either<Boolean, ResponseFormat> validateCapabilityTypeExists(User user,
+ ICapabilityTypeOperation capabilityTypeOperation, Resource resource, List<?> validationObjects,
+ AuditingActionEnum actionEnum, Either<Boolean, ResponseFormat> eitherResult, String type,
+ boolean inTransaction) {
+ Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation
+ .getCapabilityType(type, inTransaction);
+ if (eitherCapTypeFound.isRight()) {
+ if (eitherCapTypeFound.right()
+ .value() == StorageOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance()
+ .logBeGraphObjectMissingError(CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES, "Capability Type",
+ type);
+ log.debug("Capability Type: {} is required by resource: {} but does not exist in the DB", type,
+ resource.getName());
+ BeEcompErrorManager.getInstance()
+ .logBeDaoSystemError(CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES);
+ }
+ log.debug("Trying to get capability type {} failed with error: {}", type, eitherCapTypeFound.right()
+ .value()
+ .name());
+ ResponseFormat errorResponse = null;
+ if (type != null) {
+ errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, type);
+ } else {
+ errorResponse = componentsUtils.getResponseFormatByElement(ActionStatus.MISSING_CAPABILITY_TYPE,
+ validationObjects);
+ }
+ eitherResult = Either.right(errorResponse);
+ componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
+ }
+ return eitherResult;
+ }
- private void createArtifactsPlaceHolderData(Resource resource, User user) {
- // create mandatory artifacts
+ private Either<Boolean, ResponseFormat> validateCapabilityTypeExists(User user,
+ ICapabilityTypeOperation capabilityTypeOperation, Resource resource, AuditingActionEnum actionEnum,
+ Either<Boolean, ResponseFormat> eitherResult, Entry<String, List<CapabilityDefinition>> typeEntry,
+ boolean inTransaction) {
+ Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation
+ .getCapabilityType(typeEntry.getKey(), inTransaction);
+ if (eitherCapTypeFound.isRight()) {
+ if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance()
+ .logBeGraphObjectMissingError(CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES, "Capability Type",
+ typeEntry.getKey());
+ log.debug("Capability Type: {} is required by resource: {} but does not exist in the DB",
+ typeEntry.getKey(), resource.getName());
+ BeEcompErrorManager.getInstance().logBeDaoSystemError(CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES);
+ }
+ log.debug("Trying to get capability type {} failed with error: {}", typeEntry.getKey(),
+ eitherCapTypeFound.right().value().name());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE,
+ typeEntry.getKey());
+ componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
+ return Either.right(errorResponse);
+ }
+ CapabilityTypeDefinition capabilityTypeDefinition = eitherCapTypeFound.left().value();
+ if (capabilityTypeDefinition.getProperties() != null) {
+ for (CapabilityDefinition capDef : typeEntry.getValue()) {
+ List<ComponentInstanceProperty> properties = capDef.getProperties();
+ List<ComponentInstanceProperty> changedProperties = new ArrayList<>();
+ if (properties == null || properties.isEmpty()) {
+ for (Entry<String, PropertyDefinition> prop : capabilityTypeDefinition.getProperties().entrySet()) {
+ ComponentInstanceProperty newProp = new ComponentInstanceProperty(prop.getValue());
+ changedProperties.add(newProp);
+ }
+ } else {
+ List<ComponentInstanceProperty> propsToAdd = new ArrayList<>();
+ for (Entry<String, PropertyDefinition> prop : capabilityTypeDefinition.getProperties().entrySet()) {
+ PropertyDefinition propFromDef = prop.getValue();
+ boolean propFound = false;
+ for (ComponentInstanceProperty cip : properties) {
+ if (propFromDef.getName().equals(cip.getName())) {
+ //merge property value and property description only, ignore other fields
+ if(cip.getDescription() != null && !cip.getDescription().equals(propFromDef.getDescription())){
+ propFromDef.setDescription(cip.getDescription());
+ }
+ propertyDataValueMergeBusinessLogic.mergePropertyValue(propFromDef, cip, new ArrayList<>());
+ if(cip.getValue() != null){
+ propFromDef.setValue(cip.getValue());
+ }
+ propsToAdd.add(new ComponentInstanceProperty(propFromDef));
+ propFound = true;
+ properties.remove(cip);
+ break;
+ }
+ }
+ if(!propFound) {
+ propsToAdd.add(new ComponentInstanceProperty(propFromDef));
+ }
+ }
+ if (!propsToAdd.isEmpty()) {
+ changedProperties.addAll(propsToAdd);
+ }
+ }
+ capDef.setProperties(changedProperties);
+ }
+ }
+ return eitherResult;
+ }
- // TODO it must be removed after that artifact uniqueId creation will be
- // moved to ArtifactOperation
+ public Resource createResourceByDao(Resource resource, User user, AuditingActionEnum actionEnum,
+ boolean isNormative, boolean inTransaction) {
+ // create resource
+
+ // lock new resource name in order to avoid creation resource with same
+ // name
+ Resource createdResource = null;
+ if (!inTransaction) {
+ Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource,
+ CREATE_RESOURCE);
+ if (lockResult.isRight()) {
+ ResponseFormat responseFormat = lockResult.right().value();
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
- setInformationalArtifactsPlaceHolder(resource, user);
- setDeploymentArtifactsPlaceHolder(resource, user);
- setToscaArtifactsPlaceHolders(resource, user);
- }
+ log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
+ }
+ try {
+ if (resource.deriveFromGeneric()) {
+ handleResourceGenericType(resource);
+ }
+ createdResource = createResourceTransaction(resource, user, isNormative);
+ componentsUtils.auditResource(componentsUtils.getResponseFormat(ActionStatus.CREATED), user,
+ createdResource, actionEnum);
+ ASDCKpiApi.countCreatedResourcesKPI();
+ } catch (ComponentException e) {
+ ResponseFormat responseFormat = e.getResponseFormat() == null
+ ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw e;
+ } catch (StorageException e) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw e;
+ } finally {
+ if (!inTransaction) {
+ graphLockOperation.unlockComponentByName(resource.getSystemName(), resource.getUniqueId(),
+ NodeTypeEnum.Resource);
+ }
+ }
+ return createdResource;
+ }
- @SuppressWarnings("unchecked")
- @Override
- public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
- Resource resource = (Resource) component;
- Map<String, ArtifactDefinition> artifactMap = resource.getDeploymentArtifacts();
- if (artifactMap == null) {
- artifactMap = new HashMap<>();
- }
- Map<String, Object> deploymentResourceArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration().getDeploymentResourceArtifacts();
- if (deploymentResourceArtifacts != null) {
- Map<String, ArtifactDefinition> finalArtifactMap = artifactMap;
- deploymentResourceArtifacts.forEach((k, v)->processDeploymentResourceArtifacts(user, resource, finalArtifactMap, k,v));
- }
- resource.setDeploymentArtifacts(artifactMap);
- }
+ private Resource createResourceTransaction(Resource resource, User user, boolean isNormative) {
+ // validate resource name uniqueness
+ log.debug("validate resource name");
+ Either<Boolean, StorageOperationStatus> eitherValidation = toscaOperationFacade.validateComponentNameExists(
+ resource.getName(), resource.getResourceType(), resource.getComponentType());
+ if (eitherValidation.isRight()) {
+ loggerSupportability.log(LoggerSupportabilityActions.VALIDATE_NAME,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR while validate component name {} Status is: {}",resource.getName(),eitherValidation.right().value());
+ log.debug("Failed to validate component name {}. Status is {}. ", resource.getName(),
+ eitherValidation.right()
+ .value());
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(eitherValidation.right()
+ .value()));
+ }
+ if (eitherValidation.left()
+ .value()) {
+ log.debug("resource with name: {}, already exists", resource.getName());
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML,resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"resource with name: {} already exists",resource.getName());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
+ ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
+ }
- private void processDeploymentResourceArtifacts(User user, Resource resource, Map<String, ArtifactDefinition> artifactMap, String k, Object v) {
- boolean shouldCreateArtifact = true;
- Map<String, Object> artifactDetails = (Map<String, Object>) v;
- Object object = artifactDetails.get(PLACE_HOLDER_RESOURCE_TYPES);
- if (object != null) {
- List<String> artifactTypes = (List<String>) object;
- if (!artifactTypes.contains(resource.getResourceType().name())) {
- shouldCreateArtifact = false;
- return;
- }
- } else {
- log.info("resource types for artifact placeholder {} were not defined. default is all resources",
- k);
- }
- if (shouldCreateArtifact) {
- if (artifactsBusinessLogic != null) {
- ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo(
- resource.getUniqueId(), k, (Map<String, Object>) v,
- user, ArtifactGroupTypeEnum.DEPLOYMENT);
- if (artifactDefinition != null
- && !artifactMap.containsKey(artifactDefinition.getArtifactLabel())) {
- artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
- }
- }
- }
- }
+ log.debug("send resource {} to dao for create", resource.getName());
+
+ createArtifactsPlaceHolderData(resource, user);
+ // enrich object
+ if (!isNormative) {
+ log.debug("enrich resource with creator, version and state");
+ resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
+ resource.setVersion(INITIAL_VERSION);
+ resource.setHighestVersion(true);
+ if (resource.getResourceType() != null && resource.getResourceType() != ResourceTypeEnum.CVFC) {
+ resource.setAbstract(false);
+ }
+ }
+ return toscaOperationFacade.createToscaComponent(resource)
+ .left()
+ .on(r -> throwComponentExceptionByResource(r, resource));
+ }
- @SuppressWarnings("unchecked")
- private void setInformationalArtifactsPlaceHolder(Resource resource, User user) {
- Map<String, ArtifactDefinition> artifactMap = resource.getArtifacts();
- if (artifactMap == null) {
- artifactMap = new HashMap<>();
- }
- String resourceUniqueId = resource.getUniqueId();
- List<String> exludeResourceCategory = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getExcludeResourceCategory();
- List<String> exludeResourceType = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getExcludeResourceType();
- Map<String, Object> informationalResourceArtifacts = ConfigurationManager.getConfigurationManager()
- .getConfiguration().getInformationalResourceArtifacts();
- List<CategoryDefinition> categories = resource.getCategories();
- boolean isCreateArtifact = true;
- if (exludeResourceCategory != null) {
- String category = categories.get(0).getName();
- isCreateArtifact = exludeResourceCategory.stream().noneMatch(e->e.equalsIgnoreCase(category));
- }
- if (isCreateArtifact && exludeResourceType != null) {
- String resourceType = resource.getResourceType().name();
- isCreateArtifact = exludeResourceType.stream().noneMatch(e->e.equalsIgnoreCase(resourceType));
- }
- if (informationalResourceArtifacts != null && isCreateArtifact) {
- Set<String> keys = informationalResourceArtifacts.keySet();
- for (String informationalResourceArtifactName : keys) {
- Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalResourceArtifacts
- .get(informationalResourceArtifactName);
- ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo(
- resourceUniqueId, informationalResourceArtifactName, artifactInfoMap, user,
- ArtifactGroupTypeEnum.INFORMATIONAL);
- artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
+ private Resource throwComponentExceptionByResource(StorageOperationStatus status, Resource resource) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(status), resource);
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
- }
- }
- resource.setArtifacts(artifactMap);
- }
+ private void createArtifactsPlaceHolderData(Resource resource, User user) {
+ // create mandatory artifacts
- /**
- * deleteResource
- *
- * @param resourceId
- * @param user
- * @return
- */
- public ResponseFormat deleteResource(String resourceId, User user) {
- ResponseFormat responseFormat;
- validateUserExists(user, DELETE_RESOURCE, false);
-
- Either<Resource, StorageOperationStatus> resourceStatus = toscaOperationFacade.getToscaElement(resourceId);
- if (resourceStatus.isRight()) {
- log.debug("failed to get resource {}", resourceId);
- return componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(resourceStatus.right().value()), "");
- }
+ // TODO it must be removed after that artifact uniqueId creation will be
+ // moved to ArtifactOperation
- Resource resource = resourceStatus.left().value();
+ setInformationalArtifactsPlaceHolder(resource, user);
+ setDeploymentArtifactsPlaceHolder(resource, user);
+ setToscaArtifactsPlaceHolders(resource, user);
+ }
- StorageOperationStatus result = StorageOperationStatus.OK;
- Either<Boolean, ResponseFormat> lockResult = lockComponent(resourceId, resource, "Mark resource to delete");
- if (lockResult.isRight()) {
- return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
+ Resource resource = (Resource) component;
+ Map<String, ArtifactDefinition> artifactMap = resource.getDeploymentArtifacts();
+ if (artifactMap == null) {
+ artifactMap = new HashMap<>();
+ }
+ Map<String, Object> deploymentResourceArtifacts = ConfigurationManager.getConfigurationManager()
+ .getConfiguration()
+ .getDeploymentResourceArtifacts();
+ if (deploymentResourceArtifacts != null) {
+ Map<String, ArtifactDefinition> finalArtifactMap = artifactMap;
+ deploymentResourceArtifacts
+ .forEach((k, v) -> processDeploymentResourceArtifacts(user, resource, finalArtifactMap, k, v));
+ }
+ resource.setDeploymentArtifacts(artifactMap);
+ }
- try {
+ private void processDeploymentResourceArtifacts(User user, Resource resource,
+ Map<String, ArtifactDefinition> artifactMap, String k, Object v) {
+ boolean shouldCreateArtifact = true;
+ Map<String, Object> artifactDetails = (Map<String, Object>) v;
+ Object object = artifactDetails.get(PLACE_HOLDER_RESOURCE_TYPES);
+ if (object != null) {
+ List<String> artifactTypes = (List<String>) object;
+ if (!artifactTypes.contains(resource.getResourceType()
+ .name())) {
+ shouldCreateArtifact = false;
+ return;
+ }
+ } else {
+ log.info("resource types for artifact placeholder {} were not defined. default is all resources", k);
+ }
+ if (shouldCreateArtifact) {
+ if (artifactsBusinessLogic != null) {
+ ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo(
+ resource.getUniqueId(), k, (Map<String, Object>) v, user, ArtifactGroupTypeEnum.DEPLOYMENT);
+ if (artifactDefinition != null && !artifactMap.containsKey(artifactDefinition.getArtifactLabel())) {
+ artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
+ }
+ }
+ }
+ }
- result = markComponentToDelete(resource);
- if (result.equals(StorageOperationStatus.OK)) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
- } else {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
- responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, resource.getName());
- }
- return responseFormat;
+ @SuppressWarnings("unchecked")
+ private void setInformationalArtifactsPlaceHolder(Resource resource, User user) {
+ Map<String, ArtifactDefinition> artifactMap = resource.getArtifacts();
+ if (artifactMap == null) {
+ artifactMap = new HashMap<>();
+ }
+ String resourceUniqueId = resource.getUniqueId();
+ List<String> exludeResourceCategory = ConfigurationManager.getConfigurationManager()
+ .getConfiguration()
+ .getExcludeResourceCategory();
+ List<String> exludeResourceType = ConfigurationManager.getConfigurationManager()
+ .getConfiguration()
+ .getExcludeResourceType();
+ Map<String, Object> informationalResourceArtifacts = ConfigurationManager.getConfigurationManager()
+ .getConfiguration()
+ .getInformationalResourceArtifacts();
+ List<CategoryDefinition> categories = resource.getCategories();
+ boolean isCreateArtifact = true;
+ if (exludeResourceCategory != null) {
+ String category = categories.get(0)
+ .getName();
+ isCreateArtifact = exludeResourceCategory.stream()
+ .noneMatch(e -> e.equalsIgnoreCase(category));
+ }
+ if (isCreateArtifact && exludeResourceType != null) {
+ String resourceType = resource.getResourceType()
+ .name();
+ isCreateArtifact = exludeResourceType.stream()
+ .noneMatch(e -> e.equalsIgnoreCase(resourceType));
+ }
+ if (informationalResourceArtifacts != null && isCreateArtifact) {
+ Set<String> keys = informationalResourceArtifacts.keySet();
+ for (String informationalResourceArtifactName : keys) {
+ Map<String, Object> artifactInfoMap = (Map<String, Object>) informationalResourceArtifacts
+ .get(informationalResourceArtifactName);
+ ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo(
+ resourceUniqueId, informationalResourceArtifactName, artifactInfoMap, user,
+ ArtifactGroupTypeEnum.INFORMATIONAL);
+ artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
- } finally {
- if (result == null || !result.equals(StorageOperationStatus.OK)) {
- janusGraphDao.rollback();
- } else {
- janusGraphDao.commit();
- }
- graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
- }
+ }
+ }
+ resource.setArtifacts(artifactMap);
+ }
- }
+ /**
+ * deleteResource
+ *
+ * @param resourceId
+ * @param user
+ * @return
+ */
+ public ResponseFormat deleteResource(String resourceId, User user) {
+ ResponseFormat responseFormat;
+ validateUserExists(user);
+
+ Either<Resource, StorageOperationStatus> resourceStatus = toscaOperationFacade.getToscaElement(resourceId);
+ if (resourceStatus.isRight()) {
+ log.debug("failed to get resource {}", resourceId);
+ return componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceStatus.right()
+ .value()), "");
+ }
- public ResponseFormat deleteResourceByNameAndVersion(String resourceName, String version, User user) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
- validateUserExists(user, DELETE_RESOURCE, false);
- Resource resource = null;
- StorageOperationStatus result = StorageOperationStatus.OK;
- try {
+ Resource resource = resourceStatus.left()
+ .value();
- Either<Resource, StorageOperationStatus> resourceStatus = toscaOperationFacade
- .getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName, version);
- if (resourceStatus.isRight()) {
- log.debug("failed to get resource {} version {}", resourceName, version);
- return componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(resourceStatus.right().value()), resourceName);
- }
+ StorageOperationStatus result = StorageOperationStatus.OK;
+ lockComponent(resourceId, resource, "Mark resource to delete");
+ try {
- resource = resourceStatus.left().value();
+ result = markComponentToDelete(resource);
+ if (result == StorageOperationStatus.OK) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
+ } else {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
+ responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, resource.getName());
+ }
+ return responseFormat;
- } finally {
- if (result == null || !result.equals(StorageOperationStatus.OK)) {
- janusGraphDao.rollback();
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
- responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, resourceName);
- } else {
+ } finally {
+ if (result == null || result != StorageOperationStatus.OK) {
+ janusGraphDao.rollback();
+ } else {
janusGraphDao.commit();
- }
- }
- if (resource != null) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(resource.getUniqueId(), resource,
- DELETE_RESOURCE);
- if (lockResult.isRight()) {
- result = StorageOperationStatus.GENERAL_ERROR;
- return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- }
- try {
- result = markComponentToDelete(resource);
- if (!result.equals(StorageOperationStatus.OK)) {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
- responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, resource.getName());
- return responseFormat;
- }
-
- } finally {
- if (result == null || !result.equals(StorageOperationStatus.OK)) {
- janusGraphDao.rollback();
- } else {
- janusGraphDao.commit();
- }
- graphLockOperation.unlockComponent(resource.getUniqueId(), NodeTypeEnum.Resource);
- }
- }
- return responseFormat;
- }
+ }
+ graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
+ }
- public Either<Resource, ResponseFormat> getResource(String resourceId, User user) {
+ }
- if (user != null) {
- validateUserExists(user, CREATE_RESOURCE, false);
- }
+ public ResponseFormat deleteResourceByNameAndVersion(String resourceName, String version, User user) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
+ validateUserExists(user);
+ Resource resource = null;
+ StorageOperationStatus result = StorageOperationStatus.OK;
+ boolean failed = false;
+ try {
+
+ Either<Resource, StorageOperationStatus> resourceStatus = toscaOperationFacade
+ .getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName, version);
+ if (resourceStatus.isRight()) {
+ log.debug("failed to get resource {} version {}", resourceName, version);
+ return componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(resourceStatus.right()
+ .value()), resourceName);
+ }
- Either<Resource, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(resourceId);
- if (storageStatus.isRight()) {
- log.debug("failed to get resource by id {}", resourceId);
- return Either.right(componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(storageStatus.right().value()), resourceId));
- }
- if (!(storageStatus.left().value() instanceof Resource)) {
- return Either.right(componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND), resourceId));
- }
- return Either.left(storageStatus.left().value());
+ resource = resourceStatus.left()
+ .value();
- }
+ } finally {
+ janusGraphDao.commit();
+ }
+ if (resource != null) {
+ lockComponent(resource.getUniqueId(), resource, DELETE_RESOURCE);
+ try {
+ result = markComponentToDelete(resource);
+ if (result != StorageOperationStatus.OK) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
+ responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, resource.getName());
+ return responseFormat;
+ }
+ }catch (ComponentException e){
+ failed = true;
+ throw e;
+ }finally {
+ if (failed || result == null || result != StorageOperationStatus.OK) {
+ janusGraphDao.rollback();
+ } else {
+ janusGraphDao.commit();
+ }
+ graphLockOperation.unlockComponent(resource.getUniqueId(), NodeTypeEnum.Resource);
+ }
+ }
+ return responseFormat;
+ }
- public Either<Resource, ResponseFormat> getResourceByNameAndVersion(String resourceName, String resourceVersion,
- String userId) {
+ public Either<Resource, ResponseFormat> getResource(String resourceId, User user) {
- validateUserExists(userId, "get Resource By Name And Version", false);
+ if (user != null) {
+ validateUserExists(user);
+ }
- Either<Resource, StorageOperationStatus> getResource = toscaOperationFacade
- .getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName, resourceVersion);
- if (getResource.isRight()) {
- log.debug("failed to get resource by name {} and version {}", resourceName, resourceVersion);
- return Either.right(componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(getResource.right().value()), resourceName));
- }
- return Either.left(getResource.left().value());
- }
+ Either<Resource, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(resourceId);
+ if (storageStatus.isRight()) {
+ log.debug("failed to get resource by id {}", resourceId);
+ return Either.right(componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus.right()
+ .value()), resourceId));
+ }
+ if (!(storageStatus.left()
+ .value() instanceof Resource)) {
+ return Either.right(componentsUtils.getResponseFormatByResource(
+ componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND), resourceId));
+ }
+ return Either.left(storageStatus.left()
+ .value());
- /**
- * updateResourceMetadata
- *
- * @param user - modifier data (userId)
- * @param inTransaction TODO
- * @param resourceIdToUpdate - the resource identifier
- * @param newResource
- * @return Either<Resource , responseFormat>
- */
- public Resource updateResourceMetadata(String resourceIdToUpdate, Resource newResource,
- Resource currentResource, User user, boolean inTransaction) {
+ }
- validateUserExists(user.getUserId(), "update Resource Metadata", false);
+ public Either<Resource, ResponseFormat> getResourceByNameAndVersion(String resourceName, String resourceVersion,
+ String userId) {
- log.debug("Get resource with id {}", resourceIdToUpdate);
- boolean needToUnlock = false;
- boolean rollbackNeeded = true;
+ validateUserExists(userId);
- try {
- if (currentResource == null) {
- Either<Resource, StorageOperationStatus> storageStatus = toscaOperationFacade
- .getToscaElement(resourceIdToUpdate);
- if (storageStatus.isRight()) {
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(storageStatus.right().value()), ""));
- }
+ Either<Resource, StorageOperationStatus> getResource = toscaOperationFacade
+ .getComponentByNameAndVersion(ComponentTypeEnum.RESOURCE, resourceName, resourceVersion);
+ if (getResource.isRight()) {
+ log.debug("failed to get resource by name {} and version {}", resourceName, resourceVersion);
+ return Either.right(componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(getResource.right()
+ .value()), resourceName));
+ }
+ return Either.left(getResource.left()
+ .value());
+ }
- currentResource = storageStatus.left().value();
- }
- // verify that resource is checked-out and the user is the last
- // updater
- if (!ComponentValidationUtils.canWorkOnResource(currentResource, user.getUserId())) {
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
- }
+ /**
+ * updateResourceMetadata
+ *
+ * @param user
+ * - modifier data (userId)
+ * @param inTransaction
+ * TODO
+ * @param resourceIdToUpdate
+ * - the resource identifier
+ * @param newResource
+ * @return Either<Resource , responseFormat>
+ */
+ public Resource updateResourceMetadata(String resourceIdToUpdate, Resource newResource, Resource currentResource,
+ User user, boolean inTransaction) {
+
+ validateUserExists(user.getUserId());
+
+ log.debug("Get resource with id {}", resourceIdToUpdate);
+ boolean needToUnlock = false;
+
+ try {
+ if (currentResource == null) {
+ Either<Resource, StorageOperationStatus> storageStatus = toscaOperationFacade
+ .getToscaElement(resourceIdToUpdate);
+ if (storageStatus.isRight()) {
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
+ componentsUtils.convertFromStorageResponse(storageStatus.right()
+ .value()),
+ ""));
+ }
+
+ currentResource = storageStatus.left()
+ .value();
+ }
+ // verify that resource is checked-out and the user is the last
+ // updater
+ if (!ComponentValidationUtils.canWorkOnResource(currentResource, user.getUserId())) {
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
- // lock resource
- StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceIdToUpdate,
- NodeTypeEnum.Resource);
- if (!lockResult.equals(StorageOperationStatus.OK)) {
- BeEcompErrorManager.getInstance().logBeFailedLockObjectError("Upload Artifact - lock ",
- NodeTypeEnum.Resource.getName(), resourceIdToUpdate);
- log.debug("Failed to lock resource: {}, error - {}", resourceIdToUpdate, lockResult);
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(lockResult));
- throw new ByResponseFormatComponentException(responseFormat);
- }
+ // lock resource
+ StorageOperationStatus lockResult = graphLockOperation.lockComponent(resourceIdToUpdate,
+ NodeTypeEnum.Resource);
+ if (lockResult != StorageOperationStatus.OK) {
+ BeEcompErrorManager.getInstance()
+ .logBeFailedLockObjectError("Upload Artifact - lock ", NodeTypeEnum.Resource.getName(),
+ resourceIdToUpdate);
+ log.debug("Failed to lock resource: {}, error - {}", resourceIdToUpdate, lockResult);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(lockResult));
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
- needToUnlock = true;
+ needToUnlock = true;
- // critical section starts here
- // convert json to object
+ // critical section starts here
+ // convert json to object
- // Update and updated resource must have a non-empty "derivedFrom"
- // list
- // This code is not called from import resources, because of root
- // VF "derivedFrom" should be null (or ignored)
- if (ModelConverter.isAtomicComponent(currentResource)) {
- validateDerivedFromNotEmpty(null, newResource, null);
- validateDerivedFromNotEmpty(null, currentResource, null);
- } else {
- newResource.setDerivedFrom(null);
- }
+ // Update and updated resource must have a non-empty "derivedFrom"
+ // list
+ // This code is not called from import resources, because of root
+ // VF "derivedFrom" should be null (or ignored)
+ if (ModelConverter.isAtomicComponent(currentResource)) {
+ validateDerivedFromNotEmpty(null, newResource, null);
+ validateDerivedFromNotEmpty(null, currentResource, null);
+ } else {
+ newResource.setDerivedFrom(null);
+ }
Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource,
user, currentResource, false, true);
if (dataModelResponse.isRight()) {
log.debug("failed to update resource metadata!!!");
- rollbackNeeded = true;
throw new ByResponseFormatComponentException(dataModelResponse.right().value());
}
- log.debug("Resource metadata updated successfully!!!");
- rollbackNeeded = false;
- return dataModelResponse.left().value();
+ log.debug("Resource metadata updated successfully!!!");
+ return dataModelResponse.left()
+ .value();
- } catch (ComponentException|StorageException e){
- rollback(inTransaction, newResource, null, null);
- throw e;
- }
- finally {
- if (!inTransaction) {
+ } catch (ComponentException | StorageException e) {
+ rollback(inTransaction, newResource, null, null);
+ throw e;
+ } finally {
+ if (!inTransaction) {
janusGraphDao.commit();
- }
- if (needToUnlock) {
- graphLockOperation.unlockComponent(resourceIdToUpdate, NodeTypeEnum.Resource);
- }
- }
- }
-
- private Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource,
- User user, Resource currentResource, boolean shouldLock, boolean inTransaction) {
- updateVfModuleGroupsNames(currentResource, newResource);
- validateResourceFieldsBeforeUpdate(currentResource, newResource, inTransaction, false);
- // Setting last updater and uniqueId
- newResource.setContactId(newResource.getContactId().toLowerCase());
- newResource.setLastUpdaterUserId(user.getUserId());
- newResource.setUniqueId(resourceIdToUpdate);
- // Cannot set highest version through UI
- newResource.setHighestVersion(currentResource.isHighestVersion());
- newResource.setCreationDate(currentResource.getCreationDate());
-
- Either<Boolean, ResponseFormat> processUpdateOfDerivedFrom = processUpdateOfDerivedFrom(currentResource,
- newResource, user.getUserId(), inTransaction);
-
- if (processUpdateOfDerivedFrom.isRight()) {
- log.debug("Couldn't update derived from for resource {}", resourceIdToUpdate);
- return Either.right(processUpdateOfDerivedFrom.right().value());
- }
-
- log.debug("send resource {} to dao for update", newResource.getUniqueId());
- if (isNotEmpty(newResource.getGroups())) {
- for (GroupDefinition group : newResource.getGroups()) {
- if (group.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) {
- groupBusinessLogic.validateAndUpdateGroupMetadata(
- newResource.getComponentMetadataDefinition().getMetadataDataDefinition().getUniqueId(),
- user, newResource.getComponentType(), group, true, false);
- }
- }
- }
- Either<Resource, StorageOperationStatus> dataModelResponse = toscaOperationFacade
- .updateToscaElement(newResource);
-
- if (dataModelResponse.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()), newResource);
- return Either.right(responseFormat);
- } else if (dataModelResponse.left().value() == null) {
- log.debug("No response from updateResource");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- return Either.left(dataModelResponse.left().value());
- }
-
-
- private void updateVfModuleGroupsNames(Resource currentResource, Resource newResource) {
- if(currentResource.getGroups() != null && !currentResource.getName().equals(newResource.getName())){
- List<GroupDefinition> updatedGroups = currentResource.getGroups()
- .stream()
- .map(group -> getUpdatedGroup(group, currentResource.getName(), newResource.getName()))
- .collect(toList());
- newResource.setGroups(updatedGroups);
- }
- }
-
- private GroupDefinition getUpdatedGroup(GroupDefinition currGroup, String replacePattern, String with) {
- GroupDefinition updatedGroup = new GroupDefinition(currGroup);
- if(updatedGroup.isSamePrefix(replacePattern) && updatedGroup.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)){
- String prefix = updatedGroup.getName().substring(0, replacePattern.length());
- String newGroupName = updatedGroup.getName().replaceFirst(prefix, with);
- updatedGroup.setName(newGroupName);
- }
- return updatedGroup;
- }
- /**
- * validateResourceFieldsBeforeCreate
- *
- * @param user - modifier data (userId)
- * @return Either<Boolean , ErrorResponse>
- */
- private Either<Boolean, ResponseFormat> validateResourceFieldsBeforeCreate(User user, Resource resource,
- AuditingActionEnum actionEnum, boolean inTransaction) {
- validateComponentFieldsBeforeCreate(user, resource, actionEnum);
- // validate category
- log.debug("validate category");
- validateCategory(user, resource, actionEnum, inTransaction);
- // validate vendor name & release & model number
- log.debug("validate vendor name");
- validateVendorName(user, resource, actionEnum);
- log.debug("validate vendor release");
- validateVendorReleaseName(user, resource, actionEnum);
- log.debug("validate resource vendor model number");
- validateResourceVendorModelNumber(user, resource, actionEnum);
- // validate cost
- log.debug("validate cost");
- validateCost(resource);
- // validate licenseType
- log.debug("validate licenseType");
- validateLicenseType(user, resource, actionEnum);
- // validate template (derived from)
- log.debug("validate derived from");
- if (!ModelConverter.isAtomicComponent(resource) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
- resource.setDerivedFrom(null);
- }
- validateDerivedFromExist(user, resource, actionEnum);
- // warn about non-updatable fields
- checkComponentFieldsForOverrideAttempt(resource);
- String currentCreatorFullName = resource.getCreatorFullName();
- if (currentCreatorFullName != null) {
- log.debug("Resource Creator fullname is automatically set and cannot be updated");
- }
-
- String currentLastUpdaterFullName = resource.getLastUpdaterFullName();
- if (currentLastUpdaterFullName != null) {
- log.debug("Resource LastUpdater fullname is automatically set and cannot be updated");
- }
-
- Long currentLastUpdateDate = resource.getLastUpdateDate();
- if (currentLastUpdateDate != null) {
- log.debug("Resource last update date is automatically set and cannot be updated");
- }
-
- Boolean currentAbstract = resource.isAbstract();
- if (currentAbstract != null) {
- log.debug("Resource abstract is automatically set and cannot be updated");
- }
-
- return Either.left(true);
- }
-
- /**
- * validateResourceFieldsBeforeUpdate
- *
- * @param currentResource - Resource object to validate
- * @param isNested
- */
- private void validateResourceFieldsBeforeUpdate(Resource currentResource, Resource updateInfoResource,
- boolean inTransaction, boolean isNested) {
- validateFields(currentResource, updateInfoResource, inTransaction, isNested);
- warnNonEditableFields(currentResource, updateInfoResource);
- }
-
- private void warnNonEditableFields(Resource currentResource, Resource updateInfoResource) {
- String currentResourceVersion = currentResource.getVersion();
- String updatedResourceVersion = updateInfoResource.getVersion();
-
- if ((updatedResourceVersion != null) && (!updatedResourceVersion.equals(currentResourceVersion))) {
- log.debug("Resource version is automatically set and cannot be updated");
- }
+ }
+ if (needToUnlock) {
+ graphLockOperation.unlockComponent(resourceIdToUpdate, NodeTypeEnum.Resource);
+ }
+ }
+ }
- String currentCreatorUserId = currentResource.getCreatorUserId();
- String updatedCreatorUserId = updateInfoResource.getCreatorUserId();
+ private Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource,
+ User user, Resource currentResource, boolean shouldLock, boolean inTransaction) {
+ updateVfModuleGroupsNames(currentResource, newResource);
+ validateResourceFieldsBeforeUpdate(currentResource, newResource, inTransaction, false);
+ // Setting last updater and uniqueId
+ newResource.setContactId(newResource.getContactId()
+ .toLowerCase());
+ newResource.setLastUpdaterUserId(user.getUserId());
+ newResource.setUniqueId(resourceIdToUpdate);
+ // Cannot set highest version through UI
+ newResource.setHighestVersion(currentResource.isHighestVersion());
+ newResource.setCreationDate(currentResource.getCreationDate());
+
+ Either<Boolean, ResponseFormat> processUpdateOfDerivedFrom = processUpdateOfDerivedFrom(currentResource,
+ newResource, user.getUserId(), inTransaction);
+
+ if (processUpdateOfDerivedFrom.isRight()) {
+ log.debug("Couldn't update derived from for resource {}", resourceIdToUpdate);
+ return Either.right(processUpdateOfDerivedFrom.right()
+ .value());
+ }
- if ((updatedCreatorUserId != null) && (!updatedCreatorUserId.equals(currentCreatorUserId))) {
- log.debug("Resource Creator UserId is automatically set and cannot be updated");
- }
+ log.debug("send resource {} to dao for update", newResource.getUniqueId());
+ if (isNotEmpty(newResource.getGroups())) {
+ for (GroupDefinition group : newResource.getGroups()) {
+ if (DEFAULT_GROUP_VF_MODULE.equals(group.getType())) {
+ groupBusinessLogic.validateAndUpdateGroupMetadata(newResource.getComponentMetadataDefinition()
+ .getMetadataDataDefinition()
+ .getUniqueId(), user, newResource.getComponentType(), group, true, false);
+ }
+ }
+ }
+ Either<Resource, StorageOperationStatus> dataModelResponse = toscaOperationFacade
+ .updateToscaElement(newResource);
+
+ if (dataModelResponse.isRight()) {
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(dataModelResponse.right()
+ .value()), newResource);
+ return Either.right(responseFormat);
+ } else if (dataModelResponse.left()
+ .value() == null) {
+ log.debug("No response from updateResource");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return Either.left(dataModelResponse.left()
+ .value());
+ }
- String currentCreatorFullName = currentResource.getCreatorFullName();
- String updatedCreatorFullName = updateInfoResource.getCreatorFullName();
+ private void updateVfModuleGroupsNames(Resource currentResource, Resource newResource) {
+ if (currentResource.getGroups() != null && !currentResource.getName()
+ .equals(newResource.getName())) {
+ List<GroupDefinition> updatedGroups = currentResource.getGroups()
+ .stream()
+ .map(group -> getUpdatedGroup(group, currentResource.getName(), newResource.getName()))
+ .collect(toList());
+ newResource.setGroups(updatedGroups);
+ }
+ }
- if ((updatedCreatorFullName != null) && (!updatedCreatorFullName.equals(currentCreatorFullName))) {
- log.debug("Resource Creator fullname is automatically set and cannot be updated");
- }
+ private GroupDefinition getUpdatedGroup(GroupDefinition currGroup, String replacePattern, String with) {
+ GroupDefinition updatedGroup = new GroupDefinition(currGroup);
+ if (updatedGroup.isSamePrefix(replacePattern) && updatedGroup.getType()
+ .equals(DEFAULT_GROUP_VF_MODULE)) {
+ String prefix = updatedGroup.getName()
+ .substring(0, replacePattern.length());
+ String newGroupName = updatedGroup.getName()
+ .replaceFirst(prefix, with);
+ updatedGroup.setName(newGroupName);
+ }
+ return updatedGroup;
+ }
- String currentLastUpdaterUserId = currentResource.getLastUpdaterUserId();
- String updatedLastUpdaterUserId = updateInfoResource.getLastUpdaterUserId();
+ /**
+ * validateResourceFieldsBeforeCreate
+ *
+ * @param user
+ * - modifier data (userId)
+ */
+ private void validateResourceFieldsBeforeCreate(User user, Resource resource,
+ AuditingActionEnum actionEnum, boolean inTransaction) {
+ componentValidator.validate(user, resource, actionEnum);
+ // validate category
+ log.debug("validate category");
+ validateCategory(user, resource, actionEnum, inTransaction);
+ // validate vendor name & release & model number
+ log.debug("validate vendor name");
+ validateVendorName(user, resource, actionEnum);
+ log.debug("validate vendor release");
+ validateVendorReleaseName(user, resource, actionEnum);
+ log.debug("validate resource vendor model number");
+ validateResourceVendorModelNumber(user, resource, actionEnum);
+ // validate cost
+ log.debug("validate cost");
+ validateCost(resource);
+ // validate licenseType
+ log.debug("validate licenseType");
+ validateLicenseType(user, resource, actionEnum);
+ // validate template (derived from)
+ log.debug("validate derived from");
+ if (!ModelConverter.isAtomicComponent(resource) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
+ resource.setDerivedFrom(null);
+ }
+ validateDerivedFromExist(user, resource, actionEnum);
+ // warn about non-updatable fields
+ checkComponentFieldsForOverrideAttempt(resource);
+ String currentCreatorFullName = resource.getCreatorFullName();
+ if (currentCreatorFullName != null) {
+ log.debug("Resource Creator fullname is automatically set and cannot be updated");
+ }
- if ((updatedLastUpdaterUserId != null) && (!updatedLastUpdaterUserId.equals(currentLastUpdaterUserId))) {
- log.debug("Resource LastUpdater userId is automatically set and cannot be updated");
- }
+ String currentLastUpdaterFullName = resource.getLastUpdaterFullName();
+ if (currentLastUpdaterFullName != null) {
+ log.debug("Resource LastUpdater fullname is automatically set and cannot be updated");
+ }
- String currentLastUpdaterFullName = currentResource.getLastUpdaterFullName();
- String updatedLastUpdaterFullName = updateInfoResource.getLastUpdaterFullName();
+ Long currentLastUpdateDate = resource.getLastUpdateDate();
+ if (currentLastUpdateDate != null) {
+ log.debug("Resource last update date is automatically set and cannot be updated");
+ }
- if ((updatedLastUpdaterFullName != null) && (!updatedLastUpdaterFullName.equals(currentLastUpdaterFullName))) {
- log.debug("Resource LastUpdater fullname is automatically set and cannot be updated");
- }
+ Boolean currentAbstract = resource.isAbstract();
+ if (currentAbstract != null) {
+ log.debug("Resource abstract is automatically set and cannot be updated");
+ }
+ }
- Long currentCreationDate = currentResource.getCreationDate();
- Long updatedCreationDate = updateInfoResource.getCreationDate();
+ /**
+ * validateResourceFieldsBeforeUpdate
+ *
+ * @param currentResource
+ * - Resource object to validate
+ * @param isNested
+ */
+ private void validateResourceFieldsBeforeUpdate(Resource currentResource, Resource updateInfoResource,
+ boolean inTransaction, boolean isNested) {
+ validateFields(currentResource, updateInfoResource, inTransaction, isNested);
+ warnNonEditableFields(currentResource, updateInfoResource);
+ }
- if ((updatedCreationDate != null) && (!updatedCreationDate.equals(currentCreationDate))) {
- log.debug("Resource Creation date is automatically set and cannot be updated");
- }
+ private void warnNonEditableFields(Resource currentResource, Resource updateInfoResource) {
+ String currentResourceVersion = currentResource.getVersion();
+ String updatedResourceVersion = updateInfoResource.getVersion();
- Long currentLastUpdateDate = currentResource.getLastUpdateDate();
- Long updatedLastUpdateDate = updateInfoResource.getLastUpdateDate();
+ if ((updatedResourceVersion != null) && (!updatedResourceVersion.equals(currentResourceVersion))) {
+ log.debug("Resource version is automatically set and cannot be updated");
+ }
- if ((updatedLastUpdateDate != null) && (!updatedLastUpdateDate.equals(currentLastUpdateDate))) {
- log.debug("Resource last update date is automatically set and cannot be updated");
- }
+ String currentCreatorUserId = currentResource.getCreatorUserId();
+ String updatedCreatorUserId = updateInfoResource.getCreatorUserId();
- LifecycleStateEnum currentLifecycleState = currentResource.getLifecycleState();
- LifecycleStateEnum updatedLifecycleState = updateInfoResource.getLifecycleState();
+ if ((updatedCreatorUserId != null) && (!updatedCreatorUserId.equals(currentCreatorUserId))) {
+ log.debug("Resource Creator UserId is automatically set and cannot be updated");
+ }
- if ((updatedLifecycleState != null) && (!updatedLifecycleState.equals(currentLifecycleState))) {
- log.debug("Resource lifecycle state date is automatically set and cannot be updated");
- }
+ String currentCreatorFullName = currentResource.getCreatorFullName();
+ String updatedCreatorFullName = updateInfoResource.getCreatorFullName();
- Boolean currentAbstract = currentResource.isAbstract();
- Boolean updatedAbstract = updateInfoResource.isAbstract();
+ if ((updatedCreatorFullName != null) && (!updatedCreatorFullName.equals(currentCreatorFullName))) {
+ log.debug("Resource Creator fullname is automatically set and cannot be updated");
+ }
- if ((updatedAbstract != null) && (!updatedAbstract.equals(currentAbstract))) {
- log.debug("Resource abstract is automatically set and cannot be updated");
- }
+ String currentLastUpdaterUserId = currentResource.getLastUpdaterUserId();
+ String updatedLastUpdaterUserId = updateInfoResource.getLastUpdaterUserId();
- Boolean currentHighestVersion = currentResource.isHighestVersion();
- Boolean updatedHighestVersion = updateInfoResource.isHighestVersion();
+ if ((updatedLastUpdaterUserId != null) && (!updatedLastUpdaterUserId.equals(currentLastUpdaterUserId))) {
+ log.debug("Resource LastUpdater userId is automatically set and cannot be updated");
+ }
- if ((updatedHighestVersion != null) && (!updatedHighestVersion.equals(currentHighestVersion))) {
- log.debug("Resource highest version is automatically set and cannot be updated");
- }
+ String currentLastUpdaterFullName = currentResource.getLastUpdaterFullName();
+ String updatedLastUpdaterFullName = updateInfoResource.getLastUpdaterFullName();
- String currentUuid = currentResource.getUUID();
- String updatedUuid = updateInfoResource.getUUID();
+ if ((updatedLastUpdaterFullName != null) && (!updatedLastUpdaterFullName.equals(currentLastUpdaterFullName))) {
+ log.debug("Resource LastUpdater fullname is automatically set and cannot be updated");
+ }
+ Long currentCreationDate = currentResource.getCreationDate();
+ Long updatedCreationDate = updateInfoResource.getCreationDate();
- if ((updatedUuid != null) && (!updatedUuid.equals(currentUuid))) {
- log.debug("Resource UUID is automatically set and cannot be updated");
- }
+ if ((updatedCreationDate != null) && (!updatedCreationDate.equals(currentCreationDate))) {
+ log.debug("Resource Creation date is automatically set and cannot be updated");
+ }
- ResourceTypeEnum currentResourceType = currentResource.getResourceType();
- ResourceTypeEnum updatedResourceType = updateInfoResource.getResourceType();
+ Long currentLastUpdateDate = currentResource.getLastUpdateDate();
+ Long updatedLastUpdateDate = updateInfoResource.getLastUpdateDate();
- if ((updatedResourceType != null) && (!updatedResourceType.equals(currentResourceType))) {
- log.debug("Resource Type cannot be updated");
+ if ((updatedLastUpdateDate != null) && (!updatedLastUpdateDate.equals(currentLastUpdateDate))) {
+ log.debug("Resource last update date is automatically set and cannot be updated");
+ }
- }
- updateInfoResource.setResourceType(currentResource.getResourceType());
+ LifecycleStateEnum currentLifecycleState = currentResource.getLifecycleState();
+ LifecycleStateEnum updatedLifecycleState = updateInfoResource.getLifecycleState();
- String currentInvariantUuid = currentResource.getInvariantUUID();
- String updatedInvariantUuid = updateInfoResource.getInvariantUUID();
+ if ((updatedLifecycleState != null) && (!updatedLifecycleState.equals(currentLifecycleState))) {
+ log.debug("Resource lifecycle state date is automatically set and cannot be updated");
+ }
- if ((updatedInvariantUuid != null) && (!updatedInvariantUuid.equals(currentInvariantUuid))) {
- log.debug("Resource invariant UUID is automatically set and cannot be updated");
- updateInfoResource.setInvariantUUID(currentInvariantUuid);
- }
- }
+ Boolean currentAbstract = currentResource.isAbstract();
+ Boolean updatedAbstract = updateInfoResource.isAbstract();
- private void validateFields(Resource currentResource, Resource updateInfoResource, boolean inTransaction, boolean isNested) {
- boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentResource.getVersion());
- log.debug("validate resource name before update");
- validateResourceName(currentResource, updateInfoResource, hasBeenCertified, isNested);
- log.debug("validate description before update");
- validateDescriptionAndCleanup(null, updateInfoResource, null);
- log.debug("validate icon before update");
- validateIcon(currentResource, updateInfoResource, hasBeenCertified);
- log.debug("validate tags before update");
- validateTagsListAndRemoveDuplicates(null, updateInfoResource, null);
- log.debug("validate vendor name before update");
- validateVendorName(null, updateInfoResource, null);
- log.debug("validate resource vendor model number before update");
- validateResourceVendorModelNumber(currentResource, updateInfoResource);
- log.debug("validate vendor release before update");
- validateVendorReleaseName(null, updateInfoResource, null);
- log.debug("validate contact info before update");
- validateContactId(null, updateInfoResource, null);
- log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
- validateDerivedFromDuringUpdate(currentResource, updateInfoResource, hasBeenCertified);
- log.debug("validate category before update");
- validateCategory(currentResource, updateInfoResource, hasBeenCertified, inTransaction);
- }
+ if ((updatedAbstract != null) && (!updatedAbstract.equals(currentAbstract))) {
+ log.debug("Resource abstract is automatically set and cannot be updated");
+ }
+ Boolean currentHighestVersion = currentResource.isHighestVersion();
+ Boolean updatedHighestVersion = updateInfoResource.isHighestVersion();
- private boolean isResourceNameEquals(Resource currentResource, Resource updateInfoResource) {
- String resourceNameUpdated = updateInfoResource.getName();
- String resourceNameCurrent = currentResource.getName();
- if (resourceNameCurrent.equals(resourceNameUpdated)) {
- return true;
- }
- // In case of CVFC type we should support the case of old VF with CVFC
- // instances that were created without the "Cvfc" suffix
- return currentResource.getResourceType().equals(ResourceTypeEnum.CVFC) &&
- resourceNameUpdated.equals(addCvfcSuffixToResourceName(resourceNameCurrent));
- }
+ if ((updatedHighestVersion != null) && (!updatedHighestVersion.equals(currentHighestVersion))) {
+ log.debug("Resource highest version is automatically set and cannot be updated");
+ }
- private String addCvfcSuffixToResourceName(String resourceName) {
- return resourceName + "Cvfc";
- }
+ String currentUuid = currentResource.getUUID();
+ String updatedUuid = updateInfoResource.getUUID();
- private void validateResourceName(Resource currentResource, Resource updateInfoResource,
- boolean hasBeenCertified, boolean isNested) {
- String resourceNameUpdated = updateInfoResource.getName();
- if (!isResourceNameEquals(currentResource, updateInfoResource)) {
- if (isNested || !hasBeenCertified) {
- validateComponentName(null, updateInfoResource, null);
- validateResourceNameUniqueness(updateInfoResource);
- currentResource.setName(resourceNameUpdated);
- currentResource.setNormalizedName(ValidationUtils.normaliseComponentName(resourceNameUpdated));
- currentResource.setSystemName(ValidationUtils.convertToSystemName(resourceNameUpdated));
+ if ((updatedUuid != null) && (!updatedUuid.equals(currentUuid))) {
+ log.debug("Resource UUID is automatically set and cannot be updated");
+ }
- } else {
- log.info("Resource name: {}, cannot be updated once the resource has been certified once.",
- resourceNameUpdated);
- throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
- }
- }
- }
+ log.debug("Resource Type cannot be updated");
+ String currentInvariantUuid = currentResource.getInvariantUUID();
+ String updatedInvariantUuid = updateInfoResource.getInvariantUUID();
- private void validateIcon(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
- String iconUpdated = updateInfoResource.getIcon();
- String iconCurrent = currentResource.getIcon();
- if (!iconCurrent.equals(iconUpdated)) {
- if (!hasBeenCertified) {
- validateIcon(null, updateInfoResource, null);
- } else {
- log.info("Icon {} cannot be updated once the resource has been certified once.", iconUpdated);
- throw new ByActionStatusComponentException(ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
- }
- }
- }
+ if ((updatedInvariantUuid != null) && (!updatedInvariantUuid.equals(currentInvariantUuid))) {
+ log.debug("Resource invariant UUID is automatically set and cannot be updated");
+ updateInfoResource.setInvariantUUID(currentInvariantUuid);
+ }
+ }
- private void validateResourceVendorModelNumber(Resource currentResource, Resource updateInfoResource) {
- String updatedResourceVendorModelNumber = updateInfoResource.getResourceVendorModelNumber();
- String currentResourceVendorModelNumber = currentResource.getResourceVendorModelNumber();
- if (!currentResourceVendorModelNumber.equals(updatedResourceVendorModelNumber)) {
- validateResourceVendorModelNumber(null, updateInfoResource, null);
- }
- }
+ private void validateFields(Resource currentResource, Resource updateInfoResource, boolean inTransaction,
+ boolean isNested) {
+ boolean hasBeenCertified = ValidationUtils.hasBeenCertified(currentResource.getVersion());
+ log.debug("validate resource name before update");
+ validateResourceName(currentResource, updateInfoResource, hasBeenCertified, isNested);
+ log.debug("validate description before update");
+ componentDescriptionValidator.validateAndCorrectField(null, updateInfoResource, null);
+ log.debug("validate icon before update");
+ validateIcon(currentResource, updateInfoResource, hasBeenCertified);
+ log.debug("validate tags before update");
+ componentTagsValidator.validateAndCorrectField(null, updateInfoResource, null);
+ log.debug("validate vendor name before update");
+ validateVendorName(null, updateInfoResource, null);
+ log.debug("validate resource vendor model number before update");
+ validateResourceVendorModelNumber(currentResource, updateInfoResource);
+ log.debug("validate vendor release before update");
+ validateVendorReleaseName(null, updateInfoResource, null);
+ log.debug("validate contact info before update");
+ componentContactIdValidator.validateAndCorrectField(null, updateInfoResource, null);
+ log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
+ validateDerivedFromDuringUpdate(currentResource, updateInfoResource, hasBeenCertified);
+ log.debug("validate category before update");
+ validateCategory(currentResource, updateInfoResource, hasBeenCertified, inTransaction);
+ }
- private Either<Boolean, ResponseFormat> validateCategory(Resource currentResource, Resource updateInfoResource,
- boolean hasBeenCertified, boolean inTransaction) {
- validateCategory(null, updateInfoResource, null, inTransaction);
- if (hasBeenCertified) {
- CategoryDefinition currentCategory = currentResource.getCategories().get(0);
- SubCategoryDefinition currentSubCategory = currentCategory.getSubcategories().get(0);
- CategoryDefinition updateCategory = updateInfoResource.getCategories().get(0);
- SubCategoryDefinition updtaeSubCategory = updateCategory.getSubcategories().get(0);
- if (!currentCategory.getName().equals(updateCategory.getName())
- || !currentSubCategory.getName().equals(updtaeSubCategory.getName())) {
- log.info("Category {} cannot be updated once the resource has been certified once.",
- currentResource.getCategories());
- ResponseFormat errorResponse = componentsUtils
- .getResponseFormat(ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
- return Either.right(errorResponse);
- }
- }
- return Either.left(true);
- }
+ private boolean isResourceNameEquals(Resource currentResource, Resource updateInfoResource) {
+ String resourceNameUpdated = updateInfoResource.getName();
+ String resourceNameCurrent = currentResource.getName();
+ if (resourceNameCurrent.equals(resourceNameUpdated)) {
+ return true;
+ }
+ // In case of CVFC type we should support the case of old VF with CVFC
+ // instances that were created without the "Cvfc" suffix
+ return currentResource.getResourceType() == ResourceTypeEnum.CVFC
+ && resourceNameUpdated.equals(addCvfcSuffixToResourceName(resourceNameCurrent));
+ }
- private Either<Boolean, ResponseFormat> validateDerivedFromDuringUpdate(Resource currentResource,
- Resource updateInfoResource, boolean hasBeenCertified) {
+ private String addCvfcSuffixToResourceName(String resourceName) {
+ return resourceName + "Cvfc";
+ }
- List<String> currentDerivedFrom = currentResource.getDerivedFrom();
- List<String> updatedDerivedFrom = updateInfoResource.getDerivedFrom();
- if (currentDerivedFrom == null || currentDerivedFrom.isEmpty() || updatedDerivedFrom == null
- || updatedDerivedFrom.isEmpty()) {
- log.trace("Update normative types");
- return Either.left(true);
- }
+ private void validateResourceName(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified,
+ boolean isNested) {
+ String resourceNameUpdated = updateInfoResource.getName();
+ if (!isResourceNameEquals(currentResource, updateInfoResource)) {
+ if (isNested || !hasBeenCertified) {
+ componentNameValidator.validateAndCorrectField(null, updateInfoResource, null);
+ validateResourceNameUniqueness(updateInfoResource);
+ currentResource.setName(resourceNameUpdated);
+ currentResource.setNormalizedName(ValidationUtils.normaliseComponentName(resourceNameUpdated));
+ currentResource.setSystemName(ValidationUtils.convertToSystemName(resourceNameUpdated));
+
+ } else {
+ log.info("Resource name: {}, cannot be updated once the resource has been certified once.",
+ resourceNameUpdated);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
+ }
+ }
+ }
- String derivedFromCurrent = currentDerivedFrom.get(0);
- String derivedFromUpdated = updatedDerivedFrom.get(0);
+ private void validateIcon(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
+ String iconUpdated = updateInfoResource.getIcon();
+ String iconCurrent = currentResource.getIcon();
+ if (!iconCurrent.equals(iconUpdated)) {
+ if (!hasBeenCertified) {
+ componentIconValidator.validateAndCorrectField(null, updateInfoResource, null);
+ } else {
+ log.info("Icon {} cannot be updated once the resource has been certified once.", iconUpdated);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
+ }
+ }
+ }
- if (!derivedFromCurrent.equals(derivedFromUpdated)) {
- if (!hasBeenCertified) {
- validateDerivedFromExist(null, updateInfoResource, null);
- } else {
- Either<Boolean, ResponseFormat> validateDerivedFromExtending = validateDerivedFromExtending(null,
- currentResource, updateInfoResource, null);
+ private void validateResourceVendorModelNumber(Resource currentResource, Resource updateInfoResource) {
+ String updatedResourceVendorModelNumber = updateInfoResource.getResourceVendorModelNumber();
+ String currentResourceVendorModelNumber = currentResource.getResourceVendorModelNumber();
+ if (!currentResourceVendorModelNumber.equals(updatedResourceVendorModelNumber)) {
+ validateResourceVendorModelNumber(null, updateInfoResource, null);
+ }
+ }
- if (validateDerivedFromExtending.isRight() || !validateDerivedFromExtending.left().value()) {
- log.debug("Derived from cannot be updated if it doesnt inherits directly or extends inheritance");
- return validateDerivedFromExtending;
- }
- }
- } else {
- // For derived from, we must know whether it was actually changed,
- // otherwise we must do no action.
- // Due to changes it inflicts on data model (remove artifacts,
- // properties...), it's not like a flat field which can be
- // overwritten if not changed.
- // So we must indicate that derived from is not changed
- updateInfoResource.setDerivedFrom(null);
- }
- return Either.left(true);
- }
+ private Either<Boolean, ResponseFormat> validateCategory(Resource currentResource, Resource updateInfoResource,
+ boolean hasBeenCertified, boolean inTransaction) {
+ validateCategory(null, updateInfoResource, null, inTransaction);
+ if (hasBeenCertified) {
+ CategoryDefinition currentCategory = currentResource.getCategories()
+ .get(0);
+ SubCategoryDefinition currentSubCategory = currentCategory.getSubcategories()
+ .get(0);
+ CategoryDefinition updateCategory = updateInfoResource.getCategories()
+ .get(0);
+ SubCategoryDefinition updtaeSubCategory = updateCategory.getSubcategories()
+ .get(0);
+ if (!currentCategory.getName()
+ .equals(updateCategory.getName())
+ || !currentSubCategory.getName()
+ .equals(updtaeSubCategory.getName())) {
+ log.info("Category {} cannot be updated once the resource has been certified once.",
+ currentResource.getCategories());
+ ResponseFormat errorResponse = componentsUtils
+ .getResponseFormat(ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
+ }
+ return Either.left(true);
+ }
- private Either<Boolean, ResponseFormat> validateNestedDerivedFromDuringUpdate(Resource currentResource,
- Resource updateInfoResource, boolean hasBeenCertified) {
+ private Either<Boolean, ResponseFormat> validateDerivedFromDuringUpdate(Resource currentResource,
+ Resource updateInfoResource, boolean hasBeenCertified) {
- List<String> currentDerivedFrom = currentResource.getDerivedFrom();
- List<String> updatedDerivedFrom = updateInfoResource.getDerivedFrom();
- if (currentDerivedFrom == null || currentDerivedFrom.isEmpty() || updatedDerivedFrom == null
- || updatedDerivedFrom.isEmpty()) {
- log.trace("Update normative types");
- return Either.left(true);
- }
+ List<String> currentDerivedFrom = currentResource.getDerivedFrom();
+ List<String> updatedDerivedFrom = updateInfoResource.getDerivedFrom();
+ if (currentDerivedFrom == null || currentDerivedFrom.isEmpty() || updatedDerivedFrom == null
+ || updatedDerivedFrom.isEmpty()) {
+ log.trace("Update normative types");
+ return Either.left(true);
+ }
- String derivedFromCurrent = currentDerivedFrom.get(0);
- String derivedFromUpdated = updatedDerivedFrom.get(0);
+ String derivedFromCurrent = currentDerivedFrom.get(0);
+ String derivedFromUpdated = updatedDerivedFrom.get(0);
+
+ if (!derivedFromCurrent.equals(derivedFromUpdated)) {
+ if (!hasBeenCertified) {
+ validateDerivedFromExist(null, updateInfoResource, null);
+ } else {
+ Either<Boolean, ResponseFormat> validateDerivedFromExtending = validateDerivedFromExtending(null,
+ currentResource, updateInfoResource, null);
+
+ if (validateDerivedFromExtending.isRight() || !validateDerivedFromExtending.left()
+ .value()) {
+ log.debug("Derived from cannot be updated if it doesnt inherits directly or extends inheritance");
+ return validateDerivedFromExtending;
+ }
+ }
+ } else {
+ // For derived from, we must know whether it was actually changed,
+ // otherwise we must do no action.
+ // Due to changes it inflicts on data model (remove artifacts,
+ // properties...), it's not like a flat field which can be
+ // overwritten if not changed.
+ // So we must indicate that derived from is not changed
+ updateInfoResource.setDerivedFrom(null);
+ }
+ return Either.left(true);
+ }
- if (!derivedFromCurrent.equals(derivedFromUpdated)) {
- if (!hasBeenCertified) {
- validateDerivedFromExist(null, updateInfoResource, null);
- } else {
- Either<Boolean, ResponseFormat> validateDerivedFromExtending = validateDerivedFromExtending(null,
- currentResource, updateInfoResource, null);
+ private Either<Boolean, ResponseFormat> validateNestedDerivedFromDuringUpdate(Resource currentResource,
+ Resource updateInfoResource, boolean hasBeenCertified) {
- if (validateDerivedFromExtending.isRight() || !validateDerivedFromExtending.left().value()) {
- log.debug("Derived from cannot be updated if it doesnt inherits directly or extends inheritance");
- return validateDerivedFromExtending;
- }
- }
- }
- return Either.left(true);
- }
-
- private void validateDerivedFromExist(User user, Resource resource, AuditingActionEnum actionEnum) {
- if (resource.getDerivedFrom() == null || resource.getDerivedFrom().isEmpty()) {
- return;
- }
- String templateName = resource.getDerivedFrom().get(0);
- Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
- .validateToscaResourceNameExists(templateName);
- if (dataModelResponse.isRight()) {
- StorageOperationStatus storageStatus = dataModelResponse.right().value();
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Create Resource - validateDerivedFromExist");
- log.debug("request to data model failed with error: {}", storageStatus);
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus), resource);
- log.trace("audit before sending response");
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageStatus));
- } else if (!dataModelResponse.left().value()) {
- log.info("resource template with name: {}, does not exists", templateName);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ByActionStatusComponentException(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
- }
- }
+ List<String> currentDerivedFrom = currentResource.getDerivedFrom();
+ List<String> updatedDerivedFrom = updateInfoResource.getDerivedFrom();
+ if (currentDerivedFrom == null || currentDerivedFrom.isEmpty() || updatedDerivedFrom == null
+ || updatedDerivedFrom.isEmpty()) {
+ log.trace("Update normative types");
+ return Either.left(true);
+ }
- // Tal G for extending inheritance US815447
- private Either<Boolean, ResponseFormat> validateDerivedFromExtending(User user, Resource currentResource,
- Resource updateInfoResource, AuditingActionEnum actionEnum) {
- String currentTemplateName = currentResource.getDerivedFrom().get(0);
- String updatedTemplateName = updateInfoResource.getDerivedFrom().get(0);
-
- Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
- .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName);
- if (dataModelResponse.isRight()) {
- StorageOperationStatus storageStatus = dataModelResponse.right().value();
- BeEcompErrorManager.getInstance()
- .logBeDaoSystemError("Create/Update Resource - validateDerivingFromExtendingType");
- ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(storageStatus), currentResource);
- log.trace("audit before sending response");
- componentsUtils.auditResource(responseFormat, user, currentResource, actionEnum);
- return Either.right(responseFormat);
- }
+ String derivedFromCurrent = currentDerivedFrom.get(0);
+ String derivedFromUpdated = updatedDerivedFrom.get(0);
+
+ if (!derivedFromCurrent.equals(derivedFromUpdated)) {
+ if (!hasBeenCertified) {
+ validateDerivedFromExist(null, updateInfoResource, null);
+ } else {
+ Either<Boolean, ResponseFormat> validateDerivedFromExtending = validateDerivedFromExtending(null,
+ currentResource, updateInfoResource, null);
+
+ if (validateDerivedFromExtending.isRight() || !validateDerivedFromExtending.left()
+ .value()) {
+ log.debug("Derived from cannot be updated if it doesnt inherits directly or extends inheritance");
+ return validateDerivedFromExtending;
+ }
+ }
+ }
+ return Either.left(true);
+ }
- if (!dataModelResponse.left().value()) {
- log.info("resource template with name {} does not inherit as original {}", updatedTemplateName,
- currentTemplateName);
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
- componentsUtils.auditResource(responseFormat, user, currentResource, actionEnum);
+ private void validateDerivedFromExist(User user, Resource resource, AuditingActionEnum actionEnum) {
+ if (resource.getDerivedFrom() == null || resource.getDerivedFrom()
+ .isEmpty()) {
+ return;
+ }
+ String templateName = resource.getDerivedFrom()
+ .get(0);
+ Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
+ .validateToscaResourceNameExists(templateName);
+ if (dataModelResponse.isRight()) {
+ StorageOperationStatus storageStatus = dataModelResponse.right()
+ .value();
+ BeEcompErrorManager.getInstance()
+ .logBeDaoSystemError("Create Resource - validateDerivedFromExist");
+ log.debug("request to data model failed with error: {}", storageStatus);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus), resource);
+ log.trace("audit before sending response");
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageStatus));
+ } else if (!dataModelResponse.left()
+ .value()) {
+ log.info("resource template with name: {}, does not exists", templateName);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ }
+ }
- return Either.right(responseFormat);
+ // Tal G for extending inheritance US815447
+ private Either<Boolean, ResponseFormat> validateDerivedFromExtending(User user, Resource currentResource,
+ Resource updateInfoResource, AuditingActionEnum actionEnum) {
+ String currentTemplateName = currentResource.getDerivedFrom()
+ .get(0);
+ String updatedTemplateName = updateInfoResource.getDerivedFrom()
+ .get(0);
+
+ Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade
+ .validateToscaResourceNameExtends(currentTemplateName, updatedTemplateName);
+ if (dataModelResponse.isRight()) {
+ StorageOperationStatus storageStatus = dataModelResponse.right()
+ .value();
+ BeEcompErrorManager.getInstance()
+ .logBeDaoSystemError("Create/Update Resource - validateDerivingFromExtendingType");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
+ componentsUtils.convertFromStorageResponse(storageStatus), currentResource);
+ log.trace("audit before sending response");
+ componentsUtils.auditResource(responseFormat, user, currentResource, actionEnum);
+ return Either.right(responseFormat);
+ }
- }
- return Either.left(true);
- }
+ if (!dataModelResponse.left()
+ .value()) {
+ log.info("resource template with name {} does not inherit as original {}", updatedTemplateName,
+ currentTemplateName);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
+ componentsUtils.auditResource(responseFormat, user, currentResource, actionEnum);
- public void validateDerivedFromNotEmpty(User user, Resource resource, AuditingActionEnum actionEnum) {
- log.debug("validate resource derivedFrom field");
- if ((resource.getDerivedFrom() == null) || (resource.getDerivedFrom().isEmpty())
- || (resource.getDerivedFrom().get(0)) == null || (resource.getDerivedFrom().get(0).trim().isEmpty())) {
- log.info("derived from (template) field is missing for the resource");
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ return Either.right(responseFormat);
- throw new ByActionStatusComponentException(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
- }
- }
+ }
+ return Either.left(true);
+ }
- private void validateResourceNameUniqueness(Resource resource) {
-
- Either<Boolean, StorageOperationStatus> resourceOperationResponse = toscaOperationFacade
- .validateComponentNameExists(resource.getName(), resource.getResourceType(),
- resource.getComponentType());
- if (resourceOperationResponse.isLeft() && resourceOperationResponse.left().value()) {
- log.debug("resource with name: {}, already exists", resource.getName());
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
- resource.getName());
- } else if(resourceOperationResponse.isRight()){
- log.debug("error while validateResourceNameExists for resource: {}", resource.getName());
- throw new StorageException(resourceOperationResponse.right().value());
- }
- }
+ public void validateDerivedFromNotEmpty(User user, Resource resource, AuditingActionEnum actionEnum) {
+ log.debug("validate resource derivedFrom field");
+ if ((resource.getDerivedFrom() == null) || (resource.getDerivedFrom()
+ .isEmpty())
+ || (resource.getDerivedFrom()
+ .get(0)) == null
+ || (resource.getDerivedFrom()
+ .get(0)
+ .trim()
+ .isEmpty())) {
+ log.info("derived from (template) field is missing for the resource");
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ }
+ }
+ private void validateResourceNameUniqueness(Resource resource) {
+
+ Either<Boolean, StorageOperationStatus> resourceOperationResponse = toscaOperationFacade
+ .validateComponentNameExists(resource.getName(), resource.getResourceType(),
+ resource.getComponentType());
+ if (resourceOperationResponse.isLeft() && resourceOperationResponse.left()
+ .value()) {
+ log.debug("resource with name: {}, already exists", resource.getName());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
+ ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
+ } else if (resourceOperationResponse.isRight()) {
+ log.debug("error while validateResourceNameExists for resource: {}", resource.getName());
+ throw new StorageException(resourceOperationResponse.right()
+ .value());
+ }
+ }
- private void validateCategory(User user, Resource resource,
- AuditingActionEnum actionEnum, boolean inTransaction) {
+ private void validateCategory(User user, Resource resource, AuditingActionEnum actionEnum, boolean inTransaction) {
- List<CategoryDefinition> categories = resource.getCategories();
- if (CollectionUtils.isEmpty(categories)) {
- log.debug(CATEGORY_IS_EMPTY);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY,
- ComponentTypeEnum.RESOURCE.getValue());
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
- ComponentTypeEnum.RESOURCE.getValue());
- }
- if (categories.size() > 1) {
- log.debug("Must be only one category for resource");
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.RESOURCE.getValue());
- }
- CategoryDefinition category = categories.get(0);
- List<SubCategoryDefinition> subcategories = category.getSubcategories();
- if (CollectionUtils.isEmpty(subcategories)) {
- log.debug("Missinig subcategory for resource");
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
- }
- if (subcategories.size() > 1) {
- log.debug("Must be only one sub category for resource");
- throw new ByActionStatusComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
- }
+ List<CategoryDefinition> categories = resource.getCategories();
+ if (CollectionUtils.isEmpty(categories)) {
+ log.debug(CATEGORY_IS_EMPTY);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY,
+ ComponentTypeEnum.RESOURCE.getValue());
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
+ ComponentTypeEnum.RESOURCE.getValue());
+ }
+ if (categories.size() > 1) {
+ log.debug("Must be only one category for resource");
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES,
+ ComponentTypeEnum.RESOURCE.getValue());
+ }
+ CategoryDefinition category = categories.get(0);
+ List<SubCategoryDefinition> subcategories = category.getSubcategories();
+ if (CollectionUtils.isEmpty(subcategories)) {
+ log.debug("Missinig subcategory for resource");
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
+ }
+ if (subcategories.size() > 1) {
+ log.debug("Must be only one sub category for resource");
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
+ }
- SubCategoryDefinition subcategory = subcategories.get(0);
+ SubCategoryDefinition subcategory = subcategories.get(0);
- if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
- log.debug(CATEGORY_IS_EMPTY);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY,
- ComponentTypeEnum.RESOURCE.getValue());
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
- ComponentTypeEnum.RESOURCE.getValue());
- }
- if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) {
- log.debug(CATEGORY_IS_EMPTY);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(
- ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
- }
+ if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+ log.debug(CATEGORY_IS_EMPTY);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY,
+ ComponentTypeEnum.RESOURCE.getValue());
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
+ ComponentTypeEnum.RESOURCE.getValue());
+ }
+ if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) {
+ log.debug(CATEGORY_IS_EMPTY);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(
+ ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY,
+ ComponentTypeEnum.RESOURCE.getValue());
+ }
- validateCategoryListed(category, subcategory, user, resource, actionEnum, inTransaction);
- }
+ validateCategoryListed(category, subcategory, user, resource, actionEnum, inTransaction);
+ }
- private void validateCategoryListed(CategoryDefinition category, SubCategoryDefinition subcategory,
- User user, Resource resource, AuditingActionEnum actionEnum, boolean inTransaction) {
- ResponseFormat responseFormat;
- if (category != null && subcategory != null) {
- log.debug("validating resource category {} against valid categories list", category);
- Either<List<CategoryDefinition>, ActionStatus> categories = elementDao
- .getAllCategories(NodeTypeEnum.ResourceNewCategory, inTransaction);
- if (categories.isRight()) {
- log.debug("failed to retrieve resource categories from JanusGraph");
- responseFormat = componentsUtils.getResponseFormat(categories.right().value());
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ByActionStatusComponentException(categories.right().value());
- }
- List<CategoryDefinition> categoryList = categories.left().value();
- Optional<CategoryDefinition> foundCategory = categoryList.stream()
- .filter(cat -> cat.getName().equals(category.getName()))
- .findFirst();
- if(!foundCategory.isPresent()){
- log.debug("Category {} is not part of resource category group. Resource category valid values are {}",
- category, categoryList);
- failOnInvalidCategory(user, resource, actionEnum);
- }
- Optional<SubCategoryDefinition> foundSubcategory = foundCategory.get()
- .getSubcategories()
- .stream()
- .filter(subcat -> subcat.getName().equals(subcategory.getName()))
- .findFirst();
- if(!foundSubcategory.isPresent()){
- log.debug("SubCategory {} is not part of resource category group. Resource subcategory valid values are {}",
- subcategory, foundCategory.get().getSubcategories());
- failOnInvalidCategory(user, resource, actionEnum);
- }
- }
- }
+ private void validateCategoryListed(CategoryDefinition category, SubCategoryDefinition subcategory, User user,
+ Resource resource, AuditingActionEnum actionEnum, boolean inTransaction) {
+ ResponseFormat responseFormat;
+ if (category != null && subcategory != null) {
+ log.debug("validating resource category {} against valid categories list", category);
+ Either<List<CategoryDefinition>, ActionStatus> categories = elementDao
+ .getAllCategories(NodeTypeEnum.ResourceNewCategory, inTransaction);
+ if (categories.isRight()) {
+ log.debug("failed to retrieve resource categories from JanusGraph");
+ responseFormat = componentsUtils.getResponseFormat(categories.right()
+ .value());
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(categories.right()
+ .value());
+ }
+ List<CategoryDefinition> categoryList = categories.left()
+ .value();
+ Optional<CategoryDefinition> foundCategory = categoryList.stream()
+ .filter(cat -> cat.getName()
+ .equals(category.getName()))
+ .findFirst();
+ if (!foundCategory.isPresent()) {
+ log.debug("Category {} is not part of resource category group. Resource category valid values are {}",
+ category, categoryList);
+ failOnInvalidCategory(user, resource, actionEnum);
+ }
+ Optional<SubCategoryDefinition> foundSubcategory = foundCategory.get()
+ .getSubcategories()
+ .stream()
+ .filter(subcat -> subcat.getName()
+ .equals(subcategory.getName()))
+ .findFirst();
+ if (!foundSubcategory.isPresent()) {
+ log.debug(
+ "SubCategory {} is not part of resource category group. Resource subcategory valid values are {}",
+ subcategory, foundCategory.get()
+ .getSubcategories());
+ failOnInvalidCategory(user, resource, actionEnum);
+ }
+ }
+ }
- private void failOnInvalidCategory(User user, Resource resource, AuditingActionEnum actionEnum) {
- ResponseFormat responseFormat;
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY,
- ComponentTypeEnum.RESOURCE.getValue());
- componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CATEGORY,
- ComponentTypeEnum.RESOURCE.getValue());
- }
+ private void failOnInvalidCategory(User user, Resource resource, AuditingActionEnum actionEnum) {
+ ResponseFormat responseFormat;
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY,
+ ComponentTypeEnum.RESOURCE.getValue());
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ }
- public void validateVendorReleaseName(User user, Resource resource, AuditingActionEnum actionEnum) {
- String vendorRelease = resource.getVendorRelease();
- log.debug("validate vendor relese name");
- if (!ValidationUtils.validateStringNotEmpty(vendorRelease)) {
- log.info("vendor relese name is missing.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE);
- componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ByActionStatusComponentException(ActionStatus.MISSING_VENDOR_RELEASE);
- }
+ public void validateVendorReleaseName(User user, Resource resource, AuditingActionEnum actionEnum) {
+ String vendorRelease = resource.getVendorRelease();
+ log.debug("validate vendor relese name");
+ if (!ValidationUtils.validateStringNotEmpty(vendorRelease)) {
+ log.info("vendor relese name is missing.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE);
+ componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_VENDOR_RELEASE);
+ }
- validateVendorReleaseName(vendorRelease, user, resource, actionEnum);
- }
+ validateVendorReleaseName(vendorRelease, user, resource, actionEnum);
+ }
- public void validateVendorReleaseName(String vendorRelease, User user, Resource resource, AuditingActionEnum actionEnum) {
- if (vendorRelease != null) {
- if (!ValidationUtils.validateVendorReleaseLength(vendorRelease)) {
- log.info("vendor release exceds limit.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(
- ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
- componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ByActionStatusComponentException(ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
- }
+ public void validateVendorReleaseName(String vendorRelease, User user, Resource resource,
+ AuditingActionEnum actionEnum) {
+ if (vendorRelease != null) {
+ if (!ValidationUtils.validateVendorReleaseLength(vendorRelease)) {
+ log.info("vendor release exceds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(
+ ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
+ componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
+ throw new ByActionStatusComponentException(ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT,
+ "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
+ }
- if (!ValidationUtils.validateVendorRelease(vendorRelease)) {
- log.info("vendor release is not valid.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_VENDOR_RELEASE);
- componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
+ if (!ValidationUtils.validateVendorRelease(vendorRelease)) {
+ log.info("vendor release is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_VENDOR_RELEASE);
+ componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
throw new ByActionStatusComponentException(ActionStatus.INVALID_VENDOR_RELEASE, vendorRelease);
}
}
@@ -4838,449 +5439,467 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
- private Either<Boolean, ResponseFormat> processUpdateOfDerivedFrom(Resource currentResource,
- Resource updatedResource, String userId, boolean inTransaction) {
- Either<Operation, ResponseFormat> deleteArtifactByInterface;
- if (updatedResource.getDerivedFrom() != null) {
- log.debug("Starting derived from update for resource {}", updatedResource.getUniqueId());
- log.debug("1. Removing interface artifacts from graph");
- // Remove all interface artifacts of resource
- String resourceId = updatedResource.getUniqueId();
- Map<String, InterfaceDefinition> interfaces = currentResource.getInterfaces();
-
- if (interfaces != null) {
- Collection<InterfaceDefinition> values = interfaces.values();
- for (InterfaceDefinition interfaceDefinition : values) {
- String interfaceType = interfaceTypeOperation.getShortInterfaceName(interfaceDefinition);
-
- log.trace("Starting interface artifacts removal for interface type {}", interfaceType);
- Map<String, Operation> operations = interfaceDefinition.getOperationsMap();
- if (operations != null) {
- for (Entry<String, Operation> operationEntry : operations.entrySet()) {
- Operation operation = operationEntry.getValue();
- ArtifactDefinition implementation = operation.getImplementationArtifact();
- if (implementation != null) {
- String uniqueId = implementation.getUniqueId();
- log.debug("Removing interface artifact definition {}, operation {}, interfaceType {}",
- uniqueId, operationEntry.getKey(), interfaceType);
- // only thing that transacts and locks here
- deleteArtifactByInterface = artifactsBusinessLogic.deleteArtifactByInterface(resourceId,
- userId, uniqueId,
- true);
- if (deleteArtifactByInterface.isRight()) {
- log.debug("Couldn't remove artifact definition with id {}", uniqueId);
- if (!inTransaction) {
+ private Either<Boolean, ResponseFormat> processUpdateOfDerivedFrom(Resource currentResource,
+ Resource updatedResource, String userId, boolean inTransaction) {
+ Either<Operation, ResponseFormat> deleteArtifactByInterface;
+ if (updatedResource.getDerivedFrom() != null) {
+ log.debug("Starting derived from update for resource {}", updatedResource.getUniqueId());
+ log.debug("1. Removing interface artifacts from graph");
+ // Remove all interface artifacts of resource
+ String resourceId = updatedResource.getUniqueId();
+ Map<String, InterfaceDefinition> interfaces = currentResource.getInterfaces();
+
+ if (interfaces != null) {
+ Collection<InterfaceDefinition> values = interfaces.values();
+ for (InterfaceDefinition interfaceDefinition : values) {
+ String interfaceType = interfaceTypeOperation.getShortInterfaceName(interfaceDefinition);
+
+ log.trace("Starting interface artifacts removal for interface type {}", interfaceType);
+ Map<String, Operation> operations = interfaceDefinition.getOperationsMap();
+ if (operations != null) {
+ for (Entry<String, Operation> operationEntry : operations.entrySet()) {
+ Operation operation = operationEntry.getValue();
+ ArtifactDefinition implementation = operation.getImplementationArtifact();
+ if (implementation != null) {
+ String uniqueId = implementation.getUniqueId();
+ log.debug("Removing interface artifact definition {}, operation {}, interfaceType {}",
+ uniqueId, operationEntry.getKey(), interfaceType);
+ // only thing that transacts and locks here
+ deleteArtifactByInterface = artifactsBusinessLogic.deleteArtifactByInterface(resourceId,
+ userId, uniqueId, true);
+ if (deleteArtifactByInterface.isRight()) {
+ log.debug("Couldn't remove artifact definition with id {}", uniqueId);
+ if (!inTransaction) {
janusGraphDao.rollback();
- }
- return Either.right(deleteArtifactByInterface.right().value());
- }
- } else {
- log.trace("No implementation found for operation {} - nothing to delete",
- operationEntry.getKey());
- }
- }
- } else {
- log.trace("No operations found for interface type {}", interfaceType);
- }
- }
- }
- log.debug("2. Removing properties");
- Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = propertyOperation
- .deleteAllPropertiesAssociatedToNode(NodeTypeEnum.Resource, resourceId);
-
- if (findPropertiesOfNode.isRight()
- && !findPropertiesOfNode.right().value().equals(StorageOperationStatus.OK)) {
- log.debug("Failed to remove all properties of resource");
- if (!inTransaction) {
+ }
+ return Either.right(deleteArtifactByInterface.right()
+ .value());
+ }
+ } else {
+ log.trace("No implementation found for operation {} - nothing to delete",
+ operationEntry.getKey());
+ }
+ }
+ } else {
+ log.trace("No operations found for interface type {}", interfaceType);
+ }
+ }
+ }
+ log.debug("2. Removing properties");
+ Either<Map<String, PropertyDefinition>, StorageOperationStatus> findPropertiesOfNode = propertyOperation
+ .deleteAllPropertiesAssociatedToNode(NodeTypeEnum.Resource, resourceId);
+
+ if (findPropertiesOfNode.isRight() && findPropertiesOfNode.right().value() != StorageOperationStatus.OK) {
+ log.debug("Failed to remove all properties of resource");
+ if (!inTransaction) {
janusGraphDao.rollback();
- }
- return Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(findPropertiesOfNode.right().value())));
- }
+ }
+ return Either.right(componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(findPropertiesOfNode.right()
+ .value())));
+ }
- } else {
- log.debug("Derived from wasn't changed during update");
- }
+ } else {
+ log.debug("Derived from wasn't changed during update");
+ }
- if (inTransaction) {
- return Either.left(true);
- }
+ if (inTransaction) {
+ return Either.left(true);
+ }
janusGraphDao.commit();
- return Either.left(true);
-
- }
+ return Either.left(true);
- /**** Auditing *******************/
-
- protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) {
- WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context
- .getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
-
- WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ }
- return webApplicationContext.getBean(class1);
- }
+ /**** Auditing *******************/
- public ICapabilityTypeOperation getCapabilityTypeOperation() {
- return capabilityTypeOperation;
- }
+ protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context
+ .getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
- @Autowired
- public void setCapabilityTypeOperation(ICapabilityTypeOperation capabilityTypeOperation) {
- this.capabilityTypeOperation = capabilityTypeOperation;
- }
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
- public Either<Boolean, ResponseFormat> validatePropertiesDefaultValues(Resource resource) {
- log.debug("validate resource properties default values");
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
- List<PropertyDefinition> properties = resource.getProperties();
- if (properties != null) {
- eitherResult = iterateOverProperties(properties);
- }
- return eitherResult;
- }
+ return webApplicationContext.getBean(class1);
+ }
- public Either<Boolean, ResponseFormat> iterateOverProperties(List<PropertyDefinition> properties){
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
- String type = null;
- String innerType = null;
- for (PropertyDefinition property : properties) {
- if (!propertyOperation.isPropertyTypeValid(property)) {
- log.info("Invalid type for property {}", property);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(
- ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
- eitherResult = Either.right(responseFormat);
- break;
- }
+ public ICapabilityTypeOperation getCapabilityTypeOperation() {
+ return capabilityTypeOperation;
+ }
- Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes = getAllDataTypes(
- applicationDataTypeCache);
- if (allDataTypes.isRight()) {
- return Either.right(allDataTypes.right().value());
- }
+ @Autowired
+ public void setCapabilityTypeOperation(ICapabilityTypeOperation capabilityTypeOperation) {
+ this.capabilityTypeOperation = capabilityTypeOperation;
+ }
- type = property.getType();
+ public Boolean validatePropertiesDefaultValues(Resource resource) {
+ log.debug("validate resource properties default values");
+ List<PropertyDefinition> properties = resource.getProperties();
+ if (properties != null) {
+ iterateOverProperties(properties);
+ }
+ return true;
+ }
- if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- ResponseFormat responseFormat = validateMapOrListPropertyType(property, innerType, allDataTypes.left().value());
- if(responseFormat != null) {
- break;
- }
- }
- eitherResult = validateDefaultPropertyValue(property, allDataTypes.left().value(), type, innerType);
- }
- return eitherResult;
- }
+ public void iterateOverProperties(List<PropertyDefinition> properties) {
+ String type = null;
+ String innerType = null;
+ for (PropertyDefinition property : properties) {
+ if (!propertyOperation.isPropertyTypeValid(property)) {
+ log.info("Invalid type for property {}", property);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_TYPE,
+ property.getType(), property.getName());
+ }
- private Either<Boolean,ResponseFormat> validateDefaultPropertyValue(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes, String type, String innerType) {
- if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes)) {
- log.info("Invalid default value for property {}", property);
- ResponseFormat responseFormat;
- if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE,
- property.getName(), type, innerType, property.getDefaultValue());
- } else {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE,
- property.getName(), type, property.getDefaultValue());
- }
- return Either.right(responseFormat);
+ Map<String, DataTypeDefinition> allDataTypes = getAllDataTypes(applicationDataTypeCache);
+ type = property.getType();
- }
- return Either.left(true);
- }
+ if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
+ ResponseFormat responseFormat = validateMapOrListPropertyType(property, innerType, allDataTypes);
+ if (responseFormat != null) {
+ break;
+ }
+ }
+ validateDefaultPropertyValue(property, allDataTypes, type, innerType);
+ }
+ }
- private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, String innerType, Map<String, DataTypeDefinition> allDataTypes) {
- ResponseFormat responseFormat = null;
- ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation
- .isPropertyInnerTypeValid(property, allDataTypes);
- innerType = propertyInnerTypeValid.getLeft();
- if (!propertyInnerTypeValid.getRight().booleanValue()) {
- log.info("Invalid inner type for property {}", property);
- responseFormat = componentsUtils.getResponseFormat(
- ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
- }
- return responseFormat;
- }
+ private void validateDefaultPropertyValue(PropertyDefinition property,
+ Map<String, DataTypeDefinition> allDataTypes, String type, String innerType) {
+ if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes)) {
+ log.info("Invalid default value for property {}", property);
+ ResponseFormat responseFormat;
+ if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE,
+ property.getName(), type, innerType, property.getDefaultValue());
+ }
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_DEFAULT_VALUE,
+ property.getName(), type, property.getDefaultValue());
+ }
+ }
- @Override
- public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
- return deleteMarkedComponents(ComponentTypeEnum.RESOURCE);
- }
+ private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, String innerType,
+ Map<String, DataTypeDefinition> allDataTypes) {
+ ResponseFormat responseFormat = null;
+ ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property,
+ allDataTypes);
+ innerType = propertyInnerTypeValid.getLeft();
+ if (!propertyInnerTypeValid.getRight()
+ .booleanValue()) {
+ log.info("Invalid inner type for property {}", property);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType,
+ property.getName());
+ }
+ return responseFormat;
+ }
- @Override
- public ComponentInstanceBusinessLogic getComponentInstanceBL() {
- return componentInstanceBusinessLogic;
- }
+ @Override
+ public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
+ return deleteMarkedComponents(ComponentTypeEnum.RESOURCE);
+ }
- private String getComponentTypeForResponse(Component component) {
- String componentTypeForResponse = "SERVICE";
- if (component instanceof Resource) {
- componentTypeForResponse = ((Resource) component).getResourceType().name();
- }
- return componentTypeForResponse;
- }
+ @Override
+ public ComponentInstanceBusinessLogic getComponentInstanceBL() {
+ return componentInstanceBusinessLogic;
+ }
- public Either<Resource, ResponseFormat> getLatestResourceFromCsarUuid(String csarUuid, User user) {
- // validate user
- if (user != null) {
- validateUserExists(user, "Get resource from csar UUID",
- false);
- }
- // get resource from csar uuid
- Either<Resource, StorageOperationStatus> either = toscaOperationFacade
- .getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, csarUuid, "");
- if (either.isRight()) {
- ResponseFormat resp = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_FROM_CSAR_NOT_FOUND,
- csarUuid);
- return Either.right(resp);
- }
+ private String getComponentTypeForResponse(Component component) {
+ String componentTypeForResponse = "SERVICE";
+ if (component instanceof Resource) {
+ componentTypeForResponse = ((Resource) component).getResourceType()
+ .name();
+ }
+ return componentTypeForResponse;
+ }
- return Either.left(either.left().value());
- }
+ public Either<Resource, ResponseFormat> getLatestResourceFromCsarUuid(String csarUuid, User user) {
+ // validate user
+ if (user != null) {
+ validateUserExists(user);
+ }
+ // get resource from csar uuid
+ Either<Resource, StorageOperationStatus> either = toscaOperationFacade
+ .getLatestComponentByCsarOrName(ComponentTypeEnum.RESOURCE, csarUuid, "");
+ if (either.isRight()) {
+ ResponseFormat resp = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_FROM_CSAR_NOT_FOUND,
+ csarUuid);
+ return Either.right(resp);
+ }
- @Override
- public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(
- String componentId, String userId) {
- return null;
- }
+ return Either.left(either.left()
+ .value());
+ }
- private Map<String, List<CapabilityDefinition>> getValidComponentInstanceCapabilities(
- String resourceId, Map<String, List<CapabilityDefinition>> defaultCapabilities,
- Map<String, List<UploadCapInfo>> uploadedCapabilities) {
+ @Override
+ public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(
+ String componentId, String userId) {
+ return null;
+ }
- Map<String, List<CapabilityDefinition>> validCapabilitiesMap = new HashMap<>();
- uploadedCapabilities.forEach((k,v)->addValidComponentInstanceCapabilities(k,v,resourceId,defaultCapabilities,validCapabilitiesMap));
- return validCapabilitiesMap;
- }
+ private Map<String, List<CapabilityDefinition>> getValidComponentInstanceCapabilities(String resourceId,
+ Map<String, List<CapabilityDefinition>> defaultCapabilities,
+ Map<String, List<UploadCapInfo>> uploadedCapabilities) {
- private void addValidComponentInstanceCapabilities(String key, List<UploadCapInfo> capabilities, String resourceId, Map<String, List<CapabilityDefinition>> defaultCapabilities, Map<String, List<CapabilityDefinition>> validCapabilitiesMap){
- String capabilityType = capabilities.get(0).getType();
- if (defaultCapabilities.containsKey(capabilityType)) {
- CapabilityDefinition defaultCapability = getCapability(resourceId, defaultCapabilities, capabilityType);
- validateCapabilityProperties(capabilities, resourceId, defaultCapability);
- List<CapabilityDefinition> validCapabilityList = new ArrayList<>();
- validCapabilityList.add(defaultCapability);
- validCapabilitiesMap.put(key, validCapabilityList);
- } else {
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, capabilityType));
- }
- }
+ Map<String, List<CapabilityDefinition>> validCapabilitiesMap = new HashMap<>();
+ uploadedCapabilities.forEach((k, v) -> addValidComponentInstanceCapabilities(k, v, resourceId,
+ defaultCapabilities, validCapabilitiesMap));
+ return validCapabilitiesMap;
+ }
- private void validateCapabilityProperties(List<UploadCapInfo> capabilities, String resourceId, CapabilityDefinition defaultCapability) {
- if (CollectionUtils.isEmpty(defaultCapability.getProperties())
- && isNotEmpty(capabilities.get(0).getProperties())) {
- log.debug("Failed to validate capability {} of component {}. Property list is empty. ",
- defaultCapability.getName(), resourceId);
- log.debug(
- "Failed to update capability property values. Property list of fetched capability {} is empty. ",
- defaultCapability.getName());
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, resourceId));
- } else if (isNotEmpty(capabilities.get(0).getProperties())) {
- validateUniquenessUpdateUploadedComponentInstanceCapability(defaultCapability, capabilities.get(0));
- }
- }
+ private void addValidComponentInstanceCapabilities(String key, List<UploadCapInfo> capabilities, String resourceId,
+ Map<String, List<CapabilityDefinition>> defaultCapabilities,
+ Map<String, List<CapabilityDefinition>> validCapabilitiesMap) {
+ String capabilityType = capabilities.get(0)
+ .getType();
+ if (defaultCapabilities.containsKey(capabilityType)) {
+ CapabilityDefinition defaultCapability = getCapability(resourceId, defaultCapabilities, capabilityType);
+ validateCapabilityProperties(capabilities, resourceId, defaultCapability);
+ List<CapabilityDefinition> validCapabilityList = new ArrayList<>();
+ validCapabilityList.add(defaultCapability);
+ validCapabilitiesMap.put(key, validCapabilityList);
+ } else {
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_CAPABILITY_TYPE, capabilityType);
+ }
+ }
- private CapabilityDefinition getCapability(String resourceId, Map<String, List<CapabilityDefinition>> defaultCapabilities, String capabilityType) {
- CapabilityDefinition defaultCapability;
- if (isNotEmpty(defaultCapabilities.get(capabilityType).get(0).getProperties())) {
- defaultCapability = defaultCapabilities.get(capabilityType).get(0);
- } else {
- Either<Component, StorageOperationStatus> getFullComponentRes = toscaOperationFacade
- .getToscaFullElement(resourceId);
- if (getFullComponentRes.isRight()) {
- log.debug("Failed to get full component {}. Status is {}. ", resourceId,
- getFullComponentRes.right().value());
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND,
- resourceId));
- }
- defaultCapability = getFullComponentRes.left().value().getCapabilities().get(capabilityType).get(0);
- }
- return defaultCapability;
- }
+ private void validateCapabilityProperties(List<UploadCapInfo> capabilities, String resourceId,
+ CapabilityDefinition defaultCapability) {
+ if (CollectionUtils.isEmpty(defaultCapability.getProperties()) && isNotEmpty(capabilities.get(0)
+ .getProperties())) {
+ log.debug("Failed to validate capability {} of component {}. Property list is empty. ",
+ defaultCapability.getName(), resourceId);
+ log.debug("Failed to update capability property values. Property list of fetched capability {} is empty. ",
+ defaultCapability.getName());
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, resourceId);
+ } else if (isNotEmpty(capabilities.get(0)
+ .getProperties())) {
+ validateUniquenessUpdateUploadedComponentInstanceCapability(defaultCapability, capabilities.get(0));
+ }
+ }
- private void validateUniquenessUpdateUploadedComponentInstanceCapability(
- CapabilityDefinition defaultCapability, UploadCapInfo uploadedCapability) {
- List<ComponentInstanceProperty> validProperties = new ArrayList<>();
- Map<String, PropertyDefinition> defaultProperties = defaultCapability.getProperties().stream()
- .collect(toMap(PropertyDefinition::getName, Function.identity()));
- List<UploadPropInfo> uploadedProperties = uploadedCapability.getProperties();
- for (UploadPropInfo property : uploadedProperties) {
- String propertyName = property.getName().toLowerCase();
- String propertyType = property.getType();
- ComponentInstanceProperty validProperty;
- if (defaultProperties.containsKey(propertyName) && propertTypeEqualsTo(defaultProperties, propertyName, propertyType)) {
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS,
- propertyName));
- }
- validProperty = new ComponentInstanceProperty();
- validProperty.setName(propertyName);
- if (property.getValue() != null) {
- validProperty.setValue(property.getValue().toString());
- }
- validProperty.setDescription(property.getDescription());
- validProperty.setPassword(property.isPassword());
- validProperties.add(validProperty);
- }
- defaultCapability.setProperties(validProperties);
- }
+ private CapabilityDefinition getCapability(String resourceId,
+ Map<String, List<CapabilityDefinition>> defaultCapabilities, String capabilityType) {
+ CapabilityDefinition defaultCapability;
+ if (isNotEmpty(defaultCapabilities.get(capabilityType)
+ .get(0)
+ .getProperties())) {
+ defaultCapability = defaultCapabilities.get(capabilityType)
+ .get(0);
+ } else {
+ Either<Component, StorageOperationStatus> getFullComponentRes = toscaOperationFacade
+ .getToscaFullElement(resourceId);
+ if (getFullComponentRes.isRight()) {
+ log.debug("Failed to get full component {}. Status is {}. ", resourceId, getFullComponentRes.right()
+ .value());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NOT_FOUND, resourceId);
+ }
+ defaultCapability = getFullComponentRes.left()
+ .value()
+ .getCapabilities()
+ .get(capabilityType)
+ .get(0);
+ }
+ return defaultCapability;
+ }
- private boolean propertTypeEqualsTo(Map<String, PropertyDefinition> defaultProperties, String propertyName, String propertyType) {
- return propertyType != null && !defaultProperties.get(propertyName).getType().equals(propertyType);
- }
+ private void validateUniquenessUpdateUploadedComponentInstanceCapability(CapabilityDefinition defaultCapability,
+ UploadCapInfo uploadedCapability) {
+ List<ComponentInstanceProperty> validProperties = new ArrayList<>();
+ Map<String, PropertyDefinition> defaultProperties = defaultCapability.getProperties()
+ .stream()
+ .collect(toMap(PropertyDefinition::getName, Function.identity()));
+ List<UploadPropInfo> uploadedProperties = uploadedCapability.getProperties();
+ for (UploadPropInfo property : uploadedProperties) {
+ String propertyName = property.getName()
+ .toLowerCase();
+ String propertyType = property.getType();
+ ComponentInstanceProperty validProperty;
+ if (defaultProperties.containsKey(propertyName)
+ && propertTypeEqualsTo(defaultProperties, propertyName, propertyType)) {
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS, propertyName);
+ }
+ validProperty = new ComponentInstanceProperty();
+ validProperty.setName(propertyName);
+ if (property.getValue() != null) {
+ validProperty.setValue(property.getValue()
+ .toString());
+ }
+ validProperty.setDescription(property.getDescription());
+ validProperty.setPassword(property.isPassword());
+ validProperties.add(validProperty);
+ }
+ defaultCapability.setProperties(validProperties);
+ }
- private Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> organizeVfCsarArtifactsByArtifactOperation(
- List<NonMetaArtifactInfo> artifactPathAndNameList, List<ArtifactDefinition> existingArtifactsToHandle,
- Resource resource, User user) {
+ private boolean propertTypeEqualsTo(Map<String, PropertyDefinition> defaultProperties, String propertyName,
+ String propertyType) {
+ return propertyType != null && !defaultProperties.get(propertyName)
+ .getType()
+ .equals(propertyType);
+ }
- EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> nodeTypeArtifactsToHandle = new EnumMap<>(
- ArtifactOperationEnum.class);
- Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
- Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> nodeTypeArtifactsToHandleRes = Either
- .left(nodeTypeArtifactsToHandle);
- try {
- // add all found Csar artifacts to list to upload
- List<NonMetaArtifactInfo> artifactsToUpload = new ArrayList<>(artifactPathAndNameList);
- List<NonMetaArtifactInfo> artifactsToUpdate = new ArrayList<>();
- List<NonMetaArtifactInfo> artifactsToDelete = new ArrayList<>();
- for (NonMetaArtifactInfo currNewArtifact : artifactPathAndNameList) {
- ArtifactDefinition foundArtifact;
-
- if (!existingArtifactsToHandle.isEmpty()) {
- foundArtifact = existingArtifactsToHandle.stream()
- .filter(a -> a.getArtifactName().equals(currNewArtifact.getArtifactName())).findFirst()
- .orElse(null);
- if (foundArtifact != null) {
- if (ArtifactTypeEnum.findType(foundArtifact.getArtifactType()) == currNewArtifact
- .getArtifactType()) {
- if (!foundArtifact.getArtifactChecksum().equals(currNewArtifact.getArtifactChecksum())) {
- currNewArtifact.setArtifactUniqueId(foundArtifact.getUniqueId());
- // if current artifact already exists, but has
- // different content, add him to the list to
- // update
- artifactsToUpdate.add(currNewArtifact);
- }
- // remove found artifact from the list of existing
- // artifacts to handle, because it was already
- // handled
- existingArtifactsToHandle.remove(foundArtifact);
- // and remove found artifact from the list to
- // upload, because it should either be updated or be
- // ignored
- artifactsToUpload.remove(currNewArtifact);
- } else {
- log.debug("Can't upload two artifact with the same name {}.",
- currNewArtifact.getArtifactName());
- ResponseFormat responseFormat = ResponseFormatManager.getInstance().getResponseFormat(
- ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR,
- currNewArtifact.getArtifactName(), currNewArtifact.getArtifactType().name(),
- foundArtifact.getArtifactType());
- AuditingActionEnum auditingAction = artifactsBusinessLogic
- .detectAuditingType(artifactsBusinessLogic.new ArtifactOperationInfo(false, false,
- ArtifactOperationEnum.CREATE), foundArtifact.getArtifactChecksum());
- artifactsBusinessLogic.handleAuditing(auditingAction, resource, resource.getUniqueId(),
- user, null, null, foundArtifact.getUniqueId(), responseFormat,
- resource.getComponentType(), null);
- responseWrapper.setInnerElement(responseFormat);
- break;
- }
- }
- }
- }
- if (responseWrapper.isEmpty()) {
- for (ArtifactDefinition currArtifact : existingArtifactsToHandle) {
- if (currArtifact.getIsFromCsar()) {
- artifactsToDelete.add(new NonMetaArtifactInfo(currArtifact.getArtifactName(), null, ArtifactTypeEnum.findType(currArtifact.getArtifactType()), currArtifact.getArtifactGroupType(), null, currArtifact.getUniqueId(), currArtifact.getIsFromCsar()));
- } else {
- artifactsToUpdate.add(new NonMetaArtifactInfo(currArtifact.getArtifactName(), null, ArtifactTypeEnum.findType(currArtifact.getArtifactType()), currArtifact.getArtifactGroupType(), null, currArtifact.getUniqueId(), currArtifact.getIsFromCsar()));
-
- }
- }
- }
- if (responseWrapper.isEmpty()) {
- if (!artifactsToUpload.isEmpty()) {
- nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.CREATE, artifactsToUpload);
- }
- if (!artifactsToUpdate.isEmpty()) {
- nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.UPDATE, artifactsToUpdate);
- }
- if (!artifactsToDelete.isEmpty()) {
- nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.DELETE, artifactsToDelete);
- }
- }
- if (!responseWrapper.isEmpty()) {
- nodeTypeArtifactsToHandleRes = Either.right(responseWrapper.getInnerElement());
- }
- } catch (Exception e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- responseWrapper.setInnerElement(responseFormat);
- log.debug("Exception occured when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage(), e);
- nodeTypeArtifactsToHandleRes = Either.right(responseWrapper.getInnerElement());
- }
- return nodeTypeArtifactsToHandleRes;
- }
+ private Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> organizeVfCsarArtifactsByArtifactOperation(
+ List<NonMetaArtifactInfo> artifactPathAndNameList, List<ArtifactDefinition> existingArtifactsToHandle,
+ Resource resource, User user) {
+
+ EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>> nodeTypeArtifactsToHandle = new EnumMap<>(
+ ArtifactOperationEnum.class);
+ Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
+ Either<EnumMap<ArtifactOperationEnum, List<NonMetaArtifactInfo>>, ResponseFormat> nodeTypeArtifactsToHandleRes = Either
+ .left(nodeTypeArtifactsToHandle);
+ try {
+ // add all found Csar artifacts to list to upload
+ List<NonMetaArtifactInfo> artifactsToUpload = new ArrayList<>(artifactPathAndNameList);
+ List<NonMetaArtifactInfo> artifactsToUpdate = new ArrayList<>();
+ List<NonMetaArtifactInfo> artifactsToDelete = new ArrayList<>();
+ for (NonMetaArtifactInfo currNewArtifact : artifactPathAndNameList) {
+ ArtifactDefinition foundArtifact;
+
+ if (!existingArtifactsToHandle.isEmpty()) {
+ foundArtifact = existingArtifactsToHandle.stream()
+ .filter(a -> a.getArtifactName()
+ .equals(currNewArtifact.getArtifactName()))
+ .findFirst()
+ .orElse(null);
+ if (foundArtifact != null) {
+ if (ArtifactTypeEnum.findType(foundArtifact.getArtifactType()) == currNewArtifact
+ .getArtifactType()) {
+ if (!foundArtifact.getArtifactChecksum()
+ .equals(currNewArtifact.getArtifactChecksum())) {
+ currNewArtifact.setArtifactUniqueId(foundArtifact.getUniqueId());
+ // if current artifact already exists, but has
+ // different content, add him to the list to
+ // update
+ artifactsToUpdate.add(currNewArtifact);
+ }
+ // remove found artifact from the list of existing
+ // artifacts to handle, because it was already
+ // handled
+ existingArtifactsToHandle.remove(foundArtifact);
+ // and remove found artifact from the list to
+ // upload, because it should either be updated or be
+ // ignored
+ artifactsToUpload.remove(currNewArtifact);
+ } else {
+ log.debug("Can't upload two artifact with the same name {}.",
+ currNewArtifact.getArtifactName());
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance()
+ .getResponseFormat(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR,
+ currNewArtifact.getArtifactName(), currNewArtifact.getArtifactType()
+ .name(),
+ foundArtifact.getArtifactType());
+ AuditingActionEnum auditingAction = artifactsBusinessLogic
+ .detectAuditingType(artifactsBusinessLogic.new ArtifactOperationInfo(false, false,
+ ArtifactOperationEnum.CREATE), foundArtifact.getArtifactChecksum());
+ artifactsBusinessLogic.handleAuditing(auditingAction, resource, resource.getUniqueId(),
+ user, null, null, foundArtifact.getUniqueId(), responseFormat,
+ resource.getComponentType(), null);
+ responseWrapper.setInnerElement(responseFormat);
+ break;
+ }
+ }
+ }
+ }
+ if (responseWrapper.isEmpty()) {
+ for (ArtifactDefinition currArtifact : existingArtifactsToHandle) {
+ if (currArtifact.getIsFromCsar()) {
+ artifactsToDelete.add(new NonMetaArtifactInfo(currArtifact.getArtifactName(), null,
+ ArtifactTypeEnum.findType(currArtifact.getArtifactType()),
+ currArtifact.getArtifactGroupType(), null, currArtifact.getUniqueId(),
+ currArtifact.getIsFromCsar()));
+ } else {
+ artifactsToUpdate.add(new NonMetaArtifactInfo(currArtifact.getArtifactName(), null,
+ ArtifactTypeEnum.findType(currArtifact.getArtifactType()),
+ currArtifact.getArtifactGroupType(), null, currArtifact.getUniqueId(),
+ currArtifact.getIsFromCsar()));
+
+ }
+ }
+ }
+ if (responseWrapper.isEmpty()) {
+ if (!artifactsToUpload.isEmpty()) {
+ nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.CREATE, artifactsToUpload);
+ }
+ if (!artifactsToUpdate.isEmpty()) {
+ nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.UPDATE, artifactsToUpdate);
+ }
+ if (!artifactsToDelete.isEmpty()) {
+ nodeTypeArtifactsToHandle.put(ArtifactOperationEnum.DELETE, artifactsToDelete);
+ }
+ }
+ if (!responseWrapper.isEmpty()) {
+ nodeTypeArtifactsToHandleRes = Either.right(responseWrapper.getInnerElement());
+ }
+ } catch (Exception e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ responseWrapper.setInnerElement(responseFormat);
+ log.debug("Exception occurred when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage(), e);
+ }
+ return nodeTypeArtifactsToHandleRes;
+ }
- ImmutablePair<String, String> buildNestedToscaResourceName(String nodeResourceType, String vfResourceName,
- String nodeTypeFullName) {
- String actualType;
- String actualVfName;
- if (ResourceTypeEnum.CVFC.name().equals(nodeResourceType)) {
- actualVfName = vfResourceName + ResourceTypeEnum.CVFC.name();
- actualType = ResourceTypeEnum.VFC.name();
- } else {
- actualVfName = vfResourceName;
- actualType = nodeResourceType;
- }
+ ImmutablePair<String, String> buildNestedToscaResourceName(String nodeResourceType, String vfResourceName,
+ String nodeTypeFullName) {
+ String actualType;
+ String actualVfName;
+ if (ResourceTypeEnum.CVFC.name()
+ .equals(nodeResourceType)) {
+ actualVfName = vfResourceName + ResourceTypeEnum.CVFC.name();
+ actualType = ResourceTypeEnum.VFC.name();
+ } else {
+ actualVfName = vfResourceName;
+ actualType = nodeResourceType;
+ }
String nameWithouNamespacePrefix;
- try {
- StringBuilder toscaResourceName = new StringBuilder(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
+ try {
+ StringBuilder toscaResourceName = new StringBuilder(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
if (!nodeTypeFullName.contains(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)){
- nameWithouNamespacePrefix = nodeTypeFullName;
+ nameWithouNamespacePrefix = nodeTypeFullName;
} else {
nameWithouNamespacePrefix = nodeTypeFullName
- .substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
- }
- String[] findTypes = nameWithouNamespacePrefix.split("\\.");
- String resourceType = findTypes[0];
- String actualName = nameWithouNamespacePrefix.substring(resourceType.length());
-
- if (actualName.startsWith(Constants.ABSTRACT)) {
- toscaResourceName.append(resourceType.toLowerCase()).append('.')
- .append(ValidationUtils.convertToSystemName(actualVfName));
- } else {
- toscaResourceName.append(actualType.toLowerCase()).append('.')
- .append(ValidationUtils.convertToSystemName(actualVfName)).append('.').append(Constants.ABSTRACT);
- }
- StringBuilder previousToscaResourceName = new StringBuilder(toscaResourceName);
- return new ImmutablePair<>(toscaResourceName.append(actualName.toLowerCase()).toString(),
- previousToscaResourceName
- .append(actualName.substring(actualName.split("\\.")[1].length() + 1).toLowerCase())
- .toString());
- } catch (Exception e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE);
- log.debug("Exception occured when buildNestedToscaResourceName, error is:{}", e.getMessage(), e);
- throw new ByActionStatusComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE, vfResourceName);
- }
- }
+ .substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
+ } String[] findTypes = nameWithouNamespacePrefix.split("\\.");
+ String resourceType = findTypes[0];
+ String actualName = nameWithouNamespacePrefix.substring(resourceType.length());
+
+ if (actualName.startsWith(Constants.ABSTRACT)) {
+ toscaResourceName.append(resourceType.toLowerCase()).append('.')
+ .append(ValidationUtils.convertToSystemName(actualVfName));
+ } else {
+ toscaResourceName.append(actualType.toLowerCase()).append('.')
+ .append(ValidationUtils.convertToSystemName(actualVfName)).append('.').append(Constants.ABSTRACT);
+ }
+ StringBuilder previousToscaResourceName = new StringBuilder(toscaResourceName);
+ return new ImmutablePair<>(toscaResourceName.append(actualName.toLowerCase()).toString(),
+ previousToscaResourceName
+ .append(actualName.substring(actualName.split("\\.")[1].length() + 1).toLowerCase())
+ .toString());
+ } catch (Exception e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE);
+ log.debug("Exception occured when buildNestedToscaResourceName, error is:{}", e.getMessage(), e);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE, vfResourceName);
+ }
+ }
- @Override
+ @Override
public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String resourceId,
List<String> dataParamsToReturn) {
ComponentParametersView paramsToRetuen = new ComponentParametersView(dataParamsToReturn);
Either<Resource, StorageOperationStatus> resourceResultEither =
toscaOperationFacade.getToscaElement(resourceId,
- paramsToRetuen);
+ paramsToRetuen);
if (resourceResultEither.isRight()) {
- if (resourceResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ if (resourceResultEither.right().value() == StorageOperationStatus.NOT_FOUND) {
log.debug("Failed to found resource with id {} ", resourceId);
Either
.right(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceId));
}
log.debug("failed to get resource by id {} with filters {}", resourceId, dataParamsToReturn);
- return Either.right(componentsUtils.getResponseFormatByResource(
- componentsUtils.convertFromStorageResponse(resourceResultEither.right().value()), ""));
+ return Either.right(componentsUtils
+ .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(resourceResultEither.right()
+ .value()), ""));
}
Resource resource = resourceResultEither.left().value();
@@ -5294,19 +5913,20 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
return Either.left(dataTransfer);
}
- @Override
- public Either<Component, ActionStatus> shouldUpgradeToLatestDerived(Component clonedComponent) {
- Resource resource = (Resource) clonedComponent;
- if (ModelConverter.isAtomicComponent(resource.getResourceType())) {
- Either<Component, StorageOperationStatus> shouldUpgradeToLatestDerived = toscaOperationFacade
- .shouldUpgradeToLatestDerived(resource);
- if (shouldUpgradeToLatestDerived.isRight()) {
- return Either.right(
- componentsUtils.convertFromStorageResponse(shouldUpgradeToLatestDerived.right().value()));
- }
- return Either.left(shouldUpgradeToLatestDerived.left().value());
- } else {
- return super.shouldUpgradeToLatestDerived(clonedComponent);
- }
- }
+ @Override
+ public Either<Component, ActionStatus> shouldUpgradeToLatestDerived(Component clonedComponent) {
+ Resource resource = (Resource) clonedComponent;
+ if (ModelConverter.isAtomicComponent(resource.getResourceType())) {
+ Either<Component, StorageOperationStatus> shouldUpgradeToLatestDerived = toscaOperationFacade
+ .shouldUpgradeToLatestDerived(resource);
+ if (shouldUpgradeToLatestDerived.isRight()) {
+ return Either.right(componentsUtils.convertFromStorageResponse(shouldUpgradeToLatestDerived.right()
+ .value()));
+ }
+ return Either.left(shouldUpgradeToLatestDerived.left()
+ .value());
+ } else {
+ return super.shouldUpgradeToLatestDerived(clonedComponent);
+ }
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
index 7d1729bcff..dfd7c6c58d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -32,6 +32,7 @@ import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.ImportUtils.Constants;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -43,7 +44,16 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
@@ -65,8 +75,15 @@ import org.springframework.web.context.WebApplicationContext;
import org.yaml.snakeyaml.Yaml;
import javax.servlet.ServletContext;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -100,26 +117,27 @@ public class ResourceImportManager {
this.toscaOperationFacade = toscaOperationFacade;
}
- public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importNormativeResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
+ public ImmutablePair<Resource, ActionStatus> importNormativeResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
lifecycleChangeInfo.setUserRemarks("certification on import");
- Function<Resource, Either<Boolean, ResponseFormat>> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+ Function<Resource, Boolean> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false, null, null, false);
}
- public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
+ public ImmutablePair<Resource, ActionStatus> importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
lifecycleChangeInfo.setUserRemarks("certification on import");
- Function<Resource, Either<Boolean, ResponseFormat>> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+ Function<Resource, Boolean> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false, null, null, false);
}
- public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, Function<Resource, Either<Boolean, ResponseFormat>> validationFunction,
- LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo, String nodeName, boolean isNested) {
+ public ImmutablePair<Resource, ActionStatus> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator,
+ Function<Resource, Boolean> validationFunction,
+ LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo, String nodeName, boolean isNested) {
Resource resource = new Resource();
ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED);
Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
@@ -130,54 +148,33 @@ public class ResourceImportManager {
setConstantMetaData(resource, shouldBeCertified);
setMetaDataFromJson(resourceMetaData, resource);
- Either<Boolean, ResponseFormat> validateResourceFromYaml = populateResourceFromYaml(resourceYml, resource);
- if (validateResourceFromYaml.isRight()) {
- ResponseFormat validationErrorResponse = validateResourceFromYaml.right().value();
- auditErrorImport(resourceMetaData, creator, validationErrorResponse, true);
- return Either.right(validationErrorResponse);
+ populateResourceFromYaml(resourceYml, resource);
- }
-
- Either<Boolean, ResponseFormat> isValidResource = validationFunction.apply(resource);
- if (isValidResource.isLeft()) {
- // The flag createNewVersion if false doesn't create new version
+ Boolean isValidResource = validationFunction.apply(resource);
if (!createNewVersion) {
Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resource.getName());
if (latestByName.isLeft()) {
- return Either.right(componentsUtils.getResponseFormatByResource(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource));
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource.getName());
}
}
resource = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo, nodeName, isNested).left;
- Either<Resource, ResponseFormat> changeStateResponse;
+ Resource changeStateResponse;
if (nodeTypeArtifactsToHandle != null && !nodeTypeArtifactsToHandle.isEmpty()) {
Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes =
resourceBusinessLogic.handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, creator, isInTransaction, false);
if (handleNodeTypeArtifactsRes.isRight()) {
- return Either.right(handleNodeTypeArtifactsRes.right().value());
+ //TODO: should be used more correct action
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
}
latestCertifiedResourceId = getLatestCertifiedResourceId(resource);
changeStateResponse = resourceBusinessLogic.propagateStateToCertified(creator, resource, lifecycleChangeInfo, isInTransaction, needLock, forceCertificationAllowed);
- if (changeStateResponse.isRight()) {
- response = Either.right(changeStateResponse.right().value());
- }
- else {
- responsePair = new ImmutablePair<>(changeStateResponse.left().value(), response.left()
- .value().right);
- response = Either.left(responsePair);
- }
- }
- else {
- ResponseFormat validationErrorResponse = isValidResource.right().value();
- auditErrorImport(resourceMetaData, creator, validationErrorResponse, true);
- response = Either.right(validationErrorResponse);
- }
-
+ responsePair = new ImmutablePair<>(changeStateResponse, response.left()
+ .value().right);
}
catch (RuntimeException e) {
- ResponseFormat exceptionResponse = handleImportResourceException(resourceMetaData, creator, true, e, null);
- response = Either.right(exceptionResponse);
+ handleImportResourceException(resourceMetaData, creator, true, e);
}
finally {
if (latestCertifiedResourceId != null && needLock) {
@@ -186,7 +183,16 @@ public class ResourceImportManager {
}
}
- return response;
+ return responsePair;
+ }
+
+ private ResponseFormat getResponseFormatFromComponentException(RuntimeException e) {
+ if(e instanceof ComponentException){
+ return ((ComponentException) e).getResponseFormat() == null ?
+ componentsUtils.getResponseFormat(((ComponentException) e).getActionStatus(), ((ComponentException) e).getParams()) :
+ ((ComponentException) e).getResponseFormat();
+ }
+ return null;
}
private String getLatestCertifiedResourceId(Resource resource) {
@@ -225,90 +231,65 @@ public class ResourceImportManager {
}
}
- public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importUserDefinedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction) {
+ public ImmutablePair<Resource, ActionStatus> importUserDefinedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction) {
Resource resource = new Resource();
ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED);
- Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
try {
setMetaDataFromJson(resourceMetaData, resource);
- Either<Boolean, ResponseFormat> validateResourceFromYaml = populateResourceFromYaml(resourceYml, resource);
- if (validateResourceFromYaml.isRight()) {
- ResponseFormat validationErrorResponse = validateResourceFromYaml.right().value();
- auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
- return Either.right(validationErrorResponse);
-
- }
+ populateResourceFromYaml(resourceYml, resource);
// currently import VF isn't supported. In future will be supported
// import VF only with CSAR file!!
- if (ResourceTypeEnum.VF.equals(resource.getResourceType())) {
+ if (ResourceTypeEnum.VF == resource.getResourceType()) {
log.debug("Now import VF isn't supported. It will be supported in future with CSAR file only");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
}
resourceBusinessLogic.validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE);
- Either<Boolean, ResponseFormat> validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+ Boolean validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource);
- if (validatePropertiesTypes.isLeft()) {
- response = Either.left(resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true, null, null, false));
- }
- else {
- ResponseFormat validationErrorResponse = validatePropertiesTypes.right().value();
- auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
- response = Either.right(validationErrorResponse);
- }
+ responsePair = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator,
+ false, isInTransaction, true, null, null, false);
}
- catch (ComponentException e) {
- response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e,
- e.getResponseFormat()));
- }
catch (RuntimeException e) {
- response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e, null));
+ handleImportResourceException(resourceMetaData, creator, false, e);
}
- return response;
+ return responsePair;
}
- Either<Boolean, ResponseFormat> populateResourceFromYaml(String resourceYml, Resource resource) {
+ void populateResourceFromYaml(String resourceYml, Resource resource) {
@SuppressWarnings("unchecked")
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
- Map<String, Object> toscaJsonAll = (Map<String, Object>) new Yaml().load(resourceYml);
- Map<String, Object> toscaJson = toscaJsonAll;
-
- // Checks if exist and builds the node_types map
- if (toscaJsonAll.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
- toscaJson = new HashMap<>();
- toscaJson.put(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName(), toscaJsonAll.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()));
- }
- // Derived From
- Either<Resource, ResponseFormat> setDerivedFrom = setDerivedFrom(toscaJson, resource);
- if (setDerivedFrom.isRight()) {
- return Either.right(setDerivedFrom.right().value());
+// Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ Object ymlObj = new Yaml().load(resourceYml);
+ if (ymlObj instanceof Map) {
+ Map<String, Object> toscaJsonAll = (Map<String, Object>) ymlObj;
+ Map<String, Object> toscaJson = toscaJsonAll;
+
+ // Checks if exist and builds the node_types map
+ if (toscaJsonAll.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
+ toscaJson = new HashMap<>();
+ toscaJson.put(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName(), toscaJsonAll.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()));
+ }
+ // Derived From
+ Resource parentResource = setDerivedFrom(toscaJson, resource);
+ if (StringUtils.isEmpty(resource.getToscaResourceName())) {
+ setToscaResourceName(toscaJson, resource);
+ }
+ setAttributes(toscaJson, resource);
+ setCapabilities(toscaJson, resource, parentResource);
+ setProperties(toscaJson, resource);
+ setRequirements(toscaJson, resource, parentResource);
+ setInterfaceLifecycle(toscaJson, resource);
}
- Resource parentResource = setDerivedFrom.left().value();
- if (StringUtils.isEmpty(resource.getToscaResourceName())) {
- setToscaResourceName(toscaJson, resource);
- }
- setAttributes(toscaJson, resource);
- eitherResult = setCapabilities(toscaJson, resource, parentResource);
- if (eitherResult.isRight()) {
- return eitherResult;
- }
- eitherResult = setProperties(toscaJson, resource);
- if (eitherResult.isRight()) {
- return eitherResult;
- }
- eitherResult = setRequirements(toscaJson, resource, parentResource);
- if (eitherResult.isRight()) {
- return eitherResult;
+ else {
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
- setInterfaceLifecycle(toscaJson, resource);
- return eitherResult;
}
private void setToscaResourceName(Map<String, Object> toscaJson, Resource resource) {
@@ -374,8 +355,7 @@ public class ResourceImportManager {
return result;
}
- private Either<Boolean, ResponseFormat> setRequirements(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ private void setRequirements(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(toscaJson, TypeUtils.ToscaTagNamesEnum.REQUIREMENTS);
if (toscaRequirements.isLeft()) {
List<Object> jsonRequirements = toscaRequirements.left().value();
@@ -384,13 +364,7 @@ public class ResourceImportManager {
Set<String> reqNames = new HashSet<>();
// Getting flattened list of capabilities of parent node - cap name
// to cap type
- Either<Map<String, String>, ResponseFormat> reqName2Type = getReqName2Type(parentResource);
- if (reqName2Type.isRight()) {
- ResponseFormat responseFormat = reqName2Type.right().value();
- log.debug("Error during setting requirements of imported resource: {}", responseFormat);
- return Either.right(responseFormat);
- }
- Map<String, String> reqName2TypeMap = reqName2Type.left().value();
+ Map<String, String> reqName2TypeMap = getReqName2Type(parentResource);
for (Object jsonRequirementObj : jsonRequirements) {
// Requirement
Map<String, Object> requirementJsonWrapper = (Map<String, Object>) jsonRequirementObj;
@@ -398,16 +372,11 @@ public class ResourceImportManager {
String reqNameLowerCase = requirementName.toLowerCase();
if (reqNames.contains(reqNameLowerCase)) {
log.debug("More than one requirement with same name {} (case-insensitive) in imported TOSCA file is invalid", reqNameLowerCase);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "requirement", reqNameLowerCase));
+ throw new ByActionStatusComponentException(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "requirement", reqNameLowerCase);
}
reqNames.add(reqNameLowerCase);
- Either<RequirementDefinition, ResponseFormat> eitherRequirement = createRequirementFromImportFile(requirementJsonWrapper
+ RequirementDefinition requirementDef = createRequirementFromImportFile(requirementJsonWrapper
.get(requirementName));
- if (eitherRequirement.isRight()) {
- log.info("error when creating Requirement:{}, for resource:{}", requirementName, resource.getName());
- return Either.right(eitherRequirement.right().value());
- }
- RequirementDefinition requirementDef = eitherRequirement.left().value();
requirementDef.setName(requirementName);
if (moduleRequirements.containsKey(requirementDef.getCapability())) {
moduleRequirements.get(requirementDef.getCapability()).add(requirementDef);
@@ -419,18 +388,14 @@ public class ResourceImportManager {
}
// Validating against req/cap of "derived from" node
- Either<Boolean, ResponseFormat> validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef
+ Boolean validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef
.getCapability(), requirementDef.getName());
- if (validateVsParentCap.isRight()) {
- return Either.right(validateVsParentCap.right().value());
- }
- if (!validateVsParentCap.left().value()) {
+ if (!validateVsParentCap) {
log.debug("Requirement with name {} already exists in parent {}", requirementDef.getName(), parentResource
.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "requirement", requirementDef
+ throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "requirement", requirementDef
.getName()
.toLowerCase(), parentResource.getName());
- return Either.right(responseFormat);
}
}
if (moduleRequirements.size() > 0) {
@@ -438,64 +403,44 @@ public class ResourceImportManager {
}
}
- return eitherResult;
-
- }
+ }
- private Either<RequirementDefinition, ResponseFormat> createRequirementFromImportFile(Object requirementJson) {
+ private RequirementDefinition createRequirementFromImportFile(Object requirementJson) {
RequirementDefinition requirement = new RequirementDefinition();
- Either<RequirementDefinition, ResponseFormat> result = Either.left(requirement);
- try {
- if (requirementJson instanceof String) {
- String requirementJsonString = (String) requirementJson;
- requirement.setCapability(requirementJsonString);
- }
- else if (requirementJson instanceof Map) {
- Map<String, Object> requirementJsonMap = (Map<String, Object>) requirementJson;
- if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName())) {
- requirement.setCapability((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName()));
- }
-
- if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.NODE.getElementName())) {
- requirement.setNode((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.NODE.getElementName()));
- }
+ if (requirementJson instanceof String) {
+ String requirementJsonString = (String) requirementJson;
+ requirement.setCapability(requirementJsonString);
+ }
+ else if (requirementJson instanceof Map) {
+ Map<String, Object> requirementJsonMap = (Map<String, Object>) requirementJson;
+ if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName())) {
+ requirement.setCapability((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName()));
+ }
- if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName())) {
- requirement.setRelationship((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName()));
- }
- if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
- List<Object> occurrencesList = (List) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName());
- Either<Boolean, ResponseFormat> validateAndSetOccurrencesStatus = validateOccurrences(occurrencesList);
- if (validateAndSetOccurrencesStatus.isRight()) {
- result = Either.right(validateAndSetOccurrencesStatus.right().value());
- return result;
- }
- if (validateAndSetOccurrencesStatus.left().value()) {
- requirement.setMinOccurrences(occurrencesList.get(0).toString());
- requirement.setMaxOccurrences(occurrencesList.get(1).toString());
- }
+ if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.NODE.getElementName())) {
+ requirement.setNode((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.NODE.getElementName()));
+ }
- }
+ if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName())) {
+ requirement.setRelationship((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName()));
}
- else {
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
+ List<Object> occurrencesList = (List) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName());
+ validateOccurrences(occurrencesList);
+ requirement.setMinOccurrences(occurrencesList.get(0).toString());
+ requirement.setMaxOccurrences(occurrencesList.get(1).toString());
}
-
}
- catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create Requirement");
- log.debug("error when creating requirement, message:{}", e.getMessage(), e);
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ else {
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML);
}
-
- return result;
+ return requirement;
}
- private Either<Boolean, ResponseFormat> setProperties(Map<String, Object> toscaJson, Resource resource) {
+ private void setProperties(Map<String, Object> toscaJson, Resource resource) {
Map<String, Object> reducedToscaJson = new HashMap<>(toscaJson);
ImportUtils.removeElementFromJsonMap(reducedToscaJson, "capabilities");
- Either<Boolean, ResponseFormat> result = Either.left(true);
Either<Map<String, PropertyDefinition>, ResultStatusEnum> properties = ImportUtils.getProperties(reducedToscaJson);
if (properties.isLeft()) {
List<PropertyDefinition> propertiesList = new ArrayList<>();
@@ -505,7 +450,7 @@ public class ResourceImportManager {
String name = entry.getKey();
if (!PROPERTY_NAME_PATTERN_IGNORE_LENGTH.matcher(name).matches()) {
log.debug("The property with invalid name {} occured upon import resource {}. ", name, resource.getName());
- result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, JsonPresentationFields.PROPERTY)));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, JsonPresentationFields.PROPERTY));
}
PropertyDefinition propertyDefinition = entry.getValue();
propertyDefinition.setName(name);
@@ -515,11 +460,10 @@ public class ResourceImportManager {
resource.setProperties(propertiesList);
}
else if (properties.right().value() != ResultStatusEnum.ELEMENT_NOT_FOUND) {
- result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromResultStatusEnum(properties
+ throw new ByActionStatusComponentException(componentsUtils.convertFromResultStatusEnum(properties
.right()
- .value(), JsonPresentationFields.PROPERTY)));
+ .value(), JsonPresentationFields.PROPERTY));
}
- return result;
}
private ResultStatusEnum setAttributes(Map<String, Object> toscaJson, Resource resource) {
@@ -544,7 +488,7 @@ public class ResourceImportManager {
return result;
}
- private Either<Resource, ResponseFormat> setDerivedFrom(Map<String, Object> toscaJson, Resource resource) {
+ private Resource setDerivedFrom(Map<String, Object> toscaJson, Resource resource) {
Either<String, ResultStatusEnum> toscaDerivedFromElement = ImportUtils.findFirstToscaStringElement(toscaJson, TypeUtils.ToscaTagNamesEnum.DERIVED_FROM);
Resource derivedFromResource = null;
if (toscaDerivedFromElement.isLeft()) {
@@ -555,22 +499,21 @@ public class ResourceImportManager {
if (latestByToscaResourceName.isRight()) {
StorageOperationStatus operationStatus = latestByToscaResourceName.right().value();
- if (operationStatus.equals(StorageOperationStatus.NOT_FOUND)) {
+ if (operationStatus == StorageOperationStatus.NOT_FOUND) {
operationStatus = StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND;
}
log.debug("Error when fetching parent resource {}, error: {}", derivedFrom, operationStatus);
ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(operationStatus);
BeEcompErrorManager.getInstance()
.logBeComponentMissingError("Import TOSCA YAML", "resource", derivedFrom);
- return Either.right(componentsUtils.getResponseFormat(convertFromStorageResponse, derivedFrom));
+ throw new ByActionStatusComponentException(convertFromStorageResponse, derivedFrom);
}
derivedFromResource = latestByToscaResourceName.left().value();
}
- return Either.left(derivedFromResource);
+ return derivedFromResource;
}
- private Either<Boolean, ResponseFormat> setCapabilities(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+ private void setCapabilities(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
Either<Map<String, Object>, ResultStatusEnum> toscaCapabilities = ImportUtils.findFirstToscaMapElement(toscaJson, TypeUtils.ToscaTagNamesEnum.CAPABILITIES);
if (toscaCapabilities.isLeft()) {
Map<String, Object> jsonCapabilities = toscaCapabilities.left().value();
@@ -579,13 +522,7 @@ public class ResourceImportManager {
Set<String> capNames = new HashSet<>();
// Getting flattened list of capabilities of parent node - cap name
// to cap type
- Either<Map<String, String>, ResponseFormat> capName2Type = getCapName2Type(parentResource);
- if (capName2Type.isRight()) {
- ResponseFormat responseFormat = capName2Type.right().value();
- log.debug("Error during setting capabilities of imported resource: {}", responseFormat);
- return Either.right(responseFormat);
- }
- Map<String, String> capName2TypeMap = capName2Type.left().value();
+ Map<String, String> capName2TypeMap = getCapName2Type(parentResource);
while (capabilitiesNameValue.hasNext()) {
Entry<String, Object> capabilityNameValue = capabilitiesNameValue.next();
@@ -593,19 +530,12 @@ public class ResourceImportManager {
String capNameLowerCase = capabilityNameValue.getKey().toLowerCase();
if (capNames.contains(capNameLowerCase)) {
log.debug("More than one capability with same name {} (case-insensitive) in imported TOSCA file is invalid", capNameLowerCase);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "capability", capNameLowerCase));
+ throw new ByActionStatusComponentException(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "capability", capNameLowerCase);
}
capNames.add(capNameLowerCase);
- Either<CapabilityDefinition, ResponseFormat> eitherCapability = createCapabilityFromImportFile(capabilityNameValue
+ CapabilityDefinition capabilityDef = createCapabilityFromImportFile(capabilityNameValue
.getValue());
- if (eitherCapability.isRight()) {
- log.debug("error when creating capability:{}, for resource:{}", capabilityNameValue.getKey(), resource
- .getName());
- return Either.right(eitherCapability.right().value());
- }
-
- CapabilityDefinition capabilityDef = eitherCapability.left().value();
capabilityDef.setName(capabilityNameValue.getKey());
if (moduleCapabilities.containsKey(capabilityDef.getType())) {
moduleCapabilities.get(capabilityDef.getType()).add(capabilityDef);
@@ -617,32 +547,26 @@ public class ResourceImportManager {
}
// Validating against req/cap of "derived from" node
- Either<Boolean, ResponseFormat> validateVsParentCap = validateCapNameVsDerived(capName2TypeMap, capabilityDef
+ Boolean validateVsParentCap = validateCapNameVsDerived(capName2TypeMap, capabilityDef
.getType(), capabilityDef.getName());
- if (validateVsParentCap.isRight()) {
- return Either.right(validateVsParentCap.right().value());
- }
- if (!validateVsParentCap.left().value()) {
+
+ if (!validateVsParentCap) {
// Here parentResource is for sure not null, so it's
// null-safe
log.debug("Capability with name {} already exists in parent {}", capabilityDef.getName(), parentResource
.getName());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "capability", capabilityDef
+ throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "capability", capabilityDef
.getName()
.toLowerCase(), parentResource.getName());
- return Either.right(responseFormat);
}
}
if (moduleCapabilities.size() > 0) {
resource.setCapabilities(moduleCapabilities);
}
}
-
- return eitherResult;
-
}
- private Either<Map<String, String>, ResponseFormat> getCapName2Type(Resource parentResource) {
+ private Map<String, String> getCapName2Type(Resource parentResource) {
Map<String, String> capName2type = new HashMap<>();
if (parentResource != null) {
Map<String, List<CapabilityDefinition>> capabilities = parentResource.getCapabilities();
@@ -655,17 +579,17 @@ public class ResourceImportManager {
log.debug("Resource with name {} has more than one capability with name {}, ignoring case", parentResourceName, nameLowerCase);
BeEcompErrorManager.getInstance()
.logInternalDataError("Import resource", "Parent resource " + parentResourceName + " of imported resource has one or more capabilities with name " + nameLowerCase, ErrorSeverity.ERROR);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
capName2type.put(nameLowerCase, capDefinition.getType());
}
}
}
}
- return Either.left(capName2type);
+ return capName2type;
}
- private Either<Map<String, String>, ResponseFormat> getReqName2Type(Resource parentResource) {
+ private Map<String, String> getReqName2Type(Resource parentResource) {
Map<String, String> reqName2type = new HashMap<>();
if (parentResource != null) {
Map<String, List<RequirementDefinition>> requirements = parentResource.getRequirements();
@@ -678,123 +602,115 @@ public class ResourceImportManager {
log.debug("Resource with name {} has more than one requirement with name {}, ignoring case", parentResourceName, nameLowerCase);
BeEcompErrorManager.getInstance()
.logInternalDataError("Import resource", "Parent resource " + parentResourceName + " of imported resource has one or more requirements with name " + nameLowerCase, ErrorSeverity.ERROR);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
reqName2type.put(nameLowerCase, reqDefinition.getCapability());
}
}
}
}
- return Either.left(reqName2type);
+ return reqName2type;
}
- private Either<Boolean, ResponseFormat> validateCapNameVsDerived(Map<String, String> parentCapName2Type, String childCapabilityType, String reqCapName) {
+ private Boolean validateCapNameVsDerived(Map<String, String> parentCapName2Type, String childCapabilityType, String reqCapName) {
String capNameLowerCase = reqCapName.toLowerCase();
log.trace("Validating capability {} vs parent resource", capNameLowerCase);
String parentCapType = parentCapName2Type.get(capNameLowerCase);
if (parentCapType != null) {
if (childCapabilityType.equals(parentCapType)) {
log.debug("Capability with name {} is of same type {} for imported resource and its parent - this is OK", capNameLowerCase, childCapabilityType);
- return Either.left(true);
+ return true;
}
Either<Boolean, StorageOperationStatus> capabilityTypeDerivedFrom = capabilityTypeOperation.isCapabilityTypeDerivedFrom(childCapabilityType, parentCapType);
if (capabilityTypeDerivedFrom.isRight()) {
log.debug("Couldn't check whether imported resource capability derives from its parent's capability");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(capabilityTypeDerivedFrom
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(capabilityTypeDerivedFrom
.right()
.value()));
- return Either.right(responseFormat);
}
- return Either.left(capabilityTypeDerivedFrom.left().value());
+ return capabilityTypeDerivedFrom.left().value();
}
- return Either.left(true);
+ return true;
}
- private Either<CapabilityDefinition, ResponseFormat> createCapabilityFromImportFile(Object capabilityJson) {
+ private CapabilityDefinition createCapabilityFromImportFile(Object capabilityJson) {
CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
- Either<CapabilityDefinition, ResponseFormat> result = Either.left(capabilityDefinition);
-
- try {
- if (capabilityJson instanceof String) {
- String capabilityJsonString = (String) capabilityJson;
- capabilityDefinition.setType(capabilityJsonString);
- }
- else if (capabilityJson instanceof Map) {
- Map<String, Object> capabilityJsonMap = (Map<String, Object>) capabilityJson;
- // Type
- if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) {
- capabilityDefinition.setType((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName()));
- }
- // ValidSourceTypes
- if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) {
- capabilityDefinition.setValidSourceTypes((List<String>) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES
- .getElementName()));
- }
- // ValidSourceTypes
- if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
- capabilityDefinition.setDescription((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName()));
- }
- if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
- List<Object> occurrencesList = (List) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName());
- Either<Boolean, ResponseFormat> validateAndSetOccurrencesStatus = validateOccurrences(occurrencesList);
- if (validateAndSetOccurrencesStatus.isRight()) {
- result = Either.right(validateAndSetOccurrencesStatus.right().value());
- return result;
- }
- if (validateAndSetOccurrencesStatus.left().value()) {
- capabilityDefinition.setMinOccurrences(occurrencesList.get(0).toString());
- capabilityDefinition.setMaxOccurrences(occurrencesList.get(1).toString());
- }
- }
- if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.PROPERTIES.getElementName())) {
- Either<Map<String, PropertyDefinition>, ResultStatusEnum> propertiesRes = ImportUtils.getProperties(capabilityJsonMap);
- if (propertiesRes.isRight()) {
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
- return result;
- }
- else {
- propertiesRes.left()
- .value()
- .entrySet()
- .stream()
- .forEach(e -> e.getValue().setName(e.getKey().toLowerCase()));
- List<ComponentInstanceProperty> capabilityProperties = propertiesRes.left()
- .value()
- .values()
- .stream()
- .map(p -> new ComponentInstanceProperty(p, p
- .getDefaultValue(), null))
- .collect(Collectors.toList());
- capabilityDefinition.setProperties(capabilityProperties);
- }
- }
+ if (capabilityJson instanceof String) {
+ String capabilityJsonString = (String) capabilityJson;
+ capabilityDefinition.setType(capabilityJsonString);
+ }
+ else if (capabilityJson instanceof Map) {
+ Map<String, Object> capabilityJsonMap = (Map<String, Object>) capabilityJson;
+ // Type
+ if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) {
+ capabilityDefinition.setType((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName()));
}
- else if (!(capabilityJson instanceof List)) {
-
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ // ValidSourceTypes
+ if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) {
+ capabilityDefinition.setValidSourceTypes((List<String>) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES
+ .getElementName()));
+ }
+ // ValidSourceTypes
+ if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
+ capabilityDefinition.setDescription((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName()));
+ }
+ if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
+ List<Object> occurrencesList = (List) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName());
+ validateOccurrences(occurrencesList);
+ capabilityDefinition.setMinOccurrences(occurrencesList.get(0).toString());
+ capabilityDefinition.setMaxOccurrences(occurrencesList.get(1).toString());
+ }
+ if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.PROPERTIES.getElementName())) {
+ Either<Map<String, PropertyDefinition>, ResultStatusEnum> propertiesRes = ImportUtils.getProperties(capabilityJsonMap);
+ if (propertiesRes.isRight()) {
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND);
+ }
+ else {
+ propertiesRes.left()
+ .value()
+ .entrySet()
+ .stream()
+ .forEach(e -> e.getValue().setName(e.getKey().toLowerCase()));
+ List<ComponentInstanceProperty> capabilityProperties = propertiesRes.left()
+ .value()
+ .values()
+ .stream()
+ .map(p -> new ComponentInstanceProperty(p, p
+ .getDefaultValue(), null))
+ .collect(Collectors.toList());
+ capabilityDefinition.setProperties(capabilityProperties);
+ }
}
}
- catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create capability");
- log.debug("error when creating capability, message:{}", e.getMessage(), e);
- result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+ else if (!(capabilityJson instanceof List)) {
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML);
}
-
- return result;
+ return capabilityDefinition;
}
- private ResponseFormat handleImportResourceException(UploadResourceInfo resourceMetaData, User user, boolean isNormative, RuntimeException e, ResponseFormat responseFormat) {
- if(responseFormat == null ){
+ private void handleImportResourceException(UploadResourceInfo resourceMetaData, User user, boolean isNormative, RuntimeException e) {
+ ResponseFormat responseFormat;
+ ComponentException newException;
+ if (e instanceof ComponentException) {
+ ComponentException componentException = (ComponentException)e;
+ responseFormat = componentException.getResponseFormat();
+ if (responseFormat == null) {
+ responseFormat = getResponseFormatManager().getResponseFormat(componentException.getActionStatus(), componentException.getParams());
+ }
+ newException = componentException;
+ }
+ else{
responseFormat = getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ newException = new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
String payloadName = (resourceMetaData != null) ? resourceMetaData.getPayloadName() : "";
BeEcompErrorManager.getInstance().logBeSystemError("Import Resource " + payloadName);
log.debug("Error when importing resource from payload:{} Exception text: {}", payloadName, e.getMessage(), e);
auditErrorImport(resourceMetaData, user, responseFormat, isNormative);
- return responseFormat;
+ throw newException;
}
private void auditErrorImport(UploadResourceInfo resourceMetaData, User user, ResponseFormat errorResponseWrapper, boolean isNormative) {
@@ -876,45 +792,37 @@ public class ResourceImportManager {
}
- private Either<Boolean, ResponseFormat> validateOccurrences(List<Object> occurrensesList) {
+ private void validateOccurrences(List<Object> occurrensesList) {
if (!ValidationUtils.validateListNotEmpty(occurrensesList)) {
log.debug("Occurrenses list empty");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
}
if (occurrensesList.size() < 2) {
log.debug("Occurrenses list size not 2");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
}
Object minObj = occurrensesList.get(0);
Object maxObj = occurrensesList.get(1);
Integer minOccurrences;
- Integer maxOccurrences = null;
+ Integer maxOccurrences;
if (minObj instanceof Integer) {
minOccurrences = (Integer) minObj;
}
else {
log.debug("Invalid occurrenses format. low_bound occurrense must be Integer {}", minObj);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
}
if (minOccurrences < 0) {
log.debug("Invalid occurrenses format.low_bound occurrense negative {}", minOccurrences);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
}
- if (maxObj instanceof String) {
- if ("UNBOUNDED".equals(maxObj)) {
- return Either.left(true);
- }
- else {
+ if (maxObj instanceof String){
+ if(!"UNBOUNDED".equals(maxObj)) {
log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
}
}
else {
@@ -923,19 +831,14 @@ public class ResourceImportManager {
}
else {
log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
}
if (maxOccurrences <= 0 || maxOccurrences < minOccurrences) {
log.debug("Invalid occurrenses format. min occurrence is {}, Max occurrence is {}", minOccurrences, maxOccurrences);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
}
}
-
- return Either.left(true);
-
}
public synchronized void init(ServletContext servletContext) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java
index 19d63f30b4..27adf93516 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResponseFormatManager.java
@@ -64,11 +64,11 @@ public class ResponseFormatManager {
String errorMessage = errorInfo.getMessage();
String errorMessageId = errorInfo.getMessageId();
ErrorInfoType errorInfoType = errorInfo.getErrorInfoType();
- if (errorInfoType.equals(ErrorInfoType.SERVICE_EXCEPTION)) {
+ if (errorInfoType == ErrorInfoType.SERVICE_EXCEPTION) {
errorResponseWrapper.setServiceException(new ServiceException(errorMessageId, errorMessage, variables));
- } else if (errorInfoType.equals(ErrorInfoType.POLICY_EXCEPTION)) {
+ } else if (errorInfoType == ErrorInfoType.POLICY_EXCEPTION) {
errorResponseWrapper.setPolicyException(new PolicyException(errorMessageId, errorMessage, variables));
- } else if (errorInfoType.equals(ErrorInfoType.OK)) {
+ } else if (errorInfoType == ErrorInfoType.OK) {
errorResponseWrapper.setOkResponseInfo(new OkResponseInfo(errorMessageId, errorMessage, variables));
}
return errorResponseWrapper;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
index 28fc2597b8..c1f7808958 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
@@ -22,43 +22,17 @@
package org.openecomp.sdc.be.components.impl;
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
-import static org.openecomp.sdc.be.components.utils.ConsumptionUtils.handleConsumptionInputMappedToCapabilityProperty;
-import static org.openecomp.sdc.be.components.utils.ConsumptionUtils.isAssignedValueFromValidType;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationOutputName;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToOtherOperationOutput;
-import static org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum.UPDATE_SERVICE_METADATA;
-import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
-import static org.openecomp.sdc.be.types.ServiceConsumptionSource.SERVICE_INPUT;
-import static org.openecomp.sdc.be.types.ServiceConsumptionSource.STATIC;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-
import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
import org.openecomp.sdc.be.components.distribution.engine.INotificationData;
import org.openecomp.sdc.be.components.distribution.engine.VfModuleArtifactPayload;
@@ -73,6 +47,19 @@ import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
import org.openecomp.sdc.be.components.utils.PropertiesUtils;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.components.validation.ServiceDistributionValidation;
+import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentIconValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentNameValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentProjectCodeValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentTagsValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
+import org.openecomp.sdc.be.components.validation.service.ServiceCategoryValidator;
+import org.openecomp.sdc.be.components.validation.service.ServiceFunctionValidator;
+import org.openecomp.sdc.be.components.validation.service.ServiceInstantiationTypeValidator;
+import org.openecomp.sdc.be.components.validation.service.ServiceRoleValidator;
+import org.openecomp.sdc.be.components.validation.service.ServiceTypeValidator;
+import org.openecomp.sdc.be.components.validation.service.ServiceValidator;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -90,7 +77,6 @@ import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.InstantiationTypes;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
@@ -148,6 +134,7 @@ import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.common.util.ThreadLocalsHolder;
@@ -159,6 +146,31 @@ import org.springframework.web.context.WebApplicationContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+import static org.openecomp.sdc.be.components.utils.ConsumptionUtils.handleConsumptionInputMappedToCapabilityProperty;
+import static org.openecomp.sdc.be.components.utils.ConsumptionUtils.isAssignedValueFromValidType;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationOutputName;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToOtherOperationOutput;
+import static org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum.UPDATE_SERVICE_METADATA;
+import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
+import static org.openecomp.sdc.be.types.ServiceConsumptionSource.SERVICE_INPUT;
+import static org.openecomp.sdc.be.types.ServiceConsumptionSource.STATIC;
+
@org.springframework.stereotype.Component("serviceBusinessLogic")
public class ServiceBusinessLogic extends ComponentBusinessLogic {
@@ -171,6 +183,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private static final String INITIAL_VERSION = "0.1";
private static final String STATUS_SUCCESS_200 = "200";
private static final String STATUS_DEPLOYED = "DEPLOYED";
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ServiceBusinessLogic.class.getName());
static final String IS_VALID = "isValid";
private ForwardingPathOperation forwardingPathOperation;
@@ -184,6 +197,34 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private final NodeFilterOperation serviceFilterOperation;
private final NodeFilterValidator serviceFilterValidator;
+ private ServiceTypeValidator serviceTypeValidator;
+
+ @Autowired
+ public void setServiceTypeValidator(ServiceTypeValidator serviceTypeValidator) {
+ this.serviceTypeValidator = serviceTypeValidator;
+ }
+
+
+ private ServiceFunctionValidator serviceFunctionValidator;
+
+ @Autowired
+ public void setServiceFunctionValidator(ServiceFunctionValidator serviceFunctionValidator) {
+ this.serviceFunctionValidator = serviceFunctionValidator;
+ }
+
+ @Autowired
+ private ServiceRoleValidator serviceRoleValidator;
+
+ @Autowired
+ private ServiceInstantiationTypeValidator serviceInstantiationTypeValidator;
+
+ @Autowired
+ private ServiceCategoryValidator serviceCategoryValidator;
+
+ @Autowired
+ private ServiceValidator serviceValidator;
+
+
@Autowired
public ServiceBusinessLogic(IElementOperation elementDao,
IGroupOperation groupOperation,
@@ -196,9 +237,18 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
IDistributionEngine distributionEngine, ComponentInstanceBusinessLogic componentInstanceBusinessLogic,
ServiceDistributionValidation serviceDistributionValidation, ForwardingPathValidator forwardingPathValidator,
UiComponentDataConverter uiComponentDataConverter, NodeFilterOperation serviceFilterOperation,
- NodeFilterValidator serviceFilterValidator, ArtifactsOperations artifactToscaOperation) {
+ NodeFilterValidator serviceFilterValidator, ArtifactsOperations artifactToscaOperation,
+ ComponentContactIdValidator componentContactIdValidator,
+ ComponentNameValidator componentNameValidator,
+ ComponentTagsValidator componentTagsValidator,
+ ComponentValidator componentValidator,
+ ComponentIconValidator componentIconValidator,
+ ComponentProjectCodeValidator componentProjectCodeValidator,
+ ComponentDescriptionValidator componentDescriptionValidator) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation);
+ interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator,
+ componentNameValidator, componentTagsValidator, componentValidator,
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
this.distributionEngine = distributionEngine;
this.componentInstanceBusinessLogic = componentInstanceBusinessLogic;
this.serviceDistributionValidation = serviceDistributionValidation;
@@ -206,76 +256,12 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
this.uiComponentDataConverter = uiComponentDataConverter;
this.serviceFilterOperation = serviceFilterOperation;
this.serviceFilterValidator = serviceFilterValidator;
- }
-
- public Either<Service, ResponseFormat> changeServiceDistributionState(String serviceId, String state, LifecycleChangeInfoWithAction commentObj, User user) {
-
- validateUserExists(user.getUserId(), "change Service Distribution State", false);
-
- log.debug("check request state");
- Either<DistributionTransitionEnum, ResponseFormat> validateEnum = validateTransitionEnum(state);
- if (validateEnum.isRight()) {
- return Either.right(validateEnum.right().value());
- }
- DistributionTransitionEnum distributionTransition = validateEnum.left().value();
- AuditingActionEnum auditAction = distributionTransition == DistributionTransitionEnum.APPROVE ? AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_APPROV : AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REJECT;
- Either<String, ResponseFormat> commentResponse = validateComment(commentObj);
- if (commentResponse.isRight()) {
- return Either.right(commentResponse.right().value());
- }
- String comment = commentResponse.left().value();
-
- Either<Service, ResponseFormat> validateService = validateServiceDistributionChange(user, serviceId, auditAction, comment);
- if (validateService.isRight()) {
- return Either.right(validateService.right().value());
- }
- Service service = validateService.left().value();
- Either<User, ResponseFormat> validateUser = validateUserDistributionChange(user, service, auditAction, comment);
- if (validateUser.isRight()) {
- return Either.right(validateUser.right().value());
- }
- user = validateUser.left().value();
-
- // lock resource
-
- Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, service, "ChangeServiceDistributionState");
- if (lockResult.isRight()) {
- ResponseFormat responseFormat = lockResult.right().value();
- createAudit(user, auditAction, comment, service, responseFormat);
- return Either.right(responseFormat);
- }
-
- try {
-
- DistributionStatusEnum newState;
- if (distributionTransition == DistributionTransitionEnum.APPROVE) {
- newState = DistributionStatusEnum.DISTRIBUTION_APPROVED;
- } else {
- newState = DistributionStatusEnum.DISTRIBUTION_REJECTED;
- }
- Either<Service, StorageOperationStatus> result = toscaOperationFacade.updateDistributionStatus(service, user, newState);
- if (result.isRight()) {
- janusGraphDao.rollback();
- BeEcompErrorManager.getInstance().logBeSystemError("ChangeServiceDistributionState");
- log.debug("service {} is change destribuation status failed", service.getUniqueId());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, service.getVersion(), service.getName());
- createAudit(user, auditAction, comment, service, responseFormat);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- janusGraphDao.commit();
- Service updatedService = result.left().value();
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
- componentsUtils.auditComponent(responseFormat, user, updatedService, auditAction, new ResourceCommonInfo(ComponentTypeEnum.SERVICE.getValue()), ResourceVersionInfo.newBuilder().build(), comment);
- return Either.left(result.left().value());
- } finally {
- graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
- }
}
+
public Either<List<Map<String, Object>>, ResponseFormat> getComponentAuditRecords(String componentVersion, String componentUUID, String userId) {
- validateUserExists(userId, "get Component Audit Records", false);
+ validateUserExists(userId);
Either<List<Map<String, Object>>, ActionStatus> result;
try {
@@ -358,7 +344,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
String operationId,
String userId,
ServiceConsumptionData serviceConsumptionData) {
- validateUserExists(userId, "create Property", false);
+ validateUserExists(userId);
Either<Service, StorageOperationStatus> serviceEither =
toscaOperationFacade.getToscaElement(serviceId);
@@ -703,33 +689,19 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private Either<Boolean, ResponseFormat> validateOperationInputConstraint(
OperationInputDefinition operationInputDefinition, String value, String type) {
-
- if (Objects.nonNull(operationInputDefinition.getParentPropertyType())
- && !operationInputDefinition.getParentPropertyType().equals(operationInputDefinition.getType())) {
- InputDefinition inputDefinition = new InputDefinition();
- inputDefinition.setDefaultValue(value);
- inputDefinition.setInputPath(operationInputDefinition.getSubPropertyInputPath());
- inputDefinition.setName(operationInputDefinition.getName());
- inputDefinition.setType(type);
-
- ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
- propertyDefinition.setType(operationInputDefinition.getParentPropertyType());
- if (operationInputDefinition.getParentPropertyType() != null) {
+ ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
+ propertyDefinition.setType(operationInputDefinition.getParentPropertyType());
+
+ InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setDefaultValue(value);
+ inputDefinition.setInputPath(operationInputDefinition.getSubPropertyInputPath());
+ inputDefinition.setType(type);
+ if (Objects.nonNull(operationInputDefinition.getParentPropertyType())) {
inputDefinition.setProperties(Collections.singletonList(propertyDefinition));
- }
-
- return PropertyValueConstraintValidationUtil.getInstance()
- .validatePropertyConstraints(Collections.singletonList(inputDefinition), applicationDataTypeCache);
- } else {
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setType(operationInputDefinition.getType());
- propertyDefinition.setSchema(operationInputDefinition.getSchema());
- propertyDefinition.setValue(value);
- propertyDefinition.setName(operationInputDefinition.getName());
-
- return PropertyValueConstraintValidationUtil.getInstance()
- .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache);
}
+
+ return PropertyValueConstraintValidationUtil.getInstance()
+ .validatePropertyConstraints(Collections.singletonList(inputDefinition), applicationDataTypeCache);
}
private void addStaticValueToInputOperation(String value, Operation operation,
@@ -833,6 +805,16 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.left(archiveAudit);
}
+ @VisibleForTesting
+ public void setServiceValidator(ServiceValidator serviceValidator) {
+ this.serviceValidator = serviceValidator;
+ }
+
+ @VisibleForTesting
+ public void setServiceCategoryValidator(ServiceCategoryValidator serviceCategoryValidator) {
+ this.serviceCategoryValidator = serviceCategoryValidator;
+ }
+
private List<Map<String, Object>> getAuditingFieldsList(List<? extends AuditingGenericEvent> prevVerAuditList) {
List<Map<String, Object>> prevVerAudit = new ArrayList<>();
@@ -856,6 +838,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
// get user details
user = validateUser(user, "Create Service", service, AuditingActionEnum.CREATE_RESOURCE, false);
+ log.debug("User returned from validation: "+ user.toString());
// validate user role
validateUserRole(user, service, new ArrayList<>(), AuditingActionEnum.CREATE_RESOURCE, null);
service.setCreatorUserId(user.getUserId());
@@ -867,12 +850,16 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
service.setVersion(INITIAL_VERSION);
service.setConformanceLevel(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel());
service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
-
+ service.setComponentType(ComponentTypeEnum.SERVICE);
Either<Service, ResponseFormat> createServiceResponse = validateServiceBeforeCreate(service, user, AuditingActionEnum.CREATE_RESOURCE);
if (createServiceResponse.isRight()) {
return createServiceResponse;
}
- return createServiceByDao(service, AuditingActionEnum.CREATE_RESOURCE, user);
+ return createServiceByDao(service, AuditingActionEnum.CREATE_RESOURCE, user)
+ .left()
+ .bind(c -> updateCatalog(c, ChangeTypeEnum.LIFECYCLE)
+ .left()
+ .map (r -> (Service) r));
}
private void checkFieldsForOverideAttampt(Service service) {
@@ -961,12 +948,18 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
}
- private Either<Service, ResponseFormat> validateServiceBeforeCreate(Service service, User user, AuditingActionEnum actionEnum) {
+ @VisibleForTesting
+ protected Either<Service, ResponseFormat> validateServiceBeforeCreate(Service service, User user, AuditingActionEnum actionEnum) {
- Either<Boolean, ResponseFormat> validationResponse = validateServiceFieldsBeforeCreate(user, service, actionEnum);
- if (validationResponse.isRight()) {
- return Either.right(validationResponse.right().value());
+ try {
+ serviceValidator.validate(user,service,actionEnum);
+ } catch (ComponentException exp) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(exp);
+ componentsUtils.auditComponentAdmin(responseFormat, user, service,
+ AuditingActionEnum.CREATE_SERVICE, ComponentTypeEnum.SERVICE);
+ throw exp;
}
+
service.setCreatorFullName(user.getFirstName() + " " + user.getLastName());
service.setContactId(service.getContactId().toLowerCase());
@@ -978,57 +971,8 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.left(service);
}
-
-
- private Either<Boolean, ResponseFormat> validateServiceFieldsBeforeCreate(User user, Service service, AuditingActionEnum actionEnum) {
- try {
- validateComponentFieldsBeforeCreate(user, service, actionEnum);
-
- Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, service, actionEnum);
- if (serviceNameUniquenessValidation.isRight()) {
- throw new ByResponseFormatComponentException(serviceNameUniquenessValidation.right().value());
- }
- Either<Boolean, ResponseFormat> categoryValidation = validateServiceCategory(user, service, actionEnum);
- if (categoryValidation.isRight()) {
- return categoryValidation;
- }
- Either<Boolean, ResponseFormat> projectCodeValidation = validateProjectCode(user, service, actionEnum);
- if (projectCodeValidation.isRight()) {
- return projectCodeValidation;
- }
- validateServiceTypeAndCleanup(service);
-
- Either<Boolean, ResponseFormat> serviceRoleValidation = validateServiceRoleAndCleanup(user, service, actionEnum);
- if (serviceRoleValidation.isRight()) {
- return serviceRoleValidation;
- }
- return validateInstantiationTypeValue(user, service, actionEnum);
- } catch (ComponentException exception) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(exception);
- componentsUtils.auditComponentAdmin(responseFormat, user, service,
- AuditingActionEnum.CREATE_SERVICE, ComponentTypeEnum.SERVICE);
- return Either.right(responseFormat);
- }
- }
-
- private Either<Boolean, ResponseFormat> validateServiceCategory(User user, Service service, AuditingActionEnum actionEnum) {
- log.debug("validate Service category");
- if (isEmpty(service.getCategories())) {
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
- componentsUtils.auditComponentAdmin(errorResponse, user, service, actionEnum, ComponentTypeEnum.SERVICE);
- return Either.right(errorResponse);
- }
- Either<Boolean, ResponseFormat> validatCategory = validateServiceCategory(service.getCategories());
- if (validatCategory.isRight()) {
- ResponseFormat responseFormat = validatCategory.right().value();
- componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE);
- return Either.right(responseFormat);
- }
- return Either.left(true);
- }
-
public Either<Map<String, Boolean>, ResponseFormat> validateServiceNameExists(String serviceName, String userId) {
- validateUserExists(userId, "validate Service Name Exists", false);
+ validateUserExists(userId);
Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade.validateComponentNameUniqueness(serviceName, null, ComponentTypeEnum.SERVICE);
// DE242223
@@ -1044,6 +988,10 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.right(responseFormat);
}
+ public void setElementDao(IElementOperation elementDao) {
+ this.elementDao = elementDao;
+ }
+
@Autowired
public void setCassandraAuditingDao(AuditCassandraDao auditingDao) {
this.auditCassandraDao = auditingDao;
@@ -1053,6 +1001,10 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return artifactsBusinessLogic;
}
+ public void setArtifactBl(ArtifactsBusinessLogic artifactBl) {
+ this.artifactsBusinessLogic = artifactBl;
+ }
+
public Either<Service, ResponseFormat> updateServiceMetadata(String serviceId, Service serviceUpdate, User user) {
user = validateUser(user, "updateServiceMetadata", serviceUpdate, null, false);
// validate user role
@@ -1078,42 +1030,49 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
Service serviceToUpdate = validationRsponse.left().value();
// lock resource
- Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, currentService, "Update Service Metadata");
- if (lockResult.isRight()) {
- return Either.right(lockResult.right().value());
- }
+ lockComponent(serviceId, currentService, "Update Service Metadata");
try {
- Either<Service, StorageOperationStatus> updateResponse = toscaOperationFacade.updateToscaElement(serviceToUpdate);
- if (updateResponse.isRight()) {
- janusGraphDao.rollback();
- BeEcompErrorManager.getInstance().logBeSystemError("Update Service Metadata");
- log.debug("failed to update sevice {}", serviceToUpdate.getUniqueId());
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- janusGraphDao.commit();
- return Either.left(updateResponse.left().value());
+ return toscaOperationFacade.updateToscaElement(serviceToUpdate)
+ .right()
+ .map(rf -> {
+ janusGraphDao.rollback();
+ BeEcompErrorManager.getInstance().logBeSystemError("Update Service Metadata");
+ log.debug("failed to update sevice {}", serviceToUpdate.getUniqueId());
+ return (componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ })
+ .left()
+ .bind(c -> updateCatalogAndCommit(c));
+
} finally {
graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
}
}
- public Either<Set<String>, ResponseFormat> deleteForwardingPaths(String serviceId, Set<String> pathIdsToDelete, User user, boolean lock) {
+ private Either<Service, ResponseFormat> updateCatalogAndCommit(Service service){
+ Either<Service, ResponseFormat> res = updateCatalog(service, ChangeTypeEnum.LIFECYCLE).left().map(s -> (Service)s);
+ janusGraphDao.commit();
+ return res;
+
+ }
+
+ public Set<String> deleteForwardingPaths(String serviceId, Set<String> pathIdsToDelete, User user, boolean lock) {
Service serviceToDelete = initServiceToDeletePaths(serviceId, pathIdsToDelete);
user = validateUser(user, "deleteForwardingPaths", serviceToDelete, null, false);
// validate user role
validateUserRole(user, serviceToDelete, new ArrayList<>(), null, null);
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
if (storageStatus.isRight()) {
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), "");
}
Service service = storageStatus.left().value();
Either<Set<String>, StorageOperationStatus> result = null;
if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(service.getUniqueId(), service, "Delete Forwarding Path on Service");
- if (lockResult.isRight()) {
+ try {
+ lockComponent(service.getUniqueId(), service, "Delete Forwarding Path on Service");
+ } catch (ComponentException e) {
janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils
- .convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse
+ (storageStatus.right().value(), ComponentTypeEnum.SERVICE), "");
}
}
try{
@@ -1121,19 +1080,20 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
if (result.isRight()) {
log.debug(FAILED_TO_LOCK_SERVICE_RESPONSE_IS, service.getName(), result.right().value());
janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE)));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse
+ (storageStatus.right().value(), ComponentTypeEnum.SERVICE));
}
janusGraphDao.commit();
log.debug(THE_SERVICE_WITH_SYSTEM_NAME_LOCKED, service.getSystemName());
- } catch (Exception e){
+ } catch (ComponentException e){
log.error("Exception occurred during delete forwarding path : {}", e.getMessage(), e);
janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
} finally {
graphLockOperation.unlockComponent(service.getUniqueId(), NodeTypeEnum.Service);
}
- return Either.left(result.left().value());
+ return result.left().value();
}
private Service initServiceToDeletePaths(String serviceId, Collection<String> pathIdsToDelete) {
@@ -1144,11 +1104,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return serviceToDelete;
}
- public Either<Service, ResponseFormat> updateForwardingPath(String serviceId, Service serviceUpdate, User user, boolean lock) {
+ public Service updateForwardingPath(String serviceId, Service serviceUpdate, User user, boolean lock) {
return createOrUpdateForwardingPath(serviceId, serviceUpdate, user, true,"updateForwardingPath", lock);
}
- public Either<Service, ResponseFormat> createForwardingPath(String serviceId, Service serviceUpdate, User user, boolean lock) {
+ public Service createForwardingPath(String serviceId, Service serviceUpdate, User user, boolean lock) {
return createOrUpdateForwardingPath(serviceId, serviceUpdate, user, false, "createForwardingPath", lock);
}
@@ -1164,7 +1124,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return dataDefinition;
}
- private Either<Service, ResponseFormat> createOrUpdateForwardingPath(String serviceId, Service serviceUpdate, User user, boolean isUpdate, String errorContext, boolean lock) {
+ private Service createOrUpdateForwardingPath(String serviceId, Service serviceUpdate, User user, boolean isUpdate, String errorContext, boolean lock) {
validateUserAndRole(serviceUpdate, user, errorContext);
Map<String, ForwardingPathDataDefinition> forwardingPaths = serviceUpdate.getForwardingPaths();
@@ -1173,83 +1133,80 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
forwardingPaths.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
entry -> new ForwardingPathDataDefinition(getTrimmedValues(entry.getValue()))));
- Either<Boolean, ResponseFormat> booleanResponseFormatEither = forwardingPathValidator.validateForwardingPaths(trimmedForwardingPaths.values(),
+ forwardingPathValidator.validateForwardingPaths(trimmedForwardingPaths.values(),
serviceId, isUpdate);
- if(booleanResponseFormatEither.isRight()){
- return Either.right(booleanResponseFormatEither.right().value());
- }
Either<Service, StorageOperationStatus> serviceStorageOperationStatusEither = toscaOperationFacade.getToscaElement(serviceId);
if(serviceStorageOperationStatusEither.isRight()){
StorageOperationStatus errorStatus = serviceStorageOperationStatusEither.right().value();
log.debug("Failed to fetch service information by service id, error {}", errorStatus);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(errorStatus));
}
Service storedService = serviceStorageOperationStatusEither.left().value();
Either<ForwardingPathDataDefinition, StorageOperationStatus> result;
- Either<Component, StorageOperationStatus> forwardingPathOrigin = toscaOperationFacade.getLatestByName(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME);
- if (forwardingPathOrigin.isRight()) {
- StorageOperationStatus errorStatus = forwardingPathOrigin.right().value();
- log.debug("Failed to fetch normative forwarding path resource by tosca name, error {}", errorStatus);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
- }
- Component component = forwardingPathOrigin.left().value();
+ Component component = getForwardingPathOriginComponent();
final String toscaResourceName;
if ( component.getComponentType() == ComponentTypeEnum.RESOURCE) {
toscaResourceName = ((Resource) component).getToscaResourceName();
} else {
toscaResourceName = "";
}
- Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- lockResult =
- lockComponent(storedService.getUniqueId(), storedService, "Add or Update Forwarding Path on Service");
- if (lockResult.isRight()) {
- log.debug(FAILED_TO_LOCK_SERVICE_RESPONSE_IS, storedService.getName(),
- lockResult.right().value().getFormattedMessage());
- return Either.right(lockResult.right().value());
- } else {
- log.debug(THE_SERVICE_WITH_SYSTEM_NAME_LOCKED, storedService.getSystemName());
- }
+ lockComponent(storedService.getUniqueId(), storedService, "Add or Update Forwarding Path on Service");
+ log.debug(THE_SERVICE_WITH_SYSTEM_NAME_LOCKED, storedService.getSystemName());
}
Map<String, ForwardingPathDataDefinition> resultMap = new HashMap<>();
try {
trimmedForwardingPaths.values().forEach(fp -> fp.setToscaResourceName(toscaResourceName));
- try {
- for (ForwardingPathDataDefinition forwardingPathDataDefinition : trimmedForwardingPaths.values()) {
- if (isUpdate) {
- result = forwardingPathOperation.updateForwardingPath(serviceId, forwardingPathDataDefinition);
- } else {
- result = forwardingPathOperation.addForwardingPath(serviceId, forwardingPathDataDefinition);
- }
- if (result.isRight()) {
- janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(result.right().value(), ComponentTypeEnum.SERVICE),
- ""));
- } else {
- ForwardingPathDataDefinition fpDataDefinition = result.left().value();
- resultMap.put(fpDataDefinition.getUniqueId(), forwardingPathDataDefinition);
- }
- }
-
- } catch (Exception e) {
- janusGraphDao.rollback();
- log.error("Exception occurred during add or update forwarding path property values: {}", e.getMessage(),
- e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
+ populateForwardingPaths(serviceId, isUpdate, trimmedForwardingPaths, resultMap);
janusGraphDao.commit();
} finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ if (lock) {
graphLockOperation.unlockComponent(storedService.getUniqueId(), NodeTypeEnum.Service);
}
}
- Service service = createServiceWithForwardingPathForResponse(serviceId, resultMap);
- return Either.left(service);
+ return createServiceWithForwardingPathForResponse(serviceId, resultMap);
+ }
+
+ private Component getForwardingPathOriginComponent() {
+ Either<Component, StorageOperationStatus> forwardingPathOrigin = toscaOperationFacade.getLatestByName(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME);
+ if (forwardingPathOrigin.isRight()) {
+ StorageOperationStatus errorStatus = forwardingPathOrigin.right().value();
+ log.debug("Failed to fetch normative forwarding path resource by tosca name, error {}", errorStatus);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(errorStatus));
+ }
+ return forwardingPathOrigin.left().value();
+ }
+
+ private void populateForwardingPaths(String serviceId, boolean isUpdate, Map<String, ForwardingPathDataDefinition> trimmedForwardingPaths, Map<String, ForwardingPathDataDefinition> resultMap) {
+ Either<ForwardingPathDataDefinition, StorageOperationStatus> result;
+ try {
+ for (ForwardingPathDataDefinition forwardingPathDataDefinition : trimmedForwardingPaths.values()) {
+ if (isUpdate) {
+ result = forwardingPathOperation.updateForwardingPath(serviceId, forwardingPathDataDefinition);
+ } else {
+ result = forwardingPathOperation.addForwardingPath(serviceId, forwardingPathDataDefinition);
+ }
+ if (result.isRight()) {
+ janusGraphDao.rollback();
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
+ componentsUtils.convertFromStorageResponse(result.right().value(), ComponentTypeEnum.SERVICE),
+ ""));
+ } else {
+ ForwardingPathDataDefinition fpDataDefinition = result.left().value();
+ resultMap.put(fpDataDefinition.getUniqueId(), forwardingPathDataDefinition);
+ }
+ }
+
+ } catch (ComponentException e) {
+ janusGraphDao.rollback();
+ log.error("Exception occurred during add or update forwarding path property values: {}",
+ e.getMessage(), e);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
}
private Service createServiceWithForwardingPathForResponse(String serviceId, Map<String,ForwardingPathDataDefinition> forwardingPathDataDefinitionMap) {
@@ -1324,6 +1281,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
verifyValuesAreIdentical(serviceUpdate.getUUID(), currentService.getUUID(), "uuid");
validateAndUpdateServiceType(currentService, serviceUpdate);
+ validateAndUpdateServiceFunction(currentService, serviceUpdate);
response = validateAndUpdateServiceRole(user, currentService, serviceUpdate, UPDATE_SERVICE_METADATA);
if (response.isRight()) {
@@ -1363,7 +1321,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
currentService.setEcompGeneratedNaming(isEcompGeneratedUpdate);
}
String namingPolicyUpdate = serviceUpdate.getNamingPolicy();
- if (currentService.isEcompGeneratedNaming()) {
+ if (currentService.isEcompGeneratedNaming() != null && currentService.isEcompGeneratedNaming()) {
currentService.setNamingPolicy(namingPolicyUpdate);
} else {
if (!StringUtils.isEmpty(namingPolicyUpdate)) {
@@ -1377,7 +1335,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
String contactIdUpdated = serviceUpdate.getContactId();
String contactIdCurrent = currentService.getContactId();
if (!contactIdCurrent.equals(contactIdUpdated)) {
- validateContactId(user, serviceUpdate, audatingAction);
+ componentContactIdValidator.validateAndCorrectField(user, serviceUpdate, audatingAction);
currentService.setContactId(contactIdUpdated.toLowerCase());
}
return Either.left(true);
@@ -1393,7 +1351,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
if (!(tagsCurrent.containsAll(tagsUpdated) && tagsUpdated.containsAll(tagsCurrent))) {
- validateTagsListAndRemoveDuplicates(user, serviceUpdate, audatingAction);
+ componentTagsValidator.validateAndCorrectField(user, serviceUpdate, audatingAction);
currentService.setTags(tagsUpdated);
}
return Either.left(true);
@@ -1403,7 +1361,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
String descriptionUpdated = serviceUpdate.getDescription();
String descriptionCurrent = currentService.getDescription();
if (!descriptionCurrent.equals(descriptionUpdated)) {
- validateDescriptionAndCleanup(user, serviceUpdate, audatingAction);
+ componentDescriptionValidator.validateAndCorrectField(user, serviceUpdate, audatingAction);
currentService.setDescription(serviceUpdate.getDescription());
}
return Either.left(true);
@@ -1412,11 +1370,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private Either<Boolean, ResponseFormat> validateAndUpdateProjectCode(User user, Service currentService, Service serviceUpdate, AuditingActionEnum audatingAction) {
String projectCodeUpdated = serviceUpdate.getProjectCode();
String projectCodeCurrent = currentService.getProjectCode();
- if (!projectCodeCurrent.equals(projectCodeUpdated)) {
+ if (StringUtils.isEmpty(projectCodeCurrent)
+ || !projectCodeCurrent.equals(projectCodeUpdated)) {
- Either<Boolean, ResponseFormat> validatProjectCodeResponse = validateProjectCode(user, serviceUpdate, audatingAction);
- if (validatProjectCodeResponse.isRight()) {
- ResponseFormat errorRespons = validatProjectCodeResponse.right().value();
+ try {
+ componentProjectCodeValidator.validateAndCorrectField(user, serviceUpdate, audatingAction);
+ } catch (ComponentException exp) {
+ ResponseFormat errorRespons = exp.getResponseFormat();
return Either.right(errorRespons);
}
currentService.setProjectCode(projectCodeUpdated);
@@ -1430,7 +1390,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
String iconCurrent = currentService.getIcon();
if (!iconCurrent.equals(iconUpdated)) {
if (!hasBeenCertified) {
- validateIcon(user, serviceUpdate, audatingAction);
+ componentIconValidator.validateAndCorrectField(user, serviceUpdate, audatingAction);
currentService.setIcon(iconUpdated);
} else {
log.info("icon {} cannot be updated once the service has been certified once.", iconUpdated);
@@ -1446,10 +1406,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
String serviceNameCurrent = currentService.getName();
if (!serviceNameCurrent.equals(serviceNameUpdated)) {
if (!hasBeenCertified) {
- validateComponentName(user, serviceUpdate, auditingAction);
- Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, serviceUpdate, auditingAction);
- if (serviceNameUniquenessValidation.isRight()) {
- return serviceNameUniquenessValidation;
+ componentNameValidator.validateAndCorrectField(user, serviceUpdate, auditingAction);
+ try {
+ componentNameValidator.validateComponentNameUnique(user, serviceUpdate, auditingAction);
+ } catch (ComponentException exp) {
+ return Either.right(exp.getResponseFormat());
}
currentService.setName(serviceNameUpdated);
currentService.getComponentMetadataDefinition().getMetadataDataDefinition().setNormalizedName(ValidationUtils.normaliseComponentName(serviceNameUpdated));
@@ -1468,34 +1429,17 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
String updatedServiceType = updatedService.getServiceType();
String currentServiceType = currentService.getServiceType();
if (!currentServiceType.equals(updatedServiceType)) {
- validateServiceTypeAndCleanup(updatedService);
+ serviceTypeValidator.validateAndCorrectField(null, updatedService, null);
currentService.setServiceType(updatedServiceType);
}
}
- private void validateServiceTypeAndCleanup(Component component) {
- log.debug("validate service type");
- String serviceType = ((Service)component).getServiceType();
- if (serviceType == null) {
- log.info("service type is not valid.");
- throw new ByActionStatusComponentException(ActionStatus.INVALID_SERVICE_TYPE);
- }
- serviceType = cleanUpText(serviceType);
- validateServiceType(serviceType);
- }
-
-
- private void validateServiceType(String serviceType) {
- if (serviceType.isEmpty()) {
- return;
- }
- if (!ValidationUtils.validateServiceTypeLength(serviceType)) {
- log.info("service type exceeds limit.");
- throw new ByActionStatusComponentException(ActionStatus.SERVICE_TYPE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_TYPE_MAX_LENGTH);
- }
- if (!ValidationUtils.validateIsEnglish(serviceType)) {
- log.info("service type is not valid.");
- throw new ByActionStatusComponentException(ActionStatus.INVALID_SERVICE_TYPE);
+ private void validateAndUpdateServiceFunction(Service currentService, Service updatedService) {
+ String updatedServiceFunction = updatedService.getServiceFunction();
+ String currentServiceFunction = currentService.getServiceFunction();
+ if (!currentServiceFunction.equals(updatedServiceFunction)) {
+ serviceFunctionValidator.validateAndCorrectField(null, updatedService, null);
+ currentService.setServiceFunction(updatedService.getServiceFunction());
}
}
@@ -1503,9 +1447,10 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
String updatedServiceRole = updatedService.getServiceRole();
String currentServiceRole = currentService.getServiceRole();
if (!currentServiceRole.equals(updatedServiceRole)) {
- Either<Boolean, ResponseFormat> validateServiceRole = validateServiceRoleAndCleanup(user, updatedService , auditingAction);
- if (validateServiceRole.isRight()) {
- ResponseFormat errorResponse = validateServiceRole.right().value();
+ try {
+ serviceRoleValidator.validateAndCorrectField(user, updatedService, auditingAction);
+ } catch (ComponentException exp) {
+ ResponseFormat errorResponse = exp.getResponseFormat();
componentsUtils.auditComponentAdmin(errorResponse, user, updatedService, auditingAction, ComponentTypeEnum.SERVICE);
return Either.right(errorResponse);
}
@@ -1514,31 +1459,14 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.left(true);
}
- protected Either<Boolean, ResponseFormat> validateServiceRoleAndCleanup(User user, Component component, AuditingActionEnum actionEnum) {
- log.debug("validate service role");
- String serviceRole = ((Service)component).getServiceRole();
- if (serviceRole != null){
- serviceRole = cleanUpText(serviceRole);
-
- Either<Boolean, ResponseFormat> validateServiceRole = validateServiceRole(serviceRole);
- if (validateServiceRole.isRight()) {
- ResponseFormat responseFormat = validateServiceRole.right().value();
- componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, ComponentTypeEnum.SERVICE);
- return Either.right(responseFormat);
- }
- return Either.left(true);
- } else {
- return Either.left(false);
- }
- }
-
private Either<Boolean, ResponseFormat> validateAndUpdateInstantiationTypeValue(User user, Service currentService, Service updatedService, AuditingActionEnum auditingAction) {
String updatedInstaType= updatedService.getInstantiationType();
String currentInstaType = currentService.getInstantiationType();
if (!currentInstaType.equals(updatedInstaType)) {
- Either<Boolean, ResponseFormat> validateInstantiationType = validateInstantiationTypeValue(user, updatedService , auditingAction);
- if (validateInstantiationType.isRight()) {
- ResponseFormat errorResponse = validateInstantiationType.right().value();
+ try {
+ serviceInstantiationTypeValidator.validateAndCorrectField(user, updatedService, auditingAction);
+ } catch (ComponentException exp) {
+ ResponseFormat errorResponse = exp.getResponseFormat();
componentsUtils.auditComponentAdmin(errorResponse, user, updatedService, auditingAction, ComponentTypeEnum.SERVICE);
return Either.right(errorResponse);
}
@@ -1547,95 +1475,27 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validateInstantiationTypeValue(User user, Service service, AuditingActionEnum actionEnum) {
- log.debug("validate instantiation type");
- String instantiationType = service.getInstantiationType();
- if (!InstantiationTypes.containsName(instantiationType) || instantiationType == null){
- log.error("Recieved Instantiation type {} is not valid.", instantiationType);
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_INSTANTIATION_TYPE);
- componentsUtils.auditComponentAdmin(errorResponse, user, service, actionEnum, ComponentTypeEnum.SERVICE);
- return Either.right(errorResponse);
- }
- return Either.left(true);
- }
-
- private Either<Boolean, ResponseFormat> validateServiceRole(String serviceRole) {
- if (serviceRole.equals("")){
- return Either.left(true);
- } else {
- if (!ValidationUtils.validateServiceRoleLength(serviceRole)) {
- log.info("service role exceeds limit.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_ROLE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_ROLE_MAX_LENGTH);
- return Either.right(errorResponse);
- }
-
- if (!ValidationUtils.validateIsEnglish(serviceRole)) {
- log.info("service role is not valid.");
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_SERVICE_ROLE);
- return Either.right(errorResponse);
- }
- return Either.left(true);
- }
- }
-
private Either<Boolean, ResponseFormat> validateAndUpdateCategory(User user, Service currentService, Service serviceUpdate, boolean hasBeenCertified, AuditingActionEnum audatingAction) {
- List<CategoryDefinition> categoryUpdated = serviceUpdate.getCategories();
- List<CategoryDefinition> categoryCurrent = currentService.getCategories();
- Either<Boolean, ResponseFormat> validateCategoryResponse = validateServiceCategory(user, serviceUpdate, audatingAction);
- if (validateCategoryResponse.isRight()) {
- return Either.right(validateCategoryResponse.right().value());
- }
- if (!categoryCurrent.get(0).getName().equals(categoryUpdated.get(0).getName())) {
- if (!hasBeenCertified) {
- currentService.setCategories(categoryUpdated);
- } else {
- log.info("category {} cannot be updated once the service has been certified once.", categoryUpdated);
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CATEGORY_CANNOT_BE_CHANGED);
- return Either.right(errorResponse);
+ try {
+ List<CategoryDefinition> categoryUpdated = serviceUpdate.getCategories();
+ List<CategoryDefinition> categoryCurrent = currentService.getCategories();
+ serviceCategoryValidator.validateAndCorrectField(user, serviceUpdate, audatingAction);
+ if (!categoryCurrent.get(0).getName().equals(categoryUpdated.get(0).getName())) {
+ if (!hasBeenCertified) {
+ currentService.setCategories(categoryUpdated);
+ } else {
+ log.info("category {} cannot be updated once the service has been certified once.", categoryUpdated);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CATEGORY_CANNOT_BE_CHANGED);
+ return Either.right(errorResponse);
+ }
}
+ } catch (ComponentException exp) {
+ return Either.right(exp.getResponseFormat());
}
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> validateServiceCategory(List<CategoryDefinition> list) {
- if (list != null) {
- if (list.size() > 1) {
- log.debug("Must be only one category for service");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.SERVICE.getValue());
- return Either.right(responseFormat);
- }
- CategoryDefinition category = list.get(0);
- if (category.getSubcategories() != null) {
- log.debug("Subcategories cannot be defined for service");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CANNOT_CONTAIN_SUBCATEGORY);
- return Either.right(responseFormat);
- }
- if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
- log.debug("Resource category is empty");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
- return Either.right(responseFormat);
- }
-
- log.debug("validating service category {} against valid categories list", list);
- Either<List<CategoryDefinition>, ActionStatus> categorys = elementDao.getAllServiceCategories();
- if (categorys.isRight()) {
- log.debug("failed to retrieve service categories from JanusGraph");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(categorys.right().value());
- return Either.right(responseFormat);
- }
- List<CategoryDefinition> categoryList = categorys.left().value();
- for (CategoryDefinition value : categoryList) {
- if (value.getName().equals(category.getName())) {
- return Either.left(true);
- }
- }
- log.debug("Category {} is not part of service category group. Service category valid values are {}", list, categoryList);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue()));
- }
- return Either.left(false);
- }
-
public Either<ServiceRelations, ResponseFormat> getServiceComponentsRelations(String serviceId, User user) {
Either<Service, ResponseFormat> serviceResponseFormatEither = getService(serviceId, user);
if (serviceResponseFormatEither.isRight()){
@@ -1649,9 +1509,8 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
public ResponseFormat deleteService(String serviceId, User user) {
ResponseFormat responseFormat;
- String ecompErrorContext = "delete service";
- validateUserExists(user, ecompErrorContext, false);
+ validateUserExists(user);
Either<Service, StorageOperationStatus> serviceStatus = toscaOperationFacade.getToscaElement(serviceId);
if (serviceStatus.isRight()) {
log.debug("failed to get service {}", serviceId);
@@ -1661,21 +1520,20 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
Service service = serviceStatus.left().value();
StorageOperationStatus result = StorageOperationStatus.OK;
- Either<Boolean, ResponseFormat> lockResult = lockComponent(service, "Mark service to delete");
- if (lockResult.isRight()) {
- return lockResult.right().value();
- }
try {
+ lockComponent(service, "Mark service to delete");
result = markComponentToDelete(service);
- if (result.equals(StorageOperationStatus.OK)) {
+ if (result == StorageOperationStatus.OK) {
responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
} else {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
responseFormat = componentsUtils.getResponseFormatByResource(actionStatus, service.getName());
}
return responseFormat;
- } finally {
- if (result == null || !result.equals(StorageOperationStatus.OK)) {
+ }catch (ComponentException e){
+ return e.getResponseFormat();
+ }finally {
+ if (result == null || result != StorageOperationStatus.OK) {
log.warn("operation failed. do rollback");
BeEcompErrorManager.getInstance().logBeSystemError("Delete Service");
janusGraphDao.rollback();
@@ -1691,7 +1549,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
ResponseFormat responseFormat;
String ecompErrorContext = "delete service";
validateUserNotEmpty(user, ecompErrorContext);
- user = validateUserExists(user, ecompErrorContext, false);
+ user = validateUserExists(user);
Either<Service, ResponseFormat> getResult = getServiceByNameAndVersion(serviceName, version, user.getUserId());
if (getResult.isRight()) {
@@ -1700,15 +1558,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
Service service = getResult.left().value();
StorageOperationStatus result = StorageOperationStatus.OK;
- Either<Boolean, ResponseFormat> lockResult = lockComponent(service, "Mark service to delete");
- if (lockResult.isRight()) {
- result = StorageOperationStatus.GENERAL_ERROR;
- return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- }
try {
+ lockComponent(service, "Mark service to delete");
result = markComponentToDelete(service);
- if (result.equals(StorageOperationStatus.OK)) {
+ if (result == StorageOperationStatus.OK) {
responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
} else {
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(result);
@@ -1716,8 +1570,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
return responseFormat;
- } finally {
- if (result == null || !result.equals(StorageOperationStatus.OK)) {
+ }catch (ComponentException e){
+ result = StorageOperationStatus.GENERAL_ERROR;
+ return componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }finally {
+ if (result == null || result != StorageOperationStatus.OK) {
log.warn("operation failed. do rollback");
BeEcompErrorManager.getInstance().logBeSystemError("Delete Service");
janusGraphDao.rollback();
@@ -1732,7 +1589,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
public Either<Service, ResponseFormat> getService(String serviceId, User user) {
String ecompErrorContext = "Get service";
validateUserNotEmpty(user, ecompErrorContext);
- validateUserExists(user, ecompErrorContext, false);
+ validateUserExists(user);
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
if (storageStatus.isRight()) {
@@ -1752,7 +1609,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
public Either<Service, ResponseFormat> getServiceByNameAndVersion(String serviceName, String serviceVersion, String userId) {
- validateUserExists(userId, "get Service By Name And Version", false);
+ validateUserExists(userId);
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getComponentByNameAndVersion(ComponentTypeEnum.SERVICE, serviceName, serviceVersion);
if (storageStatus.isRight()) {
log.debug("failed to get service by name {} and version {}", serviceName, serviceVersion);
@@ -1812,28 +1669,24 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return artifactInfo;
}
- private Either<DistributionTransitionEnum, ResponseFormat> validateTransitionEnum(String distributionTransition) {
- DistributionTransitionEnum transitionEnum = null;
+ private DistributionTransitionEnum validateTransitionEnum(String distributionTransition) {
+ DistributionTransitionEnum transitionEnum;
transitionEnum = DistributionTransitionEnum.getFromDisplayName(distributionTransition);
if (transitionEnum == null) {
BeEcompErrorManager.getInstance().logBeSystemError(CHANGE_SERVICE_DISTRIBUTION);
log.info("state operation is not valid. operations allowed are: {}", DistributionTransitionEnum.valuesAsString());
- ResponseFormat error = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- return Either.right(error);
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_DISTRIBUTION_STATUS, distributionTransition));
}
- return Either.left(transitionEnum);
+ return transitionEnum;
}
- private Either<String, ResponseFormat> validateComment(LifecycleChangeInfoWithAction comment) {
- String data = comment.getUserRemarks();
-
- if (data == null || data.trim().isEmpty()) {
- BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CHANGE_SERVICE_DISTRIBUTION);
- log.debug("user comment cannot be empty or null.");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ private String validateComment(LifecycleChangeInfoWithAction comment) {
+ if (comment==null || StringUtils.isEmpty(comment.getUserRemarks())) {
+ return "";
}
+ String data = comment.getUserRemarks();
data = ValidationUtils.removeNoneUtf8Chars(data);
data = ValidationUtils.removeHtmlTags(data);
data = ValidationUtils.normaliseWhitespace(data);
@@ -1842,45 +1695,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
if (!ValidationUtils.validateLength(data, ValidationUtils.COMMENT_MAX_LENGTH)) {
BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CHANGE_SERVICE_DISTRIBUTION);
log.debug("user comment exceeds limit.");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, "comment", String.valueOf(ValidationUtils.COMMENT_MAX_LENGTH)));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, "comment", String.valueOf(ValidationUtils.COMMENT_MAX_LENGTH)));
}
- if (!ValidationUtils.validateIsEnglish(data)) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- return Either.left(data);
- }
-
- private Either<Service, ResponseFormat> validateServiceDistributionChange(User user, String serviceId, AuditingActionEnum auditAction, String comment) {
- Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
- if (storageStatus.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_FOUND, serviceId);
- log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
- componentsUtils.auditComponent(responseFormat, user, auditAction, new ResourceCommonInfo(serviceId, ComponentTypeEnum.SERVICE.getValue()), comment);
- return Either.right(responseFormat);
+ if (!ValidationUtils.validateCommentPattern(data)) {
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
- Service service = storageStatus.left().value();
- if (service.getLifecycleState() != LifecycleStateEnum.CERTIFIED) {
- log.info("service {} is not available for distribution. Should be in certified state", service.getUniqueId());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_AVAILABLE_FOR_DISTRIBUTION, service.getVersion(), service.getName());
- createAudit(user, auditAction, comment, service, responseFormat);
- return Either.right(responseFormat);
- }
- return Either.left(service);
- }
-
- private Either<User, ResponseFormat> validateUserDistributionChange(User user, Service service, AuditingActionEnum auditAction, String comment) {
- log.debug("get user from DB");
-
- // get user details
- user = validateUser(user, "Activate Distribution", service, auditAction, false);
- // validate user role
- List<Role> roles = new ArrayList<>();
- roles.add(Role.ADMIN);
- roles.add(Role.GOVERNOR);
- roles.add(Role.OPS);
- validateUserRole(user, service, roles, auditAction, comment);
- return Either.left(user);
+ return data;
}
private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component, ResponseFormat responseFormat) {
@@ -1931,10 +1752,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
public Either<Service, ResponseFormat> activateDistribution(String serviceId, String envName, User modifier, HttpServletRequest request) {
- User user = validateUserExists(modifier.getUserId(), "activate Distribution", false);
- Either<Service, ResponseFormat> result = null;
- ResponseFormat response = null;
- Service updatedService = null;
+ User user = validateUserExists(modifier.getUserId());
+ validateUserRole(user, Collections.singletonList(Role.DESIGNER));
+ Either<Service, ResponseFormat> result;
+ ResponseFormat response;
+ Service updatedService;
String did = ThreadLocalsHolder.getUuid();
// DE194021
String configuredEnvName = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getEnvironments().get(0);
@@ -1965,10 +1787,19 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.right(response);
}
Service service = serviceRes.left().value();
+ if (service.isArchived()) {
+ log.info("Component is archived. Component id: {}", serviceId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_IS_ARCHIVED, service.getName()));
+ }
+ if (service.getLifecycleState() != LifecycleStateEnum.CERTIFIED) {
+ log.info("service {} is not available for distribution. Should be in certified state", service.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_AVAILABLE_FOR_DISTRIBUTION, service.getVersion(), service.getName());
+ return Either.right(responseFormat);
+ }
String dcurrStatus = service.getDistributionStatus().name();
String updatedStatus = dcurrStatus;
StorageOperationStatus readyForDistribution = distributionEngine.isReadyForDistribution(envName);
- if (readyForDistribution.equals(StorageOperationStatus.OK)) {
+ if (readyForDistribution == StorageOperationStatus.OK) {
INotificationData notificationData = distributionEngine.buildServiceForDistribution(service, did, null);
ActionStatus notifyServiceResponse = distributionEngine.notifyService(did, service, notificationData, envName, user);
if (notifyServiceResponse == ActionStatus.OK) {
@@ -1990,7 +1821,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
result = Either.right(response);
}
} else {
- response = componentsUtils.getResponseFormatByDE(componentsUtils.convertFromStorageResponse(readyForDistribution), envName);
+ response = componentsUtils.getResponseFormatByDE(componentsUtils.convertFromStorageResponse(readyForDistribution, ComponentTypeEnum.SERVICE), envName);
result = Either.right(response);
}
componentsUtils.auditComponent(response, user, service, AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST,
@@ -2008,13 +1839,10 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
// convert to private after deletion of temp url
public Either<Service, ResponseFormat> updateDistributionStatusForActivation(Service service, User user, DistributionStatusEnum state) {
- validateUserExists(user.getUserId(), "update Distribution Status For Activation", false);
+ validateUserExists(user.getUserId());
String serviceId = service.getUniqueId();
- Either<Boolean, ResponseFormat> lockResult = lockComponent(serviceId, service, "updateDistributionStatusForActivation");
- if (lockResult.isRight()) {
- return Either.right(lockResult.right().value());
- }
+ lockComponent(serviceId, service, "updateDistributionStatusForActivation");
try {
Either<Service, StorageOperationStatus> result = toscaOperationFacade.updateDistributionStatus(service, user, state);
if (result.isRight()) {
@@ -2024,6 +1852,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
janusGraphDao.commit();
+ updateCatalog(service, ChangeTypeEnum.LIFECYCLE);
return Either.left(result.left().value());
} finally {
graphLockOperation.unlockComponent(serviceId, NodeTypeEnum.Service);
@@ -2032,7 +1861,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
public Either<Service, ResponseFormat> markDistributionAsDeployed(String serviceId, String did, User user) {
- validateUserExists(user.getUserId(), "mark Distribution As Deployed", false);
+ validateUserExists(user.getUserId());
log.debug("mark distribution deployed");
AuditingActionEnum auditAction = AuditingActionEnum.DISTRIBUTION_DEPLOY;
@@ -2172,13 +2001,14 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
vfModuleArtifactDefinition.setArtifactChecksum(newCheckSum);
- Either<ArtifactDefinition, StorageOperationStatus> addArifactToComponent = artifactToscaOperation.addArifactToComponent(vfModuleArtifactDefinition, service.getUniqueId(), NodeTypeEnum.ResourceInstance, true, currVF.getUniqueId());
+ Either<ArtifactDefinition, StorageOperationStatus> addArtifactToComponent = artifactToscaOperation.addArtifactToComponent(
+ vfModuleArtifactDefinition, service, NodeTypeEnum.ResourceInstance, true, currVF.getUniqueId());
Either<ArtifactDefinition, ResponseFormat> result;
- if (addArifactToComponent.isLeft()) {
- result = Either.left(addArifactToComponent.left().value());
+ if (addArtifactToComponent.isLeft()) {
+ result = Either.left(addArtifactToComponent.left().value());
} else {
- result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArifactToComponent.right().value())));
+ result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtifactToComponent.right().value())));
}
return result;
@@ -2205,19 +2035,8 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
if (service.getComponentInstances() != null) {
List<ArtifactGenerator<CallVal>> artifactGenList = service.getComponentInstances().stream().flatMap(ri -> artifactTaskGeneratorCreator.apply(ri).stream()).collect(Collectors.toList());
if (artifactGenList != null && !artifactGenList.isEmpty()) {
- for (ArtifactGenerator<CallVal> entry : artifactGenList) {
- Either<CallVal, ResponseFormat> callRes;
- try {
- callRes = entry.call();
- if (callRes.isRight()) {
- log.debug("Failed to generate artifact error : {}", callRes.right().value());
- return Either.right(callRes.right().value());
- }
- } catch (Exception e) {
- log.debug("Failed to generate artifact exception : {}", e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
+ Either<Service, ResponseFormat> callRes = checkDeploymentArtifact(artifactGenList);
+ if (callRes != null) return callRes;
}
}
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaFullElement(service.getUniqueId());
@@ -2231,6 +2050,23 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
+ private <CallVal> Either<Service, ResponseFormat> checkDeploymentArtifact(List<ArtifactGenerator<CallVal>> artifactGenList) {
+ for (ArtifactGenerator<CallVal> entry : artifactGenList) {
+ Either<CallVal, ResponseFormat> callRes;
+ try {
+ callRes = entry.call();
+ if (callRes.isRight()) {
+ log.debug("Failed to generate artifact error : {}", callRes.right().value());
+ return Either.right(callRes.right().value());
+ }
+ } catch (Exception e) {
+ log.debug("Failed to generate artifact exception : {}", e);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+ return null;
+ }
+
abstract class ArtifactGenerator<CallVal> implements Callable<Either<CallVal, ResponseFormat>> {
}
@@ -2388,19 +2224,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
private User validateRoleForDeploy(String did, User user, AuditingActionEnum auditAction, Service service) {
- Either<User, ActionStatus> eitherCreator = userAdmin.getUser(user.getUserId(), false);
- if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
- BeEcompErrorManager.getInstance().logBeUserMissingError("Deploy Service", user.getUserId());
- log.debug("validateRoleForDeploy method - user is not listed. userId= {}", user.getUserId());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, user.getUserId());
- auditDeployError(did, user, auditAction, service, ActionStatus.USER_NOT_FOUND);
- throw new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND, user.getUserId());
- }
- user = eitherCreator.left().value();
+ user = userAdmin.getUser(user.getUserId());
log.debug("validate user role");
List<Role> roles = new ArrayList<>();
roles.add(Role.ADMIN);
- roles.add(Role.OPS);
+ roles.add(Role.DESIGNER);
try{
validateUserRole(user, service, roles, auditAction, null);
} catch (ByActionStatusComponentException e){
@@ -2440,7 +2268,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
@Override
public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, String userId) {
- validateUserExists(userId, "Get Component Instances", false);
+ validateUserExists(userId);
Either<Component, StorageOperationStatus> getComponentRes = toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll);
if (getComponentRes.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getComponentRes.right().value()));
@@ -2566,7 +2394,6 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
private Either<ImmutablePair<Component, User>, ResponseFormat> validateUserAndComponent(String serviceId, User modifier) {
Either<ImmutablePair<Component, User>, ResponseFormat> result = null;
- Either<Component, ResponseFormat> validateComponentExistsRes = null;
User currUser = null;
Component component = null;
Either<User, ResponseFormat> validationUserResult = validateUserIgnoreAudit(modifier, "updateGroupInstancePropertyValues");
@@ -2576,19 +2403,18 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
if (result == null) {
currUser = validationUserResult.left().value();
- validateComponentExistsRes = validateComponentExists(serviceId, ComponentTypeEnum.SERVICE, null);
- if (validateComponentExistsRes.isRight()) {
+ try {
+ component = validateComponentExists(serviceId, ComponentTypeEnum.SERVICE, null);
+ if (!ComponentValidationUtils.canWorkOnComponent(component, currUser.getUserId())) {
+ log.info("#validateUserAndComponent - Restricted operation for user: {}, on service: {}", currUser.getUserId(), component.getCreatorUserId());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ }
+ } catch (ComponentException e) {
log.debug("#validateUserAndComponent - Failed to validate service existing {}. ", serviceId);
- result = Either.right(validateComponentExistsRes.right().value());
- }
- }
- if (result == null) {
- component = validateComponentExistsRes.left().value();
- if (!ComponentValidationUtils.canWorkOnComponent(component, currUser.getUserId())) {
- log.info("#validateUserAndComponent - Restricted operation for user: {}, on service: {}", currUser.getUserId(), component.getCreatorUserId());
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ result = Either.right(e.getResponseFormat());
}
}
+
if (result == null) {
result = Either.left(new ImmutablePair<>(component, currUser));
}
@@ -2641,7 +2467,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
Either<Service, StorageOperationStatus> serviceResultEither = toscaOperationFacade.getToscaElement(serviceId, paramsToReturn);
if (serviceResultEither.isRight()) {
- if(serviceResultEither.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
+ if(serviceResultEither.right().value() == StorageOperationStatus.NOT_FOUND) {
log.debug("#getUiComponentDataTransferByComponentId - Failed to find service with id {} ", serviceId);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.SERVICE_NOT_FOUND, serviceId));
}
@@ -2661,11 +2487,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
public Either<String, ResponseFormat> deleteIfNotAlreadyDeletedServiceFilter(String serviceId, String resourceId, String userId, boolean lock) {
- Service serviceToDelete = initServiceToDeleteServiceFilter(serviceId);
- User user = validateUserExists(userId, "Create service Filter", false);
-
- user =
- validateUser(user, "deleteIfNotAlreadyDeletedServiceFilter", serviceToDelete, null, false);
+ validateUserExists(userId);
Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
if (storageStatus.isRight()) {
@@ -2687,15 +2509,10 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
Either<String, StorageOperationStatus> result;
- if (lock) {
- Either<Boolean, ResponseFormat> lockResult = lockComponent(service.getUniqueId(), service, "Delete Service Filter from service");
- if (lockResult.isRight()) {
- janusGraphDao.rollback();
- return Either.right(componentsUtils.getResponseFormat(componentsUtils
- .convertFromStorageResponse(storageStatus.right().value(), ComponentTypeEnum.SERVICE), ""));
- }
- }
try{
+ if (lock) {
+ lockComponent(service.getUniqueId(), service, "Delete Service Filter from service");
+ }
result = serviceFilterOperation.deleteNodeFilter(service , resourceId);
if (result.isRight()) {
log.debug("Failed to delete node filter in service {}. Response is {}. ", service.getName(), result.right().value());
@@ -2716,16 +2533,9 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
}
- private Service initServiceToDeleteServiceFilter(String serviceId) {
- Service serviceToDelete = new Service();
- serviceToDelete.setUniqueId(serviceId);
- return serviceToDelete;
- }
-
-
public Either<CINodeFilterDataDefinition, ResponseFormat> createIfNotAlreadyExistServiceFilter(String serviceId, String componentInstanceId, String userId, boolean lock) {
String errorContext = "createIfNotAlreadyExistServiceFilter";
- User user = validateUserExists(userId, "Create service Filter", false);
+ User user = validateUserExists(userId);
Either<Service, StorageOperationStatus> serviceEither = toscaOperationFacade.getToscaElement(serviceId);
if (serviceEither.isRight()) {
@@ -2743,21 +2553,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
if (serviceFilter != null){
return Either.left(serviceFilter);
}
-
- Either<CINodeFilterDataDefinition, StorageOperationStatus> result;
-
- Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- lockResult =
- lockComponent(service.getUniqueId(), service, "Create Service Filter");
- if (lockResult.isRight()) {
- log.debug("Failed to lock service {}. Response is {}. ", service.getName(),
- lockResult.right().value().getFormattedMessage());
- return Either.right(lockResult.right().value());
- } else {
- log.debug("The service with system name {} locked. ", service.getSystemName());
- }
+ lockComponent(service.getUniqueId(), service, "Create Service Filter");
}
+ Either<CINodeFilterDataDefinition, StorageOperationStatus> result;
+
CINodeFilterDataDefinition serviceFilterResult;
try {
result = serviceFilterOperation.createNodeFilter(serviceId, componentInstanceId);
@@ -2778,9 +2578,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
} finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
- graphLockOperation.unlockComponent(service.getUniqueId(), NodeTypeEnum.Service);
- }
+ graphLockOperation.unlockComponent(service.getUniqueId(), NodeTypeEnum.Service);
}
return Either.left(serviceFilterResult);
}
@@ -2788,8 +2586,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
public Either<CINodeFilterDataDefinition, ResponseFormat> updateServiceFilter(String serviceId, String componentInstanceId,
List<String> constraints, User inUser, boolean lock) {
- String errorContext = "createIfNotAlreadyExistServiceFilter";
- User user = validateUserExists(inUser, errorContext, true);
+ User user = validateUserExists(inUser.getUserId());
validateUserRole(user, Arrays.asList(Role.DESIGNER, Role.ADMIN));
Either<Service, StorageOperationStatus> serviceStorageOperationStatusEither = toscaOperationFacade.getToscaElement(serviceId);
@@ -2810,15 +2607,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
Either<Boolean, ResponseFormat> lockResult = null;
if (lock) {
- lockResult =
- lockComponent(storedService.getUniqueId(), storedService, "Add or Update Service Filter on Service");
- if (lockResult.isRight()) {
- log.debug("Failed to lock service {}. Response is {}. ", storedService.getName(),
- lockResult.right().value().getFormattedMessage());
- return Either.right(lockResult.right().value());
- } else {
- log.debug("The service with system name {} locked. ", storedService.getSystemName());
- }
+ lockComponent(storedService.getUniqueId(), storedService, "Add or Update Service Filter on Service");
}
Optional<ComponentInstance> componentInstanceOptional = storedService.getComponentInstanceById(componentInstanceId);
if (!componentInstanceOptional.isPresent()){
@@ -2865,8 +2654,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
public Either<CINodeFilterDataDefinition, ResponseFormat> addOrDeleteServiceFilter(String serviceId, String componentInstanceId,
NodeFilterConstraintAction action, String propertyName, String constraint, int position, User inUser, boolean lock) {
- String errorContext = "createIfNotAlreadyExistServiceFilter";
- User user = validateUserExists(inUser, errorContext, true);
+ User user = validateUserExists(inUser.getUserId());
validateUserRole(user, Arrays.asList(Role.DESIGNER, Role.ADMIN));
Either<Service, StorageOperationStatus> serviceStorageOperationStatusEither = toscaOperationFacade.getToscaElement(serviceId);
@@ -2891,24 +2679,16 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
CINodeFilterDataDefinition serviceFilterResult = null;
try {
if (lock) {
- lockResult =
- lockComponent(storedService.getUniqueId(), storedService, "Add or Update Service Filter on Service");
- if (lockResult.isRight()) {
- log.debug("Failed to lock service {}. Response is {}. ", storedService.getName(),
- lockResult.right().value().getFormattedMessage());
- return Either.right(lockResult.right().value());
- } else {
- log.debug("The service with system name {} locked. ", storedService.getSystemName());
- }
+ lockComponent(storedService.getUniqueId(), storedService, "Add or Update Service Filter on Service");
}
Optional<ComponentInstance> componentInstanceOptional = storedService.getComponentInstanceById(componentInstanceId);
- if (!componentInstanceOptional.isPresent()){
- return Either.right(ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND));
+ if (!componentInstanceOptional.isPresent()) {
+ return Either.right(ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND));
}
CINodeFilterDataDefinition serviceFilter = componentInstanceOptional.get().getNodeFilter();
- if(serviceFilter == null){
- return Either.right(ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND));
+ if (serviceFilter == null) {
+ return Either.right(ResponseFormatManager.getInstance().getResponseFormat(ActionStatus.NODE_FILTER_NOT_FOUND));
}
@@ -2917,13 +2697,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
RequirementNodeFilterPropertyDataDefinition newProperty = new RequirementNodeFilterPropertyDataDefinition();
newProperty.setName(propertyName);
newProperty.setConstraints(Collections.singletonList(constraint));
- result = serviceFilterOperation.addNewProperty(serviceId, componentInstanceId,serviceFilter,newProperty);
+ result = serviceFilterOperation.addNewProperty(serviceId, componentInstanceId, serviceFilter, newProperty);
break;
case DELETE:
result = serviceFilterOperation.deleteConstraint(serviceId, componentInstanceId, serviceFilter, position);
break;
default:
- log.error("Unsupported operation "+action);
+ log.error("Unsupported operation " + action);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java
index 3129befb8c..3605856994 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/SoftwareInformationBusinessLogic.java
@@ -19,23 +19,24 @@
package org.openecomp.sdc.be.components.impl;
-import static java.util.stream.Collectors.toList;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
-
-import java.util.List;
-import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.components.csar.CsarInfo;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.csar.pnf.PnfSoftwareInformation;
import org.openecomp.sdc.be.csar.pnf.PnfSoftwareVersion;
import org.openecomp.sdc.be.csar.pnf.SoftwareInformationArtifactYamlParser;
-import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import java.util.List;
+import java.util.Optional;
+
+import static java.util.stream.Collectors.toList;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
+
@Component("softwareInformationBusinessLogic")
public class SoftwareInformationBusinessLogic {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/AafPermission.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/AafPermission.java
new file mode 100644
index 0000000000..9c952415a3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/AafPermission.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.aaf;
+
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+
+public enum AafPermission {
+
+ READ(PermNames.READ_VALUE),
+ WRITE(PermNames.WRITE_VALUE),
+ DELETE(PermNames.DELETE_VALUE),
+ INTERNAL_ALL(PermNames.INTERNAL_ALL_VALUE);
+
+ private String permission;
+ private String permissionSuffix;
+
+ AafPermission(String permissionSuffix) {
+ this.permissionSuffix = permissionSuffix;
+ this.permission = String.format("%s.%s",
+ ConfigurationManager.getConfigurationManager().getConfiguration().getAafNamespace(),
+ permissionSuffix);
+ }
+
+ public String getFullPermission() {
+ return permission;
+ }
+
+ public static AafPermission getEnumByString(String perm) {
+ for (AafPermission e : AafPermission.values()) {
+ if (perm.equals(e.getPermissionSuffix()))
+ return e;
+ }
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, perm);
+ }
+
+ public String getPermissionSuffix() {
+ return this.permissionSuffix;
+ }
+
+ public static class PermNames {
+ public static final String READ_VALUE = "endpoint.api.access|*|read";
+ public static final String WRITE_VALUE = "endpoint.api.access|*|write";
+ public static final String DELETE_VALUE = "endpoint.api.access|*|delete";
+ public static final String INTERNAL_ALL_VALUE = "endpoint.api.internal.access|*|all";
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/AafRoles.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/AafRoles.java
new file mode 100644
index 0000000000..34ca5965a1
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/AafRoles.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.aaf;
+
+import org.openecomp.sdc.be.config.ConfigurationManager;
+
+public enum AafRoles {
+
+ READ_ONLY("app.readonly"),
+ ALL("app.all");
+
+ private String role;
+
+ AafRoles(String roleSuffix) {
+ this.role = ConfigurationManager.getConfigurationManager().getConfiguration().getAafNamespace() + "." + roleSuffix;
+ }
+
+ public String getRole() {
+ return role;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/PermissionAllowed.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/PermissionAllowed.java
new file mode 100644
index 0000000000..a963e5e533
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/PermissionAllowed.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.aaf;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface PermissionAllowed {
+ String[] value();
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/RoleAuthorizationHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/RoleAuthorizationHandler.java
new file mode 100644
index 0000000000..859872f5f3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/aaf/RoleAuthorizationHandler.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.aaf;
+
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.servlets.BeGenericServlet;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+
+import javax.servlet.http.HttpServletRequest;
+
+// aop id defined via application-context.xml. the annotations are only for test purposes
+@Aspect
+public class RoleAuthorizationHandler {
+
+ private static final Logger log = Logger.getLogger(RoleAuthorizationHandler.class);
+
+ private ConfigurationManager configurationManager = ConfigurationManager.getConfigurationManager();
+
+ @Before("@annotation(permissions)")
+ public void authorizeRole(JoinPoint joinPoint, PermissionAllowed permissions) {
+
+ if (isPermissionAuthenticationNeeded()) {
+ String methodName = joinPoint.getSignature().toShortString();
+ HttpServletRequest request = ((BeGenericServlet) joinPoint.getThis()).getServletRequest();
+ String[] perms = permissions.value();
+ logAuth(methodName, perms, true, null);
+ for (String perm : perms) {
+ if (request.isUserInRole(getFullPermission(perm))) {
+ logAuth(methodName, perms, false, true);
+ return;
+ }
+ }
+ logAuth(methodName, perms, false, false);
+ throw new ByActionStatusComponentException(ActionStatus.AUTH_FAILED);
+ }
+
+ }
+
+ private void logAuth(String methodName, String[] perms, boolean beforeAuth, Boolean success) {
+ if (beforeAuth)
+ log.trace("#{} - authorizing before invoking endpoint {}", methodName);
+ else {
+ String status = success ? "SUCCESS" : "FAILED";
+ log.trace("#{} - authorizing before invoking endpoint {}, Status: {}", methodName, status);
+ }
+ }
+
+ private String getFullPermission(String role) {
+ return AafPermission.getEnumByString(role).getFullPermission();
+ }
+
+ private boolean isPermissionAuthenticationNeeded() {
+ if (configurationManager.getConfiguration().getAafAuthNeeded() && ThreadLocalsHolder.isExternalRequest()) {
+ return true;
+ } else return false;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByActionStatusComponentException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByActionStatusComponentException.java
index 4a19fdaf06..788d63819e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByActionStatusComponentException.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByActionStatusComponentException.java
@@ -19,17 +19,19 @@
*/
package org.openecomp.sdc.be.components.impl.exceptions;
-import java.util.Arrays;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.exception.ResponseFormat;
+import java.util.Arrays;
+
public class ByActionStatusComponentException extends ComponentException {
private final ActionStatus actionStatus;
private final String[] params;
public ByActionStatusComponentException(ActionStatus actionStatus, String... params) {
+ super(actionStatus, params);
this.actionStatus = actionStatus;
this.params = params.clone();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByResponseFormatComponentException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByResponseFormatComponentException.java
index 0737c45d49..85fe3ec58a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByResponseFormatComponentException.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByResponseFormatComponentException.java
@@ -19,14 +19,28 @@
*/
package org.openecomp.sdc.be.components.impl.exceptions;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.exception.ResponseFormat;
public class ByResponseFormatComponentException extends ComponentException {
private final transient ResponseFormat responseFormat;
+ private final ActionStatus actionStatus;
+ private final String[] params;
- public ByResponseFormatComponentException(ResponseFormat responseFormat) {
+ public ByResponseFormatComponentException(ResponseFormat responseFormat, String... params) {
+ super(responseFormat);
this.responseFormat = responseFormat;
+ this.params = params.clone();
+ this.actionStatus = ActionStatus.OK;
+ }
+
+ public String[] getParams() {
+ return params.clone();
+ }
+
+ public ActionStatus getActionStatus(){
+ return actionStatus;
}
@Override
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java
index bedb299163..1d9809806c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,22 +16,64 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- * Modifications copyright (c) 2019 Nokia
- * ================================================================================
*/
+
package org.openecomp.sdc.be.components.impl.exceptions;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.exception.ResponseFormat;
-/**
- * This class will be initialized either by action status and params or by ResponseFormat
- */
-public abstract class ComponentException extends RuntimeException {
+import javax.annotation.Nullable;
+
+public class ComponentException extends RuntimeException {
+
+ /**
+ * This class will be initialized either by action status and params or by ResponseFormat
+ */
+
+ private final transient ResponseFormat responseFormat;
+ private final ActionStatus actionStatus;
+ private final String[] params;
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ private final Resource resource;
+
+ public ComponentException(ResponseFormat responseFormat) {
+ this(responseFormat, ActionStatus.OK, null);
+ }
- public abstract ResponseFormat getResponseFormat();
+ public ComponentException(ActionStatus actionStatus, String... params) {
+ this(ResponseFormatManager.getInstance().getResponseFormat(actionStatus, params), actionStatus, null, params);
+ }
+
+ public ComponentException(ActionStatus actionStatus, Resource resource, String... params) {
+ this(ResponseFormatManager.getInstance().getResponseFormat(actionStatus, params), actionStatus, resource, params);
+ }
- @Override
- public String getMessage() {
- return this.toString();
+ private ComponentException(ResponseFormat responseFormat, ActionStatus actionStatus, Resource resource, String... params) {
+ this.actionStatus = actionStatus;
+ this.params = params.clone();
+ this.responseFormat = responseFormat;
+ this.resource = resource;
}
+
+ @Nullable
+ public ResponseFormat getResponseFormat() {
+ return responseFormat;
+ }
+
+ public ActionStatus getActionStatus() {
+ return actionStatus;
+ }
+
+ public String[] getParams() {
+ return params.clone();
+ }
+
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java
new file mode 100644
index 0000000000..bb4d884811
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/group/GroupVersionUpdater.java
@@ -0,0 +1,125 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.group;
+
+
+import org.openecomp.sdc.be.components.impl.version.OnChangeVersionCommand;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.GroupTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.GroupsOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.utils.GroupUtils;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+
+
+/**
+ * A Helper class which handles altering the version of a group
+ */
+@org.springframework.stereotype.Component
+public class GroupVersionUpdater implements OnChangeVersionCommand {
+
+ private static final Logger log = Logger.getLogger(GroupVersionUpdater.class);
+ private final GroupsOperation groupsOperation;
+ private final ComponentsUtils componentsUtils;
+
+
+ public GroupVersionUpdater(GroupsOperation groupsOperation, ComponentsUtils componentsUtils) {
+ this.groupsOperation = groupsOperation;
+ this.componentsUtils = componentsUtils;
+
+ }
+
+
+ @Override
+ public ActionStatus onChangeVersion(Component container) {
+ log.debug("#onChangeVersion - replacing all group members for component instance");
+ Consumer<List<GroupDefinition>> replaceGroupMemberTask = (groups) -> increaseVersion(groups, container);
+ return updateGroupsVersion(container, replaceGroupMemberTask);
+ }
+
+ public void increaseVersion(List<GroupDefinition> groups, Component container) {
+ groups.forEach(group -> increaseMajorVersion(group, container));
+ }
+
+
+ private void increaseMajorVersion(GroupDefinition group, Component container) {
+ String version = group.getVersion();
+
+ String newVersion = GroupUtils.updateVersion(PromoteVersionEnum.MAJOR, group.getVersion());
+
+ if(!version.equals(newVersion) ){
+ if(isGenerateGroupUUID(group, container)) {
+ String groupUUID = UniqueIdBuilder.generateUUID();
+ group.setGroupUUID(groupUUID);
+ }
+ group.setVersion(String.valueOf(newVersion));
+ }
+
+ }
+
+ private boolean isGenerateGroupUUID(GroupDefinition group, Component container) {
+ if(GroupTypeEnum.VF_MODULE.getGroupTypeName().equals(group.getType())){
+ List<String> artifactsUuid = group.getArtifactsUuid();
+ List<String> heatArtifactUniqueIDs = group.getArtifacts().stream().filter(a->!a.endsWith("env")).collect(Collectors.toList());
+ Map<String, ArtifactDefinition> deploymentArtifacts = container.getDeploymentArtifacts();
+ for (String heatArtifactUniqueID : heatArtifactUniqueIDs){
+ ArtifactDefinition artifactDefinition = deploymentArtifacts.get(heatArtifactUniqueID.split("\\.", -1)[1]);
+ if((artifactDefinition == null || artifactDefinition.isEmpty())
+ && !artifactsUuid.contains(artifactDefinition.getArtifactUUID()) ){
+ return true;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+
+ private ActionStatus updateGroupsVersion(Component groupsContainer, Consumer<List<GroupDefinition>> updateGroupVersion) {
+ List<GroupDefinition> groups = groupsContainer.getGroups();
+ if (isEmpty(groups)) {
+ return ActionStatus.OK;
+ }
+ updateGroupVersion.accept(groups);
+ return updateGroups(groupsContainer.getUniqueId(), groups);
+ }
+
+
+ private ActionStatus updateGroups(String componentId, List<GroupDefinition> groupsToUpdate) {
+ log.debug("#updateGroups - updating {} groups for container {}", groupsToUpdate.size(), componentId);
+ return componentsUtils.convertFromStorageResponse(groupsOperation.updateGroupsOnComponent(componentId, groupsToUpdate));
+
+ }
+
+}
+
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/instance/GroupMembersUpdateOperation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/instance/GroupMembersUpdateOperation.java
index d3d78333a9..656dd2e6e3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/instance/GroupMembersUpdateOperation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/instance/GroupMembersUpdateOperation.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.components.impl.instance;
import org.openecomp.sdc.be.components.impl.group.GroupMembersUpdater;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
@@ -73,7 +74,7 @@ public class GroupMembersUpdateOperation implements OnComponentInstanceChangeOpe
private ActionStatus updateGroups(Component container, List<GroupDefinition> groupsToUpdate) {
log.debug("#updateGroups - updating {} groups for container {}", groupsToUpdate.size(), container.getUniqueId());
- return groupsOperation.updateGroups(container, groupsToUpdate, false)
+ return groupsOperation.updateGroups(container, groupsToUpdate, PromoteVersionEnum.MINOR)
.either(groupsUpdated -> ActionStatus.OK,
err -> componentsUtils.convertFromStorageResponse(err, container.getComponentType()));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/lock/LockingTransactional.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/lock/LockingTransactional.java
index f75f0b7022..44e49eb039 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/lock/LockingTransactional.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/lock/LockingTransactional.java
@@ -22,7 +22,11 @@ package org.openecomp.sdc.be.components.impl.lock;
import org.springframework.transaction.annotation.Transactional;
-import java.lang.annotation.*;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdater.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdater.java
index 74b39f9f29..adf927178f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdater.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdater.java
@@ -22,7 +22,9 @@ package org.openecomp.sdc.be.components.impl.policy;
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.utils.GroupUtils;
import org.springframework.stereotype.Component;
import java.util.List;
@@ -39,7 +41,7 @@ import static org.apache.commons.collections.CollectionUtils.isEmpty;
public class PolicyTargetsUpdater {
public void removeTarget(List<PolicyDefinition> policies, String targetId, PolicyTargetType targetType) {
- policies.forEach(policy -> removePolicyTarget(policy, targetId, targetType));
+ policies.forEach(policy ->removePolicyTarget(policy, targetId, targetType));
}
public void replaceTarget(List<PolicyDefinition> policies, String oldTargetId, String newTargetId, PolicyTargetType targetType) {
@@ -52,6 +54,7 @@ public class PolicyTargetsUpdater {
return;
}
policyTargets.replaceAll(prevInstanceIdByNewInstanceId(oldTargetId, newTargetId));
+ policyDefinition.setVersion(GroupUtils.updateVersion(PromoteVersionEnum.MINOR, policyDefinition.getVersion()));
}
private void removePolicyTarget(PolicyDefinition policy, String targetId, PolicyTargetType targetType) {
@@ -59,7 +62,9 @@ public class PolicyTargetsUpdater {
if (isEmpty(policyTargets)) {
return;
}
+
policyTargets.remove(targetId);
+ policy.setVersion(GroupUtils.updateVersion(PromoteVersionEnum.MINOR, policy.getVersion()));
}
private List<String> getTargetsList(PolicyDefinition policyDefinition, PolicyTargetType targetType) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyVersionUpdater.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyVersionUpdater.java
new file mode 100644
index 0000000000..ef2f8cbad9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/policy/PolicyVersionUpdater.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.policy;
+
+
+import org.openecomp.sdc.be.components.impl.version.OnChangeVersionCommand;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.utils.GroupUtils;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
+import java.util.List;
+import java.util.function.Consumer;
+
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+
+
+/**
+ * A Helper class which handles altering the version of a group
+ */
+@org.springframework.stereotype.Component
+public class PolicyVersionUpdater implements OnChangeVersionCommand {
+
+ private static final Logger log = Logger.getLogger(PolicyVersionUpdater.class);
+ private final ToscaOperationFacade toscaOperationFacade;
+ private final ComponentsUtils componentsUtils;
+
+
+ public PolicyVersionUpdater(ToscaOperationFacade toscaOperationFacade, ComponentsUtils componentsUtils) {
+ this.toscaOperationFacade = toscaOperationFacade;
+ this.componentsUtils = componentsUtils;
+
+ }
+
+
+ @Override
+ public ActionStatus onChangeVersion(Component container) {
+ log.debug("#onChangeVersion - replacing all group members for component instance");
+ Consumer<List<PolicyDefinition>> replaceGroupMemberTask = (policies) -> increaseVesion(policies);
+ return updatePoliciesVersion(container, replaceGroupMemberTask);
+ }
+
+ public void increaseVesion(List<PolicyDefinition> policies) {
+ policies.forEach(policy -> increaseMajorVersion(policy));
+ }
+
+
+ private void increaseMajorVersion(PolicyDefinition policy) {
+ String version = policy.getVersion();
+
+ String newVersion = GroupUtils.updateVersion(PromoteVersionEnum.MAJOR, policy.getVersion());
+
+ if(!version.equals(newVersion) ){
+ String groupUUID = UniqueIdBuilder.generateUUID();
+ policy.setPolicyUUID(groupUUID);
+ policy.setVersion(String.valueOf(newVersion));
+ }
+
+ }
+
+
+ private ActionStatus updatePoliciesVersion(Component container, Consumer<List<PolicyDefinition>> updatePoliciesVersion) {
+ List<PolicyDefinition> policies = container.resolvePoliciesList();
+ if (isEmpty(policies)) {
+ return ActionStatus.OK;
+ }
+ updatePoliciesVersion.accept(policies);
+ return updatePolicies(container, policies);
+ }
+
+
+ private ActionStatus updatePolicies(Component policiesContainer, List<PolicyDefinition> policiesToUpdate) {
+ log.debug("#updatePolicies - updating {} policies for container {}", policiesToUpdate.size(), policiesContainer.getUniqueId());
+ StorageOperationStatus updatePolicyResult = toscaOperationFacade.updatePoliciesOfComponent(policiesContainer.getUniqueId(), policiesToUpdate);
+ return componentsUtils.convertFromStorageResponse(updatePolicyResult, policiesContainer.getComponentType());
+ }
+
+}
+
+
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java
index 73ec3352b3..36c1e585d8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/CINodeFilterUtils.java
@@ -16,9 +16,6 @@
package org.openecomp.sdc.be.components.impl.utils;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
@@ -28,6 +25,10 @@ import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterPropertyInfo;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
public class CINodeFilterUtils {
Logger log = Logger.getLogger(CINodeFilterUtils.class);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java
index b19f0592c1..900e961359 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtils.java
@@ -17,11 +17,12 @@
package org.openecomp.sdc.be.components.impl.utils;
import com.google.common.collect.Sets;
-import java.util.List;
-import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
+import java.util.List;
+import java.util.Optional;
+
public class DirectivesUtils {
public static final String SUBSTITUTABLE = "substitutable";
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java
index e51caabd00..ec4192c966 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java
@@ -24,8 +24,8 @@ package org.openecomp.sdc.be.components.impl.utils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.exception.ResponseFormat;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/version/OnChangeVersionCommand.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/version/OnChangeVersionCommand.java
new file mode 100644
index 0000000000..de115b5099
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/version/OnChangeVersionCommand.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.version;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.Component;
+
+
+@FunctionalInterface
+public interface OnChangeVersionCommand {
+
+ /**
+ * A side effect operation to execute when a component instance version was changed from {@code prevVersion} to {@code newVersion}
+ * @param container the container which contains the instance which is version was changed
+ * @param prevVersion the previous version of the component instance.
+ * @param newVersion the new version of the component instance.
+ * @return the status of the operation
+ */
+ ActionStatus onChangeVersion(Component container);
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/version/VesionUpdateHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/version/VesionUpdateHandler.java
new file mode 100644
index 0000000000..13086c7884
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/version/VesionUpdateHandler.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.version;
+
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.function.Function;
+
+
+
+
+@org.springframework.stereotype.Component
+public class VesionUpdateHandler {
+
+ private static final Logger log = Logger.getLogger(VesionUpdateHandler.class);
+
+ private final List<OnChangeVersionCommand> onChangeVersionOperations;
+
+ public VesionUpdateHandler( List<OnChangeVersionCommand> onChangeVersionOperations) {
+
+ this.onChangeVersionOperations = onChangeVersionOperations;
+ }
+
+
+ public ActionStatus doPostChangeVersionCommand(Component container) {
+ log.debug("#doPostChangeVersionOperations - starting post change version operations for component {}. from instance {} to instance {}", container.getUniqueId());
+ Function<OnChangeVersionCommand, ActionStatus> vesionChangeTaskRunner = operation -> operation.onChangeVersion(container);
+ return doOnChangeVesionOperations(vesionChangeTaskRunner);
+ }
+
+ private ActionStatus doOnChangeVesionOperations(Function<OnChangeVersionCommand, ActionStatus> vesionChangeTaskRunner) {
+ ActionStatus onVesionChangeResult = ActionStatus.OK;
+ Iterator<OnChangeVersionCommand> onChangeVesionIter = onChangeVersionOperations.iterator();
+ while(onChangeVesionIter.hasNext() && onVesionChangeResult == ActionStatus.OK) {
+ onVesionChangeResult = vesionChangeTaskRunner.apply(onChangeVesionIter.next());
+ }
+ return onVesionChangeResult;
+ }
+
+
+
+
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java
index 409fad22b4..9a5e9d266c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationChangeTransition.java
@@ -21,14 +21,23 @@
package org.openecomp.sdc.be.components.lifecycle;
import fj.data.Either;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTemplateOperation;
@@ -40,6 +49,7 @@ import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.tosca.ToscaUtils;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import java.util.Arrays;
@@ -60,36 +70,22 @@ public class CertificationChangeTransition extends LifeCycleTransition {
private LifeCycleTransitionEnum name;
private AuditingActionEnum auditingAction;
private NodeTemplateOperation nodeTemplateOperation;
+ private ServiceBusinessLogic serviceBusinessLogic;
- public CertificationChangeTransition(LifeCycleTransitionEnum name, ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao) {
+ public CertificationChangeTransition(ServiceBusinessLogic serviceBusinessLogic, LifeCycleTransitionEnum name, ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao) {
super(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
this.name = name;
+ this.serviceBusinessLogic = serviceBusinessLogic;
// authorized roles
- Role[] certificationChangeRoles = { Role.ADMIN, Role.TESTER };
- Role[] resourceRoles = { Role.ADMIN, Role.TESTER, Role.DESIGNER};
+ Role[] certificationChangeRoles = { Role.ADMIN, Role.DESIGNER };
+ Role[] resourceRoles = { Role.ADMIN, Role.DESIGNER};
addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(resourceRoles));
addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(certificationChangeRoles));
- //additional authorized roles for resource type
- switch (this.name) {
- case CERTIFY:
- this.auditingAction = AuditingActionEnum.CERTIFICATION_SUCCESS_RESOURCE;
- this.nextState = LifecycleStateEnum.CERTIFIED;
- break;
- case FAIL_CERTIFICATION:
- this.auditingAction = AuditingActionEnum.FAIL_CERTIFICATION_RESOURCE;
- nextState = LifecycleStateEnum.NOT_CERTIFIED_CHECKIN;
- break;
- case CANCEL_CERTIFICATION:
- this.auditingAction = AuditingActionEnum.CANCEL_CERTIFICATION_RESOURCE;
- nextState = LifecycleStateEnum.READY_FOR_CERTIFICATION;
- break;
- default:
- break;
- }
-
+ this.auditingAction = AuditingActionEnum.CERTIFICATION_SUCCESS_RESOURCE;
+ this.nextState = LifecycleStateEnum.CERTIFIED;
}
@Override
@@ -129,19 +125,10 @@ public class CertificationChangeTransition extends LifeCycleTransition {
return userValidationResponse;
}
- if ( componentType != ComponentTypeEnum.RESOURCE ){
- if (!oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS) ) {
- log.debug("oldState={} should be={}",oldState,ActionStatus.COMPONENT_NOT_READY_FOR_CERTIFICATION);
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_READY_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase());
- return Either.right(error);
- }
-
- if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS) && !modifier.getUserId().equals(owner.getUserId()) && !modifier.getRole().equals(Role.ADMIN.name())) {
- log.debug("oldState={} should not be={}",oldState,ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE);
- log.debug("&& modifier({})!={} && modifier.role({})!={}", modifier, owner, modifier.getRole(), owner.getRole());
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
+ if (oldState != LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT && oldState != LifecycleStateEnum.NOT_CERTIFIED_CHECKIN) {
+ log.debug("Valid states for certification are NOT_CERTIFIED_CHECKIN and NOT_CERTIFIED_CHECKOUT. {} is invalid state", oldState);
+ ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.ILLEGAL_COMPONENT_STATE, componentName, componentType.name().toLowerCase(), oldState.name());
+ return Either.right(error);
}
return Either.left(true);
}
@@ -153,12 +140,9 @@ public class CertificationChangeTransition extends LifeCycleTransition {
Either<? extends Component, ResponseFormat> result = null;
try {
- Either<ToscaElement, StorageOperationStatus> certificationChangeResult = Either.right(StorageOperationStatus.GENERAL_ERROR);
- if (nextState.equals(LifecycleStateEnum.CERTIFIED)) {
- certificationChangeResult = lifeCycleOperation.certifyToscaElement(component.getUniqueId(), modifier.getUserId(), owner.getUserId());
- } else {
- certificationChangeResult = lifeCycleOperation.cancelOrFailCertification(component.getUniqueId(), modifier.getUserId(), owner.getUserId(), nextState);
- }
+ handleValidationsAndArtifactsGenerationBeforeCertifying(componentType, component, componentBl, modifier, shouldLock, inTransaction);
+ Either<ToscaElement, StorageOperationStatus> certificationChangeResult =
+ lifeCycleOperation.certifyToscaElement(component.getUniqueId(), modifier.getUserId(), owner.getUserId());
if (certificationChangeResult.isRight()) {
ResponseFormat responseFormat = formatCertificationError(component, certificationChangeResult.right().value(), componentType);
@@ -166,14 +150,6 @@ public class CertificationChangeTransition extends LifeCycleTransition {
return result;
}
- if (nextState.equals(LifecycleStateEnum.CERTIFIED)) {
- Either<Boolean, StorageOperationStatus> deleteOldComponentVersions = lifeCycleOperation.deleteOldToscaElementVersions(ModelConverter.getVertexType(component), componentType, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName(),
- component.getComponentMetadataDefinition().getMetadataDataDefinition().getUUID());
- if (deleteOldComponentVersions.isRight()) {
- ResponseFormat responseFormat = formatCertificationError(component, deleteOldComponentVersions.right().value(), componentType);
- result = Either.right(responseFormat);
- }
- }
ToscaElement certificationResult = certificationChangeResult.left().value();
Component componentAfterCertification = ModelConverter.convertFromToscaElement(certificationResult);
if ( result == null || result.isLeft() ){
@@ -211,6 +187,88 @@ public class CertificationChangeTransition extends LifeCycleTransition {
}
}
+ Either<Boolean, ResponseFormat> validateAllResourceInstanceCertified(Component component) {
+ Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+
+ if (component.isVspArchived()){
+ return Either.right(componentUtils.getResponseFormat(ActionStatus.ARCHIVED_ORIGINS_FOUND, component.getComponentType().name(), component.getName()));
+ }
+
+ List<ComponentInstance> resourceInstance = component.getComponentInstances();
+ if (resourceInstance != null) {
+
+ //Filter components instances with archived origins
+ Optional<ComponentInstance> archivedRIOptional = resourceInstance.stream().filter(ComponentInstanceDataDefinition::isOriginArchived).findAny();
+
+ //RIs with archived origins found, return relevant error
+ if (archivedRIOptional.isPresent()){
+ return Either.right(componentUtils.getResponseFormat(ActionStatus.ARCHIVED_ORIGINS_FOUND, component.getComponentType().name(), component.getName()));
+ }
+
+ //Continue with searching for non certified RIs
+ Optional<ComponentInstance> nonCertifiedRIOptional = resourceInstance.stream().filter(p -> !ValidationUtils.validateCertifiedVersion(p.getComponentVersion())).findAny();
+ // Uncertified Resource Found
+ if (nonCertifiedRIOptional.isPresent()) {
+ ComponentInstance nonCertifiedRI = nonCertifiedRIOptional.get();
+ ResponseFormat resFormat = getRelevantResponseFormatUncertifiedRI(nonCertifiedRI, component.getComponentType());
+ eitherResult = Either.right(resFormat);
+ }
+
+ }
+ return eitherResult;
+ }
+
+ private ResponseFormat getRelevantResponseFormatUncertifiedRI(ComponentInstance nonCertifiedRI, ComponentTypeEnum componentType) {
+
+ Either<Resource, StorageOperationStatus> eitherResource = toscaOperationFacade.getToscaElement(nonCertifiedRI.getComponentUid());
+ if (eitherResource.isRight()) {
+ return componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ }
+ ActionStatus actionStatus;
+ Resource resource = eitherResource.left().value();
+ Either<Resource, StorageOperationStatus> status = toscaOperationFacade.findLastCertifiedToscaElementByUUID(resource);
+
+ if (ValidationUtils.validateMinorVersion(nonCertifiedRI.getComponentVersion())) {
+ if (status.isRight() || status.left().value() == null) {
+ actionStatus = ActionStatus.VALIDATED_RESOURCE_NOT_FOUND;
+ } else {
+ actionStatus = ActionStatus.FOUND_ALREADY_VALIDATED_RESOURCE;
+ }
+ } else {
+ if (status.isRight() || status.left().value() == null) {
+ actionStatus = ActionStatus.FOUND_LIST_VALIDATED_RESOURCES;
+ } else {
+ actionStatus = ActionStatus.FOUND_ALREADY_VALIDATED_RESOURCE;
+ }
+ }
+ return componentUtils.getResponseFormat(actionStatus, componentType == ComponentTypeEnum.RESOURCE ? "VF" : "service", resource.getName());
+ }
+
+ private void handleValidationsAndArtifactsGenerationBeforeCertifying(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, boolean shouldLock, boolean inTransaction) {
+ if (component.isTopologyTemplate()) {
+ Either<Boolean, ResponseFormat> statusCert = validateAllResourceInstanceCertified(component);
+ if (statusCert.isRight()) {
+ throw new ByResponseFormatComponentException(statusCert.right().value());
+ }
+ }
+ if (componentType == ComponentTypeEnum.SERVICE) {
+
+ Either<Service, ResponseFormat> generateHeatEnvResult = serviceBusinessLogic.generateHeatEnvArtifacts((Service) component, modifier, shouldLock, inTransaction);
+
+ if (generateHeatEnvResult.isRight()) {
+ throw new ByResponseFormatComponentException(generateHeatEnvResult.right().value());
+ }
+ Either<Service, ResponseFormat> generateVfModuleResult = serviceBusinessLogic.generateVfModuleArtifacts(generateHeatEnvResult.left().value(), modifier, shouldLock, inTransaction);
+ if (generateVfModuleResult.isRight()) {
+ throw new ByResponseFormatComponentException(generateVfModuleResult.right().value());
+ }
+ component = generateVfModuleResult.left().value();
+ }
+
+ componentBl.populateToscaArtifacts(component, modifier, true, inTransaction, shouldLock);
+ }
+
+
private void updateCalculatedCapabilitiesRequirements(Component certifiedComponent) {
if(certifiedComponent.getComponentType() == ComponentTypeEnum.SERVICE){
toscaOperationFacade.updateNamesOfCalculatedCapabilitiesRequirements(certifiedComponent.getUniqueId());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java
deleted file mode 100644
index a0e9bc8c15..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CertificationRequestTransition.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/*-
- * ============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.sdc.be.components.lifecycle;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
-import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
-import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.user.Role;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.util.ValidationUtils;
-import org.openecomp.sdc.exception.ResponseFormat;
-
-import java.util.*;
-
-public class CertificationRequestTransition extends LifeCycleTransition {
-
- private static final Logger log = Logger.getLogger(CertificationRequestTransition.class);
-
- private ServiceBusinessLogic serviceBusinessLogic;
-
- public CertificationRequestTransition(ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, ServiceBusinessLogic serviceBusinessLogic,
- ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao) {
- super(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
-
- // authorized roles
- Role[] resourceServiceCheckoutRoles = { Role.ADMIN, Role.DESIGNER };
- addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(resourceServiceCheckoutRoles));
- addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(resourceServiceCheckoutRoles));
- Role[] resourceRoles = { Role.TESTER};
- addResouceAuthorizedRoles(ResourceTypeEnum.VFCMT, Arrays.asList(resourceRoles));
-
- this.serviceBusinessLogic = serviceBusinessLogic;
- }
-
- @Override
- public LifeCycleTransitionEnum getName() {
- return LifeCycleTransitionEnum.CERTIFICATION_REQUEST;
- }
-
- @Override
- public AuditingActionEnum getAuditingAction() {
- return AuditingActionEnum.CERTIFICATION_REQUEST_RESOURCE;
- }
-
- Either<Boolean, ResponseFormat> validateAllResourceInstanceCertified(Component component) {
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
-
- if (component.isVspArchived()){
- return Either.right(componentUtils.getResponseFormat(ActionStatus.ARCHIVED_ORIGINS_FOUND, component.getComponentType().name(), component.getName()));
- }
-
- List<ComponentInstance> resourceInstance = component.getComponentInstances();
- if (resourceInstance != null) {
-
- //Filter components instances with archived origins
- Optional<ComponentInstance> archivedRIOptional = resourceInstance.stream().filter(ComponentInstanceDataDefinition::isOriginArchived).findAny();
-
- //RIs with archived origins found, return relevant error
- if (archivedRIOptional.isPresent()){
- return Either.right(componentUtils.getResponseFormat(ActionStatus.ARCHIVED_ORIGINS_FOUND, component.getComponentType().name(), component.getName()));
- }
-
- //Continue with searching for non certified RIs
- Optional<ComponentInstance> nonCertifiedRIOptional = resourceInstance.stream().filter(p -> !ValidationUtils.validateCertifiedVersion(p.getComponentVersion())).findAny();
- // Uncertified Resource Found
- if (nonCertifiedRIOptional.isPresent()) {
- ComponentInstance nonCertifiedRI = nonCertifiedRIOptional.get();
- ResponseFormat resFormat = getRelevantResponseFormatUncertifiedRI(nonCertifiedRI, component.getComponentType());
- eitherResult = Either.right(resFormat);
- }
-
- }
- return eitherResult;
- }
-
- private ResponseFormat getRelevantResponseFormatUncertifiedRI(ComponentInstance nonCertifiedRI, ComponentTypeEnum componentType) {
-
- Either<Resource, StorageOperationStatus> eitherResource = toscaOperationFacade.getToscaElement(nonCertifiedRI.getComponentUid());
- if (eitherResource.isRight()) {
- return componentUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- }
- ActionStatus actionStatus;
- Resource resource = eitherResource.left().value();
- Either<Resource, StorageOperationStatus> status = toscaOperationFacade.findLastCertifiedToscaElementByUUID(resource);
-
- if (ValidationUtils.validateMinorVersion(nonCertifiedRI.getComponentVersion())) {
- if (status.isRight() || status.left().value() == null) {
- actionStatus = ActionStatus.VALIDATED_RESOURCE_NOT_FOUND;
- } else {
- actionStatus = ActionStatus.FOUND_ALREADY_VALIDATED_RESOURCE;
- }
- } else {
- if (status.isRight() || status.left().value() == null) {
- actionStatus = ActionStatus.FOUND_LIST_VALIDATED_RESOURCES;
- } else {
- actionStatus = ActionStatus.FOUND_ALREADY_VALIDATED_RESOURCE;
- }
- }
- return componentUtils.getResponseFormat(actionStatus, componentType == ComponentTypeEnum.RESOURCE ? "VF" : "service", resource.getName());
- }
-
- @Override
- public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
-
- log.debug("start performing certification request for resource {}", component.getUniqueId());
-
- ActionStatus actionStatus;
- ResponseFormat responseFormat;
- Either<? extends Component, ResponseFormat> result = null;
- try{
- if (component.isTopologyTemplate()) {
-
- Either<Boolean, ResponseFormat> statusCert = validateAllResourceInstanceCertified(component);
- if (statusCert.isRight()) {
- return Either.right(statusCert.right().value());
- }
-
- statusCert = validateConfiguredAtomicReqCapSatisfied(component);
- if (statusCert.isRight()) {
- return Either.right(statusCert.right().value());
- }
- }
- if (componentType == ComponentTypeEnum.SERVICE) {
-
- Either<Service, ResponseFormat> generateHeatEnvResult = serviceBusinessLogic.generateHeatEnvArtifacts((Service) component, modifier, shouldLock, inTransaction);
-
- if (generateHeatEnvResult.isRight()) {
- return Either.right(generateHeatEnvResult.right().value());
- }
- Either<Service, ResponseFormat> generateVfModuleResult = serviceBusinessLogic.generateVfModuleArtifacts(generateHeatEnvResult.left().value(), modifier, shouldLock, inTransaction);
- if (generateVfModuleResult.isRight()) {
- return Either.right(generateVfModuleResult.right().value());
- }
- component = generateVfModuleResult.left().value();
-
- }
-
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> eitherPopulated = componentBl.populateToscaArtifacts(component, modifier, true, inTransaction, shouldLock);
- if (eitherPopulated != null && eitherPopulated.isRight()) {
- return Either.right(eitherPopulated.right().value());
- }
-
- Either<ToscaElement, StorageOperationStatus> certificationRequestResult = lifeCycleOperation.requestCertificationToscaElement(component.getUniqueId(), modifier.getUserId(), owner.getUserId());
- if (certificationRequestResult.isRight()) {
- log.debug("checkout failed on graph");
- StorageOperationStatus response = certificationRequestResult.right().value();
- actionStatus = componentUtils.convertFromStorageResponse(response);
-
- if (response.equals(StorageOperationStatus.ENTITY_ALREADY_EXISTS)) {
- actionStatus = ActionStatus.COMPONENT_VERSION_ALREADY_EXIST;
- }
- responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
- result = Either.right(responseFormat);
- }
- else {
- result = Either.left(ModelConverter.convertFromToscaElement(certificationRequestResult.left().value()));
- }
- } finally {
- if (result == null || result.isRight()) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Change LifecycleState");
- if (!inTransaction) {
- log.debug("operation failed. do rollback");
- janusGraphDao.rollback();
- }
- } else {
- if (!inTransaction) {
- log.debug("operation success. do commit");
- janusGraphDao.commit();
- }
- }
- }
- return result;
- }
-
- private Either<Boolean, ResponseFormat> validateConfiguredAtomicReqCapSatisfied(Component component) {
- log.debug("Submit for testing validation - Start validating configured req/cap satisfied for inner atomic instances, component id:{}", component.getUniqueId());
- List<ComponentInstance> componentInstances = component.getComponentInstances();
- if (componentInstances != null) {
- // Prepare relationships data structures
- // Better make it list than set in case we need to count req/cap
- // occurrences in the future
- Map<String, List<String>> reqName2Ids = new HashMap<>();
- Map<String, List<String>> capName2Ids = new HashMap<>();
- Map<String, Set<String>> requirementsToFulfillBeforeCert = configurationManager.getConfiguration().getRequirementsToFulfillBeforeCert();
- Map<String, Set<String>> capabilitiesToConsumeBeforeCert = configurationManager.getConfiguration().getCapabilitiesToConsumeBeforeCert();
- for (ComponentInstance compInst : componentInstances) {
- String compInstId = compInst.getUniqueId();
- OriginTypeEnum originType = compInst.getOriginType();
- if (originType == null) {
- log.debug("Origin type is not set for component instance {} - it shouldn't happen. Skipping this component instance...", compInst.getUniqueId());
- continue;
- }
- String compInstType = originType.getValue();
- // Validating configured requirements fulfilled
- if (null != requirementsToFulfillBeforeCert) {
- Set<String> reqToFulfillForType = requirementsToFulfillBeforeCert.get(compInstType);
- if (reqToFulfillForType != null) {
- for (String reqNameToFulfill : reqToFulfillForType) {
- List<String> reqNameList = reqName2Ids.get(reqNameToFulfill);
- if (reqNameList == null || !reqNameList.contains(compInstId)) {
- log.debug("Requirement {} wasn't fulfilled for component instance {} of type {}", reqNameToFulfill, compInstId, compInstType);
- ComponentTypeEnum componentType = component.getComponentType();
- String compParam = (componentType == ComponentTypeEnum.RESOURCE) ? "VF" : componentType.getValue().toLowerCase();
- ResponseFormat responseFormat = componentUtils.getResponseFormat(ActionStatus.REQ_CAP_NOT_SATISFIED_BEFORE_CERTIFICATION, component.getName(), compParam, originType.getDisplayValue(), compInst.getName(), "requirement",
- reqNameToFulfill, "fulfilled");
- return Either.right(responseFormat);
- }
- }
- }
- }
- // Validating configured capabilities consumed
- if (null != capabilitiesToConsumeBeforeCert) {
- Set<String> capToConsumeForType = capabilitiesToConsumeBeforeCert.get(compInstType);
- if (capToConsumeForType != null) {
- for (String capNameToConsume : capToConsumeForType) {
- List<String> capNameList = capName2Ids.get(capNameToConsume);
- if (capNameList == null || !capNameList.contains(compInstId)) {
- log.debug("Capability {} wasn't consumed for component instance {} of type {}", capNameToConsume, compInstId, compInstType);
- ComponentTypeEnum componentType = component.getComponentType();
- String compParam = (componentType == ComponentTypeEnum.RESOURCE) ? "VF" : componentType.getValue().toLowerCase();
- ResponseFormat responseFormat = componentUtils.getResponseFormat(ActionStatus.REQ_CAP_NOT_SATISFIED_BEFORE_CERTIFICATION, component.getName(), compParam, originType.getDisplayValue(), compInst.getName(), "capability",
- capNameToConsume, "consumed");
- return Either.right(responseFormat);
- }
- }
- }
- }
- }
- }
- log.debug("Submit for testing validation - validating configured req/cap satisfied for inner atomic instances finished successfully, component id:{}", component.getUniqueId());
- return Either.left(true);
- }
-
- @Override
- public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
- String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
- log.debug("validate before certification request. resource name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId());
-
- // validate user
- Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier,component, componentType, lifecycleChangeInfo);
- if (userValidationResponse.isRight()) {
- return userValidationResponse;
- }
-
- // case of "atomic" checkin and certification request - modifier must be
- // the owner
- if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) && !modifier.equals(owner) && !modifier.getRole().equals(Role.ADMIN.name())) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_CHECKOUT_BY_ANOTHER_USER, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
-
- // other states
- if (oldState.equals(LifecycleStateEnum.CERTIFIED)) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_ALREADY_CERTIFIED, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
- if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
- if (oldState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION)) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
-
- return Either.left(true);
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java
index f6cc7dcb53..db4bef40b1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckinTransition.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.components.lifecycle;
import fj.data.Either;
import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.version.VesionUpdateHandler;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
@@ -49,9 +50,11 @@ public class CheckinTransition extends LifeCycleTransition {
private static final Logger log = Logger.getLogger(CheckinTransition.class);
- public CheckinTransition(ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao) {
- super(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
+ private VesionUpdateHandler vesionUpdateHandler;
+ public CheckinTransition(ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao, VesionUpdateHandler groupUpdateHandler) {
+ super(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
+ this.vesionUpdateHandler = groupUpdateHandler;
// authorized roles
Role[] resourceServiceCheckoutRoles = { Role.ADMIN, Role.DESIGNER };
Role[] productCheckoutRoles = { Role.ADMIN, Role.PRODUCT_MANAGER };
@@ -93,7 +96,11 @@ public class CheckinTransition extends LifeCycleTransition {
}
else {
updateCalculatedCapabilitiesRequirements(checkinResourceResult.left().value());
- result = Either.left(ModelConverter.convertFromToscaElement(checkinResourceResult.left().value()));
+ Component r = ModelConverter.convertFromToscaElement(checkinResourceResult.left().value());
+ updateGroupsAndPolicesVersion(r);
+ result = Either.left(r);
+
+
}
} finally {
if (result == null || result.isRight()) {
@@ -112,6 +119,10 @@ public class CheckinTransition extends LifeCycleTransition {
return result;
}
+ private void updateGroupsAndPolicesVersion(Component container) {
+ vesionUpdateHandler.doPostChangeVersionCommand(container);
+ }
+
@Override
public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
@@ -123,11 +134,9 @@ public class CheckinTransition extends LifeCycleTransition {
return userValidationResponse;
}
- if (!oldState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION) && !oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ if (!oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
ActionStatus action = ActionStatus.COMPONENT_ALREADY_CHECKED_IN;
- if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)){
- action = ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION;
- } else if (oldState.equals(LifecycleStateEnum.CERTIFIED)){
+ if (oldState.equals(LifecycleStateEnum.CERTIFIED)){
action = ActionStatus.COMPONENT_ALREADY_CERTIFIED;
}
ResponseFormat error = componentUtils.getResponseFormat(action, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
@@ -139,11 +148,6 @@ public class CheckinTransition extends LifeCycleTransition {
return Either.right(error);
}
- if (oldState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION) && !modifier.equals(owner) && !modifier.getRole().equals(Role.ADMIN.name())) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
-
return Either.left(true);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java
index d97c171868..352371c3d9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTransition.java
@@ -30,7 +30,12 @@ import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
@@ -177,24 +182,11 @@ public class CheckoutTransition extends LifeCycleTransition {
if (userValidationResponse.isRight()) {
return userValidationResponse;
}
-
// check resource is not locked by another user
if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CHECKOUT_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
return Either.right(error);
}
-
- if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
-
- if (oldState.equals(LifecycleStateEnum.READY_FOR_CERTIFICATION)) {
- if (!modifier.getRole().equals(Role.DESIGNER.name()) && !modifier.getRole().equals(Role.ADMIN.name())) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_SENT_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
- }
return Either.left(true);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
index 91f4f5680a..d29f23eef8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
@@ -22,11 +22,17 @@
package org.openecomp.sdc.be.components.lifecycle;
+import com.google.common.annotations.VisibleForTesting;
import fj.data.Either;
-import org.apache.commons.lang3.StringUtils;
-import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
-import org.openecomp.sdc.be.components.impl.*;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.version.VesionUpdateHandler;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
@@ -34,8 +40,13 @@ import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.facade.operations.CatalogOperation;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTemplateOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
@@ -43,21 +54,19 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.CapabilityOperation;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
-import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
-import org.springframework.context.annotation.Lazy;
@org.springframework.stereotype.Component("lifecycleBusinessLogic")
public class LifecycleBusinessLogic {
@@ -70,9 +79,6 @@ public class LifecycleBusinessLogic {
@Autowired
private JanusGraphDao janusGraphDao;
- @Autowired
- private CapabilityOperation capabilityOperation;
-
private static final Logger log = Logger.getLogger(LifecycleBusinessLogic.class);
@javax.annotation.Resource
@@ -81,9 +87,6 @@ public class LifecycleBusinessLogic {
@javax.annotation.Resource
private ToscaElementLifecycleOperation lifecycleOperation;
- @javax.annotation.Resource
- private ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder;
-
@Autowired
@Lazy
private ServiceBusinessLogic serviceBusinessLogic;
@@ -97,28 +100,22 @@ public class LifecycleBusinessLogic {
private ProductBusinessLogic productBusinessLogic;
@Autowired
- private ToscaExportHandler toscaExportUtils;
-
- @Autowired
ToscaOperationFacade toscaOperationFacade;
@Autowired
NodeTemplateOperation nodeTemplateOperation;
+ @Autowired
+ CatalogOperation catalogOperations;
+
+ @Autowired
+ VesionUpdateHandler groupUpdateHandler;
+
private Map<String, LifeCycleTransition> stateTransitions;
- private static volatile boolean isInitialized = false;
@PostConstruct
public void init() {
- // init parameters
- if (!isInitialized) {
- synchronized (this) {
- if (!isInitialized) {
- initStateOperations();
- isInitialized = true;
- }
- }
- }
+ initStateOperations();
}
private void initStateOperations() {
@@ -128,42 +125,21 @@ public class LifecycleBusinessLogic {
janusGraphDao);
stateTransitions.put(checkoutOp.getName().name(), checkoutOp);
- UndoCheckoutTransition undoCheckoutOp = new UndoCheckoutTransition(componentUtils, lifecycleOperation, toscaOperationFacade,
- janusGraphDao);
+ UndoCheckoutTransition undoCheckoutOp = new UndoCheckoutTransition(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
+ undoCheckoutOp.setCatalogOperations(catalogOperations);
stateTransitions.put(undoCheckoutOp.getName().name(), undoCheckoutOp);
- LifeCycleTransition checkinOp = new CheckinTransition(componentUtils, lifecycleOperation, toscaOperationFacade,
- janusGraphDao);
+ LifeCycleTransition checkinOp = new CheckinTransition(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao, groupUpdateHandler);
stateTransitions.put(checkinOp.getName().name(), checkinOp);
- LifeCycleTransition certificationRequest = new CertificationRequestTransition(componentUtils, lifecycleOperation, serviceBusinessLogic, toscaOperationFacade,
- janusGraphDao);
- stateTransitions.put(certificationRequest.getName().name(), certificationRequest);
-
- LifeCycleTransition startCertification = new StartCertificationTransition(componentUtils, lifecycleOperation, toscaOperationFacade,
- janusGraphDao);
- stateTransitions.put(startCertification.getName().name(), startCertification);
-
- LifeCycleTransition failCertification = new CertificationChangeTransition(LifeCycleTransitionEnum.FAIL_CERTIFICATION, componentUtils, lifecycleOperation, toscaOperationFacade,
- janusGraphDao);
- stateTransitions.put(failCertification.getName().name(), failCertification);
-
- LifeCycleTransition cancelCertification = new CertificationChangeTransition(LifeCycleTransitionEnum.CANCEL_CERTIFICATION, componentUtils, lifecycleOperation, toscaOperationFacade,
- janusGraphDao);
- stateTransitions.put(cancelCertification.getName().name(), cancelCertification);
-
- CertificationChangeTransition successCertification = new CertificationChangeTransition(LifeCycleTransitionEnum.CERTIFY, componentUtils, lifecycleOperation, toscaOperationFacade,
- janusGraphDao);
+ CertificationChangeTransition successCertification = new CertificationChangeTransition(serviceBusinessLogic, LifeCycleTransitionEnum.CERTIFY, componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
successCertification.setNodeTemplateOperation(nodeTemplateOperation);
stateTransitions.put(successCertification.getName().name(), successCertification);
}
- public LifeCycleTransition getLifecycleTransition(LifeCycleTransitionEnum transitionEnum) {
- return stateTransitions.get(transitionEnum.name());
- }
-
- public Either<Service, ResponseFormat> changeServiceState(String serviceId, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, boolean needLock) {
- return (Either<Service, ResponseFormat>) changeComponentState(ComponentTypeEnum.SERVICE, serviceId, modifier, transitionEnum, changeInfo, inTransaction, needLock);
+ @VisibleForTesting
+ Map<String, LifeCycleTransition> getStartTransition() {
+ return stateTransitions;
}
// TODO: rhalili - should use changeComponentState when possible
@@ -190,7 +166,7 @@ public class LifecycleBusinessLogic {
ResponseFormat error = componentUtils.getInvalidContentErrorAndAudit(modifier, componentId, AuditingActionEnum.CHECKOUT_RESOURCE);
return Either.right(error);
}
- Component component = null;
+ Component component;
log.debug("get resource from graph");
ResponseFormat errorResponse;
@@ -205,9 +181,10 @@ public class LifecycleBusinessLogic {
// lock resource
if (!inTransaction && needLock) {
log.debug("lock component {}", componentId);
- Either<Boolean, ResponseFormat> eitherLockResource = lockComponent(componentType, component);
- if (eitherLockResource.isRight()) {
- errorResponse = eitherLockResource.right().value();
+ try {
+ lockComponent(componentType, component);
+ }catch (ComponentException e){
+ errorResponse = e.getResponseFormat();
componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(),
new ResourceCommonInfo(componentType.getValue()),
ResourceVersionInfo.newBuilder()
@@ -241,14 +218,17 @@ public class LifecycleBusinessLogic {
return Either.right(validateHighestVersion.right().value());
}
log.debug("after validate Highest Version");
- if (componentType == ComponentTypeEnum.RESOURCE) {
- Either<? extends Component, ResponseFormat> changeResourceResponse = changeResourceState(componentType, modifier, transitionEnum, changeInfo, true, component);
- if (changeResourceResponse.isRight()) {
- return changeResourceResponse;
- }
- component = changeResourceResponse.left().value();
+ final Component oldComponent = component;
+ Either<? extends Component, ResponseFormat> checkedInComponentEither = checkInBeforeCertifyIfNeeded(componentType, modifier, transitionEnum, changeInfo, inTransaction, component);
+ if(checkedInComponentEither.isRight()) {
+ return Either.right(checkedInComponentEither.right().value());
}
- return changeState(component, lifeCycleTransition, componentType, modifier, changeInfo, inTransaction);
+ component = checkedInComponentEither.left().value();
+ return changeState(component, lifeCycleTransition, componentType, modifier, changeInfo, inTransaction)
+ .left()
+ .bind(c -> updateCatalog(c, oldComponent, ChangeTypeEnum.LIFECYCLE));
+
+
} finally {
component.setUniqueId(componentId);
if (!inTransaction && needLock) {
@@ -262,66 +242,36 @@ public class LifecycleBusinessLogic {
}
- /*
- * special case for certification of VFCMT - VFCMT can be certified by Designer or Tester right after checkin in case the operation "submit for test" / "start testing" is done to "VFCMT" - please return error 400
- */
- private Either<? extends Component, ResponseFormat> changeResourceState(ComponentTypeEnum componentType, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
- Component component) {
- LifecycleStateEnum oldState = component.getLifecycleState();
- Component updatedComponent = component;
- if (transitionEnum == LifeCycleTransitionEnum.START_CERTIFICATION || transitionEnum == LifeCycleTransitionEnum.CERTIFICATION_REQUEST) {
- //for VFCMT use old error for backward comp.
- ActionStatus status = isComponentVFCMT(component, componentType) ? ActionStatus.RESOURCE_VFCMT_LIFECYCLE_STATE_NOT_VALID : ActionStatus.RESOURCE_LIFECYCLE_STATE_NOT_VALID;
- return Either.right(componentUtils.getResponseFormat(status, transitionEnum.getDisplayName()));
- } // certify is done directly from checkin
- else if (transitionEnum == LifeCycleTransitionEnum.CERTIFY) {
- log.debug("Certification request for resource {} ", component.getUniqueId());
- if (oldState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
- log.debug("Resource {} is in Checkout state perform checkin", component.getUniqueId());
- Either<? extends Component, ResponseFormat> actionResponse = changeState(component, stateTransitions.get(LifeCycleTransitionEnum.CHECKIN.name()), componentType, modifier, changeInfo, inTransaction);
- if (actionResponse.isRight()) {
- log.debug("Failed to check in Resource {} error {}", component.getUniqueId(), actionResponse.right().value());
- return actionResponse;
- }
- updatedComponent = actionResponse.left().value();
- oldState = updatedComponent.getLifecycleState();
- }
- if (oldState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN) {
- // we will call for submit for testing first and then for certify
- Either<? extends Component, ResponseFormat> actionResponse = changeState(updatedComponent, stateTransitions.get(LifeCycleTransitionEnum.CERTIFICATION_REQUEST.name()), componentType, modifier, changeInfo, inTransaction);
- if (actionResponse.isRight()) {
- return actionResponse;
- }
- updatedComponent = actionResponse.left().value();
- actionResponse = changeState(updatedComponent, stateTransitions.get(LifeCycleTransitionEnum.START_CERTIFICATION.name()), componentType, modifier, changeInfo, inTransaction);
- if (actionResponse.isRight()) {
- return actionResponse;
+ private Either<Component, ResponseFormat> updateCatalog(Component component, Component oldComponent, ChangeTypeEnum changeStatus){
+
+ log.debug("updateCatalog start");
+ Component result = component == null? oldComponent : component;
+ if(component != null){
+ ActionStatus status = catalogOperations.updateCatalog(changeStatus,component);
+ if(status != ActionStatus.OK){
+ return Either.right( componentUtils.getResponseFormat(status));
}
- updatedComponent = actionResponse.left().value();
- }
- if(oldState == LifecycleStateEnum.CERTIFIED){
- failOnAlreadyCertifiedResource(component);
- }
}
- return Either.left(updatedComponent);
+
+ return Either.left(result);
}
- private void failOnAlreadyCertifiedResource(Component component) {
- String firstName = null;
- String lastName = null;
- if(StringUtils.isNotEmpty(component.getLastUpdaterFullName())){
- String[] fullName = component.getLastUpdaterFullName().split(" ");
- if(fullName.length == 2){
- firstName = fullName[0];
- lastName = fullName[1];
+ private Either<? extends Component, ResponseFormat> checkInBeforeCertifyIfNeeded(ComponentTypeEnum componentType, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
+ Component component) {
+
+ LifecycleStateEnum oldState = component.getLifecycleState();
+ Component updatedComponent = component;
+ log.debug("Certification request for resource {} ", component.getUniqueId());
+ if (oldState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT && transitionEnum == LifeCycleTransitionEnum.CERTIFY) {
+ log.debug("Resource {} is in Checkout state perform checkin", component.getUniqueId());
+ Either<? extends Component, ResponseFormat> actionResponse = changeState(component, stateTransitions.get(LifeCycleTransitionEnum.CHECKIN.name()), componentType, modifier, changeInfo, inTransaction);
+ if (actionResponse.isRight()) {
+ log.debug("Failed to check in Resource {} error {}", component.getUniqueId(), actionResponse.right().value());
}
+ return actionResponse;
}
- throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ALREADY_CERTIFIED,
- component.getName(),
- component.getComponentType().name().toLowerCase(),
- firstName,
- lastName,
- component.getLastUpdaterUserId());
+
+ return Either.left(updatedComponent);
}
private Either<? extends Component, ResponseFormat> changeState(Component component, LifeCycleTransition lifeCycleTransition, ComponentTypeEnum componentType, User modifier, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction) {
@@ -365,7 +315,7 @@ public class LifecycleBusinessLogic {
return Either.right(errorResponse);
}
- Component resourceAfterOperation = operationResult.left().value();
+ Component resourceAfterOperation = operationResult.left().value() == null? component: operationResult.left().value() ;
componentUtils.auditComponent(componentUtils.getResponseFormat(ActionStatus.OK), modifier, resourceAfterOperation,
lifeCycleTransition.getAuditingAction(), new ResourceCommonInfo(componentType.getValue()),
ResourceVersionInfo.newBuilder()
@@ -411,24 +361,21 @@ public class LifecycleBusinessLogic {
return Either.left(true);
}
- private Either<Boolean, ResponseFormat> lockComponent(ComponentTypeEnum componentType, Component component) {
+ private Boolean lockComponent(ComponentTypeEnum componentType, Component component) {
NodeTypeEnum nodeType = componentType.getNodeType();
StorageOperationStatus lockResourceStatus = graphLockOperation.lockComponent(component.getUniqueId(), nodeType);
if (lockResourceStatus.equals(StorageOperationStatus.OK)) {
- return Either.left(true);
+ return true;
} else {
ActionStatus actionStatus = componentUtils.convertFromStorageResponse(lockResourceStatus);
- ResponseFormat responseFormat = componentUtils.getResponseFormat(actionStatus, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(actionStatus, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
}
-
}
private Either<String, ResponseFormat> validateComment(LifecycleChangeInfoWithAction changeInfo, LifeCycleTransitionEnum transitionEnum) {
String comment = changeInfo.getUserRemarks();
- if (LifeCycleTransitionEnum.CANCEL_CERTIFICATION == transitionEnum || LifeCycleTransitionEnum.CERTIFY == transitionEnum || LifeCycleTransitionEnum.FAIL_CERTIFICATION == transitionEnum || LifeCycleTransitionEnum.CHECKIN == transitionEnum
- || LifeCycleTransitionEnum.CERTIFICATION_REQUEST == transitionEnum
+ if (LifeCycleTransitionEnum.CERTIFY == transitionEnum || LifeCycleTransitionEnum.CHECKIN == transitionEnum
// import?
) {
@@ -497,43 +444,36 @@ public class LifecycleBusinessLogic {
* @param needLock
* @return
*/
- public Either<Resource, ResponseFormat> forceResourceCertification(Resource resource, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
- Either<Resource, ResponseFormat> result = null;
+ public Resource forceResourceCertification(Resource resource, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
+ Resource result = null;
Either<ToscaElement, StorageOperationStatus> certifyResourceRes = null;
if (lifecycleChangeInfo.getAction() != LifecycleChanceActionEnum.CREATE_FROM_CSAR) {
log.debug("Force certification is not allowed for the action {}. ", lifecycleChangeInfo.getAction());
- result = Either.right(componentUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ throw new ByActionStatusComponentException(ActionStatus.NOT_ALLOWED);
}
if (!isFirstCertification(resource.getVersion())) {
log.debug("Failed to perform a force certification of resource{}. Force certification is allowed for the first certification only. ", resource.getName());
- result = Either.right(componentUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
+ throw new ByActionStatusComponentException(ActionStatus.NOT_ALLOWED);
}
// lock resource
- if (result == null && !inTransaction && needLock) {
+ if (!inTransaction && needLock) {
log.info("lock component {}", resource.getUniqueId());
- Either<Boolean, ResponseFormat> eitherLockResource = lockComponent(resource.getComponentType(), resource);
- if (eitherLockResource.isRight()) {
- log.error("lock component {} failed", resource.getUniqueId());
- result = Either.right(eitherLockResource.right().value());
- }
+ lockComponent(resource.getComponentType(), resource);
log.info("after lock component {}", resource.getUniqueId());
}
try {
- if (result == null) {
- certifyResourceRes = lifecycleOperation.forceCerificationOfToscaElement(resource.getUniqueId(), user.getUserId(), user.getUserId(), resource.getVersion());
- if (certifyResourceRes.isRight()) {
- StorageOperationStatus status = certifyResourceRes.right().value();
- log.debug("Failed to perform a force certification of resource {}. The status is {}. ", resource.getName(), status);
- result = Either.right(componentUtils.getResponseFormatByResource(componentUtils.convertFromStorageResponse(status), resource));
- }
- }
- if (result == null) {
- result = Either.left(ModelConverter.convertFromToscaElement(certifyResourceRes.left().value()));
+ certifyResourceRes = lifecycleOperation.forceCerificationOfToscaElement(resource.getUniqueId(), user.getUserId(), user.getUserId(), resource.getVersion());
+ if (certifyResourceRes.isRight()) {
+ StorageOperationStatus status = certifyResourceRes.right().value();
+ log.debug("Failed to perform a force certification of resource {}. The status is {}. ", resource.getName(), status);
+ throw new ByResponseFormatComponentException(componentUtils.getResponseFormatByResource(componentUtils.convertFromStorageResponse(status), resource));
}
+ result = ModelConverter.convertFromToscaElement(certifyResourceRes.left().value());
+ resource.setMetadataDefinition(result.getComponentMetadataDefinition());
} finally {
log.info("unlock component {}", resource.getUniqueId());
if (!inTransaction) {
- if (result.isLeft()) {
+ if (result != null) {
janusGraphDao.commit();
} else {
janusGraphDao.rollback();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java
index a63fe2088a..239f15ad5f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoBase.java
@@ -20,9 +20,9 @@
package org.openecomp.sdc.be.components.lifecycle;
-public class LifecycleChangeInfoBase {
+import com.fasterxml.jackson.annotation.JsonInclude;
- private String userRemarks;
+public class LifecycleChangeInfoBase {
public LifecycleChangeInfoBase() {
}
@@ -32,6 +32,9 @@ public class LifecycleChangeInfoBase {
this.userRemarks = userRemarks;
}
+ @JsonInclude
+ private String userRemarks;
+
public String getUserRemarks() {
return userRemarks;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java
index 51ec61ea6b..3df42e4857 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleChangeInfoWithAction.java
@@ -20,12 +20,15 @@
package org.openecomp.sdc.be.components.lifecycle;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
public class LifecycleChangeInfoWithAction extends LifecycleChangeInfoBase {
public enum LifecycleChanceActionEnum {
CREATE_FROM_CSAR, UPDATE_FROM_EXTERNAL_API, UPGRADE_MIGRATION
};
+ @JsonInclude
private LifecycleChanceActionEnum action;
public LifecycleChangeInfoWithAction() {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/StartCertificationTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/StartCertificationTransition.java
deleted file mode 100644
index 582b3fd81c..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/StartCertificationTransition.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*-
- * ============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.sdc.be.components.lifecycle;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
-import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.user.Role;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-
-import java.util.Arrays;
-
-public class StartCertificationTransition extends LifeCycleTransition {
-
- private static final Logger log = Logger.getLogger(StartCertificationTransition.class);
-
- public StartCertificationTransition(ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao) {
- super(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
-
- // authorized roles
- Role[] rsrcServiceStartCertificationRoles = { Role.ADMIN, Role.TESTER };
- Role[] resourceRoles = { Role.ADMIN, Role.TESTER, Role.DESIGNER};
- addAuthorizedRoles(ComponentTypeEnum.RESOURCE, Arrays.asList(resourceRoles));
- addAuthorizedRoles(ComponentTypeEnum.SERVICE, Arrays.asList(rsrcServiceStartCertificationRoles));
- // TODO to be later defined for product
-
- //additional authorized roles for resource type
-// addResouceAuthorizedRoles(ResourceTypeEnum.VFCMT, Arrays.asList(resourceRoles));
- }
-
- @Override
- public LifeCycleTransitionEnum getName() {
- return LifeCycleTransitionEnum.START_CERTIFICATION;
- }
-
- @Override
- public AuditingActionEnum getAuditingAction() {
- return AuditingActionEnum.START_CERTIFICATION_RESOURCE;
- }
-
- @Override
- public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component, ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock, boolean inTransaction) {
-
- log.debug("start performing certification test for resource {}", component.getUniqueId());
- Either<? extends Component, ResponseFormat> result = null;
- try{
- Either<ToscaElement, StorageOperationStatus> stateChangeResult = lifeCycleOperation.startCertificationToscaElement(component.getUniqueId(), modifier.getUserId(), owner.getUserId());
- if (stateChangeResult.isRight()) {
- log.debug("start certification failed on graph");
- StorageOperationStatus response = stateChangeResult.right().value();
- ActionStatus actionStatus = componentUtils.convertFromStorageResponse(response);
-
- if (response.equals(StorageOperationStatus.ENTITY_ALREADY_EXISTS)) {
- actionStatus = ActionStatus.COMPONENT_VERSION_ALREADY_EXIST;
- }
- ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
- result = Either.right(responseFormat);
- }
- else {
- result = Either.left(ModelConverter.convertFromToscaElement(stateChangeResult.left().value()));
- }
- } finally {
- if (result == null || result.isRight()) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Change LifecycleState");
- if (!inTransaction) {
- log.debug("operation failed. do rollback");
- janusGraphDao.rollback();
- }
- } else {
- if (!inTransaction) {
- log.debug("operation success. do commit");
- janusGraphDao.commit();
- }
- }
- }
- return result;
- }
-
- @Override
- public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
- String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
- log.debug("validate before start certification test. resource name={}, oldState={}, owner userId={}", componentName, oldState, owner.getUserId());
-
- // validate user
- Either<Boolean, ResponseFormat> userValidationResponse = userRoleValidation(modifier,component, componentType, lifecycleChangeInfo);
- if (userValidationResponse.isRight()) {
- return userValidationResponse;
- }
-
- if (oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN) || oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_READY_FOR_CERTIFICATION, componentName, componentType.name().toLowerCase());
- return Either.right(error);
- }
-
- if (oldState.equals(LifecycleStateEnum.CERTIFIED)) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_ALREADY_CERTIFIED, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
-
- if (oldState.equals(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS)) {
- ResponseFormat error = componentUtils.getResponseFormat(ActionStatus.COMPONENT_IN_CERT_IN_PROGRESS_STATE, componentName, componentType.name().toLowerCase(), owner.getFirstName(), owner.getLastName(), owner.getUserId());
- return Either.right(error);
- }
-
- return Either.left(true);
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java
index 5342367a09..c66f7ea5dd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/UndoCheckoutTransition.java
@@ -21,11 +21,13 @@
package org.openecomp.sdc.be.components.lifecycle;
import fj.data.Either;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.facade.operations.CatalogOperation;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
@@ -46,6 +48,8 @@ import java.util.Arrays;
public class UndoCheckoutTransition extends LifeCycleTransition {
private static final Logger log = Logger.getLogger(CheckoutTransition.class);
+ private CatalogOperation catalogOperations;
+
public UndoCheckoutTransition(ComponentsUtils componentUtils, ToscaElementLifecycleOperation lifecycleOperation, ToscaOperationFacade toscaOperationFacade, JanusGraphDao janusGraphDao) {
super(componentUtils, lifecycleOperation, toscaOperationFacade, janusGraphDao);
@@ -68,6 +72,10 @@ public class UndoCheckoutTransition extends LifeCycleTransition {
return AuditingActionEnum.UNDO_CHECKOUT_RESOURCE;
}
+ void setCatalogOperations(CatalogOperation catalogOperations) {
+ this.catalogOperations = catalogOperations;
+ }
+
@Override
public Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier, User owner, LifecycleStateEnum oldState, LifecycleChangeInfoWithAction lifecycleChangeInfo) {
String componentName = component.getComponentMetadataDefinition().getMetadataDataDefinition().getName();
@@ -110,7 +118,14 @@ public class UndoCheckoutTransition extends LifeCycleTransition {
result = Either.right(responseFormat);
}
else {
- result = Either.left(ModelConverter.convertFromToscaElement(undoCheckoutResourceResult.left().value()));
+ ToscaElement element = undoCheckoutResourceResult.left().value();
+ if(element == null){
+ catalogOperations.updateCatalog(ChangeTypeEnum.DELETE, component);
+ result = Either.left(null);
+ }
+ else{
+ result = Either.left(ModelConverter.convertFromToscaElement(element));
+ }
}
} finally {
if (result == null || result.isRight()) {
@@ -124,5 +139,6 @@ public class UndoCheckoutTransition extends LifeCycleTransition {
}
return result;
}
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/RelationsComparator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/RelationsComparator.java
index 03ad2164b7..47f71cb05d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/RelationsComparator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/RelationsComparator.java
@@ -41,8 +41,8 @@ public class RelationsComparator {
* a change in relation is determine by comparing the relations type, node, capability and requirement name
*/
public boolean isRelationsChanged(Resource oldResource, Resource newResource) {
- Map<String, List<RequirementCapabilityRelDef>> oldRelationsByInstance = oldResource.groupRelationsByInstanceName(oldResource);
- Map<String, List<RequirementCapabilityRelDef>> newRelationsByInstance = newResource.groupRelationsByInstanceName(newResource);
+ Map<String, List<RequirementCapabilityRelDef>> oldRelationsByInstance = oldResource.groupRelationsFromCsarByInstanceName(oldResource);
+ Map<String, List<RequirementCapabilityRelDef>> newRelationsByInstance = newResource.groupRelationsFromCsarByInstanceName(newResource);
for (Map.Entry<String, List<RequirementCapabilityRelDef>> relationByInst : newRelationsByInstance.entrySet()) {
List<RequirementCapabilityRelDef> oldRelations = oldRelationsByInstance.get(relationByInst.getKey());
List<RequirementCapabilityRelDef> newRelations = relationByInst.getValue();
@@ -79,7 +79,7 @@ public class RelationsComparator {
String newToNodeId = newRelation.getToNode();
Optional<ComponentInstance> oldRelationToNode = oldResource.getComponentInstanceById(oldToNodeId);
Optional<ComponentInstance> newRelationToNode = newResource.getComponentInstanceById(newToNodeId);
- return oldRelationToNode.isPresent() && newRelationToNode.isPresent() && oldRelationToNode.get().getName().equals(newRelationToNode.get().getName());
+ return oldRelationToNode.isPresent() && newRelationToNode.isPresent() && oldRelationToNode.get().getInvariantName().equals(newRelationToNode.get().getInvariantName());
}
private boolean isRelationEqual(RelationshipInfo oldRelationship, RelationshipInfo newRelationship) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/TopologyComparator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/TopologyComparator.java
index 1b14c7bd60..24e669a92d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/TopologyComparator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/TopologyComparator.java
@@ -65,8 +65,8 @@ public class TopologyComparator {
if (oldInstances == null && newInstances == null) {
return Either.left(false);
}
- Map<String, ComponentInstance> oldInstancesByName = MapUtil.toMap(oldInstances, ComponentInstance::getName);
- Map<String, ComponentInstance> newInstancesByName = MapUtil.toMap(newInstances, ComponentInstance::getName);
+ Map<String, ComponentInstance> oldInstancesByName = MapUtil.toMap(oldInstances, ComponentInstance::getInvariantName);
+ Map<String, ComponentInstance> newInstancesByName = MapUtil.toMap(newInstances, ComponentInstance::getInvariantName);
return isTopologyInstancesChanged(oldResource, newResource, oldInstancesByName, newInstancesByName);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolver.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolver.java
index 398b56e148..3f6ed7d7b2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolver.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/capability/SimpleCapabilityResolver.java
@@ -26,7 +26,11 @@ import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
import static java.util.stream.Collectors.toList;
import static org.openecomp.sdc.be.dao.utils.MapUtil.flattenMapValues;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommand.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommand.java
index 9a518e9368..00276a9363 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommand.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/group/GroupPropertiesMergeCommand.java
@@ -25,6 +25,7 @@ import org.openecomp.sdc.be.components.merge.VspComponentsMergeCommand;
import org.openecomp.sdc.be.components.merge.property.DataDefinitionsValuesMergingBusinessLogic;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.PromoteVersionEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.GroupDefinition;
@@ -116,7 +117,7 @@ public class GroupPropertiesMergeCommand implements VspComponentsMergeCommand, C
if (isEmpty(groupsToUpdate)) {
return ActionStatus.OK;
}
- return groupsOperation.updateGroups(currentComponent, groupsToUpdate, false)
+ return groupsOperation.updateGroups(currentComponent, groupsToUpdate, PromoteVersionEnum.MINOR)
.either(updatedGroups -> ActionStatus.OK,
err -> componentsUtils.convertFromStorageResponse(err, currentComponent.getComponentType()));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBL.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBL.java
index 7053b9c8aa..0e88c8f710 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBL.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/ComponentInputsMergeBL.java
@@ -35,11 +35,11 @@ import java.util.Map.Entry;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toMap;
-import static org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic.LAST_COMMAND;
+import static org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic.PENULTIMATE_COMMAND;
import static org.openecomp.sdc.be.utils.PropertyDefinitionUtils.convertListOfProperties;
@org.springframework.stereotype.Component
-@Order(LAST_COMMAND)//must run after all properties values were merged
+@Order(PENULTIMATE_COMMAND)//must run after all properties values were merged but before component instance relations merge
public class ComponentInputsMergeBL extends InputsMergeCommand implements VspComponentsMergeCommand {
public ComponentInputsMergeBL(InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogic, DeclaredInputsResolver declaredInputsResolver, ToscaOperationFacade toscaOperationFacade, ComponentsUtils componentsUtils) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolver.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolver.java
index 8f5fdd3dfd..0d3d294844 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolver.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/DeclaredInputsResolver.java
@@ -21,17 +21,17 @@
package org.openecomp.sdc.be.components.merge.input;
+import com.google.common.base.Strings;
import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.InputDefinition;
-import com.google.common.base.Strings;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.stream.Collectors;
import static org.openecomp.sdc.be.utils.PropertyDefinitionUtils.resolveGetInputProperties;
@@ -88,6 +88,7 @@ public class DeclaredInputsResolver {
List<InputDefinition> inputsForRedeclaration = redeclareInputData.declaredInputIds.stream()
.filter(oldInputsById::containsKey)
.map(oldInputsById::get)
+ .filter(Objects::nonNull)
.map(InputDefinition::new)
.collect(Collectors.toList());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommand.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommand.java
index 3303fe5420..91c6ff05b3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommand.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/GlobalInputsMergeCommand.java
@@ -69,7 +69,10 @@ public class GlobalInputsMergeCommand extends InputsMergeCommand implements Comp
@Override
Map<String, List<PropertyDataDefinition>> getProperties(Component component) {
- return Stream.of(component.safeGetGroupsProperties(), component.safeGetPolicyProperties())
+ return Stream.of(component.safeGetUiComponentInstancesProperties(),
+ component.safeGetUiComponentInstancesInputs(),
+ component.safeGetGroupsProperties(),
+ component.safeGetPolicyProperties())
.flatMap(map -> map.entrySet().stream())
.collect(toMap(Map.Entry::getKey, entry -> convertListOfProperties(entry.getValue())));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsMergeCommand.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsMergeCommand.java
index 385a2c5bf3..0f6c89a592 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsMergeCommand.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsMergeCommand.java
@@ -30,6 +30,7 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import static java.util.Collections.emptyList;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
@@ -59,11 +60,13 @@ public abstract class InputsMergeCommand {
return ActionStatus.OK;
}
List<InputDefinition> mergedInputs = mergeInputsValues(prevComponent, currComponent);
- List<InputDefinition> previouslyDeclaredInputsToMerge = getPreviouslyDeclaredInputsToMerge(prevComponent, currComponent);
+ List<InputDefinition> previouslyDeclaredInputsToMerge = getUniquePreviouslyDeclaredInputsToMerge(prevComponent, currComponent, mergedInputs);
mergedInputs.addAll(previouslyDeclaredInputsToMerge);
return updateInputs(currComponent.getUniqueId(), mergedInputs);
}
+
+
private List<InputDefinition> mergeInputsValues(Component prevComponent, Component currComponent) {
log.debug("#mergeInputsValues - merge inputs values from previous component {} to current component {}", prevComponent.getUniqueId(), currComponent.getUniqueId());
List<InputDefinition> inputsToMerge = getInputsToMerge(currComponent);
@@ -72,6 +75,14 @@ public abstract class InputsMergeCommand {
return inputsToMerge;
}
+ private List<InputDefinition> getUniquePreviouslyDeclaredInputsToMerge(Component prevComponent, Component currComponent, List<InputDefinition> mergedInputs) {
+ List<InputDefinition> previouslyDeclaredInputsToMerge = getPreviouslyDeclaredInputsToMerge(prevComponent, currComponent);
+ return previouslyDeclaredInputsToMerge.stream()
+ .filter(prev -> mergedInputs.stream()
+ .noneMatch(merged -> merged.getName().equals(prev.getName()))).collect(Collectors.toList());
+ }
+
+
private List<InputDefinition> getPreviouslyDeclaredInputsToMerge(Component prevComponent, Component currComponent) {
log.debug("#getPreviouslyDeclaredInputsToMerge - getting inputs that were previously declared from previous component {} and setting on current component {}", prevComponent.getUniqueId(), currComponent.getUniqueId());
if (isEmpty(prevComponent.getInputs())) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogic.java
index ac9a8474bf..d3214fbcd9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/input/InputsValuesMergingBusinessLogic.java
@@ -20,13 +20,12 @@
package org.openecomp.sdc.be.components.merge.input;
-import java.util.List;
-import java.util.Map;
-
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.model.InputDefinition;
+import java.util.List;
+import java.util.Map;
@org.springframework.stereotype.Component
public class InputsValuesMergingBusinessLogic {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentCapabilitiesPropertiesMergeBL.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentCapabilitiesPropertiesMergeBL.java
index 6d2f19e4db..daf20f8c9a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentCapabilitiesPropertiesMergeBL.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentCapabilitiesPropertiesMergeBL.java
@@ -115,6 +115,7 @@ public class ComponentCapabilitiesPropertiesMergeBL implements VspComponentsMerg
propertiesCapabilitiesFilter.setIgnoreCapabiltyProperties(false);
propertiesCapabilitiesFilter.setIgnoreComponentInstances(false);
propertiesCapabilitiesFilter.setIgnoreCapabilities(false);
+ propertiesCapabilitiesFilter.setIgnoreGroups(false);
return toscaOperationFacade.getToscaElement(cmptId, propertiesCapabilitiesFilter)
.right()
.map(err -> {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java
index 7b90bb625e..e4f19355dc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceArtifactsMerge.java
@@ -20,16 +20,19 @@
package org.openecomp.sdc.be.components.merge.instance;
-import fj.data.Either;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
-import org.openecomp.sdc.be.model.*;
+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.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -52,10 +55,14 @@ public class ComponentInstanceArtifactsMerge implements ComponentInstanceMergeIn
Map<String, ArtifactDefinition> deploymentArtifactsCreatedOnTheInstance = componentInstancesDeploymentArtifacts.entrySet()
.stream()
.filter(i -> !originalComponentDeploymentArtifacts.containsKey(i.getKey()))
+ .filter(i -> !ArtifactTypeEnum.VF_MODULES_METADATA.name().equals(i.getValue().getArtifactType()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
dataHolder.setOrigComponentDeploymentArtifactsCreatedOnTheInstance(deploymentArtifactsCreatedOnTheInstance);
-
+// dataHolder.setComponentInstanceDeploymentArtifactsTimeOut(componentInstancesDeploymentArtifacts.entrySet().stream()
+// .collect(Collectors.toMap(Map.Entry::getKey, artifact -> artifact.getValue().getTimeout())));
+ dataHolder.setComponentInstanceDeploymentArtifactsTimeOut(componentInstancesDeploymentArtifacts.entrySet().stream()
+ .collect(HashMap::new, (map,entry) -> map.put(entry.getKey(), entry.getValue().getTimeout()) ,HashMap::putAll));
Map<String, ArtifactDefinition> componentInstancesInformationalArtifacts = currentResourceInstance.safeGetArtifacts();
Map<String, ArtifactDefinition> originalComponentInformationalArtifacts = originComponent.getArtifacts();
Map<String, ArtifactDefinition> informationalArtifactsCreatedOnTheInstance = componentInstancesInformationalArtifacts.entrySet()
@@ -70,12 +77,13 @@ public class ComponentInstanceArtifactsMerge implements ComponentInstanceMergeIn
}
@Override
- public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
+ public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
Map<String, ArtifactDefinition> origInstanceDeploymentArtifactsCreatedOnTheInstance = dataHolder.getOrigComponentDeploymentArtifactsCreatedOnTheInstance();
Map<String, ArtifactDefinition> currentInstanceDeploymentArtifacts = updatedContainerComponent.safeGetComponentInstanceDeploymentArtifacts(newInstanceId);
Map<String, ArtifactDefinition> filteredDeploymentArtifactsToAdd = Optional.ofNullable(origInstanceDeploymentArtifactsCreatedOnTheInstance).orElse(new HashMap<>()).entrySet().stream()
.filter(artifact -> noArtifactWithTheSameLabel(artifact.getValue().getArtifactLabel(), currentInstanceDeploymentArtifacts))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ Map<String, ArtifactDefinition> updatedTimeOutDeploymentArtifacts = getUpdatedTimeOutDeploymentArtifacts(dataHolder, currentInstanceDeploymentArtifacts);
Map<String, ArtifactDefinition> origInstanceInformationalArtifactsCreatedOnTheInstance = dataHolder.getOrigComponentInformationalArtifactsCreatedOnTheInstance();
Map<String, ArtifactDefinition> currentInstanceInformationalArtifacts = updatedContainerComponent.safeGetComponentInstanceInformationalArtifacts(newInstanceId);
Map<String, ArtifactDefinition> filteredInformationalArtifactsToAdd = Optional.ofNullable(origInstanceInformationalArtifactsCreatedOnTheInstance).orElse(new HashMap<>()).entrySet().stream()
@@ -83,6 +91,7 @@ public class ComponentInstanceArtifactsMerge implements ComponentInstanceMergeIn
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Map<String, ArtifactDefinition> allFilteredArtifactsToAdd = new HashMap<>();
allFilteredArtifactsToAdd.putAll(filteredDeploymentArtifactsToAdd);
+ allFilteredArtifactsToAdd.putAll(updatedTimeOutDeploymentArtifacts);
allFilteredArtifactsToAdd.putAll(filteredInformationalArtifactsToAdd);
for (Map.Entry<String, ArtifactDefinition> currentArtifactDefinition : allFilteredArtifactsToAdd.entrySet()) {
@@ -97,15 +106,24 @@ public class ComponentInstanceArtifactsMerge implements ComponentInstanceMergeIn
currentArtifactDefinition.getValue().getPayloadData(),
null, currentArtifactDefinition.getValue().getListHeatParameters());
addEsIdToArtifactJson(jsonForUpdateArtifact, currentArtifactDefinition.getValue().getEsId());
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService =
- artifactsBusinessLogic.updateResourceInstanceArtifactNoContent(newInstanceId, updatedContainerComponent,
+ artifactsBusinessLogic.updateResourceInstanceArtifactNoContent(newInstanceId, updatedContainerComponent,
user, jsonForUpdateArtifact, artifactsBusinessLogic.new ArtifactOperationInfo(
false, false, ArtifactsBusinessLogic.ArtifactOperationEnum.LINK), currentArtifactDefinition.getValue());
- if (uploadArtifactToService.isRight()) {
- return Either.right(uploadArtifactToService.right().value());
- }
}
- return Either.left(updatedContainerComponent);
+ return updatedContainerComponent;
+ }
+
+ private Map<String, ArtifactDefinition> getUpdatedTimeOutDeploymentArtifacts(DataForMergeHolder dataHolder, Map<String, ArtifactDefinition> currentInstanceDeploymentArtifacts) {
+ return currentInstanceDeploymentArtifacts.entrySet().stream()
+ .filter(artifact -> Objects.isNull(artifact.getValue().getTimeout()) || !artifact.getValue().getTimeout()
+ .equals(dataHolder.getComponentInstanceDeploymentArtifactsTimeOut().get(artifact.getKey())))
+ .collect(Collectors.toMap(Map.Entry::getKey, artifact -> mergeTimeOut(artifact.getValue(), dataHolder
+ .getComponentInstanceDeploymentArtifactsTimeOut().get(artifact.getKey()))));
+ }
+
+ private ArtifactDefinition mergeTimeOut(ArtifactDefinition artifact, Integer updatedTimeOut) {
+ artifact.setTimeout(updatedTimeOut);
+ return artifact;
}
private boolean noArtifactWithTheSameLabel(String artifactLabel, Map<String, ArtifactDefinition> currDeploymentArtifacts) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesPropertiesMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesPropertiesMerge.java
index cf19a4d013..9c845046c0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesPropertiesMerge.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceCapabilitiesPropertiesMerge.java
@@ -20,14 +20,13 @@
package org.openecomp.sdc.be.components.merge.instance;
-import fj.data.Either;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.exception.ResponseFormat;
import java.util.ArrayList;
import java.util.Collection;
@@ -54,11 +53,14 @@ public class ComponentInstanceCapabilitiesPropertiesMerge implements ComponentIn
}
@Override
- public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
+ public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
Component origInstanceNode = dataHolder.getOrigInstanceNode();
List<CapabilityDefinition> origInstanceCapabilities = dataHolder.getOrigInstanceCapabilities();
ActionStatus mergeStatus = capabilitiesPropertiesMergeBL.mergeComponentInstanceCapabilities(updatedContainerComponent, origInstanceNode, newInstanceId, origInstanceCapabilities);
- return Either.iif(!ActionStatus.OK.equals(mergeStatus), () -> componentsUtils.getResponseFormat(mergeStatus), () -> updatedContainerComponent);
+ if(!ActionStatus.OK.equals(mergeStatus)){
+ throw new ByActionStatusComponentException(mergeStatus);
+ }
+ return updatedContainerComponent;
}
private List<CapabilityDefinition> getAllInstanceCapabilities(ComponentInstance currentResourceInstance) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceForwardingPathMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceForwardingPathMerge.java
index afcce39a41..68851b1811 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceForwardingPathMerge.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceForwardingPathMerge.java
@@ -23,18 +23,27 @@ package org.openecomp.sdc.be.components.merge.instance;
import fj.data.Either;
import org.javatuples.Pair;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ForwardingPathUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
@org.springframework.stereotype.Component
@@ -60,25 +69,21 @@ public class ComponentInstanceForwardingPathMerge implements ComponentInstanceMe
}
@Override
- public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder,
- Component updatedContainerComponent, String newInstanceId) {
+ public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder,
+ Component updatedContainerComponent, String newInstanceId) {
if (!(updatedContainerComponent instanceof Service)) {
// no need to handle forwarding paths
- return Either.left(updatedContainerComponent);
+ return updatedContainerComponent;
}
Service service = (Service) updatedContainerComponent;
ComponentInstance ci = service.getComponentInstanceById(newInstanceId).orElse(null);
if (ci == null){
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, newInstanceId);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, newInstanceId);
}
Either<Component, StorageOperationStatus> resourceEither = toscaOperationFacade.getToscaFullElement(ci.getComponentUid());
if (resourceEither.isRight() ) {
log.debug("Failed to fetch resource with id {} for instance {}",ci.getComponentUid() ,ci.getUniqueId());
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(resourceEither.right().value()));
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(resourceEither.right().value()));
}
Component fetchedComponent = resourceEither.left().value();
@@ -88,32 +93,18 @@ public class ComponentInstanceForwardingPathMerge implements ComponentInstanceMe
Map<String, ForwardingPathDataDefinition> updated = pair.getValue0();
Map<String, ForwardingPathDataDefinition> deleted = pair.getValue1();
if (deleted != null && !deleted.isEmpty()) {
- Either<Set<String>, ResponseFormat> deleteEither = serviceBusinessLogic
+ Set<String> deleteEither = serviceBusinessLogic
.deleteForwardingPaths(service.getUniqueId(), new HashSet<>(deleted.keySet()), user, false);
- if (deleteEither.isRight()) {
- if (log.isDebugEnabled()) {
- log.debug("Failed to delete forwarding paths : {}", deleted.values().stream()
- .map(ForwardingPathDataDefinition::getName).collect(Collectors.joining(", ", "( ", " )")));
- }
- return Either.right(deleteEither.right().value());
- }
deleted.keySet().forEach(key -> service.getForwardingPaths().remove(key));
}
if (updated != null && !updated.isEmpty()) {
Service updateFPService = new Service();
updateFPService.setForwardingPaths(updated);
- Either<Service, ResponseFormat> updateFPEither = serviceBusinessLogic
+ Service updateFPEither = serviceBusinessLogic
.updateForwardingPath(service.getUniqueId(), updateFPService, user, false);
- if (updateFPEither.isRight()) {
- if (log.isDebugEnabled()) {
- log.debug("Failed to update forwarding paths : {}", updated.values().stream()
- .map(ForwardingPathDataDefinition::getName).collect(Collectors.joining(", ", "( ", " )")));
- }
- return Either.right(updateFPEither.right().value());
- }
updated.forEach((key, forwardingPathDataDefinition) -> service.getForwardingPaths().put(key,forwardingPathDataDefinition));
}
- return Either.left(updatedContainerComponent);
+ return updatedContainerComponent;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMerge.java
index cc1043900b..aa0dc22486 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMerge.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceHeatEnvMerge.java
@@ -24,10 +24,13 @@ import fj.data.Either;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.merge.heat.HeatEnvArtifactsMergeBusinessLogic;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+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.Operation;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@@ -57,7 +60,7 @@ public class ComponentInstanceHeatEnvMerge implements ComponentInstanceMergeInte
}
@Override
- public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
+ public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
List<ArtifactDefinition> origCompInstHeatEnvArtifacts = dataHolder.getOrigComponentInstanceHeatEnvArtifacts();
List<ArtifactDefinition> newCompInstHeatEnvArtifacts = updatedContainerComponent.safeGetComponentInstanceHeatArtifacts(newInstanceId);
List<ArtifactDefinition> artifactsToUpdate = heatEnvArtifactsMergeBusinessLogic.mergeInstanceHeatEnvArtifacts(origCompInstHeatEnvArtifacts, newCompInstHeatEnvArtifacts);
@@ -65,13 +68,9 @@ public class ComponentInstanceHeatEnvMerge implements ComponentInstanceMergeInte
for (ArtifactDefinition artifactInfo : artifactsToUpdate) {
Map<String, Object> json = artifactsBusinessLogic.buildJsonForUpdateArtifact(artifactInfo, ArtifactGroupTypeEnum.DEPLOYMENT, null);
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> uploadArtifactToService = artifactsBusinessLogic.updateResourceInstanceArtifactNoContent(newInstanceId, updatedContainerComponent, user, json,
+ Either<ArtifactDefinition, Operation> uploadArtifactToService = artifactsBusinessLogic.updateResourceInstanceArtifactNoContent(newInstanceId, updatedContainerComponent, user, json,
artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE), null);
- if (uploadArtifactToService.isRight()) {
- log.error("Failed to update artifact {} on resourceInstance {}", artifactInfo.getArtifactLabel(), newInstanceId);
- return Either.right(uploadArtifactToService.right().value());
- }
}
- return Either.left(updatedContainerComponent);
+ return updatedContainerComponent;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInterfacesMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInterfacesMerge.java
index b6aae77c64..b2579b73d2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInterfacesMerge.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceInterfacesMerge.java
@@ -20,10 +20,9 @@
package org.openecomp.sdc.be.components.merge.instance;
-import fj.data.Either;
-import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
@@ -34,9 +33,10 @@ import org.openecomp.sdc.be.model.ComponentInstanceInterface;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.List;
+
@org.springframework.stereotype.Component("ComponentInstanceInterfacesMerge")
public class ComponentInstanceInterfacesMerge implements ComponentInstanceMergeInterface {
@@ -53,10 +53,15 @@ public class ComponentInstanceInterfacesMerge implements ComponentInstanceMergeI
}
@Override
- public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
+ public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
List<ComponentInstanceInterface> origInstanceInterfaces = dataHolder.getOrigComponentInstanceInterfaces();
ActionStatus mergeStatus = mergeComponentInstanceInterfaces(updatedContainerComponent, newInstanceId, origInstanceInterfaces);
- return Either.iif(!ActionStatus.OK.equals(mergeStatus), () -> componentsUtils.getResponseFormat(mergeStatus), () -> updatedContainerComponent);
+ if (!ActionStatus.OK.equals(mergeStatus)){
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(mergeStatus));
+ }
+ else {
+ return updatedContainerComponent;
+ }
}
private ActionStatus mergeComponentInstanceInterfaces(Component currentComponent, String instanceId, List<ComponentInstanceInterface> prevInstanceInterfaces) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogic.java
index a9e3aa4cbf..ee01aa0801 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeDataBusinessLogic.java
@@ -21,7 +21,7 @@
package org.openecomp.sdc.be.components.merge.instance;
import fj.data.Either;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.Component;
@@ -31,11 +31,10 @@ import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
import java.util.List;
-import org.springframework.context.annotation.Lazy;
/**
* Created by chaya on 9/12/2017.
@@ -80,29 +79,18 @@ public class ComponentInstanceMergeDataBusinessLogic {
* @param newInstanceId
* @return
*/
- public Either<Component, ResponseFormat> mergeComponentUserOrigData(User user, DataForMergeHolder dataHolder, org.openecomp.sdc.be.model.Component containerComponent, String newContainerComponentId, String newInstanceId) {
+ public Component mergeComponentUserOrigData(User user, DataForMergeHolder dataHolder, org.openecomp.sdc.be.model.Component containerComponent, String newContainerComponentId, String newInstanceId) {
Either<Component, StorageOperationStatus> componentWithInstancesInputsAndProperties = getComponentWithInstancesMergeEntities(newContainerComponentId);
if (componentWithInstancesInputsAndProperties.isRight()) {
log.error("Component with id {} was not found", newContainerComponentId);
StorageOperationStatus storageOperationStatus = componentWithInstancesInputsAndProperties.right().value();
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageOperationStatus, containerComponent.getComponentType());
- return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ throw new ByActionStatusComponentException(actionStatus);
}
Component updatedContainerComponent = componentWithInstancesInputsAndProperties.left().value();
-
- for (ComponentInstanceMergeInterface compInstMergeBL: componentInstancesMergeBLs) {
- try {
- Either<Component, ResponseFormat> compInstanceMergeEither = compInstMergeBL.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, newInstanceId);
- if (compInstanceMergeEither.isRight()) {
- return Either.right(compInstanceMergeEither.right().value());
- }
- } catch (ComponentException e) {
- return Either.right(componentsUtils.getResponseFormat(e));
- }
- }
-
- return Either.left(updatedContainerComponent);
+ componentInstancesMergeBLs.forEach(c-> c.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, newInstanceId));
+ return updatedContainerComponent;
}
private Either<Component, StorageOperationStatus> getComponentWithInstancesMergeEntities(String containerComponentId) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeInterface.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeInterface.java
index 3492699b24..29ce663fe3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeInterface.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceMergeInterface.java
@@ -20,11 +20,9 @@
package org.openecomp.sdc.be.components.merge.instance;
-import fj.data.Either;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.exception.ResponseFormat;
/**
* Created by chaya on 9/20/2017.
@@ -33,5 +31,5 @@ public interface ComponentInstanceMergeInterface {
void saveDataBeforeMerge(DataForMergeHolder dataHolder, Component containerComponent, ComponentInstance currentResourceInstance, Component originComponent);
- Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId);
+ Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java
index a8c96ea697..cbfc97013a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstancePropsAndInputsMerge.java
@@ -21,13 +21,19 @@
package org.openecomp.sdc.be.components.merge.instance;
import fj.data.Either;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+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.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
import java.util.ArrayList;
import java.util.List;
@@ -64,23 +70,23 @@ public class ComponentInstancePropsAndInputsMerge implements ComponentInstanceMe
}
@Override
- public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
+ public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
Either<List<ComponentInstanceInput>, ActionStatus> instanceInputsEither = mergeComponentInstanceInputsIntoContainer(dataHolder, updatedContainerComponent, newInstanceId);
if (instanceInputsEither.isRight()) {
ActionStatus actionStatus = instanceInputsEither.right().value();
- return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ throw new ByActionStatusComponentException(actionStatus);
}
Either<List<ComponentInstanceProperty>, ActionStatus> instancePropsEither = mergeComponentInstancePropsIntoContainer(dataHolder, updatedContainerComponent, newInstanceId);
if (instancePropsEither.isRight()) {
ActionStatus actionStatus = instancePropsEither.right().value();
- return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ throw new ByActionStatusComponentException(actionStatus);
}
Either<List<InputDefinition>, ActionStatus> inputsEither = mergeComponentInputsIntoContainer(dataHolder, updatedContainerComponent.getUniqueId(), newInstanceId);
if (inputsEither.isRight()) {
ActionStatus actionStatus = inputsEither.right().value();
- return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ throw new ByActionStatusComponentException(actionStatus);
}
- return Either.left(updatedContainerComponent);
+ return updatedContainerComponent;
}
private Either<List<ComponentInstanceProperty>, ActionStatus> mergeComponentInstancePropsIntoContainer(DataForMergeHolder dataHolder, Component updatedComponent, String instanceId) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMerge.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMerge.java
index 07333daa17..8c515a5e8b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMerge.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMerge.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.components.merge.instance;
import fj.data.Either;
import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.merge.utils.CapabilityOwner;
import org.openecomp.sdc.be.components.merge.utils.ComponentInstanceBuildingBlocks;
import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
@@ -94,7 +95,7 @@ public class ComponentInstanceRelationMerge implements ComponentInstanceMergeInt
@Override
- public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
+ public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
Wrapper<Either<Component, ResponseFormat>> resultWrapper = new Wrapper<>();
ContainerRelationsMergeInfo containerRelationsMergeInfo = getRelationsMergeInfo(dataHolder, updatedContainerComponent, resultWrapper);
@@ -113,18 +114,19 @@ public class ComponentInstanceRelationMerge implements ComponentInstanceMergeInt
Stream<RequirementCapabilityRelDef> toRelationsInfoStream = getCapabilitiesRelationInfoStream(updatedContainerComponent, newInstanceId, containerRelationsMergeInfo, instanceBuildBlocks);
Stream<RequirementCapabilityRelDef> fromRelationsInfoStream = getRequirementRelationsInfoStream(updatedContainerComponent, newInstanceId, containerRelationsMergeInfo, instanceBuildBlocks);
List<RequirementCapabilityRelDef> updatedRelations = getUpdatedRelations(toRelationsInfoStream, fromRelationsInfoStream);
- StorageOperationStatus saveResult = toscaOperationFacade.associateResourceInstances(updatedContainerComponent.getUniqueId(), updatedRelations);
- if (saveResult == StorageOperationStatus.OK) {
+ Either<List<RequirementCapabilityRelDef>, StorageOperationStatus> listStorageOperationStatusEither = toscaOperationFacade.associateResourceInstances(null, updatedContainerComponent.getUniqueId(), updatedRelations);
+ if (listStorageOperationStatusEither.isLeft()) {
resultWrapper.setInnerElement(Either.left(updatedContainerComponent));
}
else {
- log.debug("Failed to associate instances of resource {} status is {}", updatedContainerComponent.getUniqueId(), saveResult);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(saveResult), updatedContainerComponent.getUniqueId());
- resultWrapper.setInnerElement(Either.right(responseFormat));
+ StorageOperationStatus status = listStorageOperationStatusEither.right().value();
+ log.debug("Failed to associate instances of resource {} status is {}", updatedContainerComponent.getUniqueId(), status);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), updatedContainerComponent.getUniqueId());
+ throw new ByResponseFormatComponentException(responseFormat);
}
}
}
- return resultWrapper.getInnerElement();
+ return resultWrapper.getInnerElement().left().value();
}
private Stream<RequirementCapabilityRelDef> getRequirementRelationsInfoStream(Component updatedContainerComponent, String newInstanceId, ContainerRelationsMergeInfo containerRelationsMergeInfo, ComponentInstanceBuildingBlocks instanceBuildBlocks) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeCommand.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeCommand.java
new file mode 100644
index 0000000000..317f528ffc
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ComponentInstanceRelationMergeCommand.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.merge.instance;
+
+import fj.data.Either;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.be.components.merge.VspComponentsMergeCommand;
+import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.springframework.core.annotation.Order;
+
+import java.util.List;
+
+import static org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic.LAST_COMMAND;
+
+@org.springframework.stereotype.Component
+@Order(LAST_COMMAND)//must run after all merge commands
+public class ComponentInstanceRelationMergeCommand implements VspComponentsMergeCommand {
+
+ private final ToscaOperationFacade toscaOperationFacade;
+ private final MergeInstanceUtils mergeInstanceUtils;
+ private final ComponentsUtils componentsUtils;
+
+ public ComponentInstanceRelationMergeCommand(ToscaOperationFacade toscaOperationFacade, MergeInstanceUtils mergeInstanceUtils, ComponentsUtils componentsUtils) {
+ this.toscaOperationFacade = toscaOperationFacade;
+ this.mergeInstanceUtils = mergeInstanceUtils;
+ this.componentsUtils = componentsUtils;
+ }
+ @Override
+ public ActionStatus mergeComponents(Component prevComponent, Component currentComponent) {
+ List<RequirementCapabilityRelDef> updatedUiRelations = mergeInstanceUtils.getUpdatedUiRelations(prevComponent, currentComponent);
+ if(CollectionUtils.isNotEmpty(updatedUiRelations)){
+ return associateResourceInstances(currentComponent, updatedUiRelations);
+ }
+ return ActionStatus.OK;
+ }
+
+ private ActionStatus associateResourceInstances(Component currentComponent, List<RequirementCapabilityRelDef> updatedUiRelations) {
+ Either<List<RequirementCapabilityRelDef>, StorageOperationStatus> listStorageOperationStatusEither = toscaOperationFacade.associateResourceInstances(null, currentComponent.getUniqueId(), updatedUiRelations);
+ if (listStorageOperationStatusEither.isLeft()) {
+ currentComponent.getComponentInstancesRelations().addAll(updatedUiRelations);
+ } else {
+ return componentsUtils.convertFromStorageResponse(listStorageOperationStatusEither.right().value());
+ }
+ return ActionStatus.OK;
+ }
+
+ @Override
+ public String description() {
+ return "merge component instances from old component to new component";
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolder.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolder.java
index 9d2df73e00..926daab1d3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolder.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/DataForMergeHolder.java
@@ -21,9 +21,20 @@
package org.openecomp.sdc.be.components.merge.instance;
-import org.openecomp.sdc.be.model.*;
-
-import java.util.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceInterface;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.InputDefinition;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
/**
* Created by chaya on 9/7/2017.
@@ -43,6 +54,7 @@ public class DataForMergeHolder {
private Component currInstanceNode;
private String origComponentInstId;
private List<ComponentInstanceInterface> origComponentInstanceInterfaces;
+ private Map <String, Integer> componentInstanceDeploymentArtifactsTimeOut;
public DataForMergeHolder() {
origComponentInstanceInputs = new ArrayList<>();
@@ -52,6 +64,7 @@ public class DataForMergeHolder {
origCompInstDeploymentArtifactsCreatedOnTheInstance = new HashMap<>();
origInstanceCapabilities = new ArrayList<>();
origComponentInstanceInterfaces = new ArrayList<>();
+ componentInstanceDeploymentArtifactsTimeOut = new HashMap<>();
}
List<ArtifactDefinition> getOrigComponentInstanceHeatEnvArtifacts() {
@@ -178,6 +191,14 @@ public class DataForMergeHolder {
this.origComponentInstId = origComponentInstId;
}
+ void setComponentInstanceDeploymentArtifactsTimeOut(Map<String,Integer> componentInstancesDeploymentArtifacts) {
+ this.componentInstanceDeploymentArtifactsTimeOut = componentInstancesDeploymentArtifacts;
+ }
+
+ public Map<String, Integer> getComponentInstanceDeploymentArtifactsTimeOut() {
+ return componentInstanceDeploymentArtifactsTimeOut;
+ }
+
public List<ComponentInstanceInterface> getOrigComponentInstanceInterfaces() {
return origComponentInstanceInterfaces;
}
@@ -185,4 +206,5 @@ public class DataForMergeHolder {
public void setOrigComponentInstanceInterfaces(List<ComponentInstanceInterface> origComponentInstanceInterfaces) {
this.origComponentInstanceInterfaces = origComponentInstanceInterfaces;
}
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java
index bc6e0309ef..e0fb64325c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java
@@ -21,14 +21,12 @@
*/
package org.openecomp.sdc.be.components.merge.instance;
-import fj.data.Either;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ExternalReferencesOperation;
-import org.openecomp.sdc.exception.ResponseFormat;
import java.util.List;
import java.util.Map;
@@ -54,7 +52,7 @@ public class ExternalRefsMergeBL implements ComponentInstanceMergeInterface {
}
@Override
- public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
+ public Component mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
Optional<ComponentInstance> componentInstance = updatedContainerComponent.getComponentInstanceById(newInstanceId);
if (!componentInstance.isPresent()) {
throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND,
@@ -65,6 +63,6 @@ public class ExternalRefsMergeBL implements ComponentInstanceMergeInterface {
externalReferencesOperation.addAllExternalReferences(updatedContainerComponent.getUniqueId(),
componentInstance.get().getUniqueId(), savedExternalRefs);
}
- return Either.left(updatedContainerComponent);
+ return updatedContainerComponent;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommand.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommand.java
index 8d09e8b7cb..c31c9fa1cd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommand.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/policy/PoliciesMergeCommand.java
@@ -34,7 +34,11 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.core.annotation.Order;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java
index 5492835a7a..c02eb2820d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java
@@ -20,13 +20,8 @@
package org.openecomp.sdc.be.components.merge.property;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
+import com.google.gson.Gson;
+import fj.data.Either;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -37,9 +32,12 @@ import org.openecomp.sdc.be.tosca.PropertyConvertor;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;
-import com.google.gson.Gson;
-
-import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
@Component
public class PropertyDataValueMergeBusinessLogic {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilder.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilder.java
index ad42fcf41d..d67f46fb07 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilder.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyInstanceMergeDataBuilder.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.components.merge.property;
-import java.util.Objects;
import org.openecomp.sdc.be.dao.utils.MapUtil;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -29,6 +28,7 @@ import org.openecomp.sdc.be.model.InputDefinition;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.stream.Collectors;
class PropertyInstanceMergeDataBuilder {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyValueMerger.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyValueMerger.java
index f9b8bc41e6..39aec8f80b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyValueMerger.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyValueMerger.java
@@ -20,12 +20,6 @@
package org.openecomp.sdc.be.components.merge.property;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.model.DataTypeDefinition;
@@ -34,6 +28,12 @@ import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.springframework.stereotype.Component;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
@Component
public class PropertyValueMerger {
@@ -60,7 +60,7 @@ public class PropertyValueMerger {
private Map<String, Object> mergeMapValue(Map<String, Object> oldValMap, Map<String, Object> newValMap, List<String> inputNamesToMerge, String type, String innertType, Map<String, DataTypeDefinition> dataTypes) {
mergeEntriesExistInOldValue(oldValMap, newValMap, inputNamesToMerge, type, innertType, dataTypes);//continue the recursion
- if (type != null && !type.equals("map")) {
+ if (type != null && !type.equals("map") && !type.equals("json")) {
setOldEntriesNotExistInNewValue(oldValMap, newValMap, inputNamesToMerge);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogic.java
index 009a045663..98957e000d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/resource/ResourceDataMergeBusinessLogic.java
@@ -33,6 +33,7 @@ public class ResourceDataMergeBusinessLogic implements MergeResourceBusinessLogi
private static final Logger log = Logger.getLogger(ResourceDataMergeBusinessLogic.class);
public static final int FIRST_COMMAND = 0;
+ public static final int PENULTIMATE_COMMAND = Integer.MAX_VALUE - 1;
public static final int LAST_COMMAND = Integer.MAX_VALUE;
public static final int ANY_ORDER_COMMAND = 1;
@@ -56,7 +57,7 @@ public class ResourceDataMergeBusinessLogic implements MergeResourceBusinessLogi
for (ComponentsMergeCommand componentMergeCommand : componentMergingCommands) {
ActionStatus mergeStatus = componentMergeCommand.mergeComponents(oldResource, newResource);
if (mergeStatus != ActionStatus.OK) {
- log.error("failed on merge command {} of resource {} status is {}", componentMergeCommand.description(), newResource.getUniqueId(), mergeStatus);
+ log.debug("failed on merge command {} of resource {} status is {}", componentMergeCommand.description(), newResource.getUniqueId(), mergeStatus);
return mergeStatus;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtils.java
index 90988832c8..00a2f6827f 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/utils/MergeInstanceUtils.java
@@ -27,13 +27,24 @@ import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
import org.openecomp.sdc.be.components.merge.instance.RelationMergeInfo;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.RelationshipInfo;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -99,11 +110,11 @@ public class MergeInstanceUtils {
* @param newResource - new version of the same Resource
* @return list of updated Relations created in UI
*/
- public List<RequirementCapabilityRelDef> updateUiRelationsInResource(Resource oldResource, Resource newResource) {
+ public List<RequirementCapabilityRelDef> getUpdatedUiRelations(Component oldResource, Component newResource) {
Map<String, ComponentInstance> mapOldComponentInstances = buildComponentInstanceMap(oldResource, ComponentInstance::getUniqueId);
Map<String, ComponentInstance> mapNewComponentInstances = buildComponentInstanceMap(newResource, ComponentInstance::getName);
- return getUpdatedCapReqDefs(oldResource,
+ return getUpdatedCapReqDefs(oldResource, newResource,
mapOldComponentInstances,
mapNewComponentInstances,
RequirementCapabilityRelDef::isOriginUI);
@@ -276,12 +287,12 @@ public class MergeInstanceUtils {
- private Map<String, ComponentInstance> buildComponentInstanceMap(Resource oldRresource, Function<ComponentInstance, String> getKeyFunc) {
+ private Map<String, ComponentInstance> buildComponentInstanceMap(Component oldRresource, Function<ComponentInstance, String> getKeyFunc) {
return oldRresource.getComponentInstances().stream()
.collect(Collectors.toMap(getKeyFunc, Function.identity(), (p1, p2) -> p1));
}
- private List<RequirementCapabilityRelDef> getUpdatedCapReqDefs(Resource oldResource,
+ private List<RequirementCapabilityRelDef> getUpdatedCapReqDefs(Component oldResource, Component newComponent,
Map<String, ComponentInstance> mapOldComponentInstances,
Map<String, ComponentInstance> mapNewComponentInstances,
Predicate<? super RequirementCapabilityRelDef> filter) {
@@ -290,9 +301,36 @@ public class MergeInstanceUtils {
.map(rel -> createRelationMergeInfoPair(rel, mapOldComponentInstances))
.map(infoPair -> restoreRequirementCapabilityRelDef(infoPair, mapNewComponentInstances))
.filter(Objects::nonNull)
+ .filter(r-> capReqMatchExist(r, newComponent))
.collect(Collectors.toList());
}
+
+ private boolean capReqMatchExist(RequirementCapabilityRelDef rel, Component currentComponent) {
+ return currentComponent.getComponentInstances().stream()
+ .anyMatch(i->isFromInstance(i, rel)) &&
+ currentComponent.getComponentInstances().stream()
+ .anyMatch(i->isToInstance(i, rel));
+ }
+
+ private boolean isToInstance(ComponentInstance inst, RequirementCapabilityRelDef rel) {
+ return inst.getUniqueId().equals(rel.getToNode()) &&
+ inst.getCapabilities().values()
+ .stream()
+ .flatMap(Collection::stream)
+ .anyMatch(cap->cap.getName().equals(rel.resolveSingleRelationship().getRelation().getCapability())
+ && cap.getOwnerId().equals(rel.resolveSingleRelationship().getRelation().getCapabilityOwnerId()));
+ }
+
+ private boolean isFromInstance(ComponentInstance inst, RequirementCapabilityRelDef rel) {
+ return inst.getUniqueId().equals(rel.getFromNode()) &&
+ inst.getRequirements().values()
+ .stream()
+ .flatMap(Collection::stream)
+ .anyMatch(req->req.getName().equals(rel.resolveSingleRelationship().getRelation().getRequirement())
+ && req.getOwnerId().equals(rel.resolveSingleRelationship().getRelation().getRequirementOwnerId()));
+ }
+
private ImmutablePair<RelationMergeInfo, RelationMergeInfo> createRelationMergeInfoPair(RequirementCapabilityRelDef reqCapDef,
Map<String, ComponentInstance> mapOldComponentInstances) {
@@ -331,11 +369,13 @@ public class MergeInstanceUtils {
}
private RequirementCapabilityRelDef restoreRequirementRelDef(ImmutablePair<RelationMergeInfo, RelationMergeInfo> mergeInfoPair, Map<String, ComponentInstance> mapNewComponentInstances) {
- RequirementCapabilityRelDef capRelDefFrom;
+ RequirementCapabilityRelDef capRelDefFrom = null;
RelationMergeInfo mergeInfoFrom = mergeInfoPair.getLeft();
if (mergeInfoFrom != null) {
ComponentInstance newComponentInstanceFrom = mapNewComponentInstances.get(mergeInfoFrom.getCapOwnerName());
- capRelDefFrom = restoreRequirementRelDef(newComponentInstanceFrom, mergeInfoFrom, newComponentInstanceFrom.getUniqueId());
+ if(newComponentInstanceFrom != null){
+ capRelDefFrom = restoreRequirementRelDef(newComponentInstanceFrom, mergeInfoFrom, newComponentInstanceFrom.getUniqueId());
+ }
}
else {
capRelDefFrom = null;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/path/ForwardingPathValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/path/ForwardingPathValidator.java
index 53b8c6c834..9d1167a8c1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/path/ForwardingPathValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/path/ForwardingPathValidator.java
@@ -23,6 +23,7 @@ package org.openecomp.sdc.be.components.path;
import fj.data.Either;
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.model.ComponentParametersView;
@@ -30,7 +31,6 @@ import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -49,108 +49,68 @@ public class ForwardingPathValidator {
private static final int PROTOCOL_LENGTH = 200;
private static final int DESTINATION_PORT_LENGTH = 200;
- public Either<Boolean, ResponseFormat> validateForwardingPaths(Collection<ForwardingPathDataDefinition> paths,
- String serviceId, boolean isUpdate) {
+ public void validateForwardingPaths(Collection<ForwardingPathDataDefinition> paths,
+ String serviceId, boolean isUpdate) {
for (ForwardingPathDataDefinition path : paths) {
- Either<Boolean, ResponseFormat> forwardingPathResponseEither = validateForwardingPath(path,
- serviceId, isUpdate);
- if (forwardingPathResponseEither.isRight()) {
- return forwardingPathResponseEither;
- }
+ validateForwardingPath(path, serviceId, isUpdate);
}
- return Either.left(Boolean.TRUE);
}
- private Either<Boolean, ResponseFormat> validateForwardingPath(ForwardingPathDataDefinition path,
- String serviceId, boolean isUpdate) {
+ private void validateForwardingPath(ForwardingPathDataDefinition path, String serviceId, boolean isUpdate) {
ResponseFormatManager responseFormatManager = getResponseFormatManager();
-
- Either<Boolean, ResponseFormat> errorResponseName = validateName(path,
- responseFormatManager, serviceId, isUpdate);
- if (errorResponseName != null)
- return errorResponseName;
-
- Either<Boolean, ResponseFormat> protocolErrorResponse = validateProtocol(path, responseFormatManager);
- if (protocolErrorResponse != null)
- return protocolErrorResponse;
-
- Either<Boolean, ResponseFormat> portNumberResponse = validateDestinationPortNumber(path, responseFormatManager);
- if (portNumberResponse != null)
- return portNumberResponse;
-
- return Either.left(true);
+ validateName(path, responseFormatManager, serviceId, isUpdate);
+ validateProtocol(path);
+ validateDestinationPortNumber(path);
}
- private Either<Boolean, ResponseFormat> validateDestinationPortNumber(ForwardingPathDataDefinition dataDefinition,
- ResponseFormatManager responseFormatManager) {
+ private void validateDestinationPortNumber(ForwardingPathDataDefinition dataDefinition) {
if (dataDefinition.getDestinationPortNumber() != null &&
dataDefinition.getDestinationPortNumber().length() > DESTINATION_PORT_LENGTH ) {
logger.debug("Forwarding path destination port {} too long, , maximum allowed 200 characters ",
dataDefinition.getDestinationPortNumber());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
+ throw new ByActionStatusComponentException(ActionStatus
.FORWARDING_PATH_DESTINATION_PORT_MAXIMUM_LENGTH, dataDefinition.getDestinationPortNumber());
- return Either.right(errorResponse);
}
- return null;
}
- private Either<Boolean, ResponseFormat> validateProtocol(ForwardingPathDataDefinition dataDefinition,
- ResponseFormatManager responseFormatManager) {
+ private void validateProtocol(ForwardingPathDataDefinition dataDefinition) {
if (dataDefinition.getProtocol() != null && dataDefinition.getProtocol().length() > PROTOCOL_LENGTH) {
logger.debug("Forwarding path protocol {} too long, , maximum allowed 200 characters ", dataDefinition.getProtocol());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .FORWARDING_PATH_PROTOCOL_MAXIMUM_LENGTH, dataDefinition.getProtocol());
- return Either.right(errorResponse);
+ throw new ByActionStatusComponentException(ActionStatus.FORWARDING_PATH_PROTOCOL_MAXIMUM_LENGTH, dataDefinition.getProtocol());
}
- return null;
}
- private Either<Boolean, ResponseFormat> validateName(ForwardingPathDataDefinition dataDefinition,
+ private void validateName(ForwardingPathDataDefinition dataDefinition,
ResponseFormatManager responseFormatManager,
String serviceId, boolean isUpdate) {
String pathName = dataDefinition.getName();
- Either<Boolean, ResponseFormat> pathEmptyResponse = validatePathNameIfEmpty(responseFormatManager, pathName);
- if (pathEmptyResponse != null)
- return pathEmptyResponse;
+ validatePathNameIfEmpty(responseFormatManager, pathName);
- Either<Boolean, ResponseFormat> pathLengthResponse = validatePathNameLength(responseFormatManager, pathName);
- if (pathLengthResponse != null)
- return pathLengthResponse;
+ validatePathNameLength(responseFormatManager, pathName);
- Either<Boolean, ResponseFormat> isPathNameUniqueResponse = validatePathIfUnique(dataDefinition, serviceId, isUpdate, responseFormatManager );
- if(isPathNameUniqueResponse.isRight()) {
- return Either.right(isPathNameUniqueResponse.right().value());
- }
- if (!isPathNameUniqueResponse.left().value()) {
+ Boolean isPathNameUniqueResponse = validatePathIfUnique(dataDefinition, serviceId, isUpdate, responseFormatManager );
+ if (!isPathNameUniqueResponse) {
logger.debug("Forwarding path name {} already in use ", dataDefinition.getName());
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .FORWARDING_PATH_NAME_ALREADY_IN_USE, dataDefinition.getName());
- return Either.right(errorResponse);
+ throw new ByActionStatusComponentException(ActionStatus.FORWARDING_PATH_NAME_ALREADY_IN_USE, dataDefinition.getName());
}
- return null;
}
- private Either<Boolean, ResponseFormat> validatePathNameLength(ResponseFormatManager responseFormatManager, String pathName) {
+ private void validatePathNameLength(ResponseFormatManager responseFormatManager, String pathName) {
if (pathName.length() > PATH_NAME_LENGTH) {
logger.debug("Forwarding path name {} too long, , maximum allowed 200 characters ", pathName);
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .FORWARDING_PATH_NAME_MAXIMUM_LENGTH, pathName);
- return Either.right(errorResponse);
+ throw new ByActionStatusComponentException(ActionStatus.FORWARDING_PATH_NAME_MAXIMUM_LENGTH, pathName);
}
- return null;
}
- private Either<Boolean, ResponseFormat> validatePathNameIfEmpty(ResponseFormatManager responseFormatManager, String pathName) {
+ private void validatePathNameIfEmpty(ResponseFormatManager responseFormatManager, String pathName) {
if (StringUtils.isEmpty(pathName)) {
logger.debug("Forwarding Path Name can't be empty");
- ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus.FORWARDING_PATH_NAME_EMPTY);
- return Either.right(errorResponse);
+ throw new ByActionStatusComponentException(ActionStatus.FORWARDING_PATH_NAME_EMPTY);
}
- return null;
}
- private Either<Boolean, ResponseFormat> validatePathIfUnique(ForwardingPathDataDefinition dataDefinition, String serviceId,
+ private Boolean validatePathIfUnique(ForwardingPathDataDefinition dataDefinition, String serviceId,
boolean isUpdate, ResponseFormatManager responseFormatManager) {
boolean isPathNameUnique = false;
ComponentParametersView filter = new ComponentParametersView(true);
@@ -158,7 +118,7 @@ public class ForwardingPathValidator {
Either<Service, StorageOperationStatus> forwardingPathOrigin = toscaOperationFacade
.getToscaElement(serviceId, filter);
if (forwardingPathOrigin.isRight()){
- return Either.right(responseFormatManager.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
Collection<ForwardingPathDataDefinition> allPaths = forwardingPathOrigin.left().value().getForwardingPaths().values();
Map<String, String> pathNames = new HashMap<>();
@@ -181,7 +141,7 @@ public class ForwardingPathValidator {
isPathNameUnique = true;
}
- return Either.left(isPathNameUnique);
+ return isPathNameUnique;
}
protected ResponseFormatManager getResponseFormatManager() {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java
index e7c97ed36e..c7d9cfb841 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclarator.java
@@ -20,15 +20,7 @@
package org.openecomp.sdc.be.components.property;
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-import static org.openecomp.sdc.be.model.utils.ComponentUtilities.getInputAnnotations;
-
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
import org.openecomp.sdc.be.datatypes.elements.Annotation;
@@ -45,6 +37,15 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+import static org.openecomp.sdc.be.model.utils.ComponentUtilities.getInputAnnotations;
+
@org.springframework.stereotype.Component
public class ComponentInstanceInputPropertyDeclarator extends DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceInput> {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java
index 3d28617369..1d8a23ec55 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclarator.java
@@ -21,11 +21,6 @@
package org.openecomp.sdc.be.components.property;
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.utils.PropertiesUtils;
@@ -41,6 +36,12 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
@org.springframework.stereotype.Component
public class ComponentInstancePropertyDeclarator extends DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceProperty> {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java
index b1910ad217..14479d4263 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclarator.java
@@ -18,10 +18,6 @@ package org.openecomp.sdc.be.components.property;
import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -34,6 +30,11 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
@org.springframework.stereotype.Component
public class ComponentPropertyDeclarator extends DefaultPropertyDeclarator<Component, PropertyDataDefinition> {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
index fde76d2a5d..030fc46887 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
@@ -20,22 +20,8 @@
package org.openecomp.sdc.be.components.property;
-import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
-import static org.openecomp.sdc.common.api.Constants.GET_POLICY;
-
import com.google.gson.Gson;
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
@@ -62,6 +48,21 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.yaml.snakeyaml.Yaml;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
+import static org.openecomp.sdc.common.api.Constants.GET_POLICY;
+
public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends PropertiesOwner, PROPERTYTYPE extends PropertyDataDefinition> implements PropertyDeclarator {
private static final Logger log = Logger.getLogger(DefaultPropertyDeclarator.class);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java
index f9ef479ab0..b27cbee037 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclarator.java
@@ -20,16 +20,7 @@
package org.openecomp.sdc.be.components.property;
-import static java.util.stream.Collectors.toList;
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
-
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -42,6 +33,16 @@ import org.openecomp.sdc.be.model.operations.impl.GroupOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+import static java.util.stream.Collectors.toList;
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
+
@org.springframework.stereotype.Component
public class GroupPropertyDeclarator extends DefaultPropertyDeclarator<GroupDefinition, PropertyDataDefinition> {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java
index 9cf6ff9fa4..eb7dd688b7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclarator.java
@@ -19,15 +19,7 @@
*/
package org.openecomp.sdc.be.components.property;
-import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
-
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -40,6 +32,15 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
+
@org.springframework.stereotype.Component
public class PolicyPropertyDeclarator extends DefaultPropertyDeclarator<PolicyDefinition, PropertyDataDefinition> {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java
new file mode 100644
index 0000000000..85370d2211
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyConstraintsUtils.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.property;
+
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
+import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraintException;
+
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Objects.nonNull;
+import static java.util.stream.Collectors.toMap;
+
+/**
+ * Provides specific functionality for property constraints
+ */
+public class PropertyConstraintsUtils {
+
+ private PropertyConstraintsUtils(){}
+
+ public static void validatePropertiesConstraints(Resource newResource, Resource oldResource) {
+ if(oldResource.getProperties() != null && newResource.getProperties() != null){
+ Map<String, PropertyDefinition> oldPropWithConstraints = oldResource.getProperties()
+ .stream()
+ .filter(p -> p.getConstraints() != null)
+ .collect(toMap(PropertyDefinition::getName,p -> p));
+
+ newResource.getProperties()
+ .stream()
+ .filter(p -> p.getConstraints() != null && oldPropWithConstraints.containsKey(p.getName()))
+ .forEach(p -> validatePropertyConstraints(p.getConstraints(), oldPropWithConstraints.get(p.getName()).getConstraints()));
+ }
+ }
+
+ private static void validatePropertyConstraints(List<PropertyConstraint> newConstraints, List<PropertyConstraint> oldConstraints) {
+ Map <ConstraintType, PropertyConstraint> oldConstraintsByType = oldConstraints.stream()
+ .filter(c -> nonNull(c) && nonNull(c.getConstraintType()))
+ .collect(toMap(PropertyConstraint::getConstraintType, c -> c));
+
+ newConstraints.stream()
+ .filter(c -> nonNull(c) && oldConstraintsByType.containsKey(c.getConstraintType()))
+ .forEach(c -> validatePropertyConstraint(c, oldConstraintsByType.get(c.getConstraintType())));
+ }
+
+ private static void validatePropertyConstraint(PropertyConstraint newConstraint, PropertyConstraint currConstraint) {
+ try {
+ currConstraint.validateValueOnUpdate(newConstraint);
+ } catch (PropertyConstraintException e) {
+ throw new ByActionStatusComponentException(e.getActionStatus(), e.getParams());
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
index 17221d153c..c60c8f21c2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
@@ -20,14 +20,12 @@
package org.openecomp.sdc.be.components.property;
-import static org.apache.commons.collections.MapUtils.isNotEmpty;
-
import fj.data.Either;
-import java.util.Arrays;
-import java.util.List;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentInstancePropertyToPolicyDeclarator;
import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentPropertyToPolicyDeclarator;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstInputsMap;
import org.openecomp.sdc.be.model.ComponentInstancePropInput;
@@ -36,6 +34,14 @@ import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.commons.collections.MapUtils.isNotEmpty;
+
@org.springframework.stereotype.Component
public class PropertyDeclarationOrchestrator {
@@ -67,24 +73,25 @@ public class PropertyDeclarationOrchestrator {
}
public Either<List<InputDefinition>, StorageOperationStatus> declarePropertiesToInputs(Component component, ComponentInstInputsMap componentInstInputsMap) {
+ updatePropertiesConstraints(component, componentInstInputsMap);
PropertyDeclarator propertyDeclarator = getPropertyDeclarator(componentInstInputsMap);
Pair<String, List<ComponentInstancePropInput>> propsToDeclare = componentInstInputsMap.resolvePropertiesToDeclare();
return propertyDeclarator.declarePropertiesAsInputs(component, propsToDeclare.getLeft(), propsToDeclare.getRight());
}
+ private void updatePropertiesConstraints(Component component, ComponentInstInputsMap componentInstInputsMap) {
+ componentInstInputsMap.getComponentInstanceProperties().forEach((k, v) -> updatePropsConstraints(component.safeGetComponentInstancesProperties(), k, v));
+ componentInstInputsMap.getComponentInstanceInputsMap().forEach((k, v) -> updatePropsConstraints(component.safeGetComponentInstancesInputs(), k, v));
+ componentInstInputsMap.getGroupProperties().forEach((k, v) -> updatePropsConstraints(component.safeGetPolicyProperties(), k, v));
+ componentInstInputsMap.getPolicyProperties().forEach((k, v) -> updatePropsConstraints(component.safeGetGroupsProperties(), k, v));
+ }
+
public Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesToPolicies(Component component, ComponentInstInputsMap componentInstInputsMap) {
PropertyDeclarator propertyDeclarator = getPropertyDeclarator(componentInstInputsMap);
Pair<String, List<ComponentInstancePropInput>> propsToDeclare = componentInstInputsMap.resolvePropertiesToDeclare();
return propertyDeclarator.declarePropertiesAsPolicies(component, propsToDeclare.getLeft(), propsToDeclare.getRight());
}
- /**
- *
- * @param component
- * @param componentInstInputsMap
- * @param input
- * @return
- */
public Either<InputDefinition, StorageOperationStatus> declarePropertiesToListInput(Component component, ComponentInstInputsMap componentInstInputsMap, InputDefinition input) {
PropertyDeclarator propertyDeclarator = getPropertyDeclarator(componentInstInputsMap);
Pair<String, List<ComponentInstancePropInput>> propsToDeclare = componentInstInputsMap.resolvePropertiesToDeclare();
@@ -92,6 +99,32 @@ public class PropertyDeclarationOrchestrator {
return propertyDeclarator.declarePropertiesAsListInput(component, propsToDeclare.getLeft(), propsToDeclare.getRight(), input);
}
+ private <T extends PropertyDataDefinition> void updatePropsConstraints(Map<String, List<T>> instancesProperties , String ownerId, List<ComponentInstancePropInput> inputs) {
+ Optional<List<T>> propertiesOpt = instancesProperties.entrySet()
+ .stream()
+ .filter(e -> e.getKey().equals(ownerId))
+ .map(Map.Entry::getValue)
+ .findFirst();
+ if(propertiesOpt.isPresent()){
+ Map<String, PropertyDataDefinition> instProps = propertiesOpt.get()
+ .stream()
+ .collect(Collectors.toMap(PropertyDataDefinition::getName, p->p));
+ inputs.stream()
+ .filter(i->instProps.containsKey(i.getName()))
+ .forEach(i->updatePropConstraints(i, instProps.get(i.getName())));
+
+ }
+ }
+
+ private void updatePropConstraints(PropertyDataDefinition input, PropertyDataDefinition property) {
+ if(CollectionUtils.isNotEmpty(property.getPropertyConstraints())){
+ input.setPropertyConstraints(property.getPropertyConstraints());
+ } else if(property.getSchemaProperty() != null && CollectionUtils.isNotEmpty(property.getSchemaProperty().getPropertyConstraints())){
+ input.setPropertyConstraints(property.getSchemaProperty().getPropertyConstraints());
+ }
+ }
+
+
public StorageOperationStatus unDeclarePropertiesAsInputs(Component component, InputDefinition inputToDelete) {
log.debug("#unDeclarePropertiesAsInputs - removing input declaration for input {} on component {}", inputToDelete.getName(), component.getUniqueId());
for (PropertyDeclarator propertyDeclarator : propertyDeclaratorsToInput) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java
index f0388157ca..e067b0cd73 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarator.java
@@ -21,13 +21,14 @@
package org.openecomp.sdc.be.components.property;
import fj.data.Either;
-import java.util.List;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstancePropInput;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import java.util.List;
+
public interface PropertyDeclarator {
/**
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java
index 597ef0266c..f8e0ea0912 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentInstancePropertyToPolicyDeclarator.java
@@ -21,10 +21,6 @@
package org.openecomp.sdc.be.components.property.propertytopolicydeclarators;
import fj.data.Either;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.components.property.DefaultPropertyDeclarator;
@@ -39,6 +35,11 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
@org.springframework.stereotype.Component
public class ComponentInstancePropertyToPolicyDeclarator extends
DefaultPropertyDeclarator<ComponentInstance, ComponentInstanceProperty> {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java
index 20dcc397d2..9ac38c3455 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/propertytopolicydeclarators/ComponentPropertyToPolicyDeclarator.java
@@ -21,8 +21,6 @@
package org.openecomp.sdc.be.components.property.propertytopolicydeclarators;
import fj.data.Either;
-import java.util.List;
-import java.util.Optional;
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.components.property.DefaultPropertyDeclarator;
@@ -37,6 +35,9 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import java.util.List;
+import java.util.Optional;
+
@org.springframework.stereotype.Component
public class ComponentPropertyToPolicyDeclarator extends DefaultPropertyDeclarator<Component, PropertyDataDefinition> {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java
index ecf2c057bb..e67b2e1235 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/AsdcComponentsCleanerTask.java
@@ -33,7 +33,11 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
@Component("asdcComponentsCleaner")
public class AsdcComponentsCleanerTask extends AbstractScheduleTaskRunner implements Runnable {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/ComponentsCleanBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/ComponentsCleanBusinessLogic.java
index 03dcf76619..8c56052dc8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/ComponentsCleanBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/scheduledtasks/ComponentsCleanBusinessLogic.java
@@ -26,7 +26,6 @@ import com.google.common.annotations.VisibleForTesting;
import fj.data.Either;
import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
import org.openecomp.sdc.be.dao.api.ActionStatus;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/upgrade/UpgradeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/upgrade/UpgradeBusinessLogic.java
index 2732cb50b4..c388611824 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/upgrade/UpgradeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/upgrade/UpgradeBusinessLogic.java
@@ -30,7 +30,16 @@ import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentDependency;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.UpgradeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -39,7 +48,11 @@ import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
@org.springframework.stereotype.Component("upgradeBusinessLogic")
@@ -80,7 +93,7 @@ public class UpgradeBusinessLogic {
*/
public UpgradeStatus automatedUpgrade(String componentId, List<UpgradeRequest> upgradeRequest, String userId) {
UpgradeStatus status = new UpgradeStatus();
- User user = userValidations.validateUserExists(userId, "automated upgrade", false);
+ User user = userValidations.validateUserExists(userId);
Either<Component, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaFullElement(componentId);
if (storageStatus.isRight()) {
@@ -126,7 +139,7 @@ public class UpgradeBusinessLogic {
*/
public Either<List<ComponentDependency>, ResponseFormat> getComponentDependencies(String componentId, String userId) {
- User user = userValidations.validateUserExists(userId, "get Component Dependencies for automated upgrade", false);
+ User user = userValidations.validateUserExists(userId);
try {
return upgradeOperation.getComponentDependencies(componentId)
.right()
@@ -426,12 +439,8 @@ public class UpgradeBusinessLogic {
LOGGER.debug("In Service {} change instance version {} to version {}", service.getName(), ci.getName(), newVersionComponent.getVersion());
ComponentInstance newComponentInstance = new ComponentInstance();
newComponentInstance.setComponentUid(newVersionComponent.getUniqueId());
- Either<ComponentInstance, ResponseFormat> changeInstanceVersion = componentInstanceBusinessLogic.changeInstanceVersion(service, ci, newComponentInstance, user, service.getComponentType());
- if (changeInstanceVersion.isLeft()) {
- return ActionStatus.OK;
- } else {
- return ActionStatus.GENERAL_ERROR;
- }
+ ComponentInstance changeInstanceVersion = componentInstanceBusinessLogic.changeInstanceVersion(service, ci, newComponentInstance, user, service.getComponentType());
+ return ActionStatus.OK;
}
private boolean matchInstance(ComponentInstance ci, Component newVersionComponent) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java
index 38cdeb8d40..4c891f8da9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/InterfaceOperationUtils.java
@@ -16,14 +16,6 @@
package org.openecomp.sdc.be.components.utils;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
@@ -38,6 +30,15 @@ import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
import org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
public class InterfaceOperationUtils {
private InterfaceOperationUtils() {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
index 613ced6454..22ba03ff27 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/PropertiesUtils.java
@@ -16,20 +16,6 @@
package org.openecomp.sdc.be.components.utils;
-import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections4.ListUtils;
@@ -44,6 +30,20 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.components.property.GetInputUtils.isGetInputValueForInput;
+
public class PropertiesUtils {
private PropertiesUtils() {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java
index c07e77bbbc..5674c2b4cb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java
@@ -51,7 +51,6 @@ public class AccessValidations {
return componentValidations.validateComponentIsCheckedOutByUser(componentId, componentType, userId);
}
-
public void validateUserCanWorkOnComponent(Component component, String userId, String actionContext) {
User user = retrieveUser(userId, actionContext);
validateUserIsAdminOrDesigner(user);
@@ -62,8 +61,9 @@ public class AccessValidations {
retrieveUser(userId, context);
}
+
public void validateUserExist(String userId, String actionContext) {
- userValidations.validateUserExists(userId, actionContext, false);
+ userValidations.validateUserExists(userId);
}
public User userIsAdminOrDesigner(String userId, String actionContext){
@@ -73,7 +73,7 @@ public class AccessValidations {
}
private User retrieveUser(String userId, String actionContext) {
- return userValidations.validateUserExists(userId, actionContext, true);
+ return userValidations.validateUserExists(userId);
}
private void validateUserIsAdminOrDesigner(User user) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
index 22757d0944..1fff794750 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
@@ -16,26 +16,7 @@
package org.openecomp.sdc.be.components.validation;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationOutputName;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOtherOperationOutputsOfComponent;
-import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
-import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
-
import com.google.common.collect.Sets;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -54,6 +35,24 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOperationOutputName;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.getOtherOperationOutputsOfComponent;
+import static org.openecomp.sdc.be.components.utils.InterfaceOperationUtils.isOperationInputMappedToComponentInput;
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.isCapabilityProperty;
+
@Component("interfaceOperationValidation")
public class InterfaceOperationValidation {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
index e87574f120..fccc034baa 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/NodeFilterValidator.java
@@ -22,12 +22,6 @@ package org.openecomp.sdc.be.components.validation;
import com.google.common.collect.ImmutableSet;
import fj.data.Either;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
@@ -50,6 +44,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
@Component("NodeFilterValidator")
public class NodeFilterValidator {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
index 008ee84bbc..7947cbc292 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PolicyUtils.java
@@ -20,17 +20,7 @@
package org.openecomp.sdc.be.components.validation;
-import static org.apache.commons.collections.MapUtils.isEmpty;
-import static org.apache.commons.collections.MapUtils.isNotEmpty;
-import static org.apache.commons.lang3.StringUtils.isEmpty;
-import static org.apache.commons.lang3.StringUtils.isNotEmpty;
-import static org.openecomp.sdc.common.api.Constants.GROUP_POLICY_NAME_DELIMETER;
-
import fj.data.Either;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -44,6 +34,17 @@ import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+import static org.apache.commons.collections.MapUtils.isEmpty;
+import static org.apache.commons.collections.MapUtils.isNotEmpty;
+import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.apache.commons.lang3.StringUtils.isNotEmpty;
+import static org.openecomp.sdc.common.api.Constants.GROUP_POLICY_NAME_DELIMETER;
+
/**
* Provides specific functionality for policy
*/
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java
index 7ad7f0e586..118ca5bd4c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidation.java
@@ -126,11 +126,11 @@ public class ServiceDistributionValidation {
}
}
private void validateUserExists(String userId) {
- userValidations.validateUserExists(userId, "activate Distribution", false);
+ userValidations.validateUserExists(userId);
}
private void validateDistributionServiceLifeCycleState(Service serviceToActivate) {
validateServiceState(serviceToActivate,
- Arrays.asList(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS, LifecycleStateEnum.CERTIFIED));
+ Arrays.asList(LifecycleStateEnum.CERTIFIED));
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
index dd65627738..cb9918cf32 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
@@ -21,47 +21,29 @@
*/
package org.openecomp.sdc.be.components.validation;
-import fj.data.Either;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.user.IUserBusinessLogic;
import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Component;
import java.util.List;
-@org.springframework.stereotype.Component
+import static org.openecomp.sdc.be.dao.api.ActionStatus.USER_INACTIVE;
+
+@Component
public class UserValidations {
private static final Logger log = Logger.getLogger(UserValidations.class);
- private final IUserBusinessLogic userAdmin;
- private final ComponentsUtils componentsUtils;
+ private final UserBusinessLogic userAdmin;
- public UserValidations(IUserBusinessLogic userAdmin, ComponentsUtils componentsUtils) {
+ public UserValidations(UserBusinessLogic userAdmin) {
this.userAdmin = userAdmin;
- this.componentsUtils = componentsUtils;
- }
-
- public User validateUserExists(String userId, String ecompErrorContext, boolean inTransaction) {
- Either<User, ActionStatus> eitherCreator = userAdmin.getUser(userId, inTransaction);
- if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
- ActionStatus status;
- if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
- log.debug("validateUserExists - not authorized user, userId {}", userId);
- status = ActionStatus.AUTH_FAILED;
- } else {
- log.debug("validateUserExists - failed to authorize user, userId {}", userId);
- status = eitherCreator.right().value();
- }
- log.debug("User is not listed. userId {}", userId);
- BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId);
- throw new ByActionStatusComponentException(status);
- }
- return eitherCreator.left().value();
}
public void validateUserRole(User user, List<Role> roles) {
@@ -74,20 +56,11 @@ public class UserValidations {
}
}
- public Either<User, ActionStatus> validateUserExistsActionStatus(String userId, String ecompErrorContext) {
- Either<User, ActionStatus> eitherCreator = userAdmin.getUser(userId, false);
- if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
- if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
- log.debug("validateUserExists - not authorized user, userId {}", userId);
- Either.right(ActionStatus.RESTRICTED_OPERATION);
- } else {
- log.debug("validateUserExists - failed to authorize user, userId {}", userId);
- }
- log.debug("User is not listed. userId {}", userId);
- BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId);
- return Either.right(eitherCreator.right().value());
+ public ActionStatus validateUserExistsActionStatus(String userId) {
+ if (!userAdmin.hasActiveUser(userId)) {
+ return ActionStatus.RESTRICTED_OPERATION;
}
- return Either.left(eitherCreator.left().value());
+ return ActionStatus.OK;
}
public User validateUserNotEmpty(User user, String ecompErrorContext) {
@@ -95,17 +68,22 @@ public class UserValidations {
if (StringUtils.isEmpty(userId)) {
log.debug("User header is missing ");
BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId());
- throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_USER_ID);
}
return user;
}
- public User validateUserExists(User user, String ecompErrorContext, boolean inTransaction) {
- return validateUserExists(user.getUserId(), ecompErrorContext, inTransaction);
+ public User validateUserExists(String userId) {
+ User user = userAdmin.getUser(userId);
+ if (UserStatusEnum.INACTIVE == user.getStatus()) {
+ throw new ByActionStatusComponentException(USER_INACTIVE, userId);
+ }
+ return user;
}
- public void validateUserExist(String userId, String ecompErrorContext) {
- validateUserExists(userId, ecompErrorContext, false);
+ public User validateUserExists(User user) {
+ return validateUserExists(user.getUserId());
}
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java
new file mode 100644
index 0000000000..0c1face3ea
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentContactIdValidator.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.component;
+
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@org.springframework.stereotype.Component
+public class ComponentContactIdValidator implements ComponentFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ComponentContactIdValidator.class.getName());
+ private ComponentsUtils componentsUtils;
+
+ public ComponentContactIdValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
+ log.debug("validate component contactId");
+ ComponentTypeEnum type = component.getComponentType();
+ String contactId = component.getContactId();
+
+ if (!ValidationUtils.validateStringNotEmpty(contactId)) {
+ log.info("contact is missing.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
+ }
+ validateContactId(contactId, user, component, actionEnum, type);
+ }
+
+ private void validateContactId(String contactId, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum, ComponentTypeEnum type) {
+ if (contactId != null && !ValidationUtils.validateContactId(contactId)) {
+ log.info("contact is invalid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java
new file mode 100644
index 0000000000..47d9f8beee
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentDescriptionValidator.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.component;
+
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@org.springframework.stereotype.Component
+public class ComponentDescriptionValidator implements ComponentFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ComponentTagsValidator.class.getName());
+ private ComponentsUtils componentsUtils;
+
+ public ComponentDescriptionValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
+ ComponentTypeEnum type = component.getComponentType();
+ String description = component.getDescription();
+ if (!ValidationUtils.validateStringNotEmpty(description)) {
+ auditErrorAndThrow(user,component, actionEnum, ActionStatus.COMPONENT_MISSING_DESCRIPTION);
+ }
+
+ description = ValidationUtils.cleanUpText(description);
+ try{
+ validateComponentDescription(description, type);
+ } catch(ComponentException e){
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(e.getActionStatus(), component.getComponentType().getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, component.getComponentType());
+ throw e;
+ }
+ component.setDescription(description);
+ }
+
+ private void auditErrorAndThrow(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum, ActionStatus actionStatus) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(actionStatus, component.getComponentType().getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, component.getComponentType());
+ throw new ByActionStatusComponentException(actionStatus, component.getComponentType().getValue());
+ }
+
+ private void validateComponentDescription(String description, ComponentTypeEnum type) {
+ if (description != null) {
+ if (!ValidationUtils.validateDescriptionLength(description)) {
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ }
+
+ if (!ValidationUtils.validateCommentPattern(description)) {
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, type.getValue());
+ }
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java
new file mode 100644
index 0000000000..b8d6117f1b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentFieldValidator.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.component;
+
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+
+
+public interface ComponentFieldValidator {
+
+ void validateAndCorrectField(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum);
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java
new file mode 100644
index 0000000000..432ff41ebb
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentIconValidator.java
@@ -0,0 +1,103 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.component;
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import java.util.Arrays;
+
+@org.springframework.stereotype.Component
+public class ComponentIconValidator implements ComponentFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ComponentIconValidator.class.getName());
+ private static final String DEFAULT_ICON = "defaulticon";
+ private ComponentsUtils componentsUtils;
+
+ public ComponentIconValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
+ log.debug("validate Icon");
+ ComponentTypeEnum type = component.getComponentType();
+ String icon = component.getIcon();
+ if (StringUtils.isEmpty(icon)) {
+ log.info("icon is missing.");
+ component.setIcon(DEFAULT_ICON);
+ }
+ try {
+ if (component.getComponentType().equals(ComponentTypeEnum.SERVICE)) {
+ validateAndSetDefaultIcon(icon, component);
+ } else {
+ validateIcon(icon,component.getComponentType());
+ }
+
+ } catch(ComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
+ : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
+ throw e;
+ }
+ }
+
+ private void validateAndSetDefaultIcon(String icon, org.openecomp.sdc.be.model.Component componnet) {
+ try {
+ if (componnet.getCategories().get(0).getIcons() == null) {
+ componnet.getCategories().get(0).setIcons(Arrays.asList(DEFAULT_ICON));
+ }
+ if (icon != null) {
+ if (componnet.getCategories().get(0).getIcons().contains(icon)) {
+ return;
+ }
+ }
+ } catch (NullPointerException exp) {
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
+ ComponentTypeEnum.SERVICE.getValue());
+ }
+ componnet.setIcon(DEFAULT_ICON);
+ }
+
+ private void validateIcon(String icon, ComponentTypeEnum type) {
+ if (icon != null) {
+ if (!ValidationUtils.validateIconLength(icon)) {
+ log.debug("icon exceeds max length");
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
+ }
+
+ if (!ValidationUtils.validateIcon(icon)) {
+ log.info("icon is invalid.");
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue());
+ }
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java
new file mode 100644
index 0000000000..7b13d2ec5f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentNameValidator.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.component;
+
+import fj.data.Either;
+import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@org.springframework.stereotype.Component
+public class ComponentNameValidator implements ComponentFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ComponentNameValidator.class.getName());
+ private ComponentsUtils componentsUtils;
+ private ToscaOperationFacade toscaOperationFacade;
+
+ public ComponentNameValidator(ComponentsUtils componentsUtils, ToscaOperationFacade toscaOperationFacade) {
+ this.componentsUtils = componentsUtils;
+ this.toscaOperationFacade = toscaOperationFacade;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
+ String componentName = component.getName();
+ if (StringUtils.isEmpty(componentName)) {
+ log.debug("component name is empty");
+ auditErrorAndThrow(user,component, actionEnum, ActionStatus.MISSING_COMPONENT_NAME);
+ }
+
+ if (!ValidationUtils.validateComponentNameLength(componentName)) {
+ log.debug("Component name exceeds max length {} ", ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ auditErrorAndThrow(user,component, actionEnum, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT);
+ }
+
+ if (!ValidationUtils.validateComponentNamePattern(componentName)) {
+ log.debug("Component name {} has invalid format", componentName);
+ auditErrorAndThrow(user,component, actionEnum, ActionStatus.INVALID_COMPONENT_NAME);
+ }
+ if (component.getComponentType().equals(ComponentTypeEnum.SERVICE)) {
+ validateComponentNameUnique(user,component,actionEnum);
+ }
+ //TODO remove assignment here
+ component.setNormalizedName(ValidationUtils.normaliseComponentName(componentName));
+ component.setSystemName(ValidationUtils.convertToSystemName(componentName));
+ }
+
+ public void validateComponentNameUnique(User user, Component component, AuditingActionEnum actionEnum) {
+ log.debug("validate component name uniqueness for: {}", component.getName());
+ ComponentTypeEnum type = component.getComponentType();
+ ResourceTypeEnum resourceType = null;
+ if(component instanceof Resource){
+ resourceType = ((Resource)component).getResourceType();
+ }
+ Either<Boolean, StorageOperationStatus> dataModelResponse = toscaOperationFacade.validateComponentNameExists(component.getName(), resourceType, type);
+
+ if (dataModelResponse.isLeft()) {
+ if (dataModelResponse.left().value()) {
+ log.info("Component with name {} already exists", component.getName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getName());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+ return;
+ }
+ BeEcompErrorManager.getInstance().logBeSystemError("validateComponentNameUnique");
+ log.debug("Error while validateComponentNameUnique for component: {}", component.getName());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+
+ private void auditErrorAndThrow(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum, ActionStatus actionStatus) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(actionStatus, component.getComponentType().getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, component.getComponentType());
+ throw new ByActionStatusComponentException(actionStatus, component.getComponentType().getValue());
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java
new file mode 100644
index 0000000000..8d0fdf173b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentProjectCodeValidator.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.component;
+
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@org.springframework.stereotype.Component
+public class ComponentProjectCodeValidator implements ComponentFieldValidator{
+
+ private static final Logger log = Logger.getLogger(ComponentProjectCodeValidator.class.getName());
+ private ComponentsUtils componentsUtils;
+
+ public ComponentProjectCodeValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
+ if (ComponentTypeEnum.RESOURCE == component.getComponentType()) {
+ return;
+ }
+ log.debug("validate ProjectCode name ");
+ String projectCode = component.getProjectCode();
+
+ if (!ValidationUtils.validateStringNotEmpty(projectCode)) {
+ log.info("projectCode is empty is allowed CR.");
+ return;
+ }
+
+ try {
+ validateProjectCode(projectCode);
+ } catch (ComponentException exp) {
+ ResponseFormat responseFormat = exp.getResponseFormat();
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType(),
+ ResourceVersionInfo.newBuilder()
+ .build());
+ throw exp;
+ }
+
+ }
+
+ private void validateProjectCode(String projectCode) {
+ if (projectCode != null) {
+ if (!ValidationUtils.validateProjectCode(projectCode)) {
+ log.info("projectCode is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROJECT_CODE);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java
new file mode 100644
index 0000000000..243e0409b3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentTagsValidator.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.component;
+
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@org.springframework.stereotype.Component
+public class ComponentTagsValidator implements ComponentFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ComponentTagsValidator.class.getName());
+ private static final String TAG_FIELD_LABEL = "tag";
+ private ComponentsUtils componentsUtils;
+
+ public ComponentTagsValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
+ List<String> tagsList = component.getTags();
+ try {
+ validateComponentTags(tagsList, component.getName(), component.getComponentType(), user, component, actionEnum);
+ } catch(ComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
+ : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType());
+ throw e;
+ }
+ ValidationUtils.removeDuplicateFromList(component.getTags());
+ }
+
+ protected void validateComponentTags(List<String> tags, String name, ComponentTypeEnum componentType, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum action) {
+ log.debug("validate component tags");
+ boolean includesComponentName = false;
+ int tagListSize = 0;
+ ResponseFormat responseFormat;
+ if (tags != null && !tags.isEmpty()) {
+ for (String tag : tags) {
+ validateTagLength(componentType, user, component, action, tag);
+ if (validateTagPattern(tag)) {
+ includesComponentName = isIncludesComponentName(name, includesComponentName, tag);
+ } else {
+ log.debug("invalid tag {}", tag);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL);
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL);
+ }
+ tagListSize += tag.length() + 1;
+ }
+ if (tagListSize > 0) {
+ tagListSize--;
+ }
+
+ if (!includesComponentName) {
+ log.debug("tags must include component name");
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
+ }
+ if (!ValidationUtils.validateTagListLength(tagListSize)) {
+ log.debug("overall tags length exceeds limit {}", ValidationUtils.TAG_LIST_MAX_LENGTH);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+ }
+ } else {
+ tags = new ArrayList<>();
+ tags.add(name);
+ component.setTags(tags);
+ }
+ }
+
+ private boolean isIncludesComponentName(String name, boolean includesComponentName, String tag) {
+ if (!includesComponentName) {
+ includesComponentName = name.equals(tag);
+ }
+ return includesComponentName;
+ }
+
+ private void validateTagLength(ComponentTypeEnum componentType, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum action, String tag) {
+ ResponseFormat responseFormat;
+ if (!ValidationUtils.validateTagLength(tag)) {
+ log.debug("tag length exceeds limit {}", ValidationUtils.TAG_MAX_LENGTH);
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
+ }
+ }
+
+ protected boolean validateTagPattern(String tag) {
+ return ValidationUtils.validateTagPattern(tag);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java
new file mode 100644
index 0000000000..3f300afe03
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/component/ComponentValidator.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.component;
+
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class ComponentValidator {
+
+ private static final Logger log = Logger.getLogger(ComponentValidator.class.getName());
+ protected ComponentsUtils componentsUtils;
+ private List<ComponentFieldValidator> componentFieldValidators;
+
+ public ComponentValidator(ComponentsUtils componentsUtils, List<ComponentFieldValidator> componentFieldValidators) {
+ this.componentsUtils = componentsUtils;
+ this.componentFieldValidators = componentFieldValidators;
+ }
+
+ public void validate(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum) {
+ componentFieldValidators.stream().forEach(validator ->
+ validator.validateAndCorrectField(user,component,actionEnum));
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java
new file mode 100644
index 0000000000..1fe14c3fda
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceCategoryValidator.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import fj.data.Either;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.operations.api.IElementOperation;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import java.util.List;
+
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+
+@org.springframework.stereotype.Component
+public class ServiceCategoryValidator implements ServiceFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ServiceCategoryValidator.class.getName());
+ private ComponentsUtils componentsUtils;
+ protected IElementOperation elementDao;
+
+ public ServiceCategoryValidator(ComponentsUtils componentsUtils, IElementOperation elementDao) {
+ this.componentsUtils = componentsUtils;
+ this.elementDao = elementDao;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
+ log.debug("validate Service category");
+ if (isEmpty(service.getCategories())) {
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ componentsUtils.auditComponentAdmin(errorResponse, user, service, actionEnum, ComponentTypeEnum.SERVICE);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ }
+ Either<Boolean, ResponseFormat> validatCategory = validateServiceCategory(service.getCategories());
+ if (validatCategory.isRight()) {
+ ResponseFormat responseFormat = validatCategory.right().value();
+ componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE);
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+
+ }
+
+ private Either<Boolean, ResponseFormat> validateServiceCategory(List<CategoryDefinition> list) {
+ if (list != null) {
+ if (list.size() > 1) {
+ log.debug("Must be only one category for service");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.SERVICE.getValue());
+ return Either.right(responseFormat);
+ }
+ CategoryDefinition category = list.get(0);
+ if (category.getSubcategories() != null) {
+ log.debug("Subcategories cannot be defined for service");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.SERVICE_CANNOT_CONTAIN_SUBCATEGORY);
+ return Either.right(responseFormat);
+ }
+ if (!ValidationUtils.validateStringNotEmpty(category.getName())) {
+ log.debug("Resource category is empty");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
+ return Either.right(responseFormat);
+ }
+
+ log.debug("validating service category {} against valid categories list", list);
+ Either<List<CategoryDefinition>, ActionStatus> categorys = elementDao.getAllServiceCategories();
+ if (categorys.isRight()) {
+ log.debug("failed to retrive service categories from JanusGraph");
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(categorys.right().value());
+ return Either.right(responseFormat);
+ }
+ List<CategoryDefinition> categoryList = categorys.left().value();
+ for (CategoryDefinition value : categoryList) {
+ if (value.getName().equals(category.getName())) {
+ return Either.left(true);
+ }
+ }
+ log.debug("Category {} is not part of service category group. Service category valid values are {}", list, categoryList);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue()));
+ }
+ return Either.left(false);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java
new file mode 100644
index 0000000000..61206735ff
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceEnvironmentContextValidator.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+
+import java.util.List;
+
+@org.springframework.stereotype.Component
+public class ServiceEnvironmentContextValidator implements ServiceFieldValidator {
+ @Override
+ public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
+ String environmentContext = service.getEnvironmentContext();
+ if (environmentContext == null) {
+ setDefaultEnvironmentContextFromConfiguration(service);
+ return;
+ }
+ List<String> environmentContextValidValues =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext().getValidValues();
+ if (!environmentContextValidValues.contains(environmentContext))
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_ENVIRONMENT_CONTEXT, environmentContext);
+ }
+
+ private void setDefaultEnvironmentContextFromConfiguration(Service service) {
+ String defaultEnvironmentContext =
+ ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext().getDefaultValue();
+ service.setEnvironmentContext(defaultEnvironmentContext);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java
new file mode 100644
index 0000000000..24d91c2325
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFieldValidator.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+
+
+public interface ServiceFieldValidator {
+ void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum);
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java
new file mode 100644
index 0000000000..ff11629584
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceFunctionValidator.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@org.springframework.stereotype.Component
+public class ServiceFunctionValidator implements ServiceFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ServiceFunctionValidator.class.getName());
+ private static final String SERVICE_FUNCTION = JsonPresentationFields.SERVICE_FUNCTION.getPresentation();
+ private ComponentsUtils componentsUtils;
+
+ public ServiceFunctionValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
+ log.debug("validate service function");
+ String serviceFunction = service.getServiceFunction();
+ if(serviceFunction == null) {
+ log.info("service function is null, assigned to empty value.");
+ service.setServiceFunction("");
+ return;
+ }
+ validateServiceFunction(serviceFunction);
+ }
+
+ private void validateServiceFunction(String serviceFunction) {
+ if (StringUtils.isEmpty(serviceFunction)){
+ return;
+ } else {
+ if (!ValidationUtils.validateServiceFunctionLength(serviceFunction)) {
+ log.info("service function exceeds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_EXCEEDS_LIMIT, "" + SERVICE_FUNCTION);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+
+ if (!ValidationUtils.validateServiceMetadata(serviceFunction)) {
+ log.info("service function is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERY, "" + SERVICE_FUNCTION);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java
new file mode 100644
index 0000000000..baa59a17c7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceInstantiationTypeValidator.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.InstantiationTypes;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@org.springframework.stereotype.Component
+public class ServiceInstantiationTypeValidator implements ServiceFieldValidator {
+ private static final Logger log = Logger.getLogger(ServiceInstantiationTypeValidator.class.getName());
+ private ComponentsUtils componentsUtils;
+
+ public ServiceInstantiationTypeValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
+ log.debug("validate instantiation type");
+ String instantiationType = service.getInstantiationType();
+ if (StringUtils.isEmpty(instantiationType)) {
+ service.setInstantiationType(InstantiationTypes.A_LA_CARTE.getValue());
+ }
+ if (!InstantiationTypes.containsName(service.getInstantiationType())){
+ log.error("Recieved Instantiation type {} is not valid.", instantiationType);
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_INSTANTIATION_TYPE, instantiationType);
+ componentsUtils.auditComponentAdmin(errorResponse, user, service, actionEnum, ComponentTypeEnum.SERVICE);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java
new file mode 100644
index 0000000000..5a7654226a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceNamingPolicyValidator.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@org.springframework.stereotype.Component
+public class ServiceNamingPolicyValidator implements ServiceFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ServiceNamingPolicyValidator.class.getName());
+ private ComponentsUtils componentsUtils;
+
+ public ServiceNamingPolicyValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+ @Override
+ public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
+ Boolean isEcompGeneratedCurr = service.isEcompGeneratedNaming();
+ String namingPolicyUpdate = service.getNamingPolicy();
+ if (isEcompGeneratedCurr == null) {
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_ECOMP_GENERATED_NAMING);
+ }
+ if (isEcompGeneratedCurr) {
+ if (!ValidationUtils.validateServiceNamingPolicyLength(namingPolicyUpdate)) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NAMING_POLICY_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_NAMING_POLICY_MAX_SIZE);
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+ if (StringUtils.isEmpty(namingPolicyUpdate)) {
+ service.setNamingPolicy("");
+ return;
+ }
+ if (!ValidationUtils.validateCommentPattern(namingPolicyUpdate)) {
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_NAMING_POLICY);
+ }
+ service.setNamingPolicy(namingPolicyUpdate);
+ } else {
+ if (!StringUtils.isEmpty(namingPolicyUpdate)) {
+ log.warn("NamingPolicy must be empty for EcompGeneratedNaming=false");
+ }
+ service.setNamingPolicy("");
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java
new file mode 100644
index 0000000000..59d2e837c5
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceRoleValidator.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+@org.springframework.stereotype.Component
+public class ServiceRoleValidator implements ServiceFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ServiceRoleValidator.class.getName());
+ private static final String SERVICE_ROLE = JsonPresentationFields.SERVICE_ROLE.getPresentation();
+ private ComponentsUtils componentsUtils;
+
+ public ServiceRoleValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
+ log.debug("validate service role");
+ String serviceRole = service.getServiceRole();
+ if (serviceRole != null){
+ validateServiceRole(serviceRole);
+ }
+
+ }
+
+ private void validateServiceRole(String serviceRole) {
+ if (StringUtils.isEmpty(serviceRole)){
+ return;
+ } else {
+
+ if (!ValidationUtils.validateServiceRoleLength(serviceRole)) {
+ log.info("service role exceeds limit.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.PROPERTY_EXCEEDS_LIMIT, "" + SERVICE_ROLE);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+
+ if (!ValidationUtils.validateServiceMetadata(serviceRole)) {
+ log.info("service role is not valid.");
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERY, ""+ SERVICE_ROLE);
+ throw new ByResponseFormatComponentException(errorResponse);
+ }
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java
new file mode 100644
index 0000000000..e5e2f0a9b9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceTypeValidator.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ValidationUtils;
+
+@org.springframework.stereotype.Component
+public class ServiceTypeValidator implements ServiceFieldValidator {
+
+ private static final Logger log = Logger.getLogger(ServiceTypeValidator.class.getName());
+ private static final String SERVICE_TYPE = JsonPresentationFields.SERVICE_TYPE.getPresentation();
+ private ComponentsUtils componentsUtils;
+
+ public ServiceTypeValidator(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public void validateAndCorrectField(User user, Service service, AuditingActionEnum actionEnum) {
+ log.debug("validate service type");
+ String serviceType = service.getServiceType();
+ if (serviceType == null) {
+ log.info("service type is not valid.");
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, "" + SERVICE_TYPE);
+ }
+ validateServiceType(serviceType);
+ }
+
+ private void validateServiceType(String serviceType) {
+ if (serviceType.isEmpty()) {
+ return;
+ }
+ if (!ValidationUtils.validateServiceTypeLength(serviceType)) {
+ log.info("service type exceeds limit.");
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_EXCEEDS_LIMIT, "" + SERVICE_TYPE);
+ }
+ if (!ValidationUtils.validateServiceMetadata(serviceType)) {
+ log.info("service type is not valid.");
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERY,"" + SERVICE_TYPE);
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java
new file mode 100644
index 0000000000..5cf490dbf3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/service/ServiceValidator.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.validation.service;
+
+import org.openecomp.sdc.be.components.validation.component.ComponentFieldValidator;
+import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class ServiceValidator extends ComponentValidator {
+
+ private List<ServiceFieldValidator> serviceFieldValidators;
+
+ public ServiceValidator(ComponentsUtils componentsUtils, List<ComponentFieldValidator> componentFieldValidators, List<ServiceFieldValidator> serviceFieldValidators) {
+ super(componentsUtils, componentFieldValidators);
+ this.serviceFieldValidators = serviceFieldValidators;
+ }
+
+ @Override
+ public void validate(User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum) {
+ super.validate(user, component, actionEnum);
+ serviceFieldValidators.forEach(validator ->
+ validator.validateAndCorrectField(user,(Service)component,actionEnum));
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
index 2192369515..9ef8ef3468 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java
@@ -22,12 +22,6 @@ package org.openecomp.sdc.be.datamodel.utils;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType;
import org.openecomp.sdc.be.ui.model.UIConstraint;
@@ -35,6 +29,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
public class ConstraintConvertor {
private static final Logger logger = LoggerFactory.getLogger(ConstraintConvertor.class);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ContainerInstanceTypesData.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ContainerInstanceTypesData.java
new file mode 100644
index 0000000000..3ee9645cd9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ContainerInstanceTypesData.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datamodel.utils;
+
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class ContainerInstanceTypesData {
+
+ private List<ResourceTypeEnum> validInstanceTypesInServiceContainer = Arrays.asList(ResourceTypeEnum.PNF,
+ ResourceTypeEnum.VF, ResourceTypeEnum.CP,
+ ResourceTypeEnum.VL, ResourceTypeEnum.CR,
+ ResourceTypeEnum.ServiceProxy,ResourceTypeEnum.Configuration);
+ private Map<ResourceTypeEnum,List<ResourceTypeEnum>> validInstanceTypesInResourceContainer = new HashMap<>();
+
+ private ContainerInstanceTypesData() {
+ List<ResourceTypeEnum> vfContainerInstances = Arrays.asList(ResourceTypeEnum.CP,
+ ResourceTypeEnum.VL, ResourceTypeEnum.Configuration,
+ ResourceTypeEnum.VFC);
+ List<ResourceTypeEnum> crContainerInstances = Arrays.asList(ResourceTypeEnum.CP,
+ ResourceTypeEnum.VL, ResourceTypeEnum.Configuration,
+ ResourceTypeEnum.VFC);
+ List<ResourceTypeEnum> pnfContainerInstances = Arrays.asList(ResourceTypeEnum.CP,
+ ResourceTypeEnum.VL, ResourceTypeEnum.Configuration,
+ ResourceTypeEnum.VFC);
+ validInstanceTypesInResourceContainer.put(ResourceTypeEnum.VF, vfContainerInstances);
+ validInstanceTypesInResourceContainer.put(ResourceTypeEnum.CR, crContainerInstances);
+ validInstanceTypesInResourceContainer.put(ResourceTypeEnum.PNF, pnfContainerInstances);
+ }
+
+ public List<ResourceTypeEnum> getServiceContainerList() {
+ return validInstanceTypesInServiceContainer;
+ }
+
+ public Map<ResourceTypeEnum, List<ResourceTypeEnum>> getValidInstanceTypesInResourceContainer() {
+ return validInstanceTypesInResourceContainer;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
index 72342e642f..24d4b2f1b8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
@@ -18,14 +18,6 @@ package org.openecomp.sdc.be.datamodel.utils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
import fj.data.Either;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
@@ -48,6 +40,14 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
public class PropertyValueConstraintValidationUtil {
private static final String UNDERSCORE = "_";
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
index fbc451dd11..fa6ffcfb93 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
@@ -20,20 +20,8 @@
package org.openecomp.sdc.be.datamodel.utils;
-import static java.util.stream.Collectors.groupingBy;
-import static java.util.stream.Collectors.toList;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
-
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
import org.openecomp.sdc.be.components.validation.PolicyUtils;
@@ -58,6 +46,18 @@ import org.openecomp.sdc.be.ui.model.UiServiceDataTransfer;
import org.openecomp.sdc.be.ui.model.UiServiceMetadata;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.toList;
+
@org.springframework.stereotype.Component("uiComponentDataConverter")
public class UiComponentDataConverter {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java
index 801f53002c..c8c2d94adc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/AuditHandler.java
@@ -1,61 +1,61 @@
-/*-
- * ============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.sdc.be.distribution;
-
-import org.openecomp.sdc.be.components.distribution.engine.CambriaErrorResponse;
-import org.openecomp.sdc.be.components.distribution.engine.SubscriberTypeEnum;
-import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
-
-public class AuditHandler {
- ComponentsUtils componentsUtils;
- String instanceID;
- private RegistrationRequest registrationRequest;
-
- public AuditHandler(ComponentsUtils componentsUtils, String instanceID, RegistrationRequest registrationRequest) {
- super();
- this.componentsUtils = componentsUtils;
- this.instanceID = instanceID;
- this.registrationRequest = registrationRequest;
- }
-
-
- public void auditRegisterACL(CambriaErrorResponse registerResponse, SubscriberTypeEnum subscriberRole , DistributionTopicData distributionTopicData) {
- componentsUtils.auditDistributionEngine(AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL, registrationRequest.getDistrEnvName(), distributionTopicData, subscriberRole.name(), registrationRequest.getApiPublicKey(), String.valueOf(registerResponse.getHttpCode()));
- }
-
- public void auditUnRegisterACL(CambriaErrorResponse registerResponse, SubscriberTypeEnum subscriberRole, DistributionTopicData distributionTopicData) {
- componentsUtils.auditDistributionEngine(AuditingActionEnum.REMOVE_KEY_FROM_TOPIC_ACL, registrationRequest.getDistrEnvName(), distributionTopicData, subscriberRole.name(), registrationRequest.getApiPublicKey(), String.valueOf(registerResponse.getHttpCode()));
- }
-
- public void auditRegisterRequest(CambriaErrorResponse registerResponse) {
- componentsUtils.auditRegisterOrUnRegisterEvent(AuditingActionEnum.DISTRIBUTION_REGISTER, instanceID, registrationRequest.getApiPublicKey(), registrationRequest.getDistrEnvName(), String.valueOf(registerResponse.getHttpCode()),
- registerResponse.getOperationStatus().name(), DistributionBusinessLogic.getNotificationTopicName(registrationRequest.getDistrEnvName()), DistributionBusinessLogic.getStatusTopicName(registrationRequest.getDistrEnvName()));
-
- }
-
- public void auditUnRegisterRequest(CambriaErrorResponse registerResponse) {
- componentsUtils.auditRegisterOrUnRegisterEvent(AuditingActionEnum.DISTRIBUTION_UN_REGISTER, instanceID, registrationRequest.getApiPublicKey(), registrationRequest.getDistrEnvName(), String.valueOf(registerResponse.getHttpCode()),
- registerResponse.getOperationStatus().name(), DistributionBusinessLogic.getNotificationTopicName(registrationRequest.getDistrEnvName()), DistributionBusinessLogic.getStatusTopicName(registrationRequest.getDistrEnvName()));
- }
-}
+/*-
+ * ============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.sdc.be.distribution;
+
+import org.openecomp.sdc.be.components.distribution.engine.CambriaErrorResponse;
+import org.openecomp.sdc.be.components.distribution.engine.SubscriberTypeEnum;
+import org.openecomp.sdc.be.distribution.api.client.RegistrationRequest;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
+
+public class AuditHandler {
+ private ComponentsUtils componentsUtils;
+ private String instanceID;
+ private RegistrationRequest registrationRequest;
+
+ public AuditHandler(ComponentsUtils componentsUtils, String instanceID, RegistrationRequest registrationRequest) {
+ super();
+ this.componentsUtils = componentsUtils;
+ this.instanceID = instanceID;
+ this.registrationRequest = registrationRequest;
+ }
+
+
+ public void auditRegisterACL(CambriaErrorResponse registerResponse, SubscriberTypeEnum subscriberRole , DistributionTopicData distributionTopicData) {
+ componentsUtils.auditDistributionEngine(AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL, registrationRequest.getDistrEnvName(), distributionTopicData, subscriberRole.name(), registrationRequest.getApiPublicKey(), String.valueOf(registerResponse.getHttpCode()));
+ }
+
+ public void auditUnRegisterACL(CambriaErrorResponse registerResponse, SubscriberTypeEnum subscriberRole, DistributionTopicData distributionTopicData) {
+ componentsUtils.auditDistributionEngine(AuditingActionEnum.REMOVE_KEY_FROM_TOPIC_ACL, registrationRequest.getDistrEnvName(), distributionTopicData, subscriberRole.name(), registrationRequest.getApiPublicKey(), String.valueOf(registerResponse.getHttpCode()));
+ }
+
+ public void auditRegisterRequest(CambriaErrorResponse registerResponse) {
+ componentsUtils.auditRegisterOrUnRegisterEvent(AuditingActionEnum.DISTRIBUTION_REGISTER, instanceID, registrationRequest.getApiPublicKey(), registrationRequest.getDistrEnvName(), String.valueOf(registerResponse.getHttpCode()),
+ registerResponse.getOperationStatus().name(), DistributionBusinessLogic.getNotificationTopicName(registrationRequest.getDistrEnvName()), DistributionBusinessLogic.getStatusTopicName(registrationRequest.getDistrEnvName()));
+
+ }
+
+ public void auditUnRegisterRequest(CambriaErrorResponse registerResponse) {
+ componentsUtils.auditRegisterOrUnRegisterEvent(AuditingActionEnum.DISTRIBUTION_UN_REGISTER, instanceID, registrationRequest.getApiPublicKey(), registrationRequest.getDistrEnvName(), String.valueOf(registerResponse.getHttpCode()),
+ registerResponse.getOperationStatus().name(), DistributionBusinessLogic.getNotificationTopicName(registrationRequest.getDistrEnvName()), DistributionBusinessLogic.getStatusTopicName(registrationRequest.getDistrEnvName()));
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java
index 1589b93822..81c41bc152 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/DistributionBusinessLogic.java
@@ -1,313 +1,322 @@
-/*-
- * ============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.sdc.be.distribution;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import fj.data.Either;
-import org.apache.http.HttpStatus;
-import org.openecomp.sdc.be.components.distribution.engine.*;
-import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.distribution.api.client.*;
-import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import javax.ws.rs.core.Response;
-import java.util.List;
-
-import static org.apache.commons.lang.BooleanUtils.isTrue;
-import static org.openecomp.sdc.be.components.distribution.engine.DistributionEngineInitTask.buildTopicName;
-import static org.openecomp.sdc.be.config.ConfigurationManager.getConfigurationManager;
-
-@Component("distributionBusinessLogic")
-public class DistributionBusinessLogic {
- public static final String REGISTER_IN_DISTRIBUTION_ENGINE = "registerInDistributionEngine";
- public static final String UN_REGISTER_IN_DISTRIBUTION_ENGINE = "unregisterInDistributionEngine";
- private Gson gson = new GsonBuilder().setPrettyPrinting().create();
- private static final Logger log = Logger.getLogger(DistributionBusinessLogic.class);
- @Resource
- private IDistributionEngine distributionEngine;
-
- private ResponseFormatManager responseFormatManager = ResponseFormatManager.getInstance();
- private CambriaHandler cambriaHandler;
-
- private void initRequestEnvEndPoints(RegistrationRequest registrationRequest, DistributionEngineConfiguration config) {
- if(registrationRequest.getDistEnvEndPoints() == null || registrationRequest.getDistEnvEndPoints().isEmpty()){
- registrationRequest.setDistEnvEndPoints(config.getUebServers());
- }
- }
- public Either<ServerListResponse, ResponseFormat> getUebServerList() {
-
- DistributionEngineConfiguration distributionEngineConfiguration = ConfigurationManager.getConfigurationManager()
- .getDistributionEngineConfiguration();
-
- List<String> serverList = distributionEngineConfiguration.getUebServers();
-
- if (serverList != null && !serverList.isEmpty()) {
-
- ServerListResponse serverListResponse = new ServerListResponse();
-
- serverListResponse.setUebServerList(serverList);
-
- return Either.left(serverListResponse);
- } else {
- ResponseFormat errorResponseWrapper = getResponseFormatManager()
- .getResponseFormat(ActionStatus.GENERAL_ERROR);
- return Either.right(errorResponseWrapper);
- }
-
- }
-
- public void handleRegistration(Wrapper<Response> responseWrapper, RegistrationRequest registrationRequest,
- AuditHandler auditHandler) {
- CambriaErrorResponse registerResponse = null;
- try {
- DistributionEngineConfiguration config = getConfigurationManager().getDistributionEngineConfiguration();
- String statusTopicName = buildTopicName(config.getDistributionStatusTopicName(),
- registrationRequest.getDistrEnvName());
- registerResponse = registerDistributionClientToTopic(responseWrapper, registrationRequest,
- SubscriberTypeEnum.PRODUCER, statusTopicName);
-
- auditHandler.auditRegisterACL(registerResponse, SubscriberTypeEnum.PRODUCER,
- DistributionTopicData.newBuilder()
- .statusTopic(statusTopicName)
- .build());
- boolean isRegisteredAsProducerOnStatusSuccess = responseWrapper.isEmpty();
-
- // Story [347698] Distribution Client Get Indication from
- // component whether to register as consumer and producer on
- // status topic
- boolean registeredAsConsumerOnStatus = false;
- if (isRegisteredAsProducerOnStatusSuccess && isTrue(registrationRequest.getIsConsumerToSdcDistrStatusTopic())) {
- registerResponse = registerDistributionClientToTopic(responseWrapper, registrationRequest,
- SubscriberTypeEnum.CONSUMER, statusTopicName);
- auditHandler.auditRegisterACL(registerResponse, SubscriberTypeEnum.CONSUMER,
- DistributionTopicData.newBuilder()
- .statusTopic(statusTopicName)
- .build());
- registeredAsConsumerOnStatus = responseWrapper.isEmpty();
-
- }
-
- if (responseWrapper.isEmpty()) {
- String notificationTopicName = buildTopicName(config.getDistributionNotifTopicName(),
- registrationRequest.getDistrEnvName());
- registerResponse = registerDistributionClientToTopic(responseWrapper, registrationRequest,
- SubscriberTypeEnum.CONSUMER, notificationTopicName);
- auditHandler.auditRegisterACL(registerResponse, SubscriberTypeEnum.CONSUMER,
- DistributionTopicData.newBuilder()
- .notificationTopic(notificationTopicName)
- .build());
- }
- // Unregister Rollback
- if (!responseWrapper.isEmpty()) {
- if (isRegisteredAsProducerOnStatusSuccess) {
- CambriaErrorResponse unRegisterResponse = unRegisterDistributionClientFromTopic(registrationRequest,
- SubscriberTypeEnum.PRODUCER, statusTopicName);
- auditHandler.auditUnRegisterACL(unRegisterResponse, SubscriberTypeEnum.PRODUCER,
- DistributionTopicData.newBuilder()
- .statusTopic(statusTopicName)
- .build());
- }
- if (registeredAsConsumerOnStatus) {
- CambriaErrorResponse unRegisterResponse = unRegisterDistributionClientFromTopic(registrationRequest,
- SubscriberTypeEnum.CONSUMER, statusTopicName);
- auditHandler.auditUnRegisterACL(unRegisterResponse, SubscriberTypeEnum.CONSUMER,
- DistributionTopicData.newBuilder()
- .statusTopic(statusTopicName)
- .build());
- }
- }
-
- if (responseWrapper.isEmpty()) {
- TopicRegistrationResponse okTopicResponse = buildTopicResponse(registrationRequest);
- responseWrapper.setInnerElement(Response.status(HttpStatus.SC_OK).entity(okTopicResponse).build());
- }
-
- } catch (Exception e) {
- log.error("registration to topic failed", e);
- BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(REGISTER_IN_DISTRIBUTION_ENGINE,
- "registration of subscriber to topic");
- Response errorResponse = buildErrorResponse(
- getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
- responseWrapper.setInnerElement(errorResponse);
- } finally {
- auditHandler.auditRegisterRequest(registerResponse);
- }
- }
-
- public void handleUnRegistration(Wrapper<Response> responseWrapper, RegistrationRequest unRegistrationRequest,
- AuditHandler auditHandler) {
- Wrapper<CambriaErrorResponse> cambriaResponseWrapper = new Wrapper<>();
- try {
- String statusTopicName = getStatusTopicName(unRegistrationRequest.getDistrEnvName());
- CambriaErrorResponse unregisterClientProducerTopicResponse = unRegisterDistributionClientFromTopic(
- unRegistrationRequest, SubscriberTypeEnum.PRODUCER, statusTopicName);
- auditHandler.auditUnRegisterACL(unregisterClientProducerTopicResponse, SubscriberTypeEnum.PRODUCER,
- DistributionTopicData.newBuilder()
- .statusTopic(statusTopicName)
- .build());
- updateResponseWrapper(cambriaResponseWrapper, unregisterClientProducerTopicResponse);
-
- String notificationTopicName = getNotificationTopicName(unRegistrationRequest.getDistrEnvName());
- CambriaErrorResponse unregisterClientConsumerTopicResponse = unRegisterDistributionClientFromTopic(
- unRegistrationRequest, SubscriberTypeEnum.CONSUMER, notificationTopicName);
- auditHandler.auditUnRegisterACL(unregisterClientConsumerTopicResponse, SubscriberTypeEnum.CONSUMER,
- DistributionTopicData.newBuilder()
- .notificationTopic(notificationTopicName)
- .build());
- updateResponseWrapper(cambriaResponseWrapper, unregisterClientConsumerTopicResponse);
-
- // Success unregister both topics
- TopicUnregistrationResponse unregisterResponse = new TopicUnregistrationResponse(
- getNotificationTopicName(unRegistrationRequest.getDistrEnvName()),
- getStatusTopicName(unRegistrationRequest.getDistrEnvName()),
- unregisterClientConsumerTopicResponse.getOperationStatus(),
- unregisterClientProducerTopicResponse.getOperationStatus());
-
- if (cambriaResponseWrapper.getInnerElement().getOperationStatus() == CambriaOperationStatus.OK) {
- responseWrapper.setInnerElement(Response.status(HttpStatus.SC_OK).entity(unregisterResponse).build());
- } else {
- BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(UN_REGISTER_IN_DISTRIBUTION_ENGINE,
- "unregistration failed");
- responseWrapper.setInnerElement(
- Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(unregisterResponse).build());
- }
- } catch (Exception e) {
- log.error("unregistered to topic failed", e);
- Response errorResponse = buildErrorResponse(
- getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
- responseWrapper.setInnerElement(errorResponse);
-
- } finally {
- auditHandler.auditUnRegisterRequest(cambriaResponseWrapper.getInnerElement());
- }
- }
-
- private void updateResponseWrapper(Wrapper<CambriaErrorResponse> cambriaResponseWrapper,
- CambriaErrorResponse currentResponse) {
- if (cambriaResponseWrapper.isEmpty()) {
- cambriaResponseWrapper.setInnerElement(currentResponse);
- } else if (currentResponse.getOperationStatus() != CambriaOperationStatus.OK) {
- cambriaResponseWrapper.setInnerElement(currentResponse);
-
- }
-
- }
-
- public static String getNotificationTopicName(String envName) {
- DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
- .getDistributionEngineConfiguration();
- return DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(), envName);
-
- }
-
- public static String getStatusTopicName(String envName) {
- DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
- .getDistributionEngineConfiguration();
- return DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(), envName);
-
- }
-
- protected CambriaErrorResponse unRegisterDistributionClientFromTopic(RegistrationRequest unRegistrationRequest,
- SubscriberTypeEnum subscriberType, String topicName) {
- DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
- .getDistributionEngineConfiguration();
- initRequestEnvEndPoints(unRegistrationRequest, config);
-
- log.debug("unregistering client as {} , from topic: {}, using DistEnvPoints: {}", subscriberType, topicName, unRegistrationRequest.getDistEnvEndPoints());
- return getCambriaHandler().unRegisterFromTopic(unRegistrationRequest.getDistEnvEndPoints(), config.getUebPublicKey(),
- config.getUebSecretKey(), unRegistrationRequest.getApiPublicKey(), subscriberType, topicName);
- }
-
- private TopicRegistrationResponse buildTopicResponse(RegistrationRequest registrationRequest) {
- DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
- .getDistributionEngineConfiguration();
- String statusTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(),
- registrationRequest.getDistrEnvName());
- String notificationTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(),
- registrationRequest.getDistrEnvName());
-
- TopicRegistrationResponse topicResponse = new TopicRegistrationResponse();
- topicResponse.setDistrNotificationTopicName(notificationTopicName);
- topicResponse.setDistrStatusTopicName(statusTopicName);
- return topicResponse;
- }
-
- protected CambriaErrorResponse registerDistributionClientToTopic(Wrapper<Response> responseWrapper,
- RegistrationRequest registrationRequest, SubscriberTypeEnum subscriberType, String topicName) {
- DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
- .getDistributionEngineConfiguration();
- initRequestEnvEndPoints(registrationRequest, config);
- String errorMsg;
-
- // Register for notifications as consumer
- if (subscriberType == SubscriberTypeEnum.CONSUMER) {
- errorMsg = "registration of subscriber to topic:" + topicName + " as consumer failed";
- }
- // Register for status as producer
- else {
- errorMsg = "registration of subscriber to topic:" + topicName + " as producer failed";
- }
- log.debug("registering client as {} , from topic: {}, using DistEnvPoints: {}", subscriberType, topicName, registrationRequest.getDistEnvEndPoints());
- CambriaErrorResponse registerToTopic = getCambriaHandler().registerToTopic(registrationRequest.getDistEnvEndPoints(),
- config.getUebPublicKey(), config.getUebSecretKey(), registrationRequest.getApiPublicKey(),
- subscriberType, topicName);
-
- if (registerToTopic.getOperationStatus() != CambriaOperationStatus.OK) {
- Response failedRegistrationResponse = buildErrorResponse(
- getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
- BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(REGISTER_IN_DISTRIBUTION_ENGINE,
- errorMsg);
- responseWrapper.setInnerElement(failedRegistrationResponse);
- }
- return registerToTopic;
- }
-
- protected Response buildErrorResponse(ResponseFormat requestErrorWrapper) {
- return Response.status(requestErrorWrapper.getStatus())
- .entity(gson.toJson(requestErrorWrapper.getRequestError())).build();
- }
-
- public ResponseFormatManager getResponseFormatManager() {
- return responseFormatManager;
- }
-
- public IDistributionEngine getDistributionEngine() {
- return distributionEngine;
- }
-
- public CambriaHandler getCambriaHandler() {
- if (cambriaHandler == null) {
- cambriaHandler = new CambriaHandler();
- }
- return cambriaHandler;
- }
-
-}
+/*-
+ * ============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.sdc.be.distribution;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import fj.data.Either;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.components.distribution.engine.CambriaErrorResponse;
+import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineInitTask;
+import org.openecomp.sdc.be.components.distribution.engine.ICambriaHandler;
+import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
+import org.openecomp.sdc.be.components.distribution.engine.SubscriberTypeEnum;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
+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.resources.data.OperationalEnvironmentEntry;
+import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import javax.ws.rs.core.Response;
+import java.util.List;
+
+import static org.apache.commons.lang.BooleanUtils.isTrue;
+import static org.openecomp.sdc.be.components.distribution.engine.DistributionEngineInitTask.buildTopicName;
+import static org.openecomp.sdc.be.config.ConfigurationManager.getConfigurationManager;
+
+@Component("distributionBusinessLogic")
+public class DistributionBusinessLogic {
+ public static final String REGISTER_IN_DISTRIBUTION_ENGINE = "registerInDistributionEngine";
+ public static final String UN_REGISTER_IN_DISTRIBUTION_ENGINE = "unregisterInDistributionEngine";
+ private Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ private static final Logger log = Logger.getLogger(DistributionBusinessLogic.class);
+ @Resource
+ private IDistributionEngine distributionEngine;
+
+ private ResponseFormatManager responseFormatManager = ResponseFormatManager.getInstance();
+ @Resource
+ private ICambriaHandler cambriaHandler;
+
+ private void initRequestEnvEndPointsAndKeys(RegistrationRequest registrationRequest, DistributionEngineConfiguration config) {
+ if(CollectionUtils.isEmpty(registrationRequest.getDistEnvEndPoints())){
+ registrationRequest.setDistEnvEndPoints(config.getUebServers());
+ registrationRequest.setManagerApiPublicKey(config.getUebPublicKey());
+ registrationRequest.setManagerApiSecretKey(config.getUebSecretKey());
+ } else {
+ OperationalEnvironmentEntry environment = distributionEngine.getEnvironmentByDmaapUebAddress(registrationRequest.getDistEnvEndPoints());
+ registrationRequest.setManagerApiPublicKey(environment.getUebApikey());
+ registrationRequest.setManagerApiSecretKey(environment.getUebSecretKey());
+ }
+ }
+ public Either<ServerListResponse, ResponseFormat> getUebServerList() {
+
+ DistributionEngineConfiguration distributionEngineConfiguration = ConfigurationManager.getConfigurationManager()
+ .getDistributionEngineConfiguration();
+
+ List<String> serverList = distributionEngineConfiguration.getUebServers();
+
+ if (serverList != null && !serverList.isEmpty()) {
+
+ ServerListResponse serverListResponse = new ServerListResponse();
+
+ serverListResponse.setUebServerList(serverList);
+
+ return Either.left(serverListResponse);
+ } else {
+ ResponseFormat errorResponseWrapper = getResponseFormatManager()
+ .getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(errorResponseWrapper);
+ }
+
+ }
+
+ public void handleRegistration(Wrapper<Response> responseWrapper, RegistrationRequest registrationRequest,
+ AuditHandler auditHandler) {
+ CambriaErrorResponse registerResponse = null;
+ try {
+ DistributionEngineConfiguration config = getConfigurationManager().getDistributionEngineConfiguration();
+ String statusTopicName = buildTopicName(config.getDistributionStatusTopicName(),
+ registrationRequest.getDistrEnvName());
+ initRequestEnvEndPointsAndKeys(registrationRequest, config);
+ registerResponse = registerDistributionClientToTopic(responseWrapper, registrationRequest,
+ SubscriberTypeEnum.PRODUCER, statusTopicName);
+
+ auditHandler.auditRegisterACL(registerResponse, SubscriberTypeEnum.PRODUCER,
+ DistributionTopicData.newBuilder()
+ .statusTopic(statusTopicName)
+ .build());
+ boolean isRegisteredAsProducerOnStatusSuccess = responseWrapper.isEmpty();
+
+ // Story [347698] Distribution Client Get Indication from
+ // component whether to register as consumer and producer on
+ // status topic
+ boolean registeredAsConsumerOnStatus = false;
+ if (isRegisteredAsProducerOnStatusSuccess && isTrue(registrationRequest.getIsConsumerToSdcDistrStatusTopic())) {
+ registerResponse = registerDistributionClientToTopic(responseWrapper, registrationRequest,
+ SubscriberTypeEnum.CONSUMER, statusTopicName);
+ auditHandler.auditRegisterACL(registerResponse, SubscriberTypeEnum.CONSUMER,
+ DistributionTopicData.newBuilder()
+ .statusTopic(statusTopicName)
+ .build());
+ registeredAsConsumerOnStatus = responseWrapper.isEmpty();
+
+ }
+
+ if (responseWrapper.isEmpty()) {
+ String notificationTopicName = buildTopicName(config.getDistributionNotifTopicName(),
+ registrationRequest.getDistrEnvName());
+ registerResponse = registerDistributionClientToTopic(responseWrapper, registrationRequest,
+ SubscriberTypeEnum.CONSUMER, notificationTopicName);
+ auditHandler.auditRegisterACL(registerResponse, SubscriberTypeEnum.CONSUMER,
+ DistributionTopicData.newBuilder()
+ .notificationTopic(notificationTopicName)
+ .build());
+ }
+ // Unregister Rollback
+ if (!responseWrapper.isEmpty()) {
+ if (isRegisteredAsProducerOnStatusSuccess) {
+ CambriaErrorResponse unRegisterResponse = unRegisterDistributionClientFromTopic(registrationRequest,
+ SubscriberTypeEnum.PRODUCER, statusTopicName);
+ auditHandler.auditUnRegisterACL(unRegisterResponse, SubscriberTypeEnum.PRODUCER,
+ DistributionTopicData.newBuilder()
+ .statusTopic(statusTopicName)
+ .build());
+ }
+ if (registeredAsConsumerOnStatus) {
+ CambriaErrorResponse unRegisterResponse = unRegisterDistributionClientFromTopic(registrationRequest,
+ SubscriberTypeEnum.CONSUMER, statusTopicName);
+ auditHandler.auditUnRegisterACL(unRegisterResponse, SubscriberTypeEnum.CONSUMER,
+ DistributionTopicData.newBuilder()
+ .statusTopic(statusTopicName)
+ .build());
+ }
+ }
+
+ if (responseWrapper.isEmpty()) {
+ TopicRegistrationResponse okTopicResponse = buildTopicResponse(registrationRequest);
+ responseWrapper.setInnerElement(Response.status(HttpStatus.SC_OK).entity(okTopicResponse).build());
+ }
+
+ } catch (Exception e) {
+ log.error("registration to topic failed", e);
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(REGISTER_IN_DISTRIBUTION_ENGINE,
+ "registration of subscriber to topic");
+ Response errorResponse = buildErrorResponse(
+ getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(errorResponse);
+ } finally {
+ auditHandler.auditRegisterRequest(registerResponse);
+ }
+ }
+
+ public void handleUnRegistration(Wrapper<Response> responseWrapper, RegistrationRequest unRegistrationRequest,
+ AuditHandler auditHandler) {
+ Wrapper<CambriaErrorResponse> cambriaResponseWrapper = new Wrapper<>();
+ try {
+ String statusTopicName = getStatusTopicName(unRegistrationRequest.getDistrEnvName());
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
+ .getDistributionEngineConfiguration();
+ initRequestEnvEndPointsAndKeys(unRegistrationRequest, config);
+ CambriaErrorResponse unregisterClientProducerTopicResponse = unRegisterDistributionClientFromTopic(
+ unRegistrationRequest, SubscriberTypeEnum.PRODUCER, statusTopicName);
+ auditHandler.auditUnRegisterACL(unregisterClientProducerTopicResponse, SubscriberTypeEnum.PRODUCER,
+ DistributionTopicData.newBuilder()
+ .statusTopic(statusTopicName)
+ .build());
+ updateResponseWrapper(cambriaResponseWrapper, unregisterClientProducerTopicResponse);
+
+ String notificationTopicName = getNotificationTopicName(unRegistrationRequest.getDistrEnvName());
+ CambriaErrorResponse unregisterClientConsumerTopicResponse = unRegisterDistributionClientFromTopic(
+ unRegistrationRequest, SubscriberTypeEnum.CONSUMER, notificationTopicName);
+ auditHandler.auditUnRegisterACL(unregisterClientConsumerTopicResponse, SubscriberTypeEnum.CONSUMER,
+ DistributionTopicData.newBuilder()
+ .notificationTopic(notificationTopicName)
+ .build());
+ updateResponseWrapper(cambriaResponseWrapper, unregisterClientConsumerTopicResponse);
+
+ // Success unregister both topics
+ TopicUnregistrationResponse unregisterResponse = new TopicUnregistrationResponse(
+ getNotificationTopicName(unRegistrationRequest.getDistrEnvName()),
+ getStatusTopicName(unRegistrationRequest.getDistrEnvName()),
+ unregisterClientConsumerTopicResponse.getOperationStatus(),
+ unregisterClientProducerTopicResponse.getOperationStatus());
+
+ if (cambriaResponseWrapper.getInnerElement().getOperationStatus() == CambriaOperationStatus.OK) {
+ responseWrapper.setInnerElement(Response.status(HttpStatus.SC_OK).entity(unregisterResponse).build());
+ } else {
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(UN_REGISTER_IN_DISTRIBUTION_ENGINE,
+ "unregistration failed");
+ responseWrapper.setInnerElement(
+ Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(unregisterResponse).build());
+ }
+ } catch (Exception e) {
+ log.error("unregistered to topic failed", e);
+ Response errorResponse = buildErrorResponse(
+ getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(errorResponse);
+
+ } finally {
+ auditHandler.auditUnRegisterRequest(cambriaResponseWrapper.getInnerElement());
+ }
+ }
+
+ private void updateResponseWrapper(Wrapper<CambriaErrorResponse> cambriaResponseWrapper,
+ CambriaErrorResponse currentResponse) {
+ if (cambriaResponseWrapper.isEmpty()) {
+ cambriaResponseWrapper.setInnerElement(currentResponse);
+ } else if (currentResponse.getOperationStatus() != CambriaOperationStatus.OK) {
+ cambriaResponseWrapper.setInnerElement(currentResponse);
+
+ }
+
+ }
+
+ public static String getNotificationTopicName(String envName) {
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
+ .getDistributionEngineConfiguration();
+ return DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(), envName);
+
+ }
+
+ public static String getStatusTopicName(String envName) {
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
+ .getDistributionEngineConfiguration();
+ return DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(), envName);
+
+ }
+
+ protected CambriaErrorResponse unRegisterDistributionClientFromTopic(RegistrationRequest unRegistrationRequest,
+ SubscriberTypeEnum subscriberType, String topicName) {
+
+ log.debug("unregistering client as {} , from topic: {}, using DistEnvPoints: {}", subscriberType, topicName, unRegistrationRequest.getDistEnvEndPoints());
+ return cambriaHandler.unRegisterFromTopic(unRegistrationRequest.getDistEnvEndPoints(), unRegistrationRequest.getManagerApiPublicKey(),
+ unRegistrationRequest.getManagerApiSecretKey(), unRegistrationRequest.getApiPublicKey(), subscriberType, topicName);
+ }
+
+ private TopicRegistrationResponse buildTopicResponse(RegistrationRequest registrationRequest) {
+ DistributionEngineConfiguration config = ConfigurationManager.getConfigurationManager()
+ .getDistributionEngineConfiguration();
+ String statusTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionStatusTopicName(),
+ registrationRequest.getDistrEnvName());
+ String notificationTopicName = DistributionEngineInitTask.buildTopicName(config.getDistributionNotifTopicName(),
+ registrationRequest.getDistrEnvName());
+
+ TopicRegistrationResponse topicResponse = new TopicRegistrationResponse();
+ topicResponse.setDistrNotificationTopicName(notificationTopicName);
+ topicResponse.setDistrStatusTopicName(statusTopicName);
+ return topicResponse;
+ }
+
+ protected CambriaErrorResponse registerDistributionClientToTopic(Wrapper<Response> responseWrapper,
+ RegistrationRequest registrationRequest, SubscriberTypeEnum subscriberType, String topicName) {
+
+ String errorMsg;
+
+ // Register for notifications as consumer
+ if (subscriberType == SubscriberTypeEnum.CONSUMER) {
+ errorMsg = "registration of subscriber to topic:" + topicName + " as consumer failed";
+ }
+ // Register for status as producer
+ else {
+ errorMsg = "registration of subscriber to topic:" + topicName + " as producer failed";
+ }
+ log.debug("registering client as {} , from topic: {}, using DistEnvPoints: {}", subscriberType, topicName, registrationRequest.getDistEnvEndPoints());
+ CambriaErrorResponse registerToTopic = cambriaHandler.registerToTopic(registrationRequest.getDistEnvEndPoints(),
+ registrationRequest.getManagerApiPublicKey(), registrationRequest.getManagerApiSecretKey(), registrationRequest.getApiPublicKey(),
+ subscriberType, topicName);
+
+ if (registerToTopic.getOperationStatus() != CambriaOperationStatus.OK) {
+ Response failedRegistrationResponse = buildErrorResponse(
+ getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(REGISTER_IN_DISTRIBUTION_ENGINE,
+ errorMsg);
+ responseWrapper.setInnerElement(failedRegistrationResponse);
+ }
+ return registerToTopic;
+ }
+
+ protected Response buildErrorResponse(ResponseFormat requestErrorWrapper) {
+ return Response.status(requestErrorWrapper.getStatus())
+ .entity(gson.toJson(requestErrorWrapper.getRequestError())).build();
+ }
+
+ public ResponseFormatManager getResponseFormatManager() {
+ return responseFormatManager;
+ }
+
+ public IDistributionEngine getDistributionEngine() {
+ return distributionEngine;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java
index 1dfbdb538d..8377749a64 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/api/client/RegistrationRequest.java
@@ -23,10 +23,12 @@ package org.openecomp.sdc.be.distribution.api.client;
import java.util.List;
public class RegistrationRequest {
- String apiPublicKey;
- String distrEnvName;
- Boolean isConsumerToSdcDistrStatusTopic;
- List<String> distEnvEndPoints;
+ private String apiPublicKey;
+ private String distrEnvName;
+ private Boolean isConsumerToSdcDistrStatusTopic;
+ private List<String> distEnvEndPoints;
+ private String managerApiPublicKey;
+ private String managerApiSecretKey;
public RegistrationRequest(String apiPublicKey, String distrEnvName, boolean isConsumerToSdcDistrStatusTopic) {
this.apiPublicKey = apiPublicKey;
@@ -59,4 +61,19 @@ public class RegistrationRequest {
this.distEnvEndPoints = distEnvEndPoints;
}
+ public String getManagerApiPublicKey() {
+ return managerApiPublicKey;
+ }
+
+ public void setManagerApiPublicKey(String managerApiPublicKey) {
+ this.managerApiPublicKey = managerApiPublicKey;
+ }
+
+ public String getManagerApiSecretKey() {
+ return managerApiSecretKey;
+ }
+
+ public void setManagerApiSecretKey(String managerApiSecretKey) {
+ this.managerApiSecretKey = managerApiSecretKey;
+ }
}
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 31c3d67aa6..4c5b4f67d8 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
@@ -1,323 +1,309 @@
-/*-
- * ============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=========================================================
- * Modifications copyright (c) 2019 Nokia
- * ================================================================================
- */
-
-package org.openecomp.sdc.be.distribution.servlet;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-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;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
-import org.openecomp.sdc.be.servlets.BeGenericServlet;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * This Servlet serves external users to download artifacts.
- *
- * @author tgitelman
- *
- */
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Distribution Catalog Servlet",description = "This Servlet serves external users to download artifacts."))
-@Singleton
-public class DistributionCatalogServlet extends BeGenericServlet {
-
- private static final String DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION = "download artifact failed with exception";
- private static final String MISSING_X_ECOMP_INSTANCE_ID_HEADER = "Missing X-ECOMP-InstanceID header";
- private static final Logger log = Logger.getLogger(DistributionCatalogServlet.class);
- private final ArtifactsBusinessLogic artifactsBusinessLogic;
-
- @Inject
- public DistributionCatalogServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- ArtifactsBusinessLogic artifactsBusinessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.artifactsBusinessLogic = artifactsBusinessLogic;
- }
-
- @Context
- private HttpServletRequest request;
-
- // *******************************************************
- // Download (GET) artifacts
- // **********************************************************/
- /**
- *
- * @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)
- @Operation(description = "Download service artifact", method = "GET", summary = "Returns downloaded artifact",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "The artifact is found and streamed.",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified Service is not found - SVC4503"),
- @ApiResponse(responseCode = "404", description = "Specified Service Version is not found - SVC4504"),
- @ApiResponse(responseCode = "404", description = "Specified artifact is not found - SVC4505"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500", description = "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(
- @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "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) {
-
- String requestURI = request.getRequestURI();
- Wrapper<Response> responseWrapper = validateInstanceIdHeader(new Wrapper<>(), instanceIdHeader, requestURI);
- if(!responseWrapper.isEmpty()) {
- return responseWrapper.getInnerElement();
- }
-
- try {
- Either<byte[], ResponseFormat> downloadRsrcArtifactEither = artifactsBusinessLogic
- .downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName);
- if (downloadRsrcArtifactEither.isRight()) {
- ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value();
- getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- byte[] value = downloadRsrcArtifactEither.left().value();
- InputStream is = new ByteArrayInputStream(value);
-
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
- responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
- }
- return responseWrapper.getInnerElement();
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download Murano package artifact for service - external API");
- log.debug(DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Wrapper<Response> validateInstanceIdHeader(Wrapper<Response> responseWrapper, String instanceIdHeader, String requestURI) {
- if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
- log.debug(MISSING_X_ECOMP_INSTANCE_ID_HEADER);
- ResponseFormat errorResponseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- getComponentsUtils().auditDistributionDownload(errorResponseFormat, new DistributionData(instanceIdHeader, requestURI));
- responseWrapper.setInnerElement(buildErrorResponse(errorResponseFormat));
- }
- return responseWrapper;
- }
-
- /**
- *
- * @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)
- @Operation(description = "Download resource artifact", method = "GET", summary = "Returns downloaded artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "The artifact is found and streamed.",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified Service is not found - SVC4503"),
- @ApiResponse(responseCode = "404", description = "Specified Resource Instance is not found - SVC4526"),
- @ApiResponse(responseCode = "404", description = "Specified Service Version is not found - SVC4504"),
- @ApiResponse(responseCode = "404", description = "Specified artifact is not found - SVC4505"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500", description = "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(
- @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "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) {
-
- String requestURI = request.getRequestURI();
- Wrapper<Response> responseWrapper = validateInstanceIdHeader(new Wrapper<>(), instanceIdHeader, requestURI);
-
- if(!responseWrapper.isEmpty()) {
- return responseWrapper.getInnerElement();
- }
-
- try {
- Either<byte[], ResponseFormat> downloadRsrcArtifactEither = artifactsBusinessLogic
- .downloadRsrcArtifactByNames(serviceName, serviceVersion, resourceName, resourceVersion, artifactName);
- if (downloadRsrcArtifactEither.isRight()) {
- ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value();
- getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- byte[] value = downloadRsrcArtifactEither.left().value();
- // Returning 64-encoded as it was received during upload
- InputStream is = new ByteArrayInputStream(value);
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
- responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
- }
- return responseWrapper.getInnerElement();
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download interface artifact for resource - external API");
- log.debug(DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /**
- *
- * @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)
- @Operation(description = "Download resource instance artifact", method = "GET", summary = "Returns downloaded artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "The artifact is found and streamed.",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified Service is not found - SVC4503"),
- @ApiResponse(responseCode = "404", description = "Specified Resource Instance is not found - SVC4526"),
- @ApiResponse(responseCode = "404", description = "Specified Service Version is not found - SVC4504"),
- @ApiResponse(responseCode = "404", description = "Specified artifact is not found - SVC4505"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500", description = "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 downloadResourceInstanceArtifactByName(
- @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "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) {
-
- String requestURI = request.getRequestURI();
- Wrapper<Response> responseWrapper = validateInstanceIdHeader(new Wrapper<>(), instanceIdHeader, requestURI);
-
- if(!responseWrapper.isEmpty()) {
- return responseWrapper.getInnerElement();
- }
-
- try {
- Either<byte[], ResponseFormat> downloadRsrcArtifactEither = artifactsBusinessLogic
- .downloadRsrcInstArtifactByNames(serviceName, serviceVersion, resourceInstanceName, artifactName);
- if (downloadRsrcArtifactEither.isRight()) {
- ResponseFormat responseFormat = downloadRsrcArtifactEither.right().value();
- getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- byte[] value = downloadRsrcArtifactEither.left().value();
- // Returning 64-encoded as it was received during upload
- InputStream is = new ByteArrayInputStream(value);
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
- responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
- }
- return responseWrapper.getInnerElement();
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download interface artifact for resource - external API");
- log.debug(DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-}
+/*-
+ * ============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=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
+
+package org.openecomp.sdc.be.distribution.servlet;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
+import org.openecomp.sdc.be.servlets.BeGenericServlet;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+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;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This Servlet serves external users to download artifacts.
+ *
+ * @author tgitelman
+ *
+ */
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Distribution Catalog Servlet",description = "This Servlet serves external users to download artifacts."))
+@Singleton
+public class DistributionCatalogServlet extends BeGenericServlet {
+
+ private static final String DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION = "download artifact failed with exception";
+ private static final String MISSING_X_ECOMP_INSTANCE_ID_HEADER = "Missing X-ECOMP-InstanceID header";
+ private static final Logger log = Logger.getLogger(DistributionCatalogServlet.class);
+ private final ArtifactsBusinessLogic artifactsBusinessLogic;
+
+ @Inject
+ public DistributionCatalogServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ ArtifactsBusinessLogic artifactsBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.artifactsBusinessLogic = artifactsBusinessLogic;
+ }
+
+ @Context
+ private HttpServletRequest request;
+
+ // *******************************************************
+ // Download (GET) artifacts
+ // **********************************************************/
+ /**
+ *
+ * @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)
+ @Operation(description = "Download service artifact", method = "GET", summary = "Returns downloaded artifact",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "The artifact is found and streamed.",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified Service is not found - SVC4503"),
+ @ApiResponse(responseCode = "404", description = "Specified Service Version is not found - SVC4504"),
+ @ApiResponse(responseCode = "404", description = "Specified artifact is not found - SVC4505"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500", description = "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")})
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
+ public Response downloadServiceArtifact(
+ @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "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) {
+
+ String requestURI = request.getRequestURI();
+ Wrapper<Response> responseWrapper = validateInstanceIdHeader(new Wrapper<>(), instanceIdHeader, requestURI);
+ if(!responseWrapper.isEmpty()) {
+ return responseWrapper.getInnerElement();
+ }
+
+ try {
+ byte[] downloadRsrcArtifactEither = artifactsBusinessLogic.downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName);
+ byte[] value = downloadRsrcArtifactEither;
+ InputStream is = new ByteArrayInputStream(value);
+
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
+ return buildOkResponse(responseFormat, is, headers);
+
+ } catch (ComponentException e) {
+ getComponentsUtils().auditDistributionDownload(e.getResponseFormat(), new DistributionData(instanceIdHeader, requestURI));
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download Murano package artifact for service - external API");
+ log.debug(DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION, e);
+ return buildErrorResponse(e.getResponseFormat());
+ }
+ }
+
+ private Wrapper<Response> validateInstanceIdHeader(Wrapper<Response> responseWrapper, String instanceIdHeader, String requestURI) {
+ if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
+ log.debug(MISSING_X_ECOMP_INSTANCE_ID_HEADER);
+ ResponseFormat errorResponseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditDistributionDownload(errorResponseFormat, new DistributionData(instanceIdHeader, requestURI));
+ responseWrapper.setInnerElement(buildErrorResponse(errorResponseFormat));
+ }
+ return responseWrapper;
+ }
+
+ /**
+ *
+ * @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)
+ @Operation(description = "Download resource artifact", method = "GET", summary = "Returns downloaded artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "The artifact is found and streamed.",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified Service is not found - SVC4503"),
+ @ApiResponse(responseCode = "404", description = "Specified Resource Instance is not found - SVC4526"),
+ @ApiResponse(responseCode = "404", description = "Specified Service Version is not found - SVC4504"),
+ @ApiResponse(responseCode = "404", description = "Specified artifact is not found - SVC4505"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500", description = "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")})
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
+ public Response downloadResourceArtifact(
+ @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "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) {
+
+ String requestURI = request.getRequestURI();
+ Wrapper<Response> responseWrapper = validateInstanceIdHeader(new Wrapper<>(), instanceIdHeader, requestURI);
+
+ if(!responseWrapper.isEmpty()) {
+ return responseWrapper.getInnerElement();
+ }
+
+ try {
+ ArtifactsBusinessLogic artifactsLogic = getArtifactBL(request.getSession().getServletContext());
+ byte[] downloadRsrcArtifactEither = artifactsLogic.downloadRsrcArtifactByNames(serviceName, serviceVersion, resourceName, resourceVersion, artifactName);
+ byte[] value = downloadRsrcArtifactEither;
+ // Returning 64-encoded as it was received during upload
+ InputStream is = new ByteArrayInputStream(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
+ return buildOkResponse(responseFormat, is, headers);
+
+ } catch (ComponentException e) {
+ getComponentsUtils().auditDistributionDownload(e.getResponseFormat(), new DistributionData(instanceIdHeader, requestURI));
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download interface artifact for resource - external API");
+ log.debug(DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION, e);
+ return buildErrorResponse(e.getResponseFormat());
+ }
+ }
+
+ /**
+ *
+ * @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)
+ @Operation(description = "Download resource instance artifact", method = "GET", summary = "Returns downloaded artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "The artifact is found and streamed.",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified Service is not found - SVC4503"),
+ @ApiResponse(responseCode = "404", description = "Specified Resource Instance is not found - SVC4526"),
+ @ApiResponse(responseCode = "404", description = "Specified Service Version is not found - SVC4504"),
+ @ApiResponse(responseCode = "404", description = "Specified artifact is not found - SVC4505"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500", description = "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")})
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
+ public Response downloadResourceInstanceArtifactByName(
+ @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "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) {
+
+ String requestURI = request.getRequestURI();
+ Wrapper<Response> responseWrapper = validateInstanceIdHeader(new Wrapper<>(), instanceIdHeader, requestURI);
+
+ if(!responseWrapper.isEmpty()) {
+ return responseWrapper.getInnerElement();
+ }
+
+ try {
+ byte[] downloadRsrcArtifactEither = artifactsBusinessLogic.downloadRsrcInstArtifactByNames(serviceName, serviceVersion, resourceInstanceName, artifactName);
+ byte[] value = downloadRsrcArtifactEither;
+ // Returning 64-encoded as it was received during upload
+ InputStream is = new ByteArrayInputStream(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(artifactName));
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditDistributionDownload(responseFormat, new DistributionData(instanceIdHeader, requestURI));
+ return buildOkResponse(responseFormat, is, headers);
+
+ } catch (ComponentException e) {
+ getComponentsUtils().auditDistributionDownload(e.getResponseFormat(), new DistributionData(instanceIdHeader, requestURI));
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("download interface artifact for resource - external API");
+ log.debug(DOWNLOAD_ARTIFACT_FAILED_WITH_EXCEPTION, e);
+ return buildErrorResponse(e.getResponseFormat());
+ }
+ }
+}
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 70556d6561..caa5db195b 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
@@ -1,385 +1,388 @@
-/*-
- * ============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.sdc.be.distribution.servlet;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-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.ComponentsUtils;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.servlets.BeGenericServlet;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.ArtifactTypeEnum;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.util.HttpUtil;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * This Servlet serves external users for distribution purposes.
- *
- * @author tgitelman
- *
- */
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1")
-@OpenAPIDefinition(info = @Info(title = "Distribution Servlet",description = "This Servlet serves external users for distribution purposes."))
-
-@Singleton
-public class DistributionServlet extends BeGenericServlet {
-
- private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
- private static final Logger log = Logger.getLogger(DistributionServlet.class);
- private final DistributionBusinessLogic distributionLogic;
- @Context
- private HttpServletRequest request;
-
- @Inject
- public DistributionServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils, DistributionBusinessLogic distributionLogic) {
- super(userBusinessLogic, componentsUtils);
- this.distributionLogic = distributionLogic;
- }
-
- /**
- *
- * @param requestId
- * @param instanceId
- * @param accept
- * @param authorization
- * @return
- */
- @GET
- @Path("/distributionUebCluster")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "UEB Server List", method = "GET", summary = "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(responseCode = "200", description = "ECOMP component is authenticated and list of Cambria API server’s FQDNs is returned",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServerListResponse.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its credentials for Basic Authentication - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed: Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500", description = "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(
- @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
- @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization) {
-
- 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().auditGetUebCluster(null, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
- return response;
- }
-
- try {
- Either<ServerListResponse, ResponseFormat> actionResponse = distributionLogic.getUebServerList();
-
- if (actionResponse.isRight()) {
- responseFormat = actionResponse.right().value();
- response = buildErrorResponse(responseFormat);
- } else {
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- response = buildOkResponse(responseFormat, actionResponse.left().value());
- }
-
- getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("failed to get ueb serbver list from cofiguration");
- log.debug("failed to get ueb serbver list from cofiguration", e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
- response = buildErrorResponse(responseFormat);
- return response;
- }
-
- }
-
- /**
- *
- * @param requestId
- * @param instanceId
- * @param accept
- * @param contentType
- * @param contenLength
- * @param authorization
- * @param requestJson
- * @return
- */
- @POST
- @Path("/registerForDistribution")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(parameters = @Parameter(name = "requestJson", required = true ), description = "Subscription status", method = "POST", summary = "Subscribes for distribution notifications")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "ECOMP component is successfully registered for distribution",content = @Content(array = @ArraySchema(schema = @Schema(implementation = TopicRegistrationResponse.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "400", description = "Missing Body - POL4500"),
- @ApiResponse(responseCode = "400", description = "Invalid Body : missing mandatory parameter 'apiPublicKey' - POL4501"),
- @ApiResponse(responseCode = "400", description = "Invalid Body : missing mandatory parameter 'distrEnvName' - POL4502"),
- @ApiResponse(responseCode = "400", description = "Invalid Body : Specified 'distrEnvName' doesn’t exist - POL4137"),
- @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed : Invalid HTTP method type used to register for distribution ( PUT,DELETE,GET will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500", description = "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(name = "requestJson", required = true, dataType = "org.openecomp.sdc.be.distribution.api.client.RegistrationRequest", paramType = "body", value = "json describe the artifact")})
-
- public Response registerForDistribution(
- @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
- @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "Determines the format of the body of the request", required = true)@HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
- @Parameter(description = "Length of the request body", required = true)@HeaderParam(value = Constants.CONTENT_LENGTH_HEADER) String contenLength,
- @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter( hidden = true) String requestJson) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<RegistrationRequest> registrationRequestWrapper = new Wrapper<>();
-
- validateHeaders(responseWrapper, request, AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL);
-
- if (responseWrapper.isEmpty()) {
- validateJson(responseWrapper, registrationRequestWrapper, requestJson);
- }
- if (responseWrapper.isEmpty()) {
- validateEnv(responseWrapper);
- }
-
- if (responseWrapper.isEmpty()) {
- distributionLogic.handleRegistration(responseWrapper, registrationRequestWrapper.getInnerElement(), buildAuditHandler(request, registrationRequestWrapper.getInnerElement()));
- } else {
- BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(DistributionBusinessLogic.REGISTER_IN_DISTRIBUTION_ENGINE, "registration validation failed");
- }
-
- return responseWrapper.getInnerElement();
- }
-
- /**
- * Returns list of valid artifact types for validation done in the distribution client.<br>
- * The list is the representation of the values of the enum ArtifactTypeEnum.
- *
- * @param requestId
- * @param instanceId
- * @param authorization
- * @param accept
- * @return
- */
- @GET
- @Path("/artifactTypes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Artifact types list", method = "GET", summary = "Fetches available artifact types list")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact types list fetched successfully", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed : Invalid HTTP method type used to register for distribution ( POST,PUT,DELETE will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500", description = "The registration failed due to internal SDC problem or Cambria Service failure ECOMP Component should continue the attempts to register for distribution - POL5000")})
- public Response getValidArtifactTypes(
- @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
- @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- Response response = null;
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
-
- //TODO check if in use
- 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 requestId
- * @param instanceId
- * @param accept
- * @param contentType
- * @param contenLength
- * @param authorization
- * @param requestJson
- * @return
- */
- @POST
- @Path("/unRegisterForDistribution")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(parameters = @Parameter(name = "requestJson", required = true ),description = "Subscription status", method = "POST", summary = "Removes from subscription for distribution notifications")
- //TODO Edit the responses
- @ApiResponses(value = {
- @ApiResponse(responseCode = "204", description = "ECOMP component is successfully unregistered",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = TopicUnregistrationResponse.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "400", description = "Missing Body - POL4500"),
- @ApiResponse(responseCode = "400", description = "Invalid Body : missing mandatory parameter 'apiPublicKey' - POL4501"),
- @ApiResponse(responseCode = "400", description = "Invalid Body : missing mandatory parameter 'distrEnvName' - SVC4506"),
- @ApiResponse(responseCode = "400", description = "Invalid Body : Specified 'distrEnvName' doesn’t exist - POL4137"),
- @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed : Invalid HTTP method type used to register for distribution ( PUT,DELETE,GET will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500", description = "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(name = "requestJson", required = true, dataType = "org.openecomp.sdc.be.distribution.api.client.RegistrationRequest", paramType = "body", value = "json describe the artifact")})
- public Response unRegisterForDistribution(
- @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
- @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "Determines the format of the body of the request", required = true)@HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
- @Parameter(description = "Length of the request body", required = true)@HeaderParam(value = Constants.CONTENT_LENGTH_HEADER) String contenLength,
- @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter( hidden = true) String requestJson) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<RegistrationRequest> unRegistrationRequestWrapper = new Wrapper<>();
-
- validateHeaders(responseWrapper, request, AuditingActionEnum.REMOVE_KEY_FROM_TOPIC_ACL);
-
- if (responseWrapper.isEmpty()) {
- validateJson(responseWrapper, unRegistrationRequestWrapper, requestJson);
- }
- if (responseWrapper.isEmpty()) {
- validateEnv(responseWrapper);
- }
- if (responseWrapper.isEmpty()) {
- distributionLogic.handleUnRegistration(responseWrapper, unRegistrationRequestWrapper.getInnerElement(), buildAuditHandler(request, unRegistrationRequestWrapper.getInnerElement()));
- } else {
- BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(DistributionBusinessLogic.UN_REGISTER_IN_DISTRIBUTION_ENGINE, "unregistration validation failed");
- }
-
- return responseWrapper.getInnerElement();
- }
-
- private void validateEnv(Wrapper<Response> responseWrapper) {
-
- // DE194021
- StorageOperationStatus environmentStatus = distributionLogic.getDistributionEngine().isEnvironmentAvailable();
- if (environmentStatus != StorageOperationStatus.OK) {
- if (environmentStatus == StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND) {
- Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.DISTRIBUTION_ENV_DOES_NOT_EXIST));
- responseWrapper.setInnerElement(missingHeaderResponse);
- } else {
- Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
- responseWrapper.setInnerElement(missingHeaderResponse);
- }
- }
-
- }
-
- private void validateHeaders(Wrapper<Response> responseWrapper, HttpServletRequest request, AuditingActionEnum auditingAction) {
- if (request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER) == null) {
- Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID));
- responseWrapper.setInnerElement(missingHeaderResponse);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- getComponentsUtils().auditMissingInstanceIdAsDistributionEngineEvent(auditingAction, responseFormat.getStatus().toString());
-
- }
-
- }
-
- private void validateJson(Wrapper<Response> responseWrapper, Wrapper<RegistrationRequest> registrationRequestWrapper, String requestJson) {
- if (requestJson == null || requestJson.isEmpty()) {
- Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_BODY));
- responseWrapper.setInnerElement(missingBodyResponse);
- } else {
- Either<RegistrationRequest, Exception> eitherRegistration = HttpUtil.convertJsonStringToObject(requestJson, RegistrationRequest.class);
- if (eitherRegistration.isLeft()) {
- RegistrationRequest registrationRequest = eitherRegistration.left().value();
- if (registrationRequest.getApiPublicKey() == null) {
- Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_PUBLIC_KEY));
- responseWrapper.setInnerElement(missingBodyResponse);
-
- } else if (registrationRequest.getDistrEnvName() == null) {
- Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_ENV_NAME));
- responseWrapper.setInnerElement(missingBodyResponse);
- } else {
- registrationRequestWrapper.setInnerElement(registrationRequest);
- }
- } else {
- Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_BODY));
- responseWrapper.setInnerElement(missingBodyResponse);
- }
- }
-
- }
-
- private AuditHandler buildAuditHandler(HttpServletRequest request, RegistrationRequest registrationRequest) {
- return new AuditHandler(getComponentsUtils(), request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), registrationRequest);
- }
-}
+/*-
+ * ============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.sdc.be.distribution.servlet;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+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.ComponentsUtils;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.servlets.BeGenericServlet;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.HttpUtil;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+/**
+ * This Servlet serves external users for distribution purposes.
+ *
+ * @author tgitelman
+ *
+ */
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1")
+@OpenAPIDefinition(info = @Info(title = "Distribution Servlet",description = "This Servlet serves external users for distribution purposes."))
+
+@Controller
+public class DistributionServlet extends BeGenericServlet {
+
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final Logger log = Logger.getLogger(DistributionServlet.class);
+ private final DistributionBusinessLogic distributionLogic;
+ @Context
+ private HttpServletRequest request;
+
+ @Inject
+ public DistributionServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils, DistributionBusinessLogic distributionLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.distributionLogic = distributionLogic;
+ }
+
+ /**
+ *
+ * @param requestId
+ * @param instanceId
+ * @param accept
+ * @param authorization
+ * @return
+ */
+ @GET
+ @Path("/distributionUebCluster")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "UEB Server List", method = "GET", summary = "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(responseCode = "200", description = "ECOMP component is authenticated and list of Cambria API server’s FQDNs is returned",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServerListResponse.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its credentials for Basic Authentication - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed: Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500", description = "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")})
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
+ public Response getUebServerList(
+ @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
+ @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization) {
+
+ 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().auditGetUebCluster(null, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
+ return response;
+ }
+
+ try {
+ Either<ServerListResponse, ResponseFormat> actionResponse = distributionLogic.getUebServerList();
+
+ if (actionResponse.isRight()) {
+ responseFormat = actionResponse.right().value();
+ response = buildErrorResponse(responseFormat);
+ } else {
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ response = buildOkResponse(responseFormat, actionResponse.left().value());
+ }
+
+ getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("failed to get ueb serbver list from cofiguration");
+ log.debug("failed to get ueb serbver list from cofiguration", e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage());
+ response = buildErrorResponse(responseFormat);
+ return response;
+ }
+
+ }
+
+ /**
+ *
+ * @param requestId
+ * @param instanceId
+ * @param accept
+ * @param contentType
+ * @param contenLength
+ * @param authorization
+ * @param requestJson
+ * @return
+ */
+ @POST
+ @Path("/registerForDistribution")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(parameters = @Parameter(name = "requestJson", required = true ), description = "Subscription status", method = "POST", summary = "Subscribes for distribution notifications")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "ECOMP component is successfully registered for distribution",content = @Content(array = @ArraySchema(schema = @Schema(implementation = TopicRegistrationResponse.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "400", description = "Missing Body - POL4500"),
+ @ApiResponse(responseCode = "400", description = "Invalid Body : missing mandatory parameter 'apiPublicKey' - POL4501"),
+ @ApiResponse(responseCode = "400", description = "Invalid Body : missing mandatory parameter 'distrEnvName' - POL4502"),
+ @ApiResponse(responseCode = "400", description = "Invalid Body : Specified 'distrEnvName' doesn’t exist - POL4137"),
+ @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed : Invalid HTTP method type used to register for distribution ( PUT,DELETE,GET will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500", description = "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(name = "requestJson", required = true, dataType = "org.openecomp.sdc.be.distribution.api.client.RegistrationRequest", paramType = "body", value = "json describe the artifact")})
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
+ public Response registerForDistribution(
+ @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
+ @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "Determines the format of the body of the request", required = true)@HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
+ @Parameter(description = "Length of the request body", required = true)@HeaderParam(value = Constants.CONTENT_LENGTH_HEADER) String contenLength,
+ @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter( hidden = true) String requestJson) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<RegistrationRequest> registrationRequestWrapper = new Wrapper<>();
+
+ validateHeaders(responseWrapper, request, AuditingActionEnum.ADD_KEY_TO_TOPIC_ACL);
+
+ if (responseWrapper.isEmpty()) {
+ validateJson(responseWrapper, registrationRequestWrapper, requestJson);
+ }
+ if (responseWrapper.isEmpty()) {
+ validateEnv(responseWrapper);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ distributionLogic.handleRegistration(responseWrapper, registrationRequestWrapper.getInnerElement(), buildAuditHandler(request, registrationRequestWrapper.getInnerElement()));
+ } else {
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(DistributionBusinessLogic.REGISTER_IN_DISTRIBUTION_ENGINE, "registration validation failed");
+ }
+
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * Returns list of valid artifact types for validation done in the distribution client.<br>
+ * The list is the representation of the values of the enum ArtifactTypeEnum.
+ */
+ @GET
+ @Path("/artifactTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Artifact types list", method = "GET", summary = "Fetches available artifact types list")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact types list fetched successfully", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed : Invalid HTTP method type used to register for distribution ( POST,PUT,DELETE will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500", description = "The registration failed due to internal SDC problem or Cambria Service failure ECOMP Component should continue the attempts to register for distribution - POL5000")})
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
+ public Response getValidArtifactTypes(
+ @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
+ @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ Response response = null;
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+
+ //TODO check if in use
+ 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 requestId
+ * @param instanceId
+ * @param accept
+ * @param contentType
+ * @param contenLength
+ * @param authorization
+ * @param requestJson
+ * @return
+ */
+ @POST
+ @Path("/unRegisterForDistribution")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(parameters = @Parameter(name = "requestJson", required = true ),description = "Subscription status", method = "POST", summary = "Removes from subscription for distribution notifications")
+ //TODO Edit the responses
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "204", description = "ECOMP component is successfully unregistered",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = TopicUnregistrationResponse.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "400", description = "Missing Body - POL4500"),
+ @ApiResponse(responseCode = "400", description = "Invalid Body : missing mandatory parameter 'apiPublicKey' - POL4501"),
+ @ApiResponse(responseCode = "400", description = "Invalid Body : missing mandatory parameter 'distrEnvName' - SVC4506"),
+ @ApiResponse(responseCode = "400", description = "Invalid Body : Specified 'distrEnvName' doesn’t exist - POL4137"),
+ @ApiResponse(responseCode = "401", description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed : Invalid HTTP method type used to register for distribution ( PUT,DELETE,GET will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500", description = "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(name = "requestJson", required = true, dataType = "org.openecomp.sdc.be.distribution.api.client.RegistrationRequest", paramType = "body", value = "json describe the artifact")})
+ @ApiImplicitParams({@ApiImplicitParam(name = "requestJson", required = true, dataType = "org.openecomp.sdc.be.distribution.api.client.RegistrationRequest", paramType = "body", value = "json describe the artifact")})
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
+ public Response unRegisterForDistribution(
+ @Parameter(description = "X-ECOMP-RequestID header", required = false)@HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true)@HeaderParam(value = Constants.X_ECOMP_INSTANCE_ID_HEADER) String instanceId,
+ @Parameter(description = "Determines the format of the body of the response", required = false)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "Determines the format of the body of the request", required = true)@HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
+ @Parameter(description = "Length of the request body", required = true)@HeaderParam(value = Constants.CONTENT_LENGTH_HEADER) String contenLength,
+ @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter( hidden = true) String requestJson) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<RegistrationRequest> unRegistrationRequestWrapper = new Wrapper<>();
+
+ validateHeaders(responseWrapper, request, AuditingActionEnum.REMOVE_KEY_FROM_TOPIC_ACL);
+
+ if (responseWrapper.isEmpty()) {
+ validateJson(responseWrapper, unRegistrationRequestWrapper, requestJson);
+ }
+ if (responseWrapper.isEmpty()) {
+ validateEnv(responseWrapper);
+ }
+ if (responseWrapper.isEmpty()) {
+ distributionLogic.handleUnRegistration(responseWrapper, unRegistrationRequestWrapper.getInnerElement(), buildAuditHandler(request, unRegistrationRequestWrapper.getInnerElement()));
+ } else {
+ BeEcompErrorManager.getInstance().logBeDistributionEngineSystemError(DistributionBusinessLogic.UN_REGISTER_IN_DISTRIBUTION_ENGINE, "unregistration validation failed");
+ }
+
+ return responseWrapper.getInnerElement();
+ }
+
+ private void validateEnv(Wrapper<Response> responseWrapper) {
+
+ // DE194021
+ StorageOperationStatus environmentStatus = distributionLogic.getDistributionEngine().isEnvironmentAvailable();
+ if (environmentStatus != StorageOperationStatus.OK) {
+ if (environmentStatus == StorageOperationStatus.DISTR_ENVIRONMENT_NOT_FOUND) {
+ Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.DISTRIBUTION_ENV_DOES_NOT_EXIST));
+ responseWrapper.setInnerElement(missingHeaderResponse);
+ } else {
+ Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(missingHeaderResponse);
+ }
+ }
+
+ }
+
+ private void validateHeaders(Wrapper<Response> responseWrapper, HttpServletRequest request, AuditingActionEnum auditingAction) {
+ if (request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER) == null) {
+ Response missingHeaderResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID));
+ responseWrapper.setInnerElement(missingHeaderResponse);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditMissingInstanceIdAsDistributionEngineEvent(auditingAction, responseFormat.getStatus().toString());
+
+ }
+
+ }
+
+ private void validateJson(Wrapper<Response> responseWrapper, Wrapper<RegistrationRequest> registrationRequestWrapper, String requestJson) {
+ if (requestJson == null || requestJson.isEmpty()) {
+ Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_BODY));
+ responseWrapper.setInnerElement(missingBodyResponse);
+ } else {
+ Either<RegistrationRequest, Exception> eitherRegistration = HttpUtil.convertJsonStringToObject(requestJson, RegistrationRequest.class);
+ if (eitherRegistration.isLeft()) {
+ RegistrationRequest registrationRequest = eitherRegistration.left().value();
+ if (registrationRequest.getApiPublicKey() == null) {
+ Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_PUBLIC_KEY));
+ responseWrapper.setInnerElement(missingBodyResponse);
+
+ } else if (registrationRequest.getDistrEnvName() == null) {
+ Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_ENV_NAME));
+ responseWrapper.setInnerElement(missingBodyResponse);
+ } else {
+ registrationRequestWrapper.setInnerElement(registrationRequest);
+ }
+ } else {
+ Response missingBodyResponse = buildErrorResponse(distributionLogic.getResponseFormatManager().getResponseFormat(ActionStatus.MISSING_BODY));
+ responseWrapper.setInnerElement(missingBodyResponse);
+ }
+ }
+
+ }
+
+ private AuditHandler buildAuditHandler(HttpServletRequest request, RegistrationRequest registrationRequest) {
+ return new AuditHandler(getComponentsUtils(), request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), registrationRequest);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/dto/ExternalRefDTO.java b/catalog-be/src/main/java/org/openecomp/sdc/be/dto/ExternalRefDTO.java
index c030cbdda3..69b50e0aa0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/dto/ExternalRefDTO.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/dto/ExternalRefDTO.java
@@ -20,8 +20,8 @@
package org.openecomp.sdc.be.dto;
+import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
-import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@@ -34,6 +34,7 @@ import lombok.Setter;
@Getter
@Setter
public class ExternalRefDTO {
+ @JsonInclude
private String referenceUUID;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java
index c84558dbd0..ec349aeac4 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java
@@ -28,6 +28,7 @@ import org.onap.portalsdk.core.onboarding.util.CipherUtil;
import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
import org.onap.portalsdk.core.restful.domain.EcompRole;
import org.onap.portalsdk.core.restful.domain.EcompUser;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -36,6 +37,7 @@ import org.openecomp.sdc.be.ecomp.converters.EcompUserConverter;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.be.user.UserBusinessLogicExt;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -50,9 +52,9 @@ import java.util.Map;
public class EcompIntImpl implements IPortalRestAPIService {
private static final String FAILED_TO_CONVERT_ROLES = "Failed to convert Roles";
- private static final String FAILED_TO_GET_ROLES = "Failed to get Roles";
+ public static final String FAILED_TO_GET_ROLES = "Failed to get Roles";
private static final String GET_USER_ROLES = "GetUserRoles";
- private static final String ERROR_FAILED_TO_GET_ROLES = "Error: Failed to get Roles";
+ public static final String ERROR_FAILED_TO_GET_ROLES = "Error: Failed to get Roles";
private static final String PUSH_USER_ROLE = "PushUserRole";
private static final String FAILED_TO_FETCH_ROLES = "Failed to fetch roles";
private static final String FAILED_TO_CONVERT_USER2 = "Failed to convert User {}";
@@ -89,32 +91,26 @@ public class EcompIntImpl implements IPortalRestAPIService {
UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
final String modifierAttId = JH0003;
- User modifier = new User();
- modifier.setUserId(modifierAttId);
log.debug("modifier id is {}", modifierAttId);
User convertedAsdcUser = EcompUserConverter.convertEcompUserToUser(user);
if (convertedAsdcUser == null) {
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CONVERT_USER, ErrorSeverity.INFO);
+ BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, NULL_POINTER_RETURNED_FROM_USER_CONVERTER, ErrorSeverity.INFO);
log.debug(FAILED_TO_CREATE_USER, user);
- throw new PortalAPIException("Failed to convert user " + user);
+ throw new PortalAPIException("Failed to create user " + convertedAsdcUser);
}
-
- Either<User, ResponseFormat> createUserResponse = userBusinessLogic.createUser(modifier, convertedAsdcUser);
-
- // ALREADY EXIST ResponseFormat
- final String ALREADY_EXISTS_RESPONSE_ID = "SVC4006";
-
- if (createUserResponse.isRight()) {
- if (!createUserResponse.right().value().getMessageId().equals(ALREADY_EXISTS_RESPONSE_ID)) {
- log.debug(FAILED_TO_CREATE_USER, user);
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_CREATE_USER + createUserResponse.right());
- }
+ userBusinessLogic.createUser(modifierAttId, convertedAsdcUser);
+ log.debug("User created {}", user);
+ } catch (ComponentException ce) {
+ if (ActionStatus.USER_ALREADY_EXIST.equals(ce.getActionStatus())) {
log.debug("User already exist {}", user);
+ } else {
+ log.debug(FAILED_TO_CREATE_USER, user);
+ BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, ErrorSeverity.ERROR);
+ throw new PortalAPIException(FAILED_TO_CREATE_USER + ce.getActionStatus());
}
- log.debug("User created {}", user);
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.debug(FAILED_TO_CREATE_USER, user, e);
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, ErrorSeverity.ERROR);
throw new PortalAPIException(FAILED_TO_CREATE_USER, e);
@@ -153,14 +149,14 @@ public class EcompIntImpl implements IPortalRestAPIService {
user.setLoginId(loginId);
}
- User convertedAsdcUser = EcompUserConverter.convertEcompUserToUser(user);
- if (convertedAsdcUser == null) {
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CONVERT_USER, ErrorSeverity.INFO);
- log.debug(FAILED_TO_CREATE_USER, user);
- throw new PortalAPIException("Failed to convert user " + user);
+ User asdcUser = EcompUserConverter.convertEcompUserToUser(user);
+ if (asdcUser == null) {
+ log.debug(NULL_POINTER_RETURNED_FROM_USER_CONVERTER);
+ BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, NULL_POINTER_RETURNED_FROM_USER_CONVERTER, ErrorSeverity.INFO);
+ throw new PortalAPIException(FAILED_TO_EDIT_USER);
}
- Either<User, ResponseFormat> updateUserCredentialsResponse = userBusinessLogic.updateUserCredentials(convertedAsdcUser);
+ Either<User, ResponseFormat> updateUserCredentialsResponse = userBusinessLogic.updateUserCredentials(asdcUser);
if (updateUserCredentialsResponse.isRight()) {
log.debug(FAILED_TO_UPDATE_USER_CREDENTIALS);
@@ -177,40 +173,29 @@ public class EcompIntImpl implements IPortalRestAPIService {
@Override
public EcompUser getUser(String loginId) throws PortalAPIException {
log.debug("Start handle request of ECOMP getUser");
-
try {
-
if (loginId == null) {
log.debug(RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID);
BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER, RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID, ErrorSeverity.INFO);
throw new PortalAPIException(RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID);
}
-
UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
-
- Either<User, ActionStatus> getUserResponse = userBusinessLogic.getUser(loginId, false);
-
- if (getUserResponse.isRight()) {
+ User user = userBusinessLogic.getUser(loginId, false);
+ Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(user);
+ if (ecompUser.isLeft() && ecompUser.left().value() != null) {
+ return ecompUser.left().value();
+ } else {
log.debug(FAILED_TO_GET_USER);
BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER, FAILED_TO_GET_USER, ErrorSeverity.INFO);
- throw new PortalAPIException(FAILED_TO_GET_USER + getUserResponse.right());
- } else {
- if (getUserResponse.left().value() != null) {
- Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(getUserResponse.left().value());
- if (ecompUser.isLeft() && ecompUser.left().value() != null) {
- return ecompUser.left().value();
- } else {
- log.debug(FAILED_TO_GET_USER);
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER, FAILED_TO_GET_USER, ErrorSeverity.INFO);
- throw new PortalAPIException(ecompUser.right().value());
- }
- } else {
- log.debug(FAILED_TO_GET_USER);
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER, FAILED_TO_GET_USER, ErrorSeverity.INFO);
- throw new PortalAPIException(FAILED_TO_GET_USER + getUserResponse.right());
- }
+ throw new PortalAPIException(ecompUser.right().value());
}
- } catch (Exception e) {
+ } catch (ComponentException ce) {
+ log.debug(FAILED_TO_GET_USER);
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER, FAILED_TO_GET_USER, ErrorSeverity.INFO);
+ throw new PortalAPIException(FAILED_TO_GET_USER + ce.getActionStatus());
+
+ }
+ catch (Exception e) {
log.debug(FAILED_TO_GET_USER);
throw new PortalAPIException(FAILED_TO_GET_USER, e);
}
@@ -222,36 +207,22 @@ public class EcompIntImpl implements IPortalRestAPIService {
try {
UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
-
- Either<List<User>, ResponseFormat> getUsersResponse = userBusinessLogic.getUsersList(JH0003, null, null);
-
- if (getUsersResponse.isRight()) {
- log.debug(FAILED_TO_GET_USERS);
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USERS, FAILED_TO_GET_USERS, ErrorSeverity.INFO);
- throw new PortalAPIException(FAILED_TO_GET_USERS + getUsersResponse.right());
- } else {
- if (getUsersResponse.left().value() != null) {
- List<EcompUser> ecompUserList = new LinkedList<>();
- for (User user : getUsersResponse.left().value()) {
- Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(user);
- if (ecompUser.isRight()) {
- log.debug(FAILED_TO_CONVERT_USER2, user);
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USERS, "Failed to convert User" + user.toString(), ErrorSeverity.WARNING);
- continue;
- } else if (ecompUser.left().value() == null) {
- log.debug(FAILED_TO_CONVERT_USER2, user);
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USERS, "Failed to convert User" + user.toString(), ErrorSeverity.WARNING);
- continue;
- }
- ecompUserList.add(ecompUser.left().value());
- }
- return ecompUserList;
- } else {
- log.debug(FAILED_TO_GET_USERS);
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USERS, FAILED_TO_GET_USERS, ErrorSeverity.INFO);
- throw new PortalAPIException(FAILED_TO_GET_USERS + getUsersResponse.right());
+ List<User> users = userBusinessLogic.getUsersList(JH0003, null, null);
+ List<EcompUser> ecompUserList = new LinkedList<>();
+ for (User user : users) {
+ Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(user);
+ if (ecompUser.isRight()) {
+ log.debug(FAILED_TO_CONVERT_USER2, user);
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_USERS, "Failed to convert User" + user.toString(), ErrorSeverity.WARNING);
+ continue;
+ } else if (ecompUser.left().value() == null) {
+ log.debug(FAILED_TO_CONVERT_USER2, user);
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_USERS, "Failed to convert User" + user.toString(), ErrorSeverity.WARNING);
+ continue;
}
+ ecompUserList.add(ecompUser.left().value());
}
+ return ecompUserList;
} catch (Exception e) {
log.debug(FAILED_TO_GET_USERS);
BeEcompErrorManager.getInstance().logInvalidInputError(GET_USERS, FAILED_TO_GET_USERS, ErrorSeverity.INFO);
@@ -266,7 +237,7 @@ public class EcompIntImpl implements IPortalRestAPIService {
List<EcompRole> ecompRolesList = new LinkedList<>();
for (Role role : Role.values()) {
EcompRole ecompRole = new EcompRole();
- ecompRole.setId(new Long(role.ordinal()));
+ ecompRole.setId((long) role.ordinal());
ecompRole.setName(role.name());
ecompRolesList.add(ecompRole);
}
@@ -292,35 +263,37 @@ public class EcompIntImpl implements IPortalRestAPIService {
log.debug("Start handle request of ECOMP pushUserRole");
final String modifierAttId = JH0003;
- User modifier = new User();
- modifier.setUserId(modifierAttId);
log.debug("modifier id is {}", modifierAttId);
UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
- String updatedRole = null;
+ String updatedRole;
if (roles == null) {
- throw new PortalAPIException("Error: Recieved null for roles");
+ throw new PortalAPIException("Error: Received null for roles");
} else if (roles.iterator().hasNext()) {
EcompRole ecompRole = roles.iterator().next();
updatedRole = EcompRoleConverter.convertEcompRoleToRole(ecompRole);
log.debug("pushing role: {} to user: {}", updatedRole, loginId);
- Either<User, ResponseFormat> updateUserRoleResponse = userBusinessLogic.updateUserRole(modifier, loginId, updatedRole);
- if (updateUserRoleResponse.isRight()) {
+ try {
+ userBusinessLogic.updateUserRole(modifierAttId, loginId, updatedRole);
+ }
+ catch (Exception e) {
log.debug("Error: Failed to update role");
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER_ROLE, "Failed to update role", ErrorSeverity.INFO);
- throw new PortalAPIException("Failed to update role" + updateUserRoleResponse.right().value().toString());
+ throw new PortalAPIException("Failed to update role" + e);
}
} else {
log.debug("Error: No roles in List");
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER_ROLE, FAILED_TO_FETCH_ROLES, ErrorSeverity.INFO);
//in this cases we want to deactivate the user
- Either<User, ResponseFormat> deActivateUserResponse = userBusinessLogic.deActivateUser(modifier, loginId);
- if (deActivateUserResponse.isRight()) {
+ try {
+ getUserBusinessLogicExt().deActivateUser(modifierAttId, loginId);
+ }
+ catch (Exception e) {
log.debug("Error: Failed to deactivate user {}",loginId);
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER_ROLE, "Failed to deactivate user", ErrorSeverity.INFO);
- throw new PortalAPIException(deActivateUserResponse.right().value().getFormattedMessage());
+ throw new PortalAPIException("Error: Failed to deactivate user" + e);
}
}
}
@@ -329,36 +302,25 @@ public class EcompIntImpl implements IPortalRestAPIService {
public List<EcompRole> getUserRoles(String loginId) throws PortalAPIException {
try {
log.debug("Start handle request of ECOMP getUserRoles");
-
UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
-
- Either<User, ActionStatus> getUserResponse = userBusinessLogic.getUser(loginId, false);
-
- if (getUserResponse.isRight()) {
- log.debug(ERROR_FAILED_TO_GET_ROLES);
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_GET_ROLES, ErrorSeverity.INFO);
- throw new PortalAPIException(FAILED_TO_GET_ROLES + getUserResponse.right());
- } else {
- if (getUserResponse.left().value() != null) {
- Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(getUserResponse.left().value());
- if (ecompUser.isRight()) {
- log.debug("Error: Failed to convert Roles");
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_CONVERT_ROLES, ErrorSeverity.ERROR);
- throw new PortalAPIException(ecompUser.right().value());
- } else if (ecompUser.left().value() == null) {
- log.debug("Error: Failed to convert Roles");
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_CONVERT_ROLES, ErrorSeverity.ERROR);
- throw new PortalAPIException();
- }
-
- return new LinkedList<>(ecompUser.left().value().getRoles());
- } else {
- log.debug(ERROR_FAILED_TO_GET_ROLES);
- BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_GET_ROLES, ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_GET_ROLES + getUserResponse.right());
- }
+ User user = userBusinessLogic.getUser(loginId, false);
+ Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(user);
+ if (ecompUser.isRight()) {
+ log.debug("Error: Failed to convert Roles");
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_CONVERT_ROLES, ErrorSeverity.ERROR);
+ throw new PortalAPIException(ecompUser.right().value());
+ } else if (ecompUser.left().value() == null) {
+ log.debug("Error: Failed to convert Roles");
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_CONVERT_ROLES, ErrorSeverity.ERROR);
+ throw new PortalAPIException();
}
- } catch (Exception e) {
+ return new LinkedList<>(ecompUser.left().value().getRoles());
+ } catch (ComponentException ce) {
+ log.debug(ERROR_FAILED_TO_GET_ROLES);
+ BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_GET_ROLES, ErrorSeverity.INFO);
+ throw new PortalAPIException(FAILED_TO_GET_ROLES + ce.getActionStatus());
+ }
+ catch (Exception e) {
log.debug(ERROR_FAILED_TO_GET_ROLES);
BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_GET_ROLES, ErrorSeverity.INFO);
throw new PortalAPIException(FAILED_TO_GET_ROLES, e);
@@ -366,7 +328,7 @@ public class EcompIntImpl implements IPortalRestAPIService {
}
@Override
- public boolean isAppAuthenticated(HttpServletRequest request) throws PortalAPIException {
+ public boolean isAppAuthenticated(HttpServletRequest request) {
final String portal_key = PortalApiProperties.getProperty("portal_pass");
final String portal_user = PortalApiProperties.getProperty("portal_user");
final String USERNAME = request.getHeader("username");
@@ -393,6 +355,11 @@ public class EcompIntImpl implements IPortalRestAPIService {
return (UserBusinessLogic) ctx.getBean("userBusinessLogic");
}
+ private UserBusinessLogicExt getUserBusinessLogicExt() {
+ ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
+ return (UserBusinessLogicExt) ctx.getBean("userBusinessLogicExt");
+ }
+
/**
* Gets and returns the userId for the logged-in user based on the request.
* If any error occurs, the method should throw PortalApiException with an
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalPropertiesEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalPropertiesEnum.java
new file mode 100644
index 0000000000..b8ecbacff8
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalPropertiesEnum.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.ecomp;
+
+public enum PortalPropertiesEnum {
+ APP_NAME("portal_app_name"),
+ ECOMP_REST_URL("ecomp_rest_url"),
+ PASSWORD("portal_pass"),
+ UEB_APP_KEY("ueb_app_key"),
+ USER("portal_user");
+
+ private final String value;
+
+ PortalPropertiesEnum(String value) {
+ this.value = value;
+ }
+
+ public String value() {
+ return value;
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java
index 9f6c661ac5..5b9c83fb98 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java
@@ -27,10 +27,13 @@ import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
import org.onap.portalsdk.core.onboarding.util.CipherUtil;
import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
import org.onap.portalsdk.core.restful.domain.EcompUser;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.ecomp.converters.EcompUserConverter;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.be.user.UserBusinessLogicExt;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
@@ -43,9 +46,7 @@ import java.util.Map;
public final class PortalRestAPICentralServiceImpl implements IPortalRestCentralService {
private static final String FAILED_TO_UPDATE_USER_CREDENTIALS = "Failed to update user credentials";
- private static final String FAILED_TO_UPDATE_USER_ROLE = "Failed to update user role";
private static final String FAILED_TO_DEACTIVATE_USER = "Failed to deactivate user {}";
- private static final String FAILED_TO_DEACTIVATE_USER2 = "Failed to deactivate user";
private static final String FAILED_TO_EDIT_USER = "Failed to edit user";
private static final String EDIT_USER = "EditUser";
private static final String CHECK_ROLES = "checkIfSingleRoleProvided";
@@ -53,19 +54,20 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
private static final String RECEIVED_NULL_ROLES = "Received null roles for user";
private static final String RECEIVED_MULTIPLE_ROLES = "Received multiple roles for user {}";
private static final String RECEIVED_MULTIPLE_ROLES2 = "Received multiple roles for user";
- private static final String NULL_POINTER_RETURNED_FROM_USER_CONVERTER = "NULL pointer returned from user converter";
private static final String FAILED_TO_CREATE_USER = "Failed to create user {}";
- private static final String FAILED_TO_CONVERT_USER = "Failed to convert user";
+ private static final String FAILED_TO_GET_USER_ID_HEADER = "Failed to get user_id header";
private static final String JH0003 = "jh0003";
private static final String PUSH_USER = "PushUser";
private static final String RECEIVED_NULL_FOR_ARGUMENT_USER = "Received null for argument user";
private static final Logger log = Logger.getLogger(PortalRestAPICentralServiceImpl.class);
private UserBusinessLogic userBusinessLogic;
+ private UserBusinessLogicExt userBusinessLogicExt;
public PortalRestAPICentralServiceImpl() throws PortalAPIException {
try {
ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
userBusinessLogic = (UserBusinessLogic) ctx.getBean("userBusinessLogic");
+ userBusinessLogicExt = (UserBusinessLogicExt) ctx.getBean("userBusinessLogicExt");
} catch (Exception e) {
log.debug("Failed to get user UserBusinessLogic", e);
BeEcompErrorManager.getInstance().logInvalidInputError("constructor", "Exception thrown" + e.getMessage(), BeEcompErrorManager.ErrorSeverity.ERROR);
@@ -74,25 +76,27 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
log.debug("PortalRestAPICentralServiceImpl Class Instantiated");
}
- PortalRestAPICentralServiceImpl(UserBusinessLogic ubl) {
+ //For testing purposes
+ PortalRestAPICentralServiceImpl(UserBusinessLogic ubl, UserBusinessLogicExt uble) {
this.userBusinessLogic = ubl;
+ this.userBusinessLogicExt = uble;
}
@Override
public Map<String, String> getAppCredentials() throws PortalAPIException {
Map<String, String> credMap = new HashMap<>();
- String portal_user = PortalApiProperties.getProperty(PortalPropertiesEnum.PORTAL_USER.value);
- String password = PortalApiProperties.getProperty(PortalPropertiesEnum.PORTAL_PASS.value);
- String appName = PortalApiProperties.getProperty(PortalPropertiesEnum.PORTAL_APP_NAME.value);
+ String portal_user = PortalApiProperties.getProperty(PortalPropertiesEnum.USER.value());
+ String password = PortalApiProperties.getProperty(PortalPropertiesEnum.PASSWORD.value());
+ String appName = PortalApiProperties.getProperty(PortalPropertiesEnum.APP_NAME.value());
try {
- credMap.put(PortalPropertiesEnum.PORTAL_USER.value, CipherUtil.decryptPKC(portal_user));
- credMap.put(PortalPropertiesEnum.PORTAL_PASS.value, CipherUtil.decryptPKC(password));
- credMap.put(PortalPropertiesEnum.PORTAL_APP_NAME.value, CipherUtil.decryptPKC(appName));
+ credMap.put("username", CipherUtil.decryptPKC(portal_user));
+ credMap.put("password", CipherUtil.decryptPKC(password));
+ credMap.put("appName", CipherUtil.decryptPKC(appName));
} catch (CipherUtilException e) {
log.debug("User authentication failed - Decryption failed", e);
throw new PortalAPIException("Failed to decrypt" + e.getMessage());
}
-
+ log.debug("the credentials map for portal is {}", credMap);
return credMap;
}
@@ -108,51 +112,24 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
checkIfSingleRoleProvided(user);
final String modifierAttId = JH0003;
- User modifier = new User();
- modifier.setUserId(modifierAttId);
log.debug("modifier id is {}", modifierAttId);
User convertedAsdcUser = EcompUserConverter.convertEcompUserToUser(user);
- if (convertedAsdcUser == null) {
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CONVERT_USER, BeEcompErrorManager.ErrorSeverity.INFO);
- log.debug(FAILED_TO_CREATE_USER, user);
- throw new PortalAPIException("Failed to convert user " + user);
- }
-
- Either<User, ResponseFormat> createUserResponse = userBusinessLogic.createUser(modifier, convertedAsdcUser);
-
- // ALREADY EXIST ResponseFormat
- final String ALREADY_EXISTS_RESPONSE_ID = "SVC4006";
-
- if (createUserResponse.isRight()) {
- if (!createUserResponse.right().value().getMessageId().equals(ALREADY_EXISTS_RESPONSE_ID)) {
- log.debug(FAILED_TO_CREATE_USER, user);
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, BeEcompErrorManager.ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_CREATE_USER + createUserResponse.right().value());
- } else {
- log.debug("User already exist and will be updated and reactivated {}", user);
- Either<User, ResponseFormat> updateUserResp = userBusinessLogic.updateUserCredentials(convertedAsdcUser);
- if(updateUserResp.isRight()){
- log.debug(FAILED_TO_UPDATE_USER_CREDENTIALS, user);
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_UPDATE_USER_CREDENTIALS, BeEcompErrorManager.ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_UPDATE_USER_CREDENTIALS + createUserResponse.right().value());
- }
- Either<User, ResponseFormat> updateUserRoleResp = userBusinessLogic.updateUserRole(modifier, convertedAsdcUser.getUserId(), convertedAsdcUser.getRole());
- if(updateUserRoleResp.isRight()){
- log.debug(FAILED_TO_UPDATE_USER_ROLE, user);
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_UPDATE_USER_ROLE, BeEcompErrorManager.ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_UPDATE_USER_ROLE + createUserResponse.right().value());
- }
- }
+ try{
+ log.debug("Before creating ecomp user {} sdc user {}", user, convertedAsdcUser);
+ userBusinessLogic.createUser(modifierAttId, convertedAsdcUser);
+ }catch (Exception e) {
+ log.debug(FAILED_TO_CREATE_USER, user, e);
+ BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, BeEcompErrorManager.ErrorSeverity.ERROR);
+ throw new PortalAPIException(FAILED_TO_CREATE_USER + e.getMessage());
}
- log.debug("User created {}", user);
+
+ log.debug("User created ecomp user {} sdc user {}", user, convertedAsdcUser);
}
@Override
public void editUser(String loginId, EcompUser user) throws PortalAPIException {
- log.debug("Start handle request of ECOMP editUser");
-
if (user == null) {
log.debug(RECEIVED_NULL_FOR_ARGUMENT_USER);
BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, RECEIVED_NULL_FOR_ARGUMENT_USER, BeEcompErrorManager.ErrorSeverity.INFO);
@@ -163,11 +140,9 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
throw new PortalAPIException(RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID);
}
- checkIfSingleRoleProvided(user);
+ log.debug("Start handle request of ECOMP editUser {} with loginId {} with follopwing roles {}", user, loginId, user.getRoles());
final String modifierAttId = JH0003;
- User modifier = new User();
- modifier.setUserId(modifierAttId);
log.debug("modifier id is {}", modifierAttId);
if (user.getLoginId() != null && !user.getLoginId().equals(loginId)) {
@@ -178,13 +153,24 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
user.setLoginId(loginId);
}
- User asdcUser = EcompUserConverter.convertEcompUserToUser(user);
- if (asdcUser == null) {
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CONVERT_USER, BeEcompErrorManager.ErrorSeverity.INFO);
- log.debug(FAILED_TO_CREATE_USER, user);
- throw new PortalAPIException("Failed to convert user " + user);
+ Either<User, ActionStatus> verifyNewUser;
+ try{
+ verifyNewUser = userBusinessLogic.verifyNewUserForPortal(user.getLoginId());
+ } catch (ComponentException e){
+ log.debug("Failed to verify new user", e);
+ throw new PortalAPIException(e.getCause());
+ }
+
+ if(verifyNewUser.isRight() &&
+ (ActionStatus.USER_NOT_FOUND.equals(verifyNewUser.right().value()) ||
+ ActionStatus.USER_INACTIVE.equals(verifyNewUser.right().value()))){
+ log.debug("Edit user for user that not exist in DB, executing push user flow {}", user);
+ pushUser(user);
+ return;
}
+ User asdcUser = EcompUserConverter.convertEcompUserToUser(user);
+ log.debug("Before editing ecomp user {} sdc user {}", user, asdcUser);
Either<User, ResponseFormat> updateUserCredentialsResponse = userBusinessLogic.updateUserCredentials(asdcUser);
if (updateUserCredentialsResponse.isRight()) {
@@ -193,28 +179,43 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
throw new PortalAPIException(FAILED_TO_EDIT_USER + updateUserCredentialsResponse.right().value());
}
- Either<User, ResponseFormat> deActivateUser;
-
- if(asdcUser.getRole() == null || asdcUser.getRole().isEmpty()){
- deActivateUser = userBusinessLogic.deActivateUser(modifier, asdcUser.getUserId());
+ if(user.getRoles() == null || user.getRoles().isEmpty()){
+ try {
+ log.debug("Before deactivating ecomp user {} sdc user {}", user, asdcUser);
+ userBusinessLogicExt.deActivateUser(modifierAttId, loginId);
+ }
+ catch (Exception e) {
+ log.debug("Error: Failed to deactivate user {}", loginId);
+ BeEcompErrorManager.getInstance().logInvalidInputError(FAILED_TO_DEACTIVATE_USER, "Failed to deactivate user", BeEcompErrorManager.ErrorSeverity.INFO);
+ throw new PortalAPIException("Error: Failed to deactivate user" + e);
+ }
} else {
- return;
- }
-
- if (deActivateUser.isRight()) {
- log.debug(FAILED_TO_DEACTIVATE_USER, asdcUser);
- BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, FAILED_TO_DEACTIVATE_USER2, BeEcompErrorManager.ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_DEACTIVATE_USER2 + deActivateUser.right().value());
+ checkIfSingleRoleProvided(user);
+ try {
+ log.debug("Before updating ecomp user {} sdc user {}", user, asdcUser);
+ userBusinessLogic.updateUserRole(modifierAttId, loginId, asdcUser.getRole());
+ }catch (Exception e) {
+ log.debug("Error: Failed to update user role {}", loginId);
+ BeEcompErrorManager.getInstance().logInvalidInputError(FAILED_TO_EDIT_USER, "Failed to update user role", BeEcompErrorManager.ErrorSeverity.INFO);
+ throw new PortalAPIException("Error: Failed to update user role" + e);
+ }
}
+ log.debug("user updated ecomp user {} sdc user {}", user, asdcUser);
}
@Override
public String getUserId(HttpServletRequest request) throws PortalAPIException {
- return request.getHeader(Constants.USER_ID_HEADER);
+ String header = request.getHeader(Constants.USER_ID_HEADER);
+ if (header == null) {
+ log.debug(FAILED_TO_GET_USER_ID_HEADER);
+ BeEcompErrorManager.getInstance().logInvalidInputError("getUserId", FAILED_TO_GET_USER_ID_HEADER, BeEcompErrorManager.ErrorSeverity.ERROR);
+ throw new PortalAPIException(FAILED_TO_GET_USER_ID_HEADER);
+ }
+ return header;
}
- private void checkIfSingleRoleProvided(EcompUser user) throws PortalAPIException {
+ public static void checkIfSingleRoleProvided(EcompUser user) throws PortalAPIException {
if(user.getRoles() == null) {
log.debug(RECEIVED_NULL_ROLES, user);
BeEcompErrorManager.getInstance().logInvalidInputError(CHECK_ROLES, RECEIVED_NULL_ROLES, BeEcompErrorManager.ErrorSeverity.ERROR);
@@ -222,23 +223,9 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
}else if(user.getRoles().size() > 1) {
log.debug(RECEIVED_MULTIPLE_ROLES, user);
BeEcompErrorManager.getInstance().logInvalidInputError(CHECK_ROLES, RECEIVED_MULTIPLE_ROLES2, BeEcompErrorManager.ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_DEACTIVATE_USER2 + user);
+ throw new PortalAPIException(RECEIVED_MULTIPLE_ROLES2 + user);
}
}
- public enum PortalPropertiesEnum{
- PORTAL_PASS ("portal_pass"),
- PORTAL_USER("portal_user"),
- PORTAL_APP_NAME("portal_app_name");
-
- private final String value;
-
- PortalPropertiesEnum(String value) {
- this.value = value;
- }
- public String value() {
- return value;
- }
- }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java
index c71c7960ab..0729ee28c6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java
@@ -26,9 +26,19 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.distribution.servlet.DistributionCatalogServlet;
-import org.openecomp.sdc.be.externalapi.servlet.representation.*;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ArtifactMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceAssetDetailedMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceAssetMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceInstanceMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceAssetDetailedMetadata;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceAssetMetadata;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+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.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -36,7 +46,11 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.*;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
@org.springframework.stereotype.Component("asset-metadata-utils")
public class AssetMetadataConverter {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java
index df20351fd8..d7beb14c7b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompRoleConverter.java
@@ -20,32 +20,35 @@
package org.openecomp.sdc.be.ecomp.converters;
+import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
import org.onap.portalsdk.core.restful.domain.EcompRole;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.common.log.wrappers.Logger;
public final class EcompRoleConverter {
-
+ private static final String FAILED_TO_CONVERT_USER = "Failed to convert user";
+ private static final String EDIT_USER = "EditUser";
private static final Logger log = Logger.getLogger(EcompRoleConverter.class);
private EcompRoleConverter() {
}
- // TODO Add Either or Exception in case of convertation failure
- public static String convertEcompRoleToRole(EcompRole ecompRole) {
+ public static String convertEcompRoleToRole(EcompRole ecompRole) throws PortalAPIException {
- log.debug("converting role");
+ log.debug("converting role{}", ecompRole);
if (ecompRole == null) {
log.debug("recieved null for roles");
return null;
}
for (Role role : Role.values()) {
- if (role.ordinal() == ecompRole.getId()) {
- return role.name();
+ if (role.name().toLowerCase().equals(ecompRole.getName().toLowerCase())){
+ return role.name();
}
}
- log.debug("no roles converted");
- return null;
+ BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, FAILED_TO_CONVERT_USER, BeEcompErrorManager.ErrorSeverity.INFO);
+ log.debug("Unsupported role for SDC user - role: {}", ecompRole);
+ throw new PortalAPIException("Unsupported role for SDC user");
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java
index 4e06c4ea41..9a5f5a5b61 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,7 +21,7 @@
package org.openecomp.sdc.be.ecomp.converters;
import fj.data.Either;
-
+import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
import org.onap.portalsdk.core.restful.domain.EcompRole;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
@@ -72,11 +72,11 @@ public final class EcompUserConverter {
return Either.left(convertedUser);
}
- public static User convertEcompUserToUser(EcompUser ecompUser) {
+ public static User convertEcompUserToUser(EcompUser ecompUser) throws PortalAPIException {
User convertedUser = new User();
if (ecompUser == null) {
- return convertedUser;
+ throw new PortalAPIException("ecomp user is null");
}
convertedUser.setFirstName(ecompUser.getFirstName());
@@ -107,4 +107,4 @@ public final class EcompUserConverter {
return convertedUser;
}
-} \ No newline at end of file
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/exception/RestrictionAccessFilterException.java
index d7a0f4b8d1..a25bf1a505 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ICommitHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/exception/RestrictionAccessFilterException.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,10 +18,12 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.common.transaction.api;
+package org.openecomp.sdc.be.exception;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
+public class RestrictionAccessFilterException extends RuntimeException{
+
+ public RestrictionAccessFilterException(Exception exception) {
+ super(exception);
+ }
-public interface ICommitHandler extends IDBType {
- DBActionCodeEnum doCommit();
}
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 6975cd9941..1dc8907254 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
@@ -1,1136 +1,1021 @@
-/*-
- * ============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.sdc.be.externalapi.servlet;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-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;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
-import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
-import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
-import org.openecomp.sdc.be.servlets.RepresentationUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.util.GeneralUtility;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * This Servlet serves external users operations on artifacts.
- *
- * @author mshitrit
- *
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-
-@OpenAPIDefinition(info = @Info(title = "Artifact External Servlet",
- description = "Servlet serves external users operations on artifacts."))
-@Singleton
-public class ArtifactExternalServlet extends AbstractValidationsServlet {
-
- private static final String FAILED_TO_UPDATE_ARTIFACT = "failed to update artifact";
-
- @Context
- private HttpServletRequest request;
-
- private final ArtifactsBusinessLogic artifactsBusinessLogic;
-
- private static final Logger log = LoggerFactory.getLogger(ArtifactExternalServlet.class);
-
- private static String startLog = "Start handle request of ";
-
- @Inject
- public ArtifactExternalServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils,
- ServletUtils servletUtils, ResourceImportManager resourceImportManager,
- ArtifactsBusinessLogic artifactsBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.artifactsBusinessLogic = artifactsBusinessLogic;
- }
-
-
- @POST
- @Path("/{assetType}/{uuid}/interfaces/{interfaceUUID}/operations/{operationUUID}/artifacts/{artifactUUID}")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(parameters = @Parameter(required = true ),description = "uploads of artifact to VF operation workflow", method = "POST",
- summary = "uploads of artifact to VF operation workflow")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact uploaded",
- content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
- @ApiResponse(responseCode = "400",
- description = "Artifact type (mandatory field) is missing in request - SVC4124"),
- @ApiResponse(responseCode = "400",
- description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
- @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
- @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
- @ApiResponse(responseCode = "400",
- description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
- @ApiResponse(responseCode = "400",
- description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
- // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =
- // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the
- // artifact")})
- public Response uploadInterfaceOperationArtifact(
- @Parameter(description = "Determines the format of the body of the request",
- required = true) @HeaderParam(value = HttpHeaders.CONTENT_TYPE) String contentType,
- @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
- required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(description = "Asset type") @PathParam("assetType") String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(description = "The uuid of the interface",
- required = true) @PathParam("interfaceUUID") final String interfaceUUID,
- @Parameter(description = "The uuid of the operation",
- required = true) @PathParam("operationUUID") final String operationUUID,
- @Parameter(description = "The uuid of the artifact",
- required = true) @PathParam("artifactUUID") final String artifactUUID,
- @Parameter(hidden = true) String data) {
- Wrapper<Response> responseWrapper = new Wrapper<>();
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(assetType);
- ArtifactDefinition artifactDefinition = null;
-
- if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
- log.debug("updateArtifact: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
- log.debug("updateArtifact: Missing USER_ID");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- try {
- if (responseWrapper.isEmpty()) {
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
- artifactsBusinessLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request,
- ComponentTypeEnum.findByParamName(assetType), uuid, interfaceUUID, operationUUID,
- artifactUUID, resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true,
- false, ArtifactOperationEnum.UPDATE));
- if (uploadArtifactEither.isRight()) {
- log.debug(FAILED_TO_UPDATE_ARTIFACT);
- responseFormat = uploadArtifactEither.right().value();
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- artifactDefinition = uploadArtifactEither.left().value();
- Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER,
- GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- responseWrapper.setInnerElement(buildOkResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
- }
- }
- } catch (Exception e) {
- final String message = "failed to update artifact on a resource or service";
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
- log.debug(message, e);
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
- } finally {
- getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPLOAD_BY_API,
- resourceCommonInfo, request, artifactDefinition, null);
- }
- return responseWrapper.getInnerElement();
- }
-
- /**
- * Uploads an artifact to resource or service
- *
- * @param contentType
- * @param checksum
- * @param userId
- * @param requestId
- * @param instanceIdHeader
- * @param accept
- * @param authorization
- * @param assetType
- * @param uuid
- * @param data
- * @return
- */
- @POST
- @Path("/{assetType}/{uuid}/artifacts")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "uploads of artifact to a resource or service", method = "POST",
- summary = "uploads of artifact to a resource or service")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact uploaded",
- content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
- @ApiResponse(responseCode = "400",
- description = "Artifact type (mandatory field) is missing in request - SVC4124"),
- @ApiResponse(responseCode = "400",
- description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
- @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
- @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
- @ApiResponse(responseCode = "400",
- description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
- @ApiResponse(responseCode = "400",
- description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
- // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =
- // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the
- // artifact")})
- public Response uploadArtifact(
- @Parameter(description = "Determines the format of the body of the request",
- required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
- @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
- required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(hidden = true) String data) {
-
- init();
-
- Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- String componentTypeValue = componentType == null ? null : componentType.getValue();
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
-
- if (componentType == null) {
- log.debug("uploadArtifact: assetType parameter {} is not valid", assetType);
- responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- if (responseWrapper.isEmpty()) {
- validateXECOMPInstanceIDHeader(instanceIdHeader, responseWrapper);
- }
- if (responseWrapper.isEmpty()) {
- validateHttpCspUserIdHeader(userId, responseWrapper);
- }
- Response response = null;
- ArtifactDefinition artifactDefinition = null;
- try {
- if (responseWrapper.isEmpty()) {
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
- artifactsBusinessLogic.uploadArtifactToComponentByUUID(data, request, componentType, uuid,
- resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false,
- ArtifactOperationEnum.CREATE));
- if (uploadArtifactEither.isRight()) {
- log.debug("failed to upload artifact");
- responseWrapper.setInnerElement(uploadArtifactEither.right().value());
- } else {
- artifactDefinition = uploadArtifactEither.left().value();
- Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER,
- GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
- responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.OK));
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation,
- headers);
- }
- }
- } catch (IOException e) {
- final String message = "failed to upload artifact to a resource or service";
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
- log.debug(message, e);
- responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- response = buildErrorResponse(responseWrapper.getInnerElement());
- } catch (ComponentException e) {
- responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(e));
- } finally {
- if (response == null) {
- response = buildErrorResponse(responseWrapper.getInnerElement());
- }
- getComponentsUtils().auditExternalCrudApi(responseWrapper.getInnerElement(),
- AuditingActionEnum.ARTIFACT_UPLOAD_BY_API, resourceCommonInfo, request, artifactDefinition, null);
- }
- return response;
- }
-
- /**
- * Uploads an artifact to resource instance
- *
- * @param assetType
- * @param uuid
- * @param resourceInstanceName
- * @return
- */
- @POST
- @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "uploads an artifact to a resource instance", method = "POST",
- summary = "uploads an artifact to a resource instance")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact uploaded",
- content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
- @ApiResponse(responseCode = "400",
- description = "Artifact type (mandatory field) is missing in request - SVC4124"),
- @ApiResponse(responseCode = "400",
- description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
- @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
- @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
- @ApiResponse(responseCode = "400",
- description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
- @ApiResponse(responseCode = "400",
- description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
- // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =
- // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the
- // artifact")})
- public Response uploadArtifactToInstance(
- @Parameter(description = "Determines the format of the body of the request",
- required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
- @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
- required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",
- required = true) @PathParam("resourceInstanceName") final String resourceInstanceName,
- @Parameter(hidden = true) String data) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- String componentTypeValue = componentType == null ? null : componentType.getValue();
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);
- ArtifactDefinition artifactDefinition = null;
-
- if (componentType == null) {
- log.debug("uploadArtifact: assetType parameter {} is not valid", assetType);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
- log.debug("uploadArtifact: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
- log.debug("uploadArtifact: Missing USER_ID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- try {
- if (responseWrapper.isEmpty()) {
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
- artifactsBusinessLogic.uploadArtifactToRiByUUID(data, request, componentType, uuid,
- resourceInstanceName, artifactsBusinessLogic.new ArtifactOperationInfo(true, false,
- ArtifactOperationEnum.CREATE));
- if (uploadArtifactEither.isRight()) {
- log.debug("failed to upload artifact");
- responseFormat = uploadArtifactEither.right().value();
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER,
- GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- responseWrapper.setInnerElement(buildOkResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
- }
- }
- } catch (IOException e) {
- final String message = "failed to upload artifact to a resource instance";
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
- log.debug(message, e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } catch (ComponentException e) {
- responseFormat = getComponentsUtils().getResponseFormat(e);
- } finally {
- getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPLOAD_BY_API,
- resourceCommonInfo, request, artifactDefinition, null);
- }
- return responseWrapper.getInnerElement();
- }
-
- /**
- *
- * @param contentType
- * @param checksum
- * @param userId
- * @param requestId
- * @param instanceIdHeader
- * @param accept
- * @param authorization
- * @param assetType
- * @param uuid
- * @param artifactUUID
- * @param data
- * @return
- */
- @POST
- @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "updates an artifact on a resource or service", method = "POST",
- summary = "uploads of artifact to a resource or service")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact updated",
- content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
- @ApiResponse(responseCode = "400",
- description = "Artifact type (mandatory field) is missing in request - SVC4124"),
- @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
- @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
- @ApiResponse(responseCode = "403",
- description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
- @ApiResponse(responseCode = "409",
- description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
- // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =
- // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the
- // artifact")})
- public Response updateArtifact(
- @Parameter(description = "Determines the format of the body of the request",
- required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
- @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
- required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(
- description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
- required = true) @PathParam("artifactUUID") final String artifactUUID,
- @Parameter(hidden = true) String data) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- String componentTypeValue = componentType == null ? null : componentType.getValue();
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
- if (componentType == null) {
- log.debug("updateArtifact: assetType parameter {} is not valid", assetType);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
- log.debug("updateArtifact: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
- log.debug("updateArtifact: Missing USER_ID");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- ArtifactDefinition artifactDefinition = null;
- try {
- if (responseWrapper.isEmpty()) {
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
- artifactsBusinessLogic.updateArtifactOnComponentByUUID(data, request, componentType, uuid,
- artifactUUID, resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true,
- false, ArtifactOperationEnum.UPDATE));
- if (uploadArtifactEither.isRight()) {
- log.debug(FAILED_TO_UPDATE_ARTIFACT);
- responseFormat = uploadArtifactEither.right().value();
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER,
- GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- responseWrapper.setInnerElement(buildOkResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
- }
- }
- } catch (IOException e) {
- final String message = "failed to update artifact on a resource or service";
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
- log.debug(message, e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } catch (ComponentException e) {
- responseFormat = getComponentsUtils().getResponseFormat(e);
- } finally {
- getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPDATE_BY_API,
- resourceCommonInfo, request, artifactDefinition, artifactUUID);
- }
- return responseWrapper.getInnerElement();
- }
-
- /**
- * updates an artifact on a resource instance
- *
- * @param assetType
- * @param uuid
- * @param resourceInstanceName
- * @param artifactUUID
- * @return
- */
- @POST
- @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "updates an artifact on a resource instance", method = "POST",
- summary = "uploads of artifact to a resource or service")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact updated",
- content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
- @ApiResponse(responseCode = "400",
- description = "Artifact type (mandatory field) is missing in request - SVC4124"),
- @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
- @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
- @ApiResponse(responseCode = "403",
- description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
- @ApiResponse(responseCode = "409",
- description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
- // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =
- // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the
- // artifact")})
- public Response updateArtifactOnResourceInstance(
- @Parameter(description = "Determines the format of the body of the request",
- required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
- @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
- required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(
- description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
- required = true) @PathParam("artifactUUID") final String artifactUUID,
- @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",
- required = true) @PathParam("resourceInstanceName") final String resourceInstanceName,
- @Parameter(hidden = true) String data) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- String componentTypeValue = componentType == null ? null : componentType.getValue();
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);
- if (componentType == null) {
- log.debug("updateArtifactOnResourceInstance: assetType parameter {} is not valid", assetType);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
- log.debug("updateArtifactOnResourceInstance: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
- log.debug("updateArtifactOnResourceInstance: Missing USER_ID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- ArtifactDefinition artifactDefinition = null;
- try {
- if (responseWrapper.isEmpty()) {
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
- artifactsBusinessLogic.updateArtifactOnRiByUUID(data, request, componentType, uuid,
- resourceInstanceName, artifactUUID, artifactsBusinessLogic.new ArtifactOperationInfo(
- true, false, ArtifactOperationEnum.UPDATE));
- if (uploadArtifactEither.isRight()) {
- log.debug(FAILED_TO_UPDATE_ARTIFACT);
- responseFormat = uploadArtifactEither.right().value();
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER,
- GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- responseWrapper.setInnerElement(buildOkResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
- }
- }
- } catch (IOException e) {
- final String message = "failed to update artifact on resource instance";
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
- log.debug(message, e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } catch (ComponentException e) {
- responseFormat = getComponentsUtils().getResponseFormat(e);
- } finally {
- getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPDATE_BY_API,
- resourceCommonInfo, request, artifactDefinition, artifactUUID);
- }
- return responseWrapper.getInnerElement();
- }
-
- /**
- * deletes an artifact of a resource or service
- *
- * @param assetType
- * @param uuid
- * @param artifactUUID
- * @return
- */
- @DELETE
- @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "deletes an artifact of a resource or service", method = "DELETE",
- summary = "deletes an artifact of a resource or service", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact deleted",
- content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
- @ApiResponse(responseCode = "400",
- description = "Artifact type (mandatory field) is missing in request - SVC4124"),
- @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
- @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
- @ApiResponse(responseCode = "403",
- description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
- @ApiResponse(responseCode = "409",
- description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
- public Response deleteArtifact(
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(
- description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
- required = true) @PathParam("artifactUUID") final String artifactUUID) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- String componentTypeValue = componentType == null ? null : componentType.getValue();
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
- ArtifactDefinition artifactDefinition = null;
- if (componentType == null) {
- log.debug("deleteArtifact: assetType parameter {} is not valid", assetType);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
- log.debug("deleteArtifact: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
- log.debug("deleteArtifact: Missing USER_ID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- try {
- if (responseWrapper.isEmpty()) {
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
- artifactsBusinessLogic.deleteArtifactOnComponentByUUID(request, componentType, uuid,
- artifactUUID, resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true,
- false, ArtifactOperationEnum.DELETE));
- if (uploadArtifactEither.isRight()) {
- log.debug("failed to delete artifact");
- responseFormat = uploadArtifactEither.right().value();
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER,
- GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- responseWrapper.setInnerElement(buildOkResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
- }
- }
- } catch (IOException e) {
- final String message = "failed to delete an artifact of a resource or service";
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
- log.debug(message, e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } catch (ComponentException e) {
- responseFormat = getComponentsUtils().getResponseFormat(e);
- } finally {
- getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_DELETE_BY_API,
- resourceCommonInfo, request, artifactDefinition, artifactUUID);
- }
- return responseWrapper.getInnerElement();
- }
-
- /**
- * deletes an artifact of a resource instance
- *
- * @param assetType
- * @param uuid
- * @param resourceInstanceName
- * @return
- */
- @DELETE
- @Path("{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "deletes an artifact of a resource insatnce", method = "DELETE",
- summary = "deletes an artifact of a resource insatnce", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact deleted",
- content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
- @ApiResponse(responseCode = "400",
- description = "Artifact type (mandatory field) is missing in request - SVC4124"),
- @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
- @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
- @ApiResponse(responseCode = "403",
- description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
- @ApiResponse(responseCode = "409",
- description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
- public Response deleteArtifactOnResourceInstance(
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(
- description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
- required = true) @PathParam("artifactUUID") final String artifactUUID,
- @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",
- required = true) @PathParam("resourceInstanceName") final String resourceInstanceName) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- String componentTypeValue = componentType == null ? null : componentType.getValue();
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);
- if (componentType == null) {
- log.debug("deleteArtifactOnResourceInsatnce: assetType parameter {} is not valid", assetType);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
- log.debug("deleteArtifactOnResourceInsatnce: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
- log.debug("deleteArtifactOnResourceInsatnce: Missing USER_ID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- ArtifactDefinition artifactDefinition = null;
- try {
- if (responseWrapper.isEmpty()) {
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
- artifactsBusinessLogic.deleteArtifactOnRiByUUID(request, componentType, uuid,
- resourceInstanceName, artifactUUID, artifactsBusinessLogic.new ArtifactOperationInfo(
- true, false, ArtifactOperationEnum.DELETE));
- if (uploadArtifactEither.isRight()) {
- log.debug("failed to delete artifact");
- responseFormat = uploadArtifactEither.right().value();
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value());
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER,
- GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- responseWrapper.setInnerElement(buildOkResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
- }
- }
- } catch (IOException e) {
- final String message = "failed to delete an artifact of a resource instance";
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
- log.debug(message, e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } catch (ComponentException e) {
- responseFormat = getComponentsUtils().getResponseFormat(e);
- } finally {
- getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_DELETE_BY_API,
- resourceCommonInfo, request, artifactDefinition, artifactUUID);
- }
- return responseWrapper.getInnerElement();
- }
-
- /**
- * downloads an artifact of a component (either a service or a resource) by artifactUUID
- *
- * @param assetType
- * @param uuid
- * @param artifactUUID
- * @return
- */
- @GET
- @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
- @Operation(description = "Download component artifact", method = "GET", summary = "Returns downloaded artifact")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact downloaded",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "404", description = "Artifact was not found - SVC4505")})
- public Response downloadComponentArtifact(
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(
- description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
- required = true) @PathParam("artifactUUID") final String artifactUUID) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- String componentTypeValue = componentType == null ? null : componentType.getValue();
- if (componentType == null) {
- log.debug("downloadComponentArtifact: assetType parameter {} is not valid", assetType);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
- log.debug("downloadComponentArtifact: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
- try {
- if (responseWrapper.isEmpty()) {
- Either<byte[], ResponseFormat> downloadComponentArtifactEither = artifactsBusinessLogic
- .downloadComponentArtifactByUUIDs(componentType, uuid, artifactUUID, resourceCommonInfo);
- if (downloadComponentArtifactEither.isRight()) {
- responseFormat = downloadComponentArtifactEither.right().value();
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- byte[] value = downloadComponentArtifactEither.left().value();
- InputStream is = new ByteArrayInputStream(value);
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
- }
- }
- } catch (ComponentException e) {
- responseFormat = getComponentsUtils().getResponseFormat(e);
- } finally {
- getComponentsUtils().auditExternalDownloadArtifact(responseFormat, resourceCommonInfo,
- new DistributionData(instanceIdHeader, requestURI), requestId, artifactUUID, userId);
- }
- return responseWrapper.getInnerElement();
- }
-
- /**
- * downloads an artifact of a resource instance of a component (either a service or a resource) by
- * artifactUUID
- *
- * @param assetType
- * @param uuid
- * @param resourceInstanceName
- * @param artifactUUID
- * @return
- */
- @GET
- @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
- @Operation(description = "Download resource instance artifact", method = "GET",
- summary = "Returns downloaded artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact downloaded",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "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"),
- @ApiResponse(responseCode = "404", description = "Artifact was not found - SVC4505")})
- public Response downloadResourceInstanceArtifact(
- @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(description = "The requested asset type",
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata",
- required = true) @PathParam("uuid") final String uuid,
- @Parameter(
- description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
- required = true) @PathParam("artifactUUID") final String artifactUUID,
- @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",
- required = true) @PathParam("resourceInstanceName") final String resourceInstanceName) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("{} {}", startLog, url);
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- String componentTypeValue = componentType == null ? null : componentType.getValue();
- if (componentType == null) {
- log.debug("downloadResourceInstanceArtifact: assetType parameter {} is not valid", assetType);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
- log.debug("downloadResourceInstanceArtifact: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- }
- try {
- if (responseWrapper.isEmpty()) {
- Either<byte[], ResponseFormat> downloadResourceArtifactEither =
- artifactsBusinessLogic.downloadResourceInstanceArtifactByUUIDs(componentType, uuid,
- resourceInstanceName, artifactUUID);
- if (downloadResourceArtifactEither.isRight()) {
- responseFormat = downloadResourceArtifactEither.right().value();
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } else {
- byte[] value = downloadResourceArtifactEither.left().value();
- InputStream is = new ByteArrayInputStream(value);
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
- }
- }
- } catch (ComponentException e) {
- responseFormat = getComponentsUtils().getResponseFormat(e);
- responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
- } finally {
- getComponentsUtils().auditExternalDownloadArtifact(responseFormat,
- new ResourceCommonInfo(resourceInstanceName, componentTypeValue),
- new DistributionData(instanceIdHeader, requestURI), requestId, artifactUUID, userId);
- }
- return responseWrapper.getInnerElement();
- }
-}
+/*-
+ * ============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.sdc.be.externalapi.servlet;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
+import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
+import org.openecomp.sdc.be.servlets.RepresentationUtils;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This Servlet serves external users operations on artifacts.
+ *
+ * @author mshitrit
+ *
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+
+@OpenAPIDefinition(info = @Info(title = "Artifact External Servlet",
+ description = "Servlet serves external users operations on artifacts."))
+@Controller
+public class ArtifactExternalServlet extends AbstractValidationsServlet {
+
+ private static final String FAILED_TO_UPDATE_ARTIFACT = "failed to update artifact";
+ private static final String DOUBLE_CURLY_BRACKETS = "{} {}";
+
+ @Context
+ private HttpServletRequest request;
+
+ private final ArtifactsBusinessLogic artifactsBusinessLogic;
+
+ private static final Logger log = Logger.getLogger(ArtifactExternalServlet.class);
+
+ private static String startLog = "Start handle request of ";
+
+ @Inject
+ public ArtifactExternalServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils,
+ ServletUtils servletUtils, ResourceImportManager resourceImportManager,
+ ArtifactsBusinessLogic artifactsBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.artifactsBusinessLogic = artifactsBusinessLogic;
+ }
+
+ @POST
+ @Path("/{assetType}/{uuid}/interfaces/{interfaceUUID}/operations/{operationUUID}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(parameters = @Parameter(required = true ),description = "uploads of artifact to VF operation workflow", method = "POST",
+ summary = "uploads of artifact to VF operation workflow")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact uploaded",
+ content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
+ @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
+ @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(responseCode = "400",
+ description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(responseCode = "400",
+ description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
+ public Response uploadInterfaceOperationArtifact(
+ @Parameter(description = "Determines the format of the body of the request",
+ required = true) @HeaderParam(value = HttpHeaders.CONTENT_TYPE) String contentType,
+ @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
+ required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(description = "Asset type") @PathParam("assetType") String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(description = "The uuid of the interface",
+ required = true) @PathParam("interfaceUUID") final String interfaceUUID,
+ @Parameter(description = "The uuid of the operation",
+ required = true) @PathParam("operationUUID") final String operationUUID,
+ @Parameter(description = "The uuid of the artifact",
+ required = true) @PathParam("artifactUUID") final String artifactUUID,
+ @Parameter(hidden = true) String data) {
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("{} {}", startLog, url);
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(assetType);
+ ArtifactDefinition artifactDefinition = null;
+
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("updateArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("updateArtifact: Missing USER_ID");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ try {
+ if (responseWrapper.isEmpty()) {
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsBusinessLogic
+ .updateArtifactOnInterfaceOperationByResourceUUID(data, request, ComponentTypeEnum
+ .findByParamName(assetType), uuid, interfaceUUID, operationUUID, artifactUUID,
+ resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
+ if (uploadArtifactEither.isRight()) {
+ log.debug(FAILED_TO_UPDATE_ARTIFACT);
+ responseFormat = uploadArtifactEither.right().value();
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } else {
+ artifactDefinition=uploadArtifactEither.left().value();
+ Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ }
+ } catch (Exception e) {
+ final String message = "failed to update artifact on a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ } finally {
+ getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPLOAD_BY_API,
+ resourceCommonInfo, request, artifactDefinition, null);
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * Uploads an artifact to resource or service
+ */
+ @POST
+ @Path("/{assetType}/{uuid}/artifacts")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "uploads of artifact to a resource or service", method = "POST",
+ summary = "uploads of artifact to a resource or service")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact uploaded",
+ content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
+ @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
+ @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(responseCode = "400",
+ description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(responseCode = "400",
+ description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =
+ // "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the
+ // artifact")})
+ @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
+ @PermissionAllowed({AafPermission.PermNames.WRITE_VALUE})
+ public Response uploadArtifact(
+ @Parameter(description = "Determines the format of the body of the request",
+ required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
+ @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
+ required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(hidden = true) String data) {
+
+ init();
+
+ Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug(DOUBLE_CURLY_BRACKETS, startLog, url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String componentTypeValue = componentType == null ? null : componentType.getValue();
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
+
+ if (componentType == null) {
+ log.debug("uploadArtifact: assetType parameter {} is not valid", assetType);
+ responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ if (responseWrapper.isEmpty()) {
+ validateXECOMPInstanceIDHeader(instanceIdHeader, responseWrapper);
+ }
+ if (responseWrapper.isEmpty() ) {
+ validateHttpCspUserIdHeader(userId, responseWrapper);
+ }
+ Response response = null;
+ ArtifactDefinition artifactDefinition = null;
+ try {
+ if (responseWrapper.isEmpty()) {
+ artifactDefinition = artifactsBusinessLogic.uploadArtifactToComponentByUUID(data, request, componentType, uuid,
+ resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.CREATE));
+ Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
+ responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.OK));
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers);
+ }
+ } catch (IOException e) {
+ final String message = "failed to upload artifact to a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ response = buildErrorResponse(responseWrapper.getInnerElement());
+ } catch (ComponentException e){
+ responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(e));
+ }finally {
+ if( response == null ){
+ response = buildErrorResponse(responseWrapper.getInnerElement());
+ }
+ getComponentsUtils().auditExternalCrudApi(responseWrapper.getInnerElement(), AuditingActionEnum.ARTIFACT_UPLOAD_BY_API,
+ resourceCommonInfo, request, artifactDefinition, null);
+ }
+ return response;
+ }
+
+ /**
+ * Uploads an artifact to resource instance
+ */
+ @POST
+ @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "uploads an artifact to a resource instance", method = "POST",
+ summary = "uploads an artifact to a resource instance")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact uploaded",
+ content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
+ @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
+ @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(responseCode = "400",
+ description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(responseCode = "400",
+ description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
+ @PermissionAllowed(AafPermission.PermNames.WRITE_VALUE)
+ public Response uploadArtifactToInstance(
+ @Parameter(description = "Determines the format of the body of the request",
+ required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
+ @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
+ required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",
+ required = true) @PathParam("resourceInstanceName") final String resourceInstanceName,
+ @Parameter(hidden = true) String data) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug(DOUBLE_CURLY_BRACKETS, startLog, url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String componentTypeValue = componentType == null ? null : componentType.getValue();
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);
+ ArtifactDefinition artifactDefinition = null;
+
+ if (componentType == null) {
+ log.debug("uploadArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("uploadArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("uploadArtifact: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ try {
+ if (responseWrapper.isEmpty()) {
+ artifactDefinition = artifactsBusinessLogic.uploadArtifactToRiByUUID(data, request, componentType, uuid, resourceInstanceName,
+ artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.CREATE));
+ Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ }catch (IOException e) {
+ final String message = "failed to upload artifact to a resource instance";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }catch (ComponentException e){
+ responseFormat = getComponentsUtils().getResponseFormat(e);
+ throw e;
+ }finally {
+ getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPLOAD_BY_API,
+ resourceCommonInfo, request, artifactDefinition, null);
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+
+ @POST
+ @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "updates an artifact on a resource or service", method = "POST",
+ summary = "uploads of artifact to a resource or service")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact updated",
+ content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
+ @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(responseCode = "403",
+ description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(responseCode = "409",
+ description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
+ @PermissionAllowed(AafPermission.PermNames.WRITE_VALUE)
+ public Response updateArtifact(
+ @Parameter(description = "Determines the format of the body of the request",
+ required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
+ @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
+ required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(
+ description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
+ required = true) @PathParam("artifactUUID") final String artifactUUID,
+ @Parameter(hidden = true) String data) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug(DOUBLE_CURLY_BRACKETS, startLog, url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String componentTypeValue = componentType == null ? null : componentType.getValue();
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
+
+ if (componentType == null) {
+ log.debug("updateArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("updateArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("updateArtifact: Missing USER_ID");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ ArtifactDefinition artifactDefinition = null;
+ try {
+ if (responseWrapper.isEmpty()) {
+ artifactDefinition = artifactsBusinessLogic.updateArtifactOnComponentByUUID(data, request, componentType, uuid, artifactUUID,
+ resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
+ Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (IOException e) {
+ final String message = "failed to update artifact on a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } catch (ComponentException e){
+ responseFormat = getComponentsUtils().getResponseFormat(e);
+ throw e;
+ }
+ finally{
+ getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPDATE_BY_API, resourceCommonInfo,
+ request, artifactDefinition, artifactUUID);
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * updates an artifact on a resource instance
+ */
+ @POST
+ @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "updates an artifact on a resource instance", method = "POST",
+ summary = "uploads of artifact to a resource or service")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact updated",
+ content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
+ @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(responseCode = "403",
+ description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(responseCode = "409",
+ description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
+ @PermissionAllowed(AafPermission.PermNames.WRITE_VALUE)
+ public Response updateArtifactOnResourceInstance(
+ @Parameter(description = "Determines the format of the body of the request",
+ required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
+ @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body",
+ required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(
+ description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
+ required = true) @PathParam("artifactUUID") final String artifactUUID,
+ @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",
+ required = true) @PathParam("resourceInstanceName") final String resourceInstanceName,
+ @Parameter(hidden = true) String data) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug(DOUBLE_CURLY_BRACKETS, startLog, url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String componentTypeValue = componentType == null ? null : componentType.getValue();
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);
+
+ if (componentType == null) {
+ log.debug("updateArtifactOnResourceInstance: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("updateArtifactOnResourceInstance: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("updateArtifactOnResourceInstance: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+
+ ArtifactDefinition artifactDefinition = null;
+ try {
+ if (responseWrapper.isEmpty()) {
+ artifactDefinition = artifactsBusinessLogic.updateArtifactOnRiByUUID(data, request, componentType, uuid, resourceInstanceName, artifactUUID,
+ artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
+ Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ responseWrapper.setInnerElement(buildOkResponse(responseFormat, representation, headers));
+ }
+ } catch (IOException e) {
+ final String message = "failed to update artifact on resource instance";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } catch (ComponentException e){
+ responseFormat = getComponentsUtils().getResponseFormat(e);
+ throw e;
+ }
+ finally{
+ getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_UPDATE_BY_API, resourceCommonInfo,
+ request, artifactDefinition, artifactUUID);
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * deletes an artifact of a resource or service
+ */
+ @DELETE
+ @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "deletes an artifact of a resource or service", method = "DELETE",
+ summary = "deletes an artifact of a resource or service", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact deleted",
+ content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
+ @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(responseCode = "403",
+ description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(responseCode = "409",
+ description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ @PermissionAllowed(AafPermission.PermNames.DELETE_VALUE)
+ public Response deleteArtifact(
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(
+ description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
+ required = true) @PathParam("artifactUUID") final String artifactUUID) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug(DOUBLE_CURLY_BRACKETS, startLog, url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String componentTypeValue = componentType == null ? null : componentType.getValue();
+
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
+ ArtifactDefinition artifactDefinition = null;
+
+ if (componentType == null) {
+ log.debug("deleteArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("deleteArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("deleteArtifact: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+
+ try {
+ if (responseWrapper.isEmpty()) {
+ artifactDefinition = artifactsBusinessLogic.deleteArtifactOnComponentByUUID(request, componentType, uuid, artifactUUID,
+ resourceCommonInfo, artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.DELETE));
+ Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (IOException e) {
+ final String message = "failed to delete an artifact of a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } catch (ComponentException e){
+ responseFormat = getComponentsUtils().getResponseFormat(e);
+ throw e;
+ }
+ finally{
+ getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_DELETE_BY_API, resourceCommonInfo,
+ request, artifactDefinition, artifactUUID);
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * deletes an artifact of a resource instance
+ */
+ @DELETE
+ @Path("{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "deletes an artifact of a resource insatnce", method = "DELETE",
+ summary = "deletes an artifact of a resource insatnce", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact deleted",
+ content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(responseCode = "400",
+ description = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(responseCode = "400", description = "Invalid MD5 header - SVC4127"),
+ @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(responseCode = "403",
+ description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(responseCode = "409",
+ description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ @PermissionAllowed(AafPermission.PermNames.DELETE_VALUE)
+ public Response deleteArtifactOnResourceInstance(
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(
+ description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
+ required = true) @PathParam("artifactUUID") final String artifactUUID,
+ @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",
+ required = true) @PathParam("resourceInstanceName") final String resourceInstanceName) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug(DOUBLE_CURLY_BRACKETS, startLog, url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String componentTypeValue = componentType == null ? null : componentType.getValue();
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(resourceInstanceName, componentTypeValue);
+
+ if (componentType == null) {
+ log.debug("deleteArtifactOnResourceInsatnce: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("deleteArtifactOnResourceInsatnce: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (userId == null || userId.isEmpty())) {
+ log.debug("deleteArtifactOnResourceInsatnce: Missing USER_ID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ ArtifactDefinition artifactDefinition = null;
+ try {
+ if (responseWrapper.isEmpty()) {
+ artifactDefinition = artifactsBusinessLogic.deleteArtifactOnRiByUUID(request, componentType, uuid, resourceInstanceName, artifactUUID,
+ artifactsBusinessLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.DELETE));
+ Object representation = RepresentationUtils.toRepresentation(artifactDefinition);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers));
+ }
+ } catch (IOException e) {
+ final String message = "failed to delete an artifact of a resource instance";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ } catch (ComponentException e){
+ responseFormat = getComponentsUtils().getResponseFormat(e);
+ throw e;
+ }
+ finally{
+ getComponentsUtils().auditExternalCrudApi(responseFormat, AuditingActionEnum.ARTIFACT_DELETE_BY_API, resourceCommonInfo,
+ request, artifactDefinition, artifactUUID);
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * downloads an artifact of a component (either a service or a resource) by artifactUUID
+ */
+ @GET
+ @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Operation(description = "Download component artifact", method = "GET", summary = "Returns downloaded artifact")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact downloaded",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "404", description = "Artifact was not found - SVC4505")})
+ @PermissionAllowed(AafPermission.PermNames.DELETE_VALUE)
+ public Response downloadComponentArtifact(
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(schema = @Schema(allowableValues = {"resources,services"}),description = "The requested asset type",
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(
+ description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
+ required = true) @PathParam("artifactUUID") final String artifactUUID) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug(DOUBLE_CURLY_BRACKETS, startLog, url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String componentTypeValue = componentType == null ? null : componentType.getValue();
+ if (componentType == null) {
+ log.debug("downloadComponentArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("downloadComponentArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
+ try {
+ if (responseWrapper.isEmpty()) {
+ byte[] value = artifactsBusinessLogic.downloadComponentArtifactByUUIDs(componentType, uuid, artifactUUID, resourceCommonInfo);
+ InputStream is = new ByteArrayInputStream(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
+ }
+ } catch (ComponentException e){
+ responseFormat = getComponentsUtils().getResponseFormat(e);
+ throw e;
+ }
+ finally{
+ getComponentsUtils().auditExternalDownloadArtifact(responseFormat, resourceCommonInfo,
+ new DistributionData(instanceIdHeader, requestURI), requestId, artifactUUID, userId);
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ /**
+ * downloads an artifact of a resource instance of a component (either a service or a resource) by artifactUUID
+ */
+ @GET
+ @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Operation(description = "Download resource instance artifact", method = "GET",
+ summary = "Returns downloaded artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact downloaded",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "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"),
+ @ApiResponse(responseCode = "404", description = "Artifact was not found - SVC4505")})
+ @PermissionAllowed(AafPermission.PermNames.READ_VALUE)
+ public Response downloadResourceInstanceArtifact(
+ @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(description = "The requested asset type",
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata",
+ required = true) @PathParam("uuid") final String uuid,
+ @Parameter(
+ description = "The uuid of the artifact as published in the asset detailed metadata or in the response of the upload / update operation",
+ required = true) @PathParam("artifactUUID") final String artifactUUID,
+ @Parameter(description = "The component instance name (as publishedin the response of the detailed query)",
+ required = true) @PathParam("resourceInstanceName") final String resourceInstanceName) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug(DOUBLE_CURLY_BRACKETS, startLog, url);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String componentTypeValue = componentType == null ? null : componentType.getValue();
+ if (componentType == null) {
+ log.debug("downloadResourceInstanceArtifact: assetType parameter {} is not valid", assetType);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ if (responseWrapper.isEmpty() && (instanceIdHeader == null || instanceIdHeader.isEmpty())) {
+ log.debug("downloadResourceInstanceArtifact: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
+ }
+ try {
+ if (responseWrapper.isEmpty()) {
+ byte[] value = artifactsBusinessLogic.downloadResourceInstanceArtifactByUUIDs(componentType, uuid, resourceInstanceName, artifactUUID);
+ InputStream is = new ByteArrayInputStream(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
+ }
+ } catch (ComponentException e){
+ responseFormat = getComponentsUtils().getResponseFormat(e);
+ throw e;
+ }
+ finally{
+ getComponentsUtils().auditExternalDownloadArtifact(responseFormat, new ResourceCommonInfo(resourceInstanceName, componentTypeValue),
+ new DistributionData(instanceIdHeader, requestURI), requestId, artifactUUID, userId);
+ }
+ return responseWrapper.getInnerElement();
+ }
+}
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 4c91ab4178..8ad80d8724 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
@@ -1,451 +1,444 @@
-/*-
- * ============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.sdc.be.externalapi.servlet;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-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;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-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.ecomp.converters.AssetMetadataConverter;
-import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
-import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
-import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
-import org.openecomp.sdc.be.servlets.RepresentationUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.util.GeneralUtility;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * This Servlet serves external users for retrieving component metadata.
- *
- * @author tgitelman
- *
- */
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-// for retrieving component metadata.")
-@OpenAPIDefinition(info = @Info(title = "Asset Metadata External Servlet",
- description = "This Servlet serves external users for retrieving component metadata."))
-@Singleton
-public class AssetsDataServlet extends AbstractValidationsServlet {
-
- @Context
- private HttpServletRequest request;
-
- private static final Logger log = Logger.getLogger(AssetsDataServlet.class);
- private final ElementBusinessLogic elementBusinessLogic;
- private final AssetMetadataConverter assetMetadataConverter;
- private final ComponentBusinessLogicProvider componentBusinessLogicProvider;
-
- @Inject
- public AssetsDataServlet(UserBusinessLogic userBusinessLogic, ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils, ResourceImportManager resourceImportManager,
- ElementBusinessLogic elementBusinessLogic, AssetMetadataConverter assetMetadataConverter,
- ComponentBusinessLogicProvider componentBusinessLogicProvider) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.elementBusinessLogic = elementBusinessLogic;
- this.assetMetadataConverter = assetMetadataConverter;
- this.componentBusinessLogicProvider = componentBusinessLogicProvider;
- }
-
- /**
- *
- * @param requestId
- * @param instanceIdHeader
- * @param accept
- * @param authorization
- * @param assetType
- * @param category
- * @param subCategory
- * @param distributionStatus
- * @param resourceType
- * @return
- */
- @GET
- @Path("/{assetType}")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Fetch list of assets", method = "GET", summary = "Returns list of assets")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200",
- description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = AssetMetadata.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed : Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
- public Response getAssetListExternal(
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(description = "The requested asset type",schema = @Schema(allowableValues = {"resources", "services"}),
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The filter key (resourceType only for resources)",
- required = false) @QueryParam("category") String category,
- @Parameter(description = "The filter key (resourceType only for resources)",
- required = false) @QueryParam("subCategory") String subCategory,
- @Parameter(description = "The filter key (resourceType only for resources)",
- required = false) @QueryParam("distributionStatus") String distributionStatus,
- @Parameter(description = "The filter key (resourceType only for resources)",
- required = false) @QueryParam("resourceType") String resourceType) {
-
- Response response = null;
- ResponseFormat responseFormat = null;
- String query = request.getQueryString();
- String requestURI =
- request.getRequestURI().endsWith("/") ? removeDuplicateSlashSeparator(request.getRequestURI())
- : request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("Start handle request of {}", url);
-
- AuditingActionEnum auditingActionEnum =
- query == null ? AuditingActionEnum.GET_ASSET_LIST : AuditingActionEnum.GET_FILTERED_ASSET_LIST;
-
- String resourceUrl = query == null ? requestURI : requestURI + "?" + query;
- DistributionData distributionData = new DistributionData(instanceIdHeader, resourceUrl);
-
- // Mandatory
- if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
- log.debug("getAssetList: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData,
- requestId);
- return buildErrorResponse(responseFormat);
- }
-
- try {
- Map<FilterKeyEnum, String> filters = new EnumMap<>(FilterKeyEnum.class);
-
- if (category != null) {
- filters.put(FilterKeyEnum.CATEGORY, category);
- }
- if (subCategory != null) {
- filters.put(FilterKeyEnum.SUB_CATEGORY, subCategory);
- }
- if (distributionStatus != null) {
- filters.put(FilterKeyEnum.DISTRIBUTION_STATUS, distributionStatus);
- }
- if (resourceType != null) {
- ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.getTypeIgnoreCase(resourceType);
- if (resourceTypeEnum == null) {
- log.debug("getAssetList: Asset Fetching Failed. Invalid resource type was received");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData,
- requestId);
- return buildErrorResponse(responseFormat);
- }
- filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypeEnum.name());
- }
-
- Either<List<? extends Component>, ResponseFormat> assetTypeData =
- elementBusinessLogic.getFilteredCatalogComponents(assetType, filters, query);
-
- if (assetTypeData.isRight()) {
- log.debug("getAssetList: Asset Fetching Failed");
- responseFormat = assetTypeData.right().value();
- getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData,
- requestId);
- return buildErrorResponse(responseFormat);
- } else {
- log.debug("getAssetList: Asset Fetching Success");
- Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata =
- assetMetadataConverter.convertToAssetMetadata(assetTypeData.left().value(), requestURI, false);
- if (resMetadata.isRight()) {
- log.debug("getAssetList: Asset conversion Failed");
- responseFormat = resMetadata.right().value();
- getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData,
- requestId);
- return buildErrorResponse(responseFormat);
- }
- Object result = RepresentationUtils.toRepresentation(resMetadata.left().value());
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData,
- requestId);
-
- response = buildOkResponse(responseFormat, result);
- return response;
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets");
- log.debug("getAssetList: Fetch list of assets failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /**
- *
- * @param requestId
- * @param instanceIdHeader
- * @param accept
- * @param authorization
- * @param assetType
- * @param uuid
- * @return
- */
- @GET
- @Path("/{assetType}/{uuid}/metadata")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Detailed metadata of asset by uuid", method = "GET",
- summary = "Returns detailed metadata of an asset by uuid")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200",
- description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = AssetMetadata.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404",
- description = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed : Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
- public Response getAssetSpecificMetadataByUuidExternal(
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(description = "The requested asset type",schema = @Schema(allowableValues = {"resources", "services"}),
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The requested asset uuid",
- required = true) @PathParam("uuid") final String uuid) {
-
- Response response = null;
- ResponseFormat responseFormat = null;
- AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_ASSET_METADATA;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("Start handle request of {}", url);
-
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
- DistributionData distributionData = new DistributionData(instanceIdHeader, requestURI);
- // Mandatory
- if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
- log.debug("getAssetList: Missing X-ECOMP-InstanceID header");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
- getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
- resourceCommonInfo, requestId, uuid);
- return buildErrorResponse(responseFormat);
- }
-
- try {
- Either<List<? extends Component>, ResponseFormat> assetTypeData =
- elementBusinessLogic.getCatalogComponentsByUuidAndAssetType(assetType, uuid);
-
- if (assetTypeData.isRight()) {
- log.debug("getAssetList: Asset Fetching Failed");
- responseFormat = assetTypeData.right().value();
- getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
- resourceCommonInfo, requestId, uuid);
-
- return buildErrorResponse(responseFormat);
- }
- resourceCommonInfo.setResourceName(assetTypeData.left().value().iterator().next().getName());
- log.debug("getAssetList: Asset Fetching Success");
- Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata =
- assetMetadataConverter.convertToAssetMetadata(assetTypeData.left().value(), requestURI, true);
- if (resMetadata.isRight()) {
- log.debug("getAssetList: Asset conversion Failed");
- responseFormat = resMetadata.right().value();
-
- getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
- resourceCommonInfo, requestId, uuid);
- return buildErrorResponse(responseFormat);
- }
- Object result = RepresentationUtils.toRepresentation(resMetadata.left().value().iterator().next());
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
- resourceCommonInfo, requestId, uuid);
-
- response = buildOkResponse(responseFormat, result);
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets");
- log.debug("getAssetList: Fetch list of assets failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /**
- *
- * @param requestId
- * @param instanceIdHeader
- * @param accept
- * @param authorization
- * @param assetType
- * @param uuid
- * @return
- */
- @GET
- @Path("/{assetType}/{uuid}/toscaModel")
- @Produces(MediaType.APPLICATION_OCTET_STREAM)
- @Operation(description = "Fetch assets CSAR", method = "GET", summary = "Returns asset csar",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200",
- description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned",
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
- @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404",
- description = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed : Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
- public Response getToscaModelExternal(
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(description = "The requested asset type",schema = @Schema(allowableValues = {"resources", "services"}),
- required = true) @PathParam("assetType") final String assetType,
- @Parameter(description = "The requested asset uuid",
- required = true) @PathParam("uuid") final String uuid) {
-
- String url = request.getRequestURI();
- log.debug("Start handle request of {} {}", request.getMethod(), url);
- Response response = null;
- ResponseFormat responseFormat = null;
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
- AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_TOSCA_MODEL;
-
- ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
- DistributionData distributionData = new DistributionData(instanceIdHeader, url);
-
- 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, distributionData,
- resourceCommonInfo, requestId, uuid);
- return buildErrorResponse(responseFormat);
- }
-
- try {
- ComponentBusinessLogic componentBL = componentBusinessLogicProvider.getInstance(componentType);
-
-
- Either<ImmutablePair<String, byte[]>, ResponseFormat> csarArtifact =
- componentBL.getToscaModelByComponentUuid(componentType, uuid, resourceCommonInfo);
- if (csarArtifact.isRight()) {
- responseFormat = csarArtifact.right().value();
- getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
- resourceCommonInfo, requestId, uuid);
- response = buildErrorResponse(responseFormat);
- } else {
- byte[] value = csarArtifact.left().value().getRight();
- InputStream is = new ByteArrayInputStream(value);
- String contenetMD5 = GeneralUtility.calculateMD5Base64EncodedByByteArray(value);
- Map<String, String> headers = new HashMap<>();
- headers.put(Constants.CONTENT_DISPOSITION_HEADER,
- getContentDispositionValue(csarArtifact.left().value().getLeft()));
- headers.put(Constants.MD5_HEADER, contenetMD5);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
- resourceCommonInfo, requestId, uuid);
- response = buildOkResponse(responseFormat, is, headers);
- }
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get asset tosca model");
- log.debug("falied to get asset tosca model", e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- response = buildErrorResponse(responseFormat);
- getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
- resourceCommonInfo, requestId, uuid);
- return response;
- }
- }
-
-
- private String removeDuplicateSlashSeparator(String requestUri) {
- return requestUri.substring(0, requestUri.length() - 1);
- }
-
-
-}
+/*-
+ * ============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.sdc.be.externalapi.servlet;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+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.ecomp.converters.AssetMetadataConverter;
+import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
+import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
+import org.openecomp.sdc.be.servlets.RepresentationUtils;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.GeneralUtility;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+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;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum.RESOURCE;
+
+/**
+ * This Servlet serves external users for retrieving component metadata.
+ *
+ * @author tgitelman
+ *
+ */
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+// for retrieving component metadata.")
+@OpenAPIDefinition(info = @Info(title = "Asset Metadata External Servlet",
+ description = "This Servlet serves external users for retrieving component metadata."))
+@Controller
+public class AssetsDataServlet extends AbstractValidationsServlet {
+
+ @Context
+ private HttpServletRequest request;
+
+ private static final Logger log = Logger.getLogger(AssetsDataServlet.class);
+
+ private final ElementBusinessLogic elementBusinessLogic;
+ private final AssetMetadataConverter assetMetadataConverter;
+ private final ServiceBusinessLogic serviceBusinessLogic;
+ private final ResourceBusinessLogic resourceBusinessLogic;
+ private final ComponentBusinessLogicProvider componentBusinessLogicProvider;
+
+ @Inject
+ public AssetsDataServlet(UserBusinessLogic userBusinessLogic, ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils, ResourceImportManager resourceImportManager,
+ ElementBusinessLogic elementBusinessLogic, AssetMetadataConverter assetMetadataConverter,
+ ComponentBusinessLogicProvider componentBusinessLogicProvider, ServiceBusinessLogic serviceBusinessLogic, ResourceBusinessLogic resourceBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.elementBusinessLogic = elementBusinessLogic;
+ this.assetMetadataConverter = assetMetadataConverter;
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ this.resourceBusinessLogic = resourceBusinessLogic;
+ this.componentBusinessLogicProvider = componentBusinessLogicProvider;
+ }
+
+ @GET
+ @Path("/{assetType}")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Fetch list of assets", method = "GET", summary = "Returns list of assets")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200",
+ description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = AssetMetadata.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed : Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
+ @PermissionAllowed(AafPermission.PermNames.READ_VALUE)
+ public Response getAssetListExternal(
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(description = "The requested asset type",schema = @Schema(allowableValues = {"resources", "services"}),
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The filter key (resourceType only for resources)",
+ required = false) @QueryParam("category") String category,
+ @Parameter(description = "The filter key (resourceType only for resources)",
+ required = false) @QueryParam("subCategory") String subCategory,
+ @Parameter(description = "The filter key (resourceType only for resources)",
+ required = false) @QueryParam("distributionStatus") String distributionStatus,
+ @Parameter(description = "The filter key (resourceType only for resources)",
+ required = false) @QueryParam("resourceType") String resourceType) throws IOException {
+
+ Response response = null;
+ ResponseFormat responseFormat = null;
+ String query = request.getQueryString();
+ String requestURI = request.getRequestURI().endsWith("/")?
+ removeDuplicateSlashSeparator(request.getRequestURI()): request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+
+ AuditingActionEnum auditingActionEnum = query == null ? AuditingActionEnum.GET_ASSET_LIST : AuditingActionEnum.GET_FILTERED_ASSET_LIST;
+
+ String resourceUrl = query == null ? requestURI : requestURI + "?" + query;
+ DistributionData distributionData = new DistributionData(instanceIdHeader, resourceUrl);
+
+ // Mandatory
+ if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
+ log.debug("getAssetList: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ Map<FilterKeyEnum, String> filters = new EnumMap<>(FilterKeyEnum.class);
+
+ if (category != null) {
+ filters.put(FilterKeyEnum.CATEGORY, category);
+ }
+ if (subCategory != null) {
+ filters.put(FilterKeyEnum.SUB_CATEGORY, subCategory);
+ }
+ if (distributionStatus != null) {
+ filters.put(FilterKeyEnum.DISTRIBUTION_STATUS, distributionStatus);
+ }
+ if (resourceType != null) {
+ ResourceTypeEnum resourceTypeEnum = ResourceTypeEnum.getTypeIgnoreCase(resourceType);
+ if (resourceTypeEnum == null) {
+ log.debug("getAssetList: Asset Fetching Failed. Invalid resource type was received");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
+ return buildErrorResponse(responseFormat);
+ }
+ filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypeEnum.name());
+ }
+
+ Either<List<? extends Component>, ResponseFormat> assetTypeData = elementBusinessLogic.getFilteredCatalogComponents(assetType, filters, query);
+
+ if (assetTypeData.isRight()) {
+ log.debug("getAssetList: Asset Fetching Failed");
+ responseFormat = assetTypeData.right().value();
+ getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
+ return buildErrorResponse(responseFormat);
+ } else {
+ log.debug("getAssetList: Asset Fetching Success");
+ Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata = assetMetadataConverter.convertToAssetMetadata(assetTypeData.left().value(), requestURI, false);
+ if (resMetadata.isRight()) {
+ log.debug("getAssetList: Asset conversion Failed");
+ responseFormat = resMetadata.right().value();
+ getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
+ return buildErrorResponse(responseFormat);
+ }
+ Object result = RepresentationUtils.toRepresentation(resMetadata.left().value());
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
+
+ response = buildOkResponse(responseFormat, result);
+ return response;
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets");
+ log.debug("getAssetList: Fetch list of assets failed with exception", e);
+ throw e;
+ }
+ }
+
+ /**
+ *
+ * @param requestId
+ * @param instanceIdHeader
+ * @param accept
+ * @param authorization
+ * @param assetType
+ * @param uuid
+ * @return
+ */
+ @GET
+ @Path("/{assetType}/{uuid}/metadata")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Detailed metadata of asset by uuid", method = "GET",
+ summary = "Returns detailed metadata of an asset by uuid")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200",
+ description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = AssetMetadata.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404",
+ description = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed : Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
+ @PermissionAllowed(AafPermission.PermNames.READ_VALUE)
+ public Response getAssetSpecificMetadataByUuidExternal(
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(description = "The requested asset type",schema = @Schema(allowableValues = {"resources", "services"}),
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The requested asset uuid",
+ required = true) @PathParam("uuid") final String uuid) throws IOException {
+
+ Response response = null;
+ ResponseFormat responseFormat = null;
+ AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_ASSET_METADATA;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
+ DistributionData distributionData = new DistributionData(instanceIdHeader, requestURI);
+ // Mandatory
+ if (instanceIdHeader == null || instanceIdHeader.isEmpty()) {
+ log.debug("getAssetList: Missing X-ECOMP-InstanceID header");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
+ resourceCommonInfo, requestId, uuid);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+
+ Either<List<? extends Component>, ResponseFormat> assetTypeData = elementBusinessLogic.getCatalogComponentsByUuidAndAssetType(assetType, uuid);
+
+ if (assetTypeData.isRight()) {
+ log.debug("getAssetList: Asset Fetching Failed");
+ responseFormat = assetTypeData.right().value();
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
+ resourceCommonInfo, requestId, uuid);
+
+ return buildErrorResponse(responseFormat);
+ }
+ resourceCommonInfo.setResourceName(assetTypeData.left().value().iterator().next().getName());
+ log.debug("getAssetList: Asset Fetching Success");
+ Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata = assetMetadataConverter.convertToAssetMetadata(assetTypeData.left().value(), requestURI, true);
+ if (resMetadata.isRight()) {
+ log.debug("getAssetList: Asset conversion Failed");
+ responseFormat = resMetadata.right().value();
+
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
+ resourceCommonInfo, requestId, uuid);
+ return buildErrorResponse(responseFormat);
+ }
+ Object result = RepresentationUtils.toRepresentation(resMetadata.left().value().iterator().next());
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
+ resourceCommonInfo, requestId, uuid);
+
+ response = buildOkResponse(responseFormat, result);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets");
+ log.debug("getAssetList: Fetch list of assets failed with exception", e);
+ throw e;
+ }
+ }
+
+ private ComponentBusinessLogic getComponentBLByType(ComponentTypeEnum componentTypeEnum) {
+ if(componentTypeEnum.equals(RESOURCE)) {
+ return resourceBusinessLogic;
+ } else {
+ // Implementation is the same for any ComponentBusinessLogic
+ return serviceBusinessLogic;
+ }
+ }
+
+ /**
+ *
+ * @param requestId
+ * @param instanceIdHeader
+ * @param accept
+ * @param authorization
+ * @param assetType
+ * @param uuid
+ * @return
+ */
+
+ @GET
+ @Path("/{assetType}/{uuid}/toscaModel")
+ @Produces(MediaType.APPLICATION_OCTET_STREAM)
+ @Operation(description = "Fetch assets CSAR", method = "GET", summary = "Returns asset csar",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200",
+ description = "ECOMP component is authenticated and list of Catalog Assets Metadata is returned",
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
+ @ApiResponse(responseCode = "400", description = "Missing 'X-ECOMP-InstanceID' HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404",
+ description = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed : Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "The GET request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000")})
+ @PermissionAllowed(AafPermission.PermNames.READ_VALUE)
+ public Response getToscaModelExternal(
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(description = "The requested asset type",schema = @Schema(allowableValues = {"resources", "services"}),
+ required = true) @PathParam("assetType") final String assetType,
+ @Parameter(description = "The requested asset uuid",
+ required = true) @PathParam("uuid") final String uuid) {
+
+ String url = request.getRequestURI();
+ log.debug("Start handle request of {} {}", request.getMethod(), url);
+ Response response = null;
+ ResponseFormat responseFormat = null;
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_TOSCA_MODEL;
+
+ ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
+ DistributionData distributionData = new DistributionData(instanceIdHeader, url);
+
+ 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, distributionData,
+ resourceCommonInfo, requestId, uuid);
+ return buildErrorResponse(responseFormat);
+ }
+
+ try {
+ ComponentBusinessLogic componentBusinessLogic = getComponentBLByType(componentType);
+ ImmutablePair<String, byte[]> csarArtifact = componentBusinessLogic.getToscaModelByComponentUuid(componentType, uuid, resourceCommonInfo);
+ byte[] value = csarArtifact.getRight();
+ InputStream is = new ByteArrayInputStream(value);
+ String contenetMD5 = GeneralUtility.calculateMD5Base64EncodedByByteArray(value);
+ Map<String, String> headers = new HashMap<>();
+ headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(csarArtifact.getLeft()));
+ headers.put(Constants.MD5_HEADER, contenetMD5);
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
+ resourceCommonInfo, requestId, uuid);
+ response = buildOkResponse(responseFormat, is, headers);
+ return response;
+
+ } catch (ComponentException e) {
+ responseFormat = e.getResponseFormat();
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
+ resourceCommonInfo, requestId, uuid);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get asset tosca model");
+ log.debug("failed to get asset tosca model", e);
+ response = buildErrorResponse(responseFormat);
+ getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData,
+ resourceCommonInfo, requestId, uuid);
+ return response;
+ }
+ }
+
+
+ private String removeDuplicateSlashSeparator(String requestUri) {
+ return requestUri.substring(0, requestUri.length()-1);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
index bca588ad14..2508c3855c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
@@ -23,6 +23,8 @@ package org.openecomp.sdc.be.externalapi.servlet;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jcabi.aspects.Loggable;
import fj.data.Either;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -33,15 +35,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.apache.commons.lang3.StringUtils;
-import org.elasticsearch.common.Strings;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoBase;
@@ -49,20 +52,20 @@ import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ExternalCategoryTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.ExternalCategoryTypeEnum;
import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter;
import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
@@ -77,17 +80,17 @@ import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
import javax.inject.Inject;
-import javax.inject.Singleton;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Path;
import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.POST;
import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -97,12 +100,15 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
+import static com.google.common.base.Strings.isNullOrEmpty;
+
+
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog")
@OpenAPIDefinition(info = @Info(title = "CRUD External Servlet",
description = "This Servlet serves external users for creating assets and changing their lifecycle state"))
-@Singleton
+@Controller
public class CrudExternalServlet extends AbstractValidationsServlet {
@Context
@@ -190,9 +196,8 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
description = "Create VFCMT request: VFCMT name exceeds character limit - SVC4073"),
@ApiResponse(responseCode = "400", description = "Invalid Content. Missing PROJECT_CODE number - SVC4129"),
@ApiResponse(responseCode = "409", description = "Error: %1 (Service) with name '%2' already exists. - SVC4050")})
- // @ApiImplicitParams({@ApiImplicitParam(required = true, dataType =
- // "org.openecomp.sdc.be.model.Resource", paramType = "body", value = "json describe the created
- // resource")})
+ @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.Resource", paramType = "body", value = "json describe the created resource")})
+ @PermissionAllowed(AafPermission.PermNames.WRITE_VALUE)
public Response createComponentExternal(
@Parameter(description = "Determines the format of the body of the request",
required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
@@ -221,7 +226,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
User modifier = null;
ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(ComponentTypeEnum.RESOURCE.getValue());
Service service = null;
-
+
ServletContext context = request.getSession().getServletContext();
try {
// Validate X-ECOMP-InstanceID Header
@@ -237,7 +242,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
if( responseWrapper.isEmpty() && !(AssetTypeEnum.RESOURCES.getValue().equals(assetType) || AssetTypeEnum.SERVICES.getValue().equals(assetType))) {
responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
}
-
+
if (responseWrapper.isEmpty() && AssetTypeEnum.SERVICES.getValue().equals(assetType)) {
modifier = new User();
@@ -258,7 +263,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
}
//validate name exist
- if(responseWrapper.isEmpty() && Strings.isEmpty(service.getName())){
+ if(responseWrapper.isEmpty() && isNullOrEmpty(service.getName())){
responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(
ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue()));
}
@@ -323,7 +328,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
}
//validate name exist
if(responseWrapper.isEmpty()){
- if( Strings.isEmpty(resource.getName())){
+ if(isNullOrEmpty(resource.getName())){
responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(
ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue()));
@@ -335,18 +340,18 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
resource.setSystemName(ValidationUtils.convertToSystemName(resource.getName()));
resource.setToscaResourceName(CommonBeUtils.generateToscaResourceName(ResourceTypeEnum.VFCMT.name(),
resource.getSystemName()));
- handleCategories(context, data, resource, responseWrapper);
+ handleCategories(data, resource, responseWrapper);
}
// Create the resource in the dataModel
if (responseWrapper.isEmpty()) {
resource = resourceBusinessLogic.createResource(resource, null,
modifier, null, null);
- return buildCreatedResourceResponse(resource, context, responseWrapper);
+ return buildCreatedResourceResponse(resource, responseWrapper);
} else {
return buildErrorResponse(responseWrapper.getInnerElement());
}
}
-
+
} catch (IOException|ParseException e) {
final String message = "failed to create vfc monitoring template resource";
BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
@@ -398,6 +403,8 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "403",
description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4080")})
// @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction", paramType = "body", value = "userRemarks - Short description (free text) about the asset version being changed")})
+ @ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction", paramType = "body", value = "userRemarks - Short description (free text) about the asset version being changed")})
+ @PermissionAllowed(AafPermission.PermNames.WRITE_VALUE)
public Response changeResourceStateExternal(
@Parameter(description = "Determines the format of the body of the request",
required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
@@ -428,9 +435,6 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
String url = request.getMethod() + " " + requestURI;
log.debug("Start handle request of {}", url);
- //get the business logic
- ServletContext context = request.getSession().getServletContext();
-
Wrapper<ResponseFormat> responseWrapper = runValidations(assetType);
ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
Component component = null;
@@ -489,8 +493,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
}
//execute business logic
- Either<? extends Component, ResponseFormat> actionResponse = lifecycleBusinessLogic
- .changeComponentState(componentType, componentId, modifier, transitionEnum, changeInfo, false, true);
+ Either<? extends Component, ResponseFormat> actionResponse = lifecycleBusinessLogic.changeComponentState(componentType, componentId, modifier, transitionEnum, changeInfo, false, true);
if (actionResponse.isRight()) {
log.info("failed to change resource state");
ResponseFormat responseFormat = actionResponse.right().value();
@@ -500,7 +503,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
log.debug("change state successful !!!");
responseObject = actionResponse.left().value();
- response = buildCreatedResourceResponse(responseObject, context, responseWrapper);
+ response = buildCreatedResourceResponse(responseObject, responseWrapper);
} else {
response = buildErrorResponse(responseWrapper.getInnerElement());
}
@@ -523,7 +526,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
}
}
- private Response buildCreatedResourceResponse(Component resource, ServletContext context,
+ private Response buildCreatedResourceResponse(Component resource,
Wrapper<ResponseFormat> responseWrapper) throws IOException {
ResponseFormat responseFormat;
Response response;
@@ -546,18 +549,18 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
return response;
}
- private void handleCategories(ServletContext context, String data, Resource resource,
+ private void handleCategories(String data, Resource resource,
Wrapper<ResponseFormat> responseWrapper) {
try {
JSONParser parser = new JSONParser();
JSONObject jsonObj = (JSONObject) parser.parse(data);
String category = (String) jsonObj.get(CategoryTypeEnum.CATEGORY.getValue());
String subcategory = (String) jsonObj.get(CategoryTypeEnum.SUBCATEGORY.getValue());
- if (Strings.isEmpty(category)) {
+ if (isNullOrEmpty(category)) {
responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(
ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()));
}
- else if (Strings.isEmpty(subcategory)) {
+ else if (isNullOrEmpty(subcategory)) {
responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(
ActionStatus.COMPONENT_MISSING_SUBCATEGORY));
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java
index ce1f3b297e..0603aa8dad 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefsServlet.java
@@ -21,10 +21,9 @@
package org.openecomp.sdc.be.externalapi.servlet;
import fj.data.Either;
-import javax.inject.Inject;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ExternalRefsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.dto.ExternalRefDTO;
@@ -35,7 +34,17 @@ import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Controller;
-import javax.ws.rs.*;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@@ -59,6 +68,7 @@ public class ExternalRefsServlet extends BeGenericServlet {
@GET
@Path("/{assetType}/{uuid}/version/{version}/resourceInstances/{componentInstanceName}/externalReferences/{objectType}")
@Produces(MediaType.APPLICATION_JSON)
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
public Response getComponentInstanceExternalRef(
@PathParam("assetType") String assetType,
@PathParam("uuid") String uuid,
@@ -84,6 +94,7 @@ public class ExternalRefsServlet extends BeGenericServlet {
@GET
@Path("/{assetType}/{uuid}/version/{version}/externalReferences/{objectType}")
@Produces(MediaType.APPLICATION_JSON)
+ @PermissionAllowed({AafPermission.PermNames.READ_VALUE})
public Map<String, List<String>> getAssetExternalRefByObjectType(
@PathParam("assetType") String assetType,
@PathParam("uuid") String uuid,
@@ -109,6 +120,7 @@ public class ExternalRefsServlet extends BeGenericServlet {
@Path("/{assetType}/{uuid}/resourceInstances/{componentInstanceName}/externalReferences/{objectType}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
+ @PermissionAllowed({AafPermission.PermNames.WRITE_VALUE})
public Response addComponentInstanceExternalRef(
@PathParam("assetType") String assetType,
@PathParam("uuid") String uuid,
@@ -122,7 +134,9 @@ public class ExternalRefsServlet extends BeGenericServlet {
return r;
}
- Either<String, ActionStatus> addResult = this.businessLogic.addExternalReference(ComponentTypeEnum.findByParamName(assetType), userId, uuid, componentInstanceName, objectType, ref);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String uid = this.businessLogic.fetchComponentUniqueIdByUuid(uuid, componentType);
+ Either<String, ActionStatus> addResult = this.businessLogic.addExternalReference(uid, componentType, userId, componentInstanceName, objectType, ref);
if (addResult.isLeft()) {
return Response.status(Response.Status.CREATED)
.entity(ref)
@@ -136,6 +150,7 @@ public class ExternalRefsServlet extends BeGenericServlet {
@DELETE
@Path("/{assetType}/{uuid}/resourceInstances/{componentInstanceName}/externalReferences/{objectType}/{reference}")
@Produces(MediaType.APPLICATION_JSON)
+ @PermissionAllowed({AafPermission.PermNames.DELETE_VALUE})
public Response deleteComponentInstanceReference(
@PathParam("assetType") String assetType,
@PathParam("uuid") String uuid,
@@ -149,8 +164,9 @@ public class ExternalRefsServlet extends BeGenericServlet {
if (r != null){
return r;
}
-
- Either<String, ActionStatus> deleteStatus = this.businessLogic.deleteExternalReference(ComponentTypeEnum.findByParamName(assetType), userId, uuid, componentInstanceName, objectType, reference);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String uid = this.businessLogic.fetchComponentUniqueIdByUuid(uuid, componentType);
+ Either<String, ActionStatus> deleteStatus = this.businessLogic.deleteExternalReference(uid, componentType, userId, componentInstanceName, objectType, reference);
if (deleteStatus.isLeft()){
return this.buildOkResponse(new ExternalRefDTO(reference));
} else {
@@ -162,6 +178,7 @@ public class ExternalRefsServlet extends BeGenericServlet {
@Path("/{assetType}/{uuid}/resourceInstances/{componentInstanceName}/externalReferences/{objectType}/{oldRefValue}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
+ @PermissionAllowed({AafPermission.PermNames.WRITE_VALUE})
public Response updateComponentInstanceReference(
@PathParam("assetType") String assetType,
@PathParam("uuid") String uuid,
@@ -178,7 +195,9 @@ public class ExternalRefsServlet extends BeGenericServlet {
}
String newRefValue = newRefValueDTO.getReferenceUUID();
- Either<String, ActionStatus> updateResult = this.businessLogic.updateExternalReference(ComponentTypeEnum.findByParamName(assetType), userId, uuid, componentInstanceName, objectType, oldRefValue, newRefValue);
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType);
+ String uid = this.businessLogic.fetchComponentUniqueIdByUuid(uuid, componentType);
+ Either<String, ActionStatus> updateResult = this.businessLogic.updateExternalReference(uid, componentType, userId, componentInstanceName, objectType, oldRefValue, newRefValue);
if (updateResult.isLeft()){
return this.buildOkResponse(new ExternalRefDTO(newRefValue));
} else {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java
index 32fb87419c..be65a202a7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ServiceActivationServlet.java
@@ -1,225 +1,222 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.externalapi.servlet;
-
-import java.io.IOException;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.StringUtils;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceDistributionReqInfo;
-import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceDistributionRespInfo;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
-import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
-import org.openecomp.sdc.be.servlets.RepresentationUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * Created by chaya on 10/17/2017.
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Service Activation External Servlet", description = "This Servlet serves external users for activating a specific service"))
-@Singleton
-public class ServiceActivationServlet extends AbstractValidationsServlet {
-
- @Context
- private HttpServletRequest request;
-
- private static final Logger log = Logger.getLogger(ServiceActivationServlet.class);
- private final ServiceBusinessLogic serviceBusinessLogic;
-
- @Inject
- public ServiceActivationServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- ServiceBusinessLogic serviceBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.serviceBusinessLogic = serviceBusinessLogic;
- }
-
-
- /**
- * Activates a service on a specific environment
- *
- * @param serviceUUID
- * @param opEnvId
- * @param userId
- * @param instanceIdHeader
- * @return
- */
- @POST
- @Path("/services/{serviceUUID}/distribution/{opEnvId}/activate")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "activate a service", method = "POST", summary = "Activates a service")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "202",
- description = "ECOMP component is authenticated and required service may be distributed"),
- @ApiResponse(responseCode = "400", description = "Missing X-ECOMP-InstanceID HTTP header - POL5001"),
- @ApiResponse(responseCode = "401",
- description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
- @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
- @ApiResponse(responseCode = "404",
- description = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
- @ApiResponse(responseCode = "405",
- description = "Method Not Allowed : Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
- @ApiResponse(responseCode = "500",
- description = "The request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000"),
- @ApiResponse(responseCode = "400",
- description = "Invalid field format. One of the provided fields does not comply with the field rules - SVC4126"),
- @ApiResponse(responseCode = "400",
- description = "Missing request body. The post request did not contain the expected body - SVC4500"),
- @ApiResponse(responseCode = "400",
- description = "The resource name is missing in the request body - SVC4062"),
- @ApiResponse(responseCode = "409", description = "Service state is invalid for this action"),
- @ApiResponse(responseCode = "502",
- description = "The server was acting as a gateway or proxy and received an invalid response from the upstream server")})
- public Response activateServiceExternal(
- @Parameter(description = "Determines the format of the body of the request",
- required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
- @Parameter(description = "The user id",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
- @Parameter(description = "X-ECOMP-RequestID header",
- required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
- @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
- value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
- @Parameter(description = "Determines the format of the body of the response",
- required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
- @Parameter(description = "The username and password",
- required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
- @Parameter(description = "The serviceUUid to activate",
- required = true) @PathParam("serviceUUID") final String serviceUUID,
- @Parameter(description = "The operational environment on which to activate the service on",
- required = true) @PathParam("opEnvId") final String opEnvId,
- String data) {
-
- init();
-
- ResponseFormat responseFormat = null;
- String requestURI = request.getRequestURI();
- String url = request.getMethod() + " " + requestURI;
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
-
- try {
-
- Wrapper<ResponseFormat> responseWrapper = validateRequestHeaders(instanceIdHeader, userId);
-
- if (responseWrapper.isEmpty()) {
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- ServiceDistributionReqInfo reqMetadata = convertJsonToActivationMetadata(data);
- Either<String, ResponseFormat> distResponse = serviceBusinessLogic
- .activateServiceOnTenantEnvironment(serviceUUID, opEnvId, modifier, reqMetadata);
-
- if (distResponse.isRight()) {
- log.debug("failed to activate service distribution");
- responseFormat = distResponse.right().value();
- return buildErrorResponse(responseFormat);
- }
- String distributionId = distResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(new ServiceDistributionRespInfo(distributionId));
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.ACCEPTED);
- return buildOkResponse(responseFormat, result);
- } else {
- log.debug("request instanceId/userId header validation failed");
- responseFormat = responseWrapper.getInnerElement();
- return buildErrorResponse(responseFormat);
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Activate Distribution");
- log.debug("activate distribution failed with exception", e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- } finally {
- getComponentsUtils().auditExternalActivateService(responseFormat,
- new DistributionData(instanceIdHeader, requestURI), requestId, serviceUUID, modifier);
- }
- }
-
- private Wrapper<ResponseFormat> validateRequestHeaders(String instanceIdHeader, String userId) {
- Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
- if (responseWrapper.isEmpty()) {
- validateXECOMPInstanceIDHeader(instanceIdHeader, responseWrapper);
- }
- if (responseWrapper.isEmpty()) {
- validateHttpCspUserIdHeader(userId, responseWrapper);
- }
- return responseWrapper;
- }
-
- private ServiceDistributionReqInfo convertJsonToActivationMetadata(String data) {
- ObjectMapper mapper = new ObjectMapper();
- try {
- return mapper.readValue(data, ServiceDistributionReqInfo.class);
- } catch (IOException e) {
- log.error("#convertJsonToActivationMetadata - json deserialization failed with error: ", e);
- return new ServiceDistributionReqInfo(null);
- }
- }
-
- @Override
- protected void validateHttpCspUserIdHeader(String header, Wrapper<ResponseFormat> responseWrapper) {
- ResponseFormat responseFormat;
- if( StringUtils.isEmpty(header)){
- log.debug("MissingUSER_ID");
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.AUTH_FAILED);
- responseWrapper.setInnerElement(responseFormat);
- }
- }
-}
-
-
-
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.externalapi.servlet;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceDistributionReqInfo;
+import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceDistributionRespInfo;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
+import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
+import org.openecomp.sdc.be.servlets.RepresentationUtils;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+/**
+ * Created by chaya on 10/17/2017.
+ */
+@SuppressWarnings("ALL")
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Service Activation External Servlet", description = "This Servlet serves external users for activating a specific service"))
+@Controller
+public class ServiceActivationServlet extends AbstractValidationsServlet {
+
+ @Context
+ private HttpServletRequest request;
+
+ private static final Logger log = Logger.getLogger(ServiceActivationServlet.class);
+
+ private final ServiceBusinessLogic serviceBusinessLogic;
+
+ @Inject
+ public ServiceActivationServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ ServiceBusinessLogic serviceBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ }
+
+ /**
+ * Activates a service on a specific environment
+ */
+ @POST
+ @Path("/services/{serviceUUID}/distribution/{opEnvId}/activate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "activate a service", method = "POST", summary = "Activates a service")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "202",
+ description = "ECOMP component is authenticated and required service may be distributed"),
+ @ApiResponse(responseCode = "400", description = "Missing X-ECOMP-InstanceID HTTP header - POL5001"),
+ @ApiResponse(responseCode = "401",
+ description = "ECOMP component should authenticate itself and to re-send again HTTP request with its Basic Authentication credentials - POL5002"),
+ @ApiResponse(responseCode = "403", description = "ECOMP component is not authorized - POL5003"),
+ @ApiResponse(responseCode = "404",
+ description = "Error: Requested '%1' (uuid) resource was not found - SVC4063"),
+ @ApiResponse(responseCode = "405",
+ description = "Method Not Allowed : Invalid HTTP method type used ( PUT,DELETE,POST will be rejected) - POL4050"),
+ @ApiResponse(responseCode = "500",
+ description = "The request failed either due to internal SDC problem. ECOMP Component should continue the attempts to get the needed information - POL5000"),
+ @ApiResponse(responseCode = "400",
+ description = "Invalid field format. One of the provided fields does not comply with the field rules - SVC4126"),
+ @ApiResponse(responseCode = "400",
+ description = "Missing request body. The post request did not contain the expected body - SVC4500"),
+ @ApiResponse(responseCode = "400",
+ description = "The resource name is missing in the request body - SVC4062"),
+ @ApiResponse(responseCode = "409", description = "Service state is invalid for this action"),
+ @ApiResponse(responseCode = "502",
+ description = "The server was acting as a gateway or proxy and received an invalid response from the upstream server")})
+ @PermissionAllowed({AafPermission.PermNames.WRITE_VALUE})
+ public Response activateServiceExternal(
+ @Parameter(description = "Determines the format of the body of the request",
+ required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
+ @Parameter(description = "The user id",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
+ @Parameter(description = "X-ECOMP-RequestID header",
+ required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
+ @Parameter(description = "X-ECOMP-InstanceID header", required = true) @HeaderParam(
+ value = Constants.X_ECOMP_INSTANCE_ID_HEADER) final String instanceIdHeader,
+ @Parameter(description = "Determines the format of the body of the response",
+ required = false) @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
+ @Parameter(description = "The username and password",
+ required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
+ @Parameter(description = "The serviceUUid to activate",
+ required = true) @PathParam("serviceUUID") final String serviceUUID,
+ @Parameter(description = "The operational environment on which to activate the service on",
+ required = true) @PathParam("opEnvId") final String opEnvId,
+ String data) throws IOException {
+
+ init();
+
+ ResponseFormat responseFormat = null;
+ String requestURI = request.getRequestURI();
+ String url = request.getMethod() + " " + requestURI;
+ log.debug("Start handle request of {}", url);
+
+ User modifier = new User();
+
+ try {
+
+ Wrapper<ResponseFormat> responseWrapper = validateRequestHeaders(instanceIdHeader, userId);
+
+ if (responseWrapper.isEmpty()) {
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ ServiceDistributionReqInfo reqMetadata = convertJsonToActivationMetadata(data);
+ Either<String, ResponseFormat> distResponse = serviceBusinessLogic.activateServiceOnTenantEnvironment(serviceUUID, opEnvId, modifier, reqMetadata);
+
+ if (distResponse.isRight()) {
+ log.debug("failed to activate service distribution");
+ responseFormat = distResponse.right().value();
+ return buildErrorResponse(responseFormat);
+ }
+ String distributionId = distResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(new ServiceDistributionRespInfo(distributionId));
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.ACCEPTED);
+ return buildOkResponse(responseFormat, result);
+ } else {
+ log.debug("request instanceId/userId header validation failed");
+ responseFormat = responseWrapper.getInnerElement();
+ return buildErrorResponse(responseFormat);
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Activate Distribution");
+ log.debug("activate distribution failed with exception", e);
+ throw e;
+ } finally {
+ getComponentsUtils().auditExternalActivateService(responseFormat,
+ new DistributionData(instanceIdHeader, requestURI), requestId, serviceUUID, modifier);
+ }
+ }
+
+ private Wrapper<ResponseFormat> validateRequestHeaders(String instanceIdHeader, String userId) {
+ Wrapper<ResponseFormat> responseWrapper = new Wrapper<>();
+ if (responseWrapper.isEmpty()) {
+ validateXECOMPInstanceIDHeader(instanceIdHeader, responseWrapper);
+ }
+ if (responseWrapper.isEmpty()) {
+ validateHttpCspUserIdHeader(userId, responseWrapper);
+ }
+ return responseWrapper;
+ }
+
+ private ServiceDistributionReqInfo convertJsonToActivationMetadata(String data) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.readValue(data, ServiceDistributionReqInfo.class);
+ } catch (IOException e) {
+ log.error("#convertJsonToActivationMetadata - json deserialization failed with error: ", e);
+ return new ServiceDistributionReqInfo(null);
+ }
+ }
+
+ @Override
+ protected void validateHttpCspUserIdHeader(String header, Wrapper<ResponseFormat> responseWrapper) {
+ ResponseFormat responseFormat;
+ if( StringUtils.isEmpty(header)){
+ log.debug("MissingUSER_ID");
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.AUTH_FAILED);
+ responseWrapper.setInnerElement(responseFormat);
+ }
+ }
+}
+
+
+
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/CatalogOperation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/CatalogOperation.java
new file mode 100644
index 0000000000..7836fcce75
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/CatalogOperation.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.facade.operations;
+
+import org.openecomp.sdc.be.catalog.api.IComponentMessage;
+import org.openecomp.sdc.be.catalog.api.IStatus;
+import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
+import org.openecomp.sdc.be.catalog.impl.ComponentMessage;
+import org.openecomp.sdc.be.catalog.impl.DmaapProducer;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
+import java.util.Arrays;
+import java.util.List;
+
+
+@org.springframework.stereotype.Component
+public class CatalogOperation {
+
+ private static final Logger log = Logger.getLogger(CatalogOperation.class);
+
+ private static final List<ResourceTypeEnum> EXCLUDE_TYPES = Arrays.asList(ResourceTypeEnum.VFCMT, ResourceTypeEnum.Configuration);
+
+ private final DmaapProducer msProducer;
+
+ public CatalogOperation(DmaapProducer msProducer){
+ this.msProducer = msProducer;
+ }
+
+ public ActionStatus updateCatalog(ChangeTypeEnum changeTypeEnum, Component component){
+ ActionStatus result = ActionStatus.OK;
+ try{
+ if(isNeedToUpdateCatalog(component)){
+ IComponentMessage message = new ComponentMessage(component, changeTypeEnum, CatalogUpdateTimestamp.buildDummyCatalogUpdateTimestamp());
+ IStatus status = msProducer.pushMessage(message);
+ result = FacadeOperationUtils.convertStatusToActionStatus(status);
+ }
+
+ }catch(Exception e){
+ log.debug("updateCatalog - failed to updateCatalog and send notification {}", e.getMessage());
+ return ActionStatus.OK;
+ }
+ return result;
+ }
+
+ private boolean isNeedToUpdateCatalog(Component component) {
+ boolean isUpdateCatalog = true;
+ if(component.getComponentType() == ComponentTypeEnum.RESOURCE){
+ return ((Resource)component).isAbstract() || EXCLUDE_TYPES.contains(((Resource)component).getResourceType())? false : true;
+
+ }
+ return isUpdateCatalog;
+ }
+
+
+ public DmaapProducer getMsProducer() {
+ return msProducer;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/FacadeOperationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/FacadeOperationUtils.java
new file mode 100644
index 0000000000..0cc4a1ccf6
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/FacadeOperationUtils.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.facade.operations;
+
+import org.openecomp.sdc.be.catalog.api.IStatus;
+import org.openecomp.sdc.be.catalog.enums.ResultStatusEnum;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
+public class FacadeOperationUtils {
+ private static final Logger log = Logger.getLogger(CatalogOperation.class);
+
+ private FacadeOperationUtils() {
+ }
+
+ public static ActionStatus convertStatusToActionStatus(IStatus status) {
+ ActionStatus result = ActionStatus.OK;
+ if (status.getResultStatus() != ResultStatusEnum.SUCCESS){
+ log.debug("updateCatalog - failed to send notification {}", status);
+ }
+ return result;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/UserOperation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/UserOperation.java
new file mode 100644
index 0000000000..c830734498
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/UserOperation.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.facade.operations;
+
+import org.openecomp.sdc.be.catalog.api.IStatus;
+import org.openecomp.sdc.be.catalog.impl.DmaapProducer;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.user.UserMessage;
+import org.openecomp.sdc.be.user.UserOperationEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class UserOperation {
+ private static final Logger log = Logger.getLogger(UserOperation.class);
+ private final DmaapProducer msProducer;
+
+ @Autowired
+ public UserOperation(DmaapProducer msProducer){
+ this.msProducer = msProducer;
+ }
+
+ public ActionStatus updateUserCache(UserOperationEnum operation, String userId, String role){
+ ActionStatus result = ActionStatus.OK;
+ try{
+ UserMessage message = new UserMessage(operation, userId,role);
+ IStatus status = msProducer.pushMessage(message);
+ result = FacadeOperationUtils.convertStatusToActionStatus(status);
+
+ }catch(Exception e){
+ log.debug("update user cache - failed to send notification to update user cache {}", e.getMessage());
+ return ActionStatus.OK;
+ }
+ return result;
+ }
+
+
+ public DmaapProducer getMsProducer() {
+ return msProducer;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java
index 5166ef94d7..1747525417 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BasicAuthenticationFilter.java
@@ -24,6 +24,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import fj.data.Either;
import org.apache.commons.codec.binary.Base64;
+import org.onap.sdc.security.Passwords;
import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -35,7 +36,6 @@ import org.openecomp.sdc.common.log.enums.Severity;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.openecomp.sdc.security.Passwords;
import org.springframework.web.context.WebApplicationContext;
import javax.annotation.Priority;
@@ -54,6 +54,7 @@ import java.util.StringTokenizer;
@Priority(10)
public class BasicAuthenticationFilter implements ContainerRequestFilter {
+
private static LoggerSdcAudit audit = new LoggerSdcAudit(BasicAuthenticationFilter.class);
private static final Logger log = Logger.getLogger(BasicAuthenticationFilter.class);
private static final String COMPONENT_UTILS_FAILED = "Authentication Filter Failed to get component utils.";
@@ -219,12 +220,12 @@ public class BasicAuthenticationFilter implements ContainerRequestFilter {
private void abortWith(ContainerRequestContext requestContext, String message, Response response) {
- audit.log(sr.getRemoteAddr(),
+ audit.logEntry(sr.getRemoteAddr(),
requestContext,
- response.getStatusInfo(),
+// response.getStatusInfo(),
LogLevel.ERROR,
Severity.WARNING,
- message);
+ message, null);
log.error(message);
audit.clearMyData();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeCadiServletFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeCadiServletFilter.java
new file mode 100644
index 0000000000..49b9fbf5d7
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeCadiServletFilter.java
@@ -0,0 +1,180 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import org.onap.aaf.cadi.Access;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.config.Config;
+import org.onap.aaf.cadi.filter.CadiFilter;
+import org.openecomp.sdc.be.components.impl.CADIHealthCheck;
+import org.openecomp.sdc.be.config.CadiFilterParams;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.springframework.web.context.WebApplicationContext;
+
+import javax.annotation.Priority;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.function.Supplier;
+
+@Priority(2)
+public class BeCadiServletFilter extends CadiFilter {
+
+ private static final Logger log = Logger.getLogger(BeCadiServletFilter.class);
+ private ConfigurationManager configurationManager = ConfigurationManager.getConfigurationManager();
+ private static final String BE_CADI_SERVICE_FILTER = "BeCadiServletFilter: ";
+
+
+ public BeCadiServletFilter() {
+ super();
+ log.debug(BE_CADI_SERVICE_FILTER);
+ }
+
+ /**
+ * This constructor to be used when directly constructing and placing in HTTP Engine
+ *
+ * @param access
+ * @param moreTafLurs
+ * @throws ServletException
+ */
+ public BeCadiServletFilter(Access access, Object... moreTafLurs) throws ServletException {
+ super(access, moreTafLurs);
+ log.debug(BE_CADI_SERVICE_FILTER);
+ }
+
+
+ /**
+ * Use this to pass in a PreContructed CADI Filter, but with initializing... let Servlet do it
+ *
+ * @param init
+ * @param access
+ * @param moreTafLurs
+ * @throws ServletException
+ */
+ public BeCadiServletFilter(boolean init, PropAccess access, Object... moreTafLurs) throws ServletException {
+
+ super(init, access, moreTafLurs);
+ log.debug(BE_CADI_SERVICE_FILTER);
+ }
+
+ private void checkIfNullProperty(String key, String value) {
+ /* When value is null, so not defined in application.properties
+ set nothing in System properties */
+ if (value != null) {
+ /* Ensure that any properties already defined in System.prop by JVM params
+ won't be overwritten by Spring application.properties values */
+ System.setProperty(key, System.getProperty(key, value));
+ }
+ }
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+
+ // set some properties in System so that Cadi filter will find its config
+ // The JVM values set will always overwrite the Spring ones.
+ CadiFilterParams cadiFilterParams = configurationManager.getConfiguration().getCadiFilterParams();
+ checkIfNullProperty(Config.HOSTNAME, cadiFilterParams.getHostname());
+ log.debug("BeCadiServletFilter: HOSTNAME", cadiFilterParams.getHostname());
+
+ checkIfNullProperty(Config.CADI_KEYFILE, cadiFilterParams.getCadi_keyfile());
+ checkIfNullProperty(Config.CADI_LOGLEVEL, cadiFilterParams.getCadi_loglevel());
+
+
+ checkIfNullProperty(Config.CADI_LATITUDE, cadiFilterParams.getAFT_LATITUDE());
+ checkIfNullProperty(Config.CADI_LONGITUDE, cadiFilterParams.getAFT_LONGITUDE());
+
+ checkIfNullProperty(Config.AAF_URL, cadiFilterParams.getAaf_url());
+ //checkIfNullProperty(Config.AAF_LOCATE_URL, cadiFilterParams.getAafLocateUrl());
+ checkIfNullProperty(Config.AAF_APPID, cadiFilterParams.getAaf_id());
+ checkIfNullProperty(Config.AAF_APPPASS, cadiFilterParams.getAaf_password());
+ checkIfNullProperty(Config.AAF_ENV, cadiFilterParams.getAFT_ENVIRONMENT());
+
+ checkIfNullProperty(Config.CADI_X509_ISSUERS, cadiFilterParams.getCadiX509Issuers());
+ checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiFilterParams.getCadi_truststore());
+ checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiFilterParams.getCadi_truststore_password());
+ super.init(filterConfig);
+ log.debug("BeCadiServletFilter finishing init(), Current status of CADI would be UP");
+ if (!isNeedAuth()) {
+ CADIHealthCheck.getCADIHealthCheckInstance().setIsCADIUp(HealthCheckInfo.HealthCheckStatus.DOWN);
+ } else {
+ CADIHealthCheck.getCADIHealthCheckInstance().setIsCADIUp(HealthCheckInfo.HealthCheckStatus.UP);
+ }
+ }
+
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+
+ if (ThreadLocalsHolder.isExternalRequest() && isNeedAuth()) {
+ log.debug("doFilter: {}", request.getContentType());
+ HttpServletRequest hreq = (HttpServletRequest) request;
+ log.debug("Need aaf authentication : {}", hreq);
+ ThreadLocalUtils threadLocalUtils = getThreadLocalUtils(((HttpServletRequest) request).getSession().getServletContext());
+ threadLocalUtils.setUserContext((HttpServletRequest) request);
+ super.doFilter(request, response, chain);
+ } else {
+ log.debug("No need aaf authentication");
+ chain.doFilter(request, response);
+ }
+ }
+
+ private boolean isNeedAuth() {
+ return configurationManager.getConfiguration().getAafAuthNeeded();
+ }
+
+
+ ThreadLocalUtils getThreadLocalUtils(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> ThreadLocalUtils.class);
+ }
+
+ <T> T getClassFromWebAppContext(ServletContext context, Supplier<Class<T>> businessLogicClassGen) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(businessLogicClassGen.get());
+ }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeRestrictionAccessFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeRestrictionAccessFilter.java
new file mode 100644
index 0000000000..de8969a310
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeRestrictionAccessFilter.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import org.onap.sdc.security.PortalClient;
+import org.onap.sdc.security.filters.RestrictionAccessFilter;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+
+@Component("beRestrictionAccessFilter")
+public class BeRestrictionAccessFilter extends RestrictionAccessFilter {
+
+ private static final Logger log = Logger.getLogger(RestrictionAccessFilter.class.getName());
+
+ public BeRestrictionAccessFilter(FilterConfiguration configuration, ThreadLocalUtils threadLocalUtils,
+ PortalClient portalClient) {
+ super(configuration, threadLocalUtils, portalClient);
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ if (ThreadLocalsHolder.isInternalRequest()) {
+ super.doFilter(servletRequest, servletResponse, filterChain);
+ } else {
+ log.debug("Access Restriction cookie validation is not needed");
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java
index c9430107df..c559751515 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/BeServletFilter.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,6 +21,8 @@
package org.openecomp.sdc.be.filters;
import com.google.gson.GsonBuilder;
+import org.onap.logging.filter.base.AuditLogContainerFilter;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -29,11 +31,9 @@ import org.openecomp.sdc.be.dao.jsongraph.HealingJanusGraphDao;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.elements.LogFieldsMdcHandler;
-import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.api.ILogConfiguration;
import org.openecomp.sdc.common.log.enums.Severity;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
import org.openecomp.sdc.common.util.ThreadLocalsHolder;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.MDC;
@@ -43,104 +43,76 @@ import javax.annotation.Priority;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseContext;
-import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
-import java.util.UUID;
@Provider
@Priority(1)
-public class BeServletFilter implements ContainerRequestFilter, ContainerResponseFilter {
+public class BeServletFilter extends AuditLogContainerFilter {
@Context
private HttpServletRequest sr;
private static final Logger log = Logger.getLogger(BeServletFilter.class);
- private static LoggerSdcAudit audit = new LoggerSdcAudit(BeServletFilter.class);
@Override
- public void filter(ContainerRequestContext requestContext) throws IOException {
- try {
-
- MDC.clear();
-
- audit.startLog(requestContext);
-
- // In case of 405 response code, this function is not entered, then
- // we'll process
- // the MDC fields and UUID during the response
- ThreadLocalsHolder.setMdcProcessed(true);
-
- // Timing HTTP request
- ThreadLocalsHolder.setRequestStartTime(System.currentTimeMillis());
-
- String uuid = processMdcFields(requestContext);
-
- ThreadLocalsHolder.setUuid(uuid);
-
- inHttpRequest();
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Error during request filter");
- log.debug("Error during request filter: {} ", e);
+ public void filter(ContainerRequestContext requestContext) {
+ if (isLoggedRequest()) {
+ try {
+ super.filter(requestContext);
+ // In case of 405 response code, this function is not entered, then
+ // we'll process
+ // the MDC fields and UUID during the response
+ ThreadLocalsHolder.setMdcProcessed(true);
+ // Timing HTTP request
+ ThreadLocalsHolder.setRequestStartTime(System.currentTimeMillis());
+ processMdcFields(requestContext);
+ ThreadLocalsHolder.setUuid(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
+ inHttpRequest();
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Error during request filter");
+ log.debug("Error during request filter: {} ", e);
+ }
}
}
@Override
- public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
- try {
- // Formatting the response in case of 405
- if (responseContext.getStatus() == Response.Status.METHOD_NOT_ALLOWED.getStatusCode()) {
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NOT_ALLOWED);
- responseContext.setEntity(new GsonBuilder().setPrettyPrinting().create().toJson(responseFormat.getRequestError()));
- }
+ protected void additionalPreHandling(ContainerRequestContext containerRequestContext) {
+ MDC.put(ILogConfiguration.MDC_REMOTE_HOST, sr.getRemoteAddr());
+ MDC.put(ILogConfiguration.MDC_SERVICE_INSTANCE_ID, containerRequestContext.getHeaderString(Constants.X_ECOMP_SERVICE_ID_HEADER));
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_SEVERITY, String.valueOf(Severity.OK.getSeverityType()));
+ }
- if (ThreadLocalsHolder.isMdcProcessed()) {
- // filter() was executed during request - this is the regular
- // flow
- responseContext.getHeaders().add(Constants.X_ECOMP_REQUEST_ID_HEADER, ThreadLocalsHolder.getUuid());
- Long startTime = ThreadLocalsHolder.getRequestStartTime();
- if (startTime != null) {
- long endTime = System.currentTimeMillis();
- MDC.put("timer", Long.toString(endTime - startTime));
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
+ if (isLoggedRequest()) {
+ try {
+ super.filter(requestContext, responseContext);
+ // Formatting the response in case of 405
+ if (responseContext.getStatus() == Response.Status.METHOD_NOT_ALLOWED.getStatusCode()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NOT_ALLOWED);
+ responseContext.setEntity(new GsonBuilder().setPrettyPrinting().create().toJson(responseFormat.getRequestError()));
}
- } else {
- // this is the 405 response code case
- // we have no MDC fields since filter() wasn't executed during
- // request
- String uuid = processMdcFields(requestContext);
-
- responseContext.getHeaders().add(Constants.X_ECOMP_REQUEST_ID_HEADER, uuid);
- // call to start-log method to fill mandatory fields
- audit.startLog(requestContext);
- }
- writeToJanusGraph(responseContext);
-
- //write to Audit log in case it's valuable action
- // (e.g. ignoring healthCheck and any other unlogged urls as in yaml
- if (isInfoLog()) {
- audit.log(sr.getRemoteAddr(),
- requestContext,
- responseContext.getStatusInfo(),
- LogLevel.INFO,
- Severity.OK,
- LogFieldsMdcHandler.getInstance()
- .getAuditMessage());
- }
+ if (ThreadLocalsHolder.isMdcProcessed()) {
+ // filter() was executed during request - this is the regular
+ // flow
+ responseContext.getHeaders().add(Constants.X_ECOMP_REQUEST_ID_HEADER, ThreadLocalsHolder.getUuid());
+ }
+ writeToJanusGraph(responseContext);
- outHttpResponse(responseContext);
+ outHttpResponse(responseContext);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Error during request filter");
- log.debug("Error during response filter: {} ", e);
- } finally {
- // Cleaning up
- MDC.clear();
- ThreadLocalsHolder.cleanup();
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Error during request filter");
+ log.debug("Error during response filter: {} ", e);
+ } finally {
+ // Cleaning up
+ MDC.clear();
+ ThreadLocalsHolder.cleanup();
+ }
}
}
@@ -161,37 +133,16 @@ public class BeServletFilter implements ContainerRequestFilter, ContainerRespons
}
}
- private String processMdcFields(ContainerRequestContext requestContext) {
+ private void processMdcFields(ContainerRequestContext requestContext) {
// UserId for logging
String userId = requestContext.getHeaderString(Constants.USER_ID_HEADER);
MDC.put("userId", userId);
String serviceInstanceID = requestContext.getHeaderString(Constants.X_ECOMP_SERVICE_ID_HEADER);
- MDC.put("serviceInstanceID", serviceInstanceID);
+ MDC.put(ILogConfiguration.MDC_SERVICE_INSTANCE_ID, serviceInstanceID);
MDC.put("remoteAddr", sr.getRemoteAddr());
MDC.put("localAddr", sr.getLocalAddr());
-
- // UUID
- String uuid = requestContext.getHeaderString(Constants.X_ECOMP_REQUEST_ID_HEADER);
- if (uuid == null) {
- // Generate the UUID
- uuid = UUID.randomUUID().toString();
-
- // Add to MDC for logging
- MDC.put("uuid", uuid);
-
- // This log message should already be with the UUID
- uuidGeneration(uuid);
-
- } else {
- // According to Ella, in case this header exists, we don't have to
- // perform any validations
- // since it's not our responsibilty, so we log the UUID just as it
- // was received.
- MDC.put("uuid", uuid);
- }
- return uuid;
}
private ComponentsUtils getComponentsUtils() {
@@ -212,23 +163,15 @@ public class BeServletFilter implements ContainerRequestFilter, ContainerRespons
// Extracted for purpose of clear method name, for logback %M parameter
private void inHttpRequest() {
- if (isInfoLog()) {
- log.info("{} {} {}", sr.getMethod(), sr.getRequestURI(), sr.getProtocol());
- } else {
- log.debug("{} {} {}", sr.getMethod(), sr.getRequestURI(), sr.getProtocol());
- }
+ log.info("{} {} {}", sr.getMethod(), sr.getRequestURI(), sr.getProtocol());
}
// Extracted for purpose of clear method name, for logback %M parameter
private void outHttpResponse(ContainerResponseContext responseContext) {
- if (isInfoLog()) {
- log.info("{} {} {} SC=\"{}\"", sr.getMethod(), sr.getRequestURI(), sr.getProtocol(), responseContext.getStatus());
- } else {
- log.debug("{} {} {} SC=\"{}\"", sr.getMethod(), sr.getRequestURI(), sr.getProtocol(), responseContext.getStatus());
- }
+ log.info("{} {} {} SC=\"{}\"", sr.getMethod(), sr.getRequestURI(), sr.getProtocol(), responseContext.getStatus());
}
- private boolean isInfoLog() {
+ private boolean isLoggedRequest() {
boolean logRequest = true;
Configuration configuration = ConfigurationManager.getConfigurationManager().getConfiguration();
String requestURI = sr.getRequestURI();
@@ -237,9 +180,4 @@ public class BeServletFilter implements ContainerRequestFilter, ContainerRespons
}
return logRequest;
}
-
- // Extracted for purpose of clear method name, for logback %M parameter
- private void uuidGeneration(String uuid) {
- log.info("No requestID provided -> Generated UUID {}", uuid);
- }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java
index 158cc2d842..5ccbb26f93 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ComponentsAvailabilityFilter.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.filters;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -34,6 +35,7 @@ import org.openecomp.sdc.common.log.enums.Severity;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.MarkerFactory;
import org.springframework.web.context.WebApplicationContext;
import javax.annotation.Priority;
@@ -92,7 +94,7 @@ public class ComponentsAvailabilityFilter implements ContainerRequestFilter {
List<HealthCheckInfo> healthCheckInfos = new ArrayList<>();
HealthCheckBusinessLogic healthCheckBusinessLogic = getHealthCheckBL(servletContext);
- healthCheckBusinessLogic.getJanusGraphHealthCheck(healthCheckInfos); // JanusGraph
+ healthCheckInfos.add(healthCheckBusinessLogic.getJanusGraphHealthCheck());
return healthCheckInfos;
}
@@ -124,12 +126,13 @@ public class ComponentsAvailabilityFilter implements ContainerRequestFilter {
private void abortWith(ContainerRequestContext requestContext, String message, Response response) {
- audit.log(sr.getRemoteAddr(),
+ audit.logExit(sr.getRemoteAddr(),
requestContext,
response.getStatusInfo(),
LogLevel.ERROR,
Severity.OK,
- message);
+ message,
+ MarkerFactory.getMarker(ONAPLogConstants.Markers.EXIT.getName()));
log.error(message);
audit.clearMyData();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/FilterConfiguration.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/FilterConfiguration.java
new file mode 100644
index 0000000000..7bd9c46780
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/FilterConfiguration.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import org.onap.sdc.security.ISessionValidationFilterConfiguration;
+import org.openecomp.sdc.be.config.Configuration;
+
+import java.util.List;
+
+public class FilterConfiguration implements ISessionValidationFilterConfiguration {
+
+ protected Configuration config;
+
+ public FilterConfiguration(org.openecomp.sdc.be.config.Configuration configuration) {
+ this.config = configuration;
+ }
+
+ @Override
+ public String getSecurityKey() {
+ return config.getAuthCookie().getSecurityKey();
+ }
+
+ @Override
+ public long getMaxSessionTimeOut() {
+ return config.getAuthCookie().getMaxSessionTimeOut();
+ }
+
+ @Override
+ public long getSessionIdleTimeOut() {
+ return config.getAuthCookie().getSessionIdleTimeOut();
+ }
+
+ @Override
+ public String getRedirectURL() {
+ return config.getAuthCookie().getRedirectURL();
+ }
+
+ @Override
+ public List<String> getExcludedUrls() {
+ return config.getAuthCookie().getExcludedUrls();
+ }
+
+ @Override
+ public String getCookieName() {
+ return config.getAuthCookie().getCookieName();
+ }
+
+ @Override
+ public String getCookieDomain() {
+ return config.getAuthCookie().getDomain();
+ }
+
+ @Override
+ public String getCookiePath() {
+ return config.getAuthCookie().getPath();
+ }
+
+ @Override
+ public boolean isCookieHttpOnly() {
+ return config.getAuthCookie().isHttpOnly();
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/GatewayFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/GatewayFilter.java
new file mode 100644
index 0000000000..3ed14f139f
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/GatewayFilter.java
@@ -0,0 +1,147 @@
+/*-
+ * ============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.sdc.be.filters;
+
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper;
+import org.openecomp.sdc.common.api.FilterDecisionEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.HttpHeaders;
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Stream;
+
+@Component("gatewayFilter")
+public class GatewayFilter implements Filter {
+
+ private Configuration.CookieConfig authCookieConf;
+ private Configuration config;
+ private static final Logger log = Logger.getLogger(BeServletFilter.class);
+
+ @Autowired
+ private ThreadLocalUtils threadLocalUtils;
+ @Autowired
+ private ComponentExceptionMapper componentExceptionMapper;
+
+
+ public GatewayFilter(org.openecomp.sdc.be.config.Configuration configuration) {
+ this.authCookieConf = configuration.getAuthCookie();
+ }
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ @Override
+ public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
+
+ HttpServletRequest httpRequest = (HttpServletRequest) req;
+ HttpServletResponse httpResponse = (HttpServletResponse) res;
+ try {
+ if (isUrlFromWhiteList(httpRequest) || isConsumerBusinessLogic()) {
+ ThreadLocalsHolder.setApiType(FilterDecisionEnum.NA);
+ threadLocalUtils.setUserContextFromDB(httpRequest);
+ filterChain.doFilter(httpRequest, res);
+// } else if (isCookieExist(httpRequest, authCookieConf.getCookieName())) {
+// ThreadLocalsHolder.setApiType(FilterDecisionEnum.INTERNAL);
+// filterChain.doFilter(httpRequest, res);
+// } else {
+// validateAuthHeaderExist(httpRequest);
+// ThreadLocalsHolder.setApiType(FilterDecisionEnum.EXTERNAL);
+// filterChain.doFilter(httpRequest, res);
+ }
+ } catch (ComponentException ce) {
+ componentExceptionMapper.writeToResponse(ce, httpResponse);
+
+ } catch (WebApplicationException we) {
+ httpResponse.setStatus(we.getResponse().getStatus());
+ setDefaultHttpParams(httpResponse);
+ httpResponse.getWriter().write(we.getMessage());
+
+ } catch (Exception ex) {
+ httpResponse.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ setDefaultHttpParams(httpResponse);
+ httpResponse.getWriter().write(ex.getMessage());
+ }
+ }
+
+ private void setDefaultHttpParams(HttpServletResponse httpResponse) {
+ httpResponse.setContentType("application/json");
+ httpResponse.setCharacterEncoding("UTF-8");
+ }
+
+ private boolean isCookieExist(HttpServletRequest httpRequest, String cookieName) {
+ Cookie[] cookies = httpRequest.getCookies();
+ if (cookies != null) {
+ for (Cookie cookie : cookies) {
+ if (cookie.getName().equals(cookieName)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isHeaderExist(HttpServletRequest req, String headerName) {
+ return req.getHeader(headerName) != null;
+ }
+
+ private void validateAuthHeaderExist(HttpServletRequest req) {
+ boolean authHeader = isHeaderExist(req, HttpHeaders.AUTHORIZATION);
+ if (!authHeader) throw new ByActionStatusComponentException(ActionStatus.AUTH_FAILED);
+ }
+
+ private boolean isUrlFromWhiteList(HttpServletRequest httpRequest) {
+ String pathInfo;
+ List<String> excludedUrls = authCookieConf.getExcludedUrls();
+ pathInfo = httpRequest.getPathInfo().toLowerCase();
+ log.debug("SessionValidationFilter: white list validation -> PathInfo: {} ", pathInfo);
+ Stream<String> stream = excludedUrls.stream();
+ pathInfo.getClass();
+ return stream.anyMatch(pathInfo::matches);
+ }
+
+ private Boolean isConsumerBusinessLogic() {
+ return config.getConsumerBusinessLogic();
+ }
+ @Override
+ public void destroy() {
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/PortalConfiguration.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/PortalConfiguration.java
new file mode 100644
index 0000000000..81920ce13c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/PortalConfiguration.java
@@ -0,0 +1,150 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang.StringUtils;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.onap.sdc.security.IPortalConfiguration;
+import org.onap.sdc.security.PortalClient;
+
+import java.security.InvalidParameterException;
+
+public class PortalConfiguration implements IPortalConfiguration {
+ private static final String PROPERTY_NOT_SET = "%s property value is not set in portal.properties file";
+ private String portalUser;
+ private String portalPassword;
+ private String ecompPortalRestURL;
+ private String portalAppName;
+ private String uebKey;
+
+ public PortalConfiguration() throws org.onap.portalsdk.core.onboarding.exception.CipherUtilException {
+ this.portalUser = org.onap.portalsdk.core.onboarding.util.PortalApiProperties.getProperty(org.onap.sdc.security.PortalClient.PortalPropertiesEnum.USER.value());
+ this.portalPassword = org.onap.portalsdk.core.onboarding.util.PortalApiProperties.getProperty(PortalClient.PortalPropertiesEnum.PASSWORD.value());
+ this.portalAppName = org.onap.portalsdk.core.onboarding.util.PortalApiProperties.getProperty(PortalClient.PortalPropertiesEnum.APP_NAME.value());
+ this.ecompPortalRestURL = org.onap.portalsdk.core.onboarding.util.PortalApiProperties.getProperty(org.onap.sdc.security.PortalClient.PortalPropertiesEnum.ECOMP_REST_URL.value());
+ this.uebKey = org.onap.portalsdk.core.onboarding.util.PortalApiProperties.getProperty(org.onap.sdc.security.PortalClient.PortalPropertiesEnum.UEB_APP_KEY.value());
+ }
+
+ @VisibleForTesting
+ String getPortalProperty(String key) {
+ String value = PortalApiProperties.getProperty(key);
+ if (StringUtils.isEmpty(value)) {
+ throw new InvalidParameterException(String.format(PROPERTY_NOT_SET, key));
+ }
+ return value;
+ }
+
+ @Override
+ public String getPortalApiPrefix() {
+ return null;
+ }
+
+ @Override
+ public long getMaxIdleTime() {
+ return 0;
+ }
+
+ @Override
+ public String getUserAttributeName() {
+ return null;
+ }
+
+ @Override
+ public boolean IsUseRestForFunctionalMenu() {
+ return false;
+ }
+
+ @Override
+ public String getPortalApiImplClass() {
+ return null;
+ }
+
+ @Override
+ public String getRoleAccessCentralized() {
+ return null;
+ }
+
+ @Override
+ public boolean getUebListenersEnable() {
+ return false;
+ }
+
+ @Override
+ public String getEcompRedirectUrl() {
+ return null;
+ }
+
+ @Override
+ public String getEcompRestUrl() {
+ return ecompPortalRestURL;
+ }
+
+ @Override
+ public String getPortalUser() {
+ return portalUser;
+ }
+
+ @Override
+ public String getPortalPass() {
+ return portalPassword;
+ }
+
+ @Override
+ public String getPortalAppName() {
+ return portalAppName;
+ }
+
+ @Override
+ public String getUebAppKey() {
+ return uebKey;
+ }
+
+ @Override
+ public String getAafNamespace() {
+ return null;
+ }
+
+ @Override
+ public String getAuthNamespace() {
+ return null;
+ }
+
+ @Override
+ public String getCspCookieName() {
+ return null;
+ }
+
+ @Override
+ public String getCspGateKeeperProdKey() {
+ return null;
+ }
+
+ @Override
+ public String getExtReqConnectionTimeout() {
+ return null;
+ }
+
+ @Override
+ public String getExtReqReadTimeout() {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ReqValidationFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ReqValidationFilter.java
new file mode 100644
index 0000000000..4fc576b79d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ReqValidationFilter.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper;
+import org.openecomp.sdc.common.api.UserRoleEnum;
+import org.openecomp.sdc.common.datastructure.UserContext;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+@Component("reqValidationFilter")
+public class ReqValidationFilter implements Filter {
+
+ private static final Logger log = Logger.getLogger(ReqValidationFilter.class);
+ @Autowired
+ public ComponentExceptionMapper componentExceptionMapper;
+
+ @Override
+ public void init(FilterConfig filterConfig){
+
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
+ try {
+ log.debug("Validating User roles - filter");
+ List<String> validRoles = Arrays.asList(UserRoleEnum.ADMIN.getName(), UserRoleEnum.DESIGNER.getName());
+ UserContext userContext = ThreadLocalsHolder.getUserContext();
+
+ if (userContext != null && CollectionUtils.isNotEmpty(userContext.getUserRoles())) {
+ Set<String> userRoles = userContext.getUserRoles();
+ if (!userRoles.stream().anyMatch(role -> validRoles.contains(role))) {
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, "SDC", "User role is invalid: {}", userRoles);
+ throw new ByActionStatusComponentException(ActionStatus.AUTH_FAILED);
+ }
+ }
+ filterChain.doFilter(servletRequest, servletResponse);
+ } catch (ComponentException exp) {
+ componentExceptionMapper.writeToResponse(exp, httpResponse);
+ }
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java
new file mode 100644
index 0000000000..3eb067c8a9
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.filters;
+
+import org.onap.sdc.security.AuthenticationCookie;
+import org.onap.sdc.security.IUsersThreadLocalHolder;
+import org.onap.sdc.security.PortalClient;
+import org.onap.sdc.security.RestrictionAccessFilterException;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.UserContext;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class ThreadLocalUtils implements IUsersThreadLocalHolder {
+
+ @Autowired
+ PortalClient portalClient;
+
+ @Autowired
+ UserBusinessLogic userBusinessLogic;
+
+ private static final Logger log = Logger.getLogger(ThreadLocalUtils.class);
+
+ @Override
+ public void setUserContext(AuthenticationCookie authenticationCookie) {
+ UserContext userContext;
+ userContext = new UserContext(authenticationCookie.getUserID(), authenticationCookie.getRoles(), authenticationCookie.getFirstName(), authenticationCookie.getLastName());
+ ThreadLocalsHolder.setUserContext(userContext);
+ }
+
+
+ protected void setUserContext(HttpServletRequest httpRequest) {
+
+ String user_id = httpRequest.getHeader(Constants.USER_ID_HEADER);
+ if (user_id != null) {
+ String userRolesFromPortal = null;
+ Set<String> roles = null;
+ try {
+ userRolesFromPortal = portalClient.fetchUserRolesFromPortal(user_id);
+ roles = new HashSet<>(Arrays.asList(userRolesFromPortal));
+ } catch (RestrictionAccessFilterException e) {
+ log.debug("Failed to fetch user ID - {} from portal", user_id);
+ log.debug(e.getMessage());
+ }
+ UserContext userContext = new UserContext(user_id, roles, null, null);
+ ThreadLocalsHolder.setUserContext(userContext);
+ } else log.debug("user_id value in req header is null, userContext will not be initialized");
+ }
+
+ protected void setUserContextFromDB(HttpServletRequest httpRequest) {
+ String user_id = httpRequest.getHeader(Constants.USER_ID_HEADER);
+ //there are some internal request that have no user_id header e.g. healthcheck
+ if (user_id != null) {
+ updateUserContext(user_id);
+ } else log.debug("user_id value in req header is null, userContext will not be initialized");
+ }
+
+ protected void setUserContextFromDB(AuthenticationCookie authenticationCookie) {
+ String user_id = authenticationCookie.getUserID();
+ updateUserContext(user_id);
+ }
+
+ private void updateUserContext(String user_id) {
+ User user = userBusinessLogic.getUser(user_id, false);
+ Set<String> roles = new HashSet<>(Arrays.asList(user.getRole()));
+ UserContext userContext = new UserContext(user_id, roles, user.getFirstName(), user.getLastName());
+ ThreadLocalsHolder.setUserContext(userContext);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
index 59e4c2e78c..d50b91fadc 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -7,9 +7,9 @@
* 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.
@@ -30,16 +30,34 @@ import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import fj.data.Either;
import org.apache.commons.lang3.StringUtils;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
-import org.openecomp.sdc.be.auditing.impl.*;
+import org.openecomp.sdc.be.auditing.impl.AuditAuthRequestEventFactory;
+import org.openecomp.sdc.be.auditing.impl.AuditConsumerEventFactory;
+import org.openecomp.sdc.be.auditing.impl.AuditEcompOpEnvEventFactory;
+import org.openecomp.sdc.be.auditing.impl.AuditGetUebClusterEventFactory;
+import org.openecomp.sdc.be.auditing.impl.AuditingManager;
import org.openecomp.sdc.be.auditing.impl.category.AuditCategoryEventFactory;
import org.openecomp.sdc.be.auditing.impl.category.AuditGetCategoryHierarchyEventFactory;
-import org.openecomp.sdc.be.auditing.impl.distribution.*;
-import org.openecomp.sdc.be.auditing.impl.externalapi.*;
+import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDeployEventFactory;
+import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDownloadEventFactory;
+import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionEngineEventFactoryManager;
+import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionNotificationEventFactory;
+import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionStatusEventFactory;
+import org.openecomp.sdc.be.auditing.impl.distribution.AuditRegUnregDistributionEngineEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditActivateServiceExternalApiEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetExternalApiEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetListExternalApiEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditChangeLifecycleExternalApiEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateResourceExternalApiEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateServiceExternalApiEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCrudExternalApiArtifactEventFactory;
+import org.openecomp.sdc.be.auditing.impl.externalapi.AuditDownloadArtifactExternalApiEventFactory;
import org.openecomp.sdc.be.auditing.impl.resourceadmin.AuditResourceEventFactoryManager;
import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditGetUsersListEventFactory;
import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAccessEventFactory;
import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAdminEventFactory;
+import org.openecomp.sdc.be.components.distribution.engine.DmaapConsumer;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
@@ -54,36 +72,61 @@ import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ConsumerDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
-import org.openecomp.sdc.be.resources.data.auditing.model.*;
+import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
+import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
+import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
+import org.openecomp.sdc.be.resources.data.auditing.model.OperationalEnvAuditData;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
import org.openecomp.sdc.be.tosca.ToscaError;
+import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.enums.LogLevel;
+import org.openecomp.sdc.common.log.enums.Severity;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
import org.openecomp.sdc.common.util.ThreadLocalsHolder;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.MarkerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.springframework.beans.factory.annotation.Autowired;
@org.springframework.stereotype.Component("componentUtils")
public class ComponentsUtils {
private static final String CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE = "convert storage response {} to action response {}";
- private static final String INSIDE_AUDITING_FOR_AUDIT_ACTION = "Inside auditing for audit action {}";
- private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response";
- private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
- private static final Logger log = Logger.getLogger(ComponentsUtils.class);
+ private static final String INSIDE_AUDITING_FOR_AUDIT_ACTION = "Inside auditing for audit action {}";
+ private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response";
+ private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
+ private static final Logger log = Logger.getLogger(ComponentsUtils.class);
+ private static final String PARTNER_NAME = "UNKNOWN";
private final AuditingManager auditingManager;
private final ResponseFormatManager responseFormatManager;
+ private static LoggerSdcAudit audit = new LoggerSdcAudit(DmaapConsumer.class);
@Autowired
public ComponentsUtils(AuditingManager auditingManager) {
@@ -122,9 +165,11 @@ public class ComponentsUtils {
}
public <T> Either<T, ResponseFormat> convertJsonToObjectUsingObjectMapper(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
- T component = null;
+ T component;
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
+ mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
+
try {
log.trace("convert json to object. json=\n{}", data);
@@ -151,14 +196,14 @@ public class ComponentsUtils {
public ResponseFormat getResponseFormat(ActionStatus actionStatus, String... params) {
return responseFormatManager.getResponseFormat(actionStatus, params);
}
-
+
public ResponseFormat getResponseFormat(StorageOperationStatus storageStatus, String... params) {
return responseFormatManager.getResponseFormat(this.convertFromStorageResponse(storageStatus), params);
}
public <T> Either<List<T>, ResponseFormat> convertToResponseFormatOrNotFoundErrorToEmptyList(StorageOperationStatus storageOperationStatus) {
return storageOperationStatus.equals(StorageOperationStatus.NOT_FOUND) ? Either.left(Collections.emptyList()) :
- Either.right(getResponseFormat(storageOperationStatus));
+ Either.right(getResponseFormat(storageOperationStatus));
}
/**
@@ -258,7 +303,7 @@ public class ComponentsUtils {
* @param user
* @return
*/
- public ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
+ ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
if (user == null) {
return getResponseFormat(actionStatus);
}
@@ -324,28 +369,30 @@ public class ComponentsUtils {
return responseFormat;
}
- public ResponseFormat getInvalidContentErrorAndAudit(User user, String resourceName, AuditingActionEnum actionEnum) {
+ public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
- auditResource(responseFormat, user, resourceName, actionEnum);
+ auditAdminUserAction(actionEnum, user, null, null, responseFormat);
return responseFormat;
}
- public ResponseFormat getInvalidContentErrorForConsumerAndAudit(User user, ConsumerDefinition consumer, AuditingActionEnum actionEnum) {
+ public ResponseFormat getInvalidContentErrorAndAudit(User user, String resourceName, AuditingActionEnum actionEnum) {
ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
- auditConsumerCredentialsEvent(actionEnum, consumer, responseFormat, user);
+ auditResource(responseFormat, user, resourceName, actionEnum);
return responseFormat;
}
- public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
+
+
+ public ResponseFormat getInvalidContentErrorForConsumerAndAudit(User user, ConsumerDefinition consumer, AuditingActionEnum actionEnum) {
ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
- auditAdminUserAction(actionEnum, user, null, null, responseFormat);
+ auditConsumerCredentialsEvent(actionEnum, consumer, responseFormat, user);
return responseFormat;
}
- public ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
+ private ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
auditComponentAdmin(responseFormat, user, null, actionEnum, typeEnum);
@@ -444,8 +491,8 @@ public class ComponentsUtils {
.description(message)
.requestId(ThreadLocalsHolder.getUuid())
.build(),
- distributionData);
- getAuditingManager().auditEvent(factory);
+ distributionData);
+ getAuditingManager().auditEvent(factory);
}
public void auditExternalGetAsset(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
@@ -472,7 +519,7 @@ public class ComponentsUtils {
.status(responseFormat.getStatus())
.description(getMessageString(responseFormat))
.requestId(requestId)
- .build(),
+ .build(),
distributionData);
getAuditingManager().auditEvent(factory);
@@ -513,11 +560,11 @@ public class ComponentsUtils {
}
AuditEventFactory factory = new AuditChangeLifecycleExternalApiEventFactory(
CommonAuditData.newBuilder()
- .serviceInstanceId(serviceInstanceId)
- .requestId(requestId)
- .description(getMessageString(responseFormat))
- .status(responseFormat.getStatus())
- .build(),
+ .serviceInstanceId(serviceInstanceId)
+ .requestId(requestId)
+ .description(getMessageString(responseFormat))
+ .status(responseFormat.getStatus())
+ .build(),
resourceCommonInfo, distributionData,
prevResourceVersionInfo, currResourceVersionInfo,
invariantUuid, modifier);
@@ -559,10 +606,10 @@ public class ComponentsUtils {
}
AuditEventFactory factory = new AuditCrudExternalApiArtifactEventFactory(actionEnum,
CommonAuditData.newBuilder()
- .status(responseFormat.getStatus())
- .description(getMessageString(responseFormat))
- .requestId(requestId)
- .build(),
+ .status(responseFormat.getStatus())
+ .description(getMessageString(responseFormat))
+ .requestId(requestId)
+ .build(),
resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().build(), currResourceVersionInfo,
null, modifier, artifactData);
@@ -644,11 +691,11 @@ public class ComponentsUtils {
public void auditExternalActivateService(ResponseFormat responseFormat, DistributionData distributionData, String requestId, String serviceInstanceUuid, User modifier) {
AuditEventFactory factory = new AuditActivateServiceExternalApiEventFactory(
CommonAuditData.newBuilder()
- .serviceInstanceId(serviceInstanceUuid)
- .description(getMessageString(responseFormat))
- .status(responseFormat.getStatus())
- .requestId(requestId)
- .build(),
+ .serviceInstanceId(serviceInstanceUuid)
+ .description(getMessageString(responseFormat))
+ .status(responseFormat.getStatus())
+ .requestId(requestId)
+ .build(),
new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()), distributionData, "", modifier);
getAuditingManager().auditEvent(factory);
}
@@ -723,79 +770,79 @@ public class ComponentsUtils {
return responseEnum;
}
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case CONNECTION_FAILURE:
- case GRAPH_IS_LOCK:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
- case BAD_REQUEST:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case ENTITY_ALREADY_EXISTS:
- responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
- break;
- case PARENT_RESOURCE_NOT_FOUND:
- responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
- break;
- case MULTIPLE_PARENT_RESOURCE_FOUND:
- responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
- break;
- case NOT_FOUND:
- if (ComponentTypeEnum.RESOURCE == type) {
- responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
- } else if (ComponentTypeEnum.PRODUCT == type) {
- responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
- } else {
- responseEnum = ActionStatus.SERVICE_NOT_FOUND;
- }
- break;
- case FAILED_TO_LOCK_ELEMENT:
- responseEnum = ActionStatus.COMPONENT_IN_USE;
- break;
- case ARTIFACT_NOT_FOUND:
- responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
- break;
- case DISTR_ENVIRONMENT_NOT_AVAILABLE:
- responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
- break;
- case DISTR_ENVIRONMENT_NOT_FOUND:
- responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
- break;
- case DISTR_ENVIRONMENT_SENT_IS_INVALID:
- responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
- break;
- case INVALID_TYPE:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case INVALID_VALUE:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case CSAR_NOT_FOUND:
- responseEnum = ActionStatus.CSAR_NOT_FOUND;
- break;
- case PROPERTY_NAME_ALREADY_EXISTS:
- responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
- break;
- case MATCH_NOT_FOUND:
- responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
- break;
- case CATEGORY_NOT_FOUND:
- responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
- break;
- case INVALID_PROPERTY:
- responseEnum = ActionStatus.INVALID_PROPERTY;
- break;
- case COMPONENT_IS_ARCHIVED:
- responseEnum = ActionStatus.COMPONENT_IS_ARCHIVED;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
+ break;
+ case PARENT_RESOURCE_NOT_FOUND:
+ responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
+ break;
+ case MULTIPLE_PARENT_RESOURCE_FOUND:
+ responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
+ break;
+ case NOT_FOUND:
+ if (ComponentTypeEnum.RESOURCE == type) {
+ responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
+ } else if (ComponentTypeEnum.PRODUCT == type) {
+ responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
+ } else {
+ responseEnum = ActionStatus.SERVICE_NOT_FOUND;
+ }
+ break;
+ case FAILED_TO_LOCK_ELEMENT:
+ responseEnum = ActionStatus.COMPONENT_IN_USE;
+ break;
+ case ARTIFACT_NOT_FOUND:
+ responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
+ break;
+ case DISTR_ENVIRONMENT_NOT_AVAILABLE:
+ responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
+ break;
+ case DISTR_ENVIRONMENT_NOT_FOUND:
+ responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
+ break;
+ case DISTR_ENVIRONMENT_SENT_IS_INVALID:
+ responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
+ break;
+ case INVALID_TYPE:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case INVALID_VALUE:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case CSAR_NOT_FOUND:
+ responseEnum = ActionStatus.CSAR_NOT_FOUND;
+ break;
+ case PROPERTY_NAME_ALREADY_EXISTS:
+ responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
+ break;
+ case MATCH_NOT_FOUND:
+ responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
+ break;
+ case CATEGORY_NOT_FOUND:
+ responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
+ break;
+ case INVALID_PROPERTY:
+ responseEnum = ActionStatus.INVALID_PROPERTY;
+ break;
+ case COMPONENT_IS_ARCHIVED:
+ responseEnum = ActionStatus.COMPONENT_IS_ARCHIVED;
+ break;
case DECLARED_INPUT_USED_BY_OPERATION:
responseEnum = ActionStatus.DECLARED_INPUT_USED_BY_OPERATION;
break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
@@ -820,96 +867,96 @@ public class ComponentsUtils {
}
public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
- ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ ActionStatus responseEnum;
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case CONNECTION_FAILURE:
- case GRAPH_IS_LOCK:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
- case BAD_REQUEST:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case ENTITY_ALREADY_EXISTS:
- responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
- break;
- case SCHEMA_VIOLATION:
- responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
}
public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
- ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ ActionStatus responseEnum;
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case CONNECTION_FAILURE:
- case GRAPH_IS_LOCK:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
- case BAD_REQUEST:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case ENTITY_ALREADY_EXISTS:
- responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
- break;
- case SCHEMA_VIOLATION:
- responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
}
public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
- ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ ActionStatus responseEnum;
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case INVALID_ID:
- responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
- break;
- case INVALID_PROPERTY:
- responseEnum = ActionStatus.INVALID_PROPERTY;
- break;
- case GRAPH_IS_LOCK:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
- case BAD_REQUEST:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case MATCH_NOT_FOUND:
- responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
- break;
- case SCHEMA_VIOLATION:
- responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
- break;
- case NOT_FOUND:
- if (isRelation) {
- responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
- } else {
- responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
- }
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case INVALID_ID:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
+ break;
+ case INVALID_PROPERTY:
+ responseEnum = ActionStatus.INVALID_PROPERTY;
+ break;
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case MATCH_NOT_FOUND:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
+ break;
+ case NOT_FOUND:
+ if (isRelation) {
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
+ } else {
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
+ }
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
@@ -939,33 +986,33 @@ public class ComponentsUtils {
}
public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
- ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ ActionStatus responseEnum;
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case INVALID_ID:
- responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
- break;
- case GRAPH_IS_LOCK:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
- case BAD_REQUEST:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case MATCH_NOT_FOUND:
- responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
- break;
- case SCHEMA_VIOLATION:
- responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
- break;
- case NOT_FOUND:
- responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case INVALID_ID:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
+ break;
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case MATCH_NOT_FOUND:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
+ break;
+ case NOT_FOUND:
+ responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
@@ -1065,7 +1112,7 @@ public class ComponentsUtils {
}
- public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role, String apiKey, String status) {
+ public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role, String apiKey, String status) {
AuditEventFactory factory = AuditDistributionEngineEventFactoryManager.createDistributionEngineEventFactory(action,
environmentName, distributionTopicData, role, apiKey, status);
getAuditingManager().auditEvent(factory);
@@ -1076,7 +1123,10 @@ public class ComponentsUtils {
String environmentType, String action, String environmentName, String tenantContext) {
AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName,
environmentType, action, tenantContext);
- getAuditingManager().auditEvent(factory);
+ audit.startAuditFetchLog(PARTNER_NAME, DmaapConsumer.class.getName());
+ audit.logEntry(LogLevel.INFO, Severity.OK, null,
+ MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), environmentID);
+ getAuditingManager().auditEvent(factory, audit);
}
public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier, String environmentName, String currState,
@@ -1084,16 +1134,16 @@ public class ComponentsUtils {
AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
CommonAuditData.newBuilder()
- .serviceInstanceId(serviceUUID)
- .status(status)
- .description(description)
- .requestId(ThreadLocalsHolder.getUuid())
- .build(),
+ .serviceInstanceId(serviceUUID)
+ .status(status)
+ .description(description)
+ .requestId(ThreadLocalsHolder.getUuid())
+ .build(),
new ResourceCommonInfo(resourceName, resourceType),
ResourceVersionInfo.newBuilder()
- .state(currState)
- .version(currVersion)
- .build(),
+ .state(currState)
+ .version(currVersion)
+ .build(),
distributionId, modifier, topicName,
new OperationalEnvAuditData(environmentName, workloadContext, tenant));
@@ -1103,25 +1153,25 @@ public class ComponentsUtils {
public void auditAuthEvent(String url, String user, String authStatus, String realm) {
AuditEventFactory factory = new AuditAuthRequestEventFactory(
CommonAuditData.newBuilder()
- .requestId(ThreadLocalsHolder.getUuid())
- .build(),
+ .requestId(ThreadLocalsHolder.getUuid())
+ .build(),
user, url, realm, authStatus);
getAuditingManager().auditEvent(factory);
}
- public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime, String status, String errorReason) {
- ThreadLocalsHolder.setUuid(distributionId);
-
+ public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName,
+ String resourceUrl, String statusTime, String status,
+ String errorReason, LoggerSdcAudit audit) {
AuditEventFactory factory = new AuditDistributionStatusEventFactory(
CommonAuditData.newBuilder()
- .description(errorReason)
- .status(status)
- .requestId(distributionId)
- .build(),
+ .description(errorReason)
+ .status(status)
+ .requestId(distributionId)
+ .build(),
new DistributionData(consumerId, resourceUrl),
distributionId, topicName, statusTime);
- getAuditingManager().auditEvent(factory);
+ getAuditingManager().auditEvent(factory, audit);
}
public void auditGetUebCluster(String consumerId, String status, String description) {
@@ -1150,13 +1200,13 @@ public class ComponentsUtils {
AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
CommonAuditData.newBuilder()
- .requestId(ThreadLocalsHolder.getUuid())
- .status(appliedStatus)
- .build(),
+ .requestId(ThreadLocalsHolder.getUuid())
+ .status(appliedStatus)
+ .build(),
DistributionTopicData.newBuilder()
- .statusTopic(statusTopicName)
- .notificationTopic(notifTopicName)
- .build(),
+ .statusTopic(statusTopicName)
+ .notificationTopic(notifTopicName)
+ .build(),
consumerId, apiPublicKey, envName);
getAuditingManager().auditEvent(factory);
@@ -1166,11 +1216,11 @@ public class ComponentsUtils {
AuditEventFactory factory = new AuditDistributionDeployEventFactory(
CommonAuditData.newBuilder()
- .requestId(ThreadLocalsHolder.getUuid())
- .serviceInstanceId(serviceUUID)
- .status(status)
- .description(desc)
- .build(),
+ .requestId(ThreadLocalsHolder.getUuid())
+ .serviceInstanceId(serviceUUID)
+ .status(status)
+ .description(desc)
+ .build(),
new ResourceCommonInfo(serviceName, "Service"),
distributionId,
modifier,
@@ -1183,10 +1233,10 @@ public class ComponentsUtils {
public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat, User modifier) {
AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
CommonAuditData.newBuilder()
- .description(getMessageString(responseFormat))
- .status(responseFormat.getStatus())
- .requestId(ThreadLocalsHolder.getUuid())
- .build(),
+ .description(getMessageString(responseFormat))
+ .status(responseFormat.getStatus())
+ .requestId(ThreadLocalsHolder.getUuid())
+ .build(),
modifier, consumer);
getAuditingManager().auditEvent(factory);
@@ -1204,6 +1254,13 @@ public class ComponentsUtils {
getAuditingManager().auditEvent(factory);
}
+ public void auditAdminUserActionAndThrowException(AuditingActionEnum actionEnum, User modifier, User userBefore,
+ User userAfter, ActionStatus status, String... params) {
+ ResponseFormat responseFormat = getResponseFormat(status, params);
+ auditAdminUserAction(actionEnum, modifier, userBefore, userAfter, responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
+ }
+
public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
@@ -1217,6 +1274,10 @@ public class ComponentsUtils {
getAuditingManager().auditEvent(factory);
}
+ public void auditUserAccess(User user, ActionStatus status, String... params) {
+ auditUserAccess(user, getResponseFormat(status, params));
+ }
+
public void auditUserAccess(User user, ResponseFormat responseFormat) {
AuditEventFactory factory = new AuditUserAccessEventFactory(CommonAuditData.newBuilder()
@@ -1232,10 +1293,10 @@ public class ComponentsUtils {
public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(CommonAuditData.newBuilder()
- .description(getMessageString(responseFormat))
- .status(responseFormat.getStatus())
- .requestId(ThreadLocalsHolder.getUuid())
- .build(),
+ .description(getMessageString(responseFormat))
+ .status(responseFormat.getStatus())
+ .requestId(ThreadLocalsHolder.getUuid())
+ .build(),
user, details);
getAuditingManager().auditEvent(factory);
@@ -1278,18 +1339,18 @@ public class ComponentsUtils {
ActionStatus responseEnum;
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case ENTITY_ALREADY_EXISTS:
- responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
- break;
- case INVALID_ID:
- responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
+ break;
+ case INVALID_ID:
+ responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
@@ -1298,24 +1359,24 @@ public class ComponentsUtils {
public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
switch (resultStatus) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case ELEMENT_NOT_FOUND:
- if(elementType!= null && elementType == JsonPresentationFields.PROPERTY){
- responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
- }
- break;
- case INVALID_PROPERTY_DEFAULT_VALUE:
- case INVALID_PROPERTY_TYPE:
- case INVALID_PROPERTY_VALUE:
- case INVALID_PROPERTY_NAME:
- case MISSING_ENTRY_SCHEMA_TYPE:
- responseEnum = ActionStatus.INVALID_PROPERTY;
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case ELEMENT_NOT_FOUND:
+ if(elementType!= null && elementType == JsonPresentationFields.PROPERTY){
+ responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
+ }
+ break;
+ case INVALID_PROPERTY_DEFAULT_VALUE:
+ case INVALID_PROPERTY_TYPE:
+ case INVALID_PROPERTY_VALUE:
+ case INVALID_PROPERTY_NAME:
+ case MISSING_ENTRY_SCHEMA_TYPE:
+ responseEnum = ActionStatus.INVALID_PROPERTY;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
return responseEnum;
}
@@ -1368,87 +1429,87 @@ public class ComponentsUtils {
ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case CONNECTION_FAILURE:
- case GRAPH_IS_LOCK:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
- case BAD_REQUEST:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case ENTITY_ALREADY_EXISTS:
- responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
- break;
- case SCHEMA_VIOLATION:
- responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
- break;
- case NOT_FOUND:
- responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
+ break;
+ case NOT_FOUND:
+ responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
}
public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
- ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ ActionStatus responseEnum;
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case CONNECTION_FAILURE:
- case GRAPH_IS_LOCK:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
- case BAD_REQUEST:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case ENTITY_ALREADY_EXISTS:
- responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
- break;
- case SCHEMA_VIOLATION:
- responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
}
public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
- ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
+ ActionStatus responseEnum;
switch (storageResponse) {
- case OK:
- responseEnum = ActionStatus.OK;
- break;
- case CONNECTION_FAILURE:
- case GRAPH_IS_LOCK:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
- case BAD_REQUEST:
- responseEnum = ActionStatus.INVALID_CONTENT;
- break;
- case ENTITY_ALREADY_EXISTS:
- responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
- break;
- case SCHEMA_VIOLATION:
- responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
- break;
- case CANNOT_UPDATE_EXISTING_ENTITY:
- responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
- break;
- default:
- responseEnum = ActionStatus.GENERAL_ERROR;
- break;
+ case OK:
+ responseEnum = ActionStatus.OK;
+ break;
+ case CONNECTION_FAILURE:
+ case GRAPH_IS_LOCK:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
+ case BAD_REQUEST:
+ responseEnum = ActionStatus.INVALID_CONTENT;
+ break;
+ case ENTITY_ALREADY_EXISTS:
+ responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
+ break;
+ case SCHEMA_VIOLATION:
+ responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
+ break;
+ case CANNOT_UPDATE_EXISTING_ENTITY:
+ responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
+ break;
+ default:
+ responseEnum = ActionStatus.GENERAL_ERROR;
+ break;
}
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
@@ -1593,4 +1654,18 @@ public class ComponentsUtils {
log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
return responseEnum;
}
+
+ public ResponseFormat getResponseFormat(StorageException exception) {
+ ActionStatus status = convertFromStorageResponse(exception.getStorageOperationStatus());
+ return getResponseFormat(status, exception.getParams());
+ }
+
+
+ public List<UiLeftPaletteComponent> convertComponentToUiLeftPaletteComponentObject(List<Component> components) {
+ List<UiLeftPaletteComponent> uiLeftPaletteComponents = new ArrayList<>();
+ components.forEach(c-> uiLeftPaletteComponents.add(new UiLeftPaletteComponent(c)));
+ return uiLeftPaletteComponents;
+ }
+
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/DownloadArtifactLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/DownloadArtifactLogic.java
deleted file mode 100644
index fef5f86cf8..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/DownloadArtifactLogic.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*-
- * ============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.sdc.be.impl;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import fj.data.Either;
-import org.apache.commons.io.IOUtils;
-import org.apache.http.HttpStatus;
-import org.eclipse.jgit.util.Base64;
-import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
-import org.openecomp.sdc.be.info.ArtifactAccessInfo;
-import org.openecomp.sdc.be.info.ArtifactAccessList;
-import org.openecomp.sdc.be.info.ServletJsonResponse;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.StreamingOutput;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-public class DownloadArtifactLogic {
-
- private static final Logger log = Logger.getLogger(DownloadArtifactLogic.class);
-
- private Gson gson = new GsonBuilder().setPrettyPrinting().create();
-
- public Response downloadArtifact(final String artifactName, Either<? extends ESArtifactData, ResourceUploadStatus> getArtifactStatus, String artifactId) {
- Response response = null;
-
- if (getArtifactStatus.isRight()) {
- log.debug("Could not find artifact for with id: {}", artifactId);
- ResourceUploadStatus status = getArtifactStatus.right().value();
- if (status == ResourceUploadStatus.COMPONENT_NOT_EXIST)
- response = Response.status(HttpStatus.SC_NO_CONTENT).build();
- else
- response = Response.status(HttpStatus.SC_NOT_FOUND).build();
-
- return response;
- }
- // convert artifact to inputstream
- else {
- ESArtifactData artifactData = getArtifactStatus.left().value();
- byte[] artifactPayload = artifactData.getDataAsArray();
-
- log.debug("payload is encoded. perform decode");
- byte[] decodedPayload = Base64.decode(new String(artifactPayload));
- final InputStream artifactStream = new ByteArrayInputStream(decodedPayload);
- log.debug("found artifact for with id: {}", artifactId);
-
- // outputstream for response
- StreamingOutput stream = output -> {
- try {
- IOUtils.copy(artifactStream, output);
- } catch (IOException e) {
- log.debug("failed to copy artifact payload into response");
- throw new WebApplicationException(e);
- }
- };
- return Response.ok(stream).type(MediaType.APPLICATION_OCTET_STREAM_TYPE)
- .header("content-disposition", "attachment; filename = " + artifactName)
- .build();
-
- }
- }
-
- public List<ArtifactAccessInfo> convertArtifactList(List<? extends ESArtifactData> artifactsList, String servletPath) {
-
- List<ArtifactAccessInfo> artifactAccessList = new ArrayList<>();
- for (ESArtifactData artifact : artifactsList) {
- ArtifactAccessInfo accessInfo = new ArtifactAccessInfo(servletPath);
- artifactAccessList.add(accessInfo);
- }
- return artifactAccessList;
- }
-
- public Response createArtifactListResponse(final String serviceName, Either<List<ESArtifactData>, ResourceUploadStatus> getArtifactsStatus/*
- * List < ? extends IResourceData> artifactsList
- */, String servletPath) {
- Response response;
- List<ArtifactAccessInfo> artifactAccessInfos;
- if (getArtifactsStatus.isRight()) {
- // if there are no artifacts - return No-Content
- ResourceUploadStatus status = getArtifactsStatus.right().value();
- if (status == ResourceUploadStatus.COMPONENT_NOT_EXIST || status == ResourceUploadStatus.SERVICE_NOT_EXIST) {
- log.debug("resource {} does not exist", serviceName);
- response = Response.status(HttpStatus.SC_NOT_FOUND).entity("[]").build();
-
- } else {
- log.debug("No content was found for {}", serviceName);
- response = Response.status(HttpStatus.SC_NO_CONTENT).entity("[]").build();
- }
- return response;
- } else {
- List<? extends ESArtifactData> artifactsList = getArtifactsStatus.left().value();
- log.debug("{} artifacts were found for {}", artifactsList.size(), serviceName);
- artifactAccessInfos = convertArtifactList(artifactsList, servletPath);
-
- String artifactDataJson = gson.toJson(new ArtifactAccessList(artifactAccessInfos));
- response = Response.status(HttpStatus.SC_OK).entity(artifactDataJson).type(MediaType.APPLICATION_JSON_TYPE).build();
-
- return response;
- }
- }
-
- public Response buildResponse(int status, String errorMessage) {
-
- ServletJsonResponse jsonResponse = new ServletJsonResponse();
- jsonResponse.setDescription(errorMessage);
- jsonResponse.setSource(Constants.CATALOG_BE);
-
- return Response.status(status).entity(jsonResponse).build();
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ForwardingPathUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ForwardingPathUtils.java
index dc7965955f..d7ccc62c6a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ForwardingPathUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ForwardingPathUtils.java
@@ -38,7 +38,13 @@ import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.Service;
-import java.util.*;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
import java.util.stream.Collectors;
public class ForwardingPathUtils {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
index 7faf89cb89..4485db1a50 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServiceFilterUtils.java
@@ -16,11 +16,6 @@
package org.openecomp.sdc.be.impl;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
import org.javatuples.Pair;
import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
@@ -31,6 +26,12 @@ import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.ui.model.UIConstraint;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
public class ServiceFilterUtils {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java
index c8128a33fc..9687a4084a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ServletUtils.java
@@ -21,7 +21,7 @@
package org.openecomp.sdc.be.impl;
import com.google.gson.Gson;
-import org.openecomp.sdc.be.user.IUserBusinessLogic;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -32,7 +32,7 @@ public class ServletUtils {
private ComponentsUtils componentsUtils;
private Gson gson = new Gson();
@Resource
- private IUserBusinessLogic adminManager;
+ private UserBusinessLogic adminManager;
public ComponentsUtils getComponentsUtils() {
return componentsUtils;
@@ -42,7 +42,7 @@ public class ServletUtils {
return gson;
}
- public IUserBusinessLogic getUserAdmin() {
+ public UserBusinessLogic getUserAdmin() {
return adminManager;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessInfo.java
deleted file mode 100644
index 490684e20d..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessInfo.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*-
- * ============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.sdc.be.info;
-
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-
-public class ArtifactAccessInfo {
-
- public ArtifactAccessInfo() {
- }
-
- public ArtifactAccessInfo(ESArtifactData artifactData) {
- this.id = artifactData.getId();
- }
-
- public ArtifactAccessInfo(String servletContext) {
- StringBuilder urlBuilder = new StringBuilder();
- urlBuilder = urlBuilder.append(servletContext).append("/");
- urlBuilder.append("resources/")
- // .append(artifactData.getResourceId()).append("/")
- .append("artifacts/");
- this.url = urlBuilder.toString();
- }
-
- private String name;
- private String url;
- private String id;
- private String type;
- private String description;
- private String creator;
- private String creationTime;
- private String lastUpdater;
- private String lastUpdateTime;
- private String checksum;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getCreator() {
- return creator;
- }
-
- public void setCreator(String creator) {
- this.creator = creator;
- }
-
- public String getCreationTime() {
- return creationTime;
- }
-
- public void setCreationTime(String creationTime) {
- this.creationTime = creationTime;
- }
-
- public String getLastUpdater() {
- return lastUpdater;
- }
-
- public void setLastUpdater(String lastUpdater) {
- this.lastUpdater = lastUpdater;
- }
-
- public String getLastUpdateTime() {
- return lastUpdateTime;
- }
-
- public void setLastUpdateTime(String lastUpdateTime) {
- this.lastUpdateTime = lastUpdateTime;
- }
-
- public String getChecksum() {
- return checksum;
- }
-
- public void setChecksum(String checksum) {
- this.checksum = checksum;
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
index 8bf56df3da..6f07cbf98e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactTemplateInfo.java
@@ -34,7 +34,11 @@ import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
public class ArtifactTemplateInfo {
private static final Logger log = Logger.getLogger(ArtifactTemplateInfo.class);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java
index 1aad998e78..b7b3b4ed0a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatus.java
@@ -22,9 +22,10 @@
package org.openecomp.sdc.be.info;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
import java.util.Arrays;
import java.util.Optional;
-import org.openecomp.sdc.common.log.wrappers.Logger;
public enum DistributionStatus {
DEPLOYED("Deployed", "DEPLOYED");
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java
index f203e76419..7162778636 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/DistributionStatusInfo.java
@@ -22,8 +22,8 @@
package org.openecomp.sdc.be.info;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
-import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
public class DistributionStatusInfo {
@@ -36,7 +36,8 @@ public class DistributionStatusInfo {
DistributionStatusInfo() {
}
- public DistributionStatusInfo(ESTimeBasedEvent distributionStatusEvent) {
+ public DistributionStatusInfo(AuditingGenericEvent distributionStatusEvent) {
+ super();
omfComponentID = String.valueOf(distributionStatusEvent.getFields().get(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName()));
timestamp = String.valueOf(distributionStatusEvent.getFields().get(AuditingFieldsKey.AUDIT_DISTRIBUTION_STATUS_TIME.getDisplayName()));
url = String.valueOf(distributionStatusEvent.getFields().get(AuditingFieldsKey.AUDIT_DISTRIBUTION_RESOURCE_URL.getDisplayName()));
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java
index 621485c7a1..d20df93737 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/GroupDefinitionInfo.java
@@ -190,4 +190,5 @@ public class GroupDefinitionInfo {
public String toString() {
return "GroupDefinitionInfo [" + super.toString() + ", isBase=" + isBase + ", artifacts=" + artifacts + "]";
}
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java
index 85618a4c9a..0b39bdcb4b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/MergedArtifactInfo.java
@@ -23,7 +23,11 @@ package org.openecomp.sdc.be.info;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.model.ArtifactDefinition;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
public class MergedArtifactInfo {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java
index 5a09362483..e21c2a5e19 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/info/ServiceInfo.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.info;
import com.google.common.annotations.VisibleForTesting;
+
import java.util.List;
public class ServiceInfo {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java b/catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java
index 34ebf14ae5..7d9de792d1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/listen/BEAppContextListener.java
@@ -21,7 +21,6 @@
package org.openecomp.sdc.be.listen;
import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.monitoring.BeMonitoringService;
import org.openecomp.sdc.common.api.Constants;
@@ -54,9 +53,6 @@ public class BEAppContextListener extends AppContextListener implements ServletC
WebAppContextWrapper webAppContextWrapper = new WebAppContextWrapper();
context.getServletContext().setAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR, webAppContextWrapper);
- DownloadArtifactLogic downloadArtifactLogic = new DownloadArtifactLogic();
- context.getServletContext().setAttribute(Constants.DOWNLOAD_ARTIFACT_LOGIC_ATTR, downloadArtifactLogic);
-
context.getServletContext().setAttribute(Constants.ASDC_RELEASE_VERSION_ATTR, getVersionFromManifest(context));
// Monitoring service
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/ComponentInstanceInputMixin.java b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/ComponentInstanceInputMixin.java
new file mode 100644
index 0000000000..547ae1738d
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/ComponentInstanceInputMixin.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.mixin;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.view.MixinTarget;
+
+import java.util.List;
+
+@MixinTarget(target = ComponentInstanceInput.class)
+public abstract class ComponentInstanceInputMixin extends InputDefinitionMixin{
+ @JsonProperty
+ abstract String getComponentInstanceId();
+ @JsonProperty
+ abstract String getComponentInstanceName();
+ @JsonProperty
+ abstract List<String> getPath();
+ @JsonProperty
+ abstract List<PropertyRule> getRules();
+ @JsonProperty
+ abstract String getValueUniqueUid();
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/ComponentInstancePropertyMixin.java b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/ComponentInstancePropertyMixin.java
new file mode 100644
index 0000000000..f9c41fb2d3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/ComponentInstancePropertyMixin.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.mixin;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.view.MixinTarget;
+
+import java.util.List;
+
+@MixinTarget(target = ComponentInstanceProperty.class)
+public abstract class ComponentInstancePropertyMixin extends PropertyDefinitionMixin {
+
+ @JsonProperty
+ abstract String getComponentInstanceId();
+ @JsonProperty
+ abstract String getComponentInstanceName();
+ @JsonProperty
+ abstract List<String> getPath();
+ @JsonProperty
+ abstract List<PropertyRule> getRules();
+ @JsonProperty
+ abstract String getValueUniqueUid();
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessList.java b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/InputDefinitionMixin.java
index fa3a333b44..dba7ff5918 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/info/ArtifactAccessList.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/InputDefinitionMixin.java
@@ -2,43 +2,37 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- * Modifications copyright (c) 2019 Nokia
- * ================================================================================
*/
-package org.openecomp.sdc.be.info;
-
-import java.util.List;
-
-public class ArtifactAccessList {
-
- ArtifactAccessList() {}
+package org.openecomp.sdc.be.mixin;
- private List<ArtifactAccessInfo> artifacts;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.view.MixinTarget;
- public ArtifactAccessList(List<ArtifactAccessInfo> artifacts) {
- this.artifacts = artifacts;
- }
+import java.util.List;
- public List<ArtifactAccessInfo> getArtifacts() {
- return artifacts;
- }
+@MixinTarget(target = InputDefinition.class)
+public abstract class InputDefinitionMixin extends PropertyDefinitionMixin {
- public void setArtifacts(List<ArtifactAccessInfo> artifacts) {
- this.artifacts = artifacts;
- }
+ @JsonProperty
+ abstract List<ComponentInstanceInput> getInputs();
+ @JsonProperty
+ abstract List<ComponentInstanceProperty> getProperties();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java
index b15be60b9f..6a5d245149 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PolicyCompositionMixin.java
@@ -21,13 +21,14 @@
package org.openecomp.sdc.be.mixin;
import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.List;
-import java.util.Map;
import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.view.Mixin;
import org.openecomp.sdc.be.view.MixinTarget;
+import java.util.List;
+import java.util.Map;
+
@MixinTarget(target = PolicyDataDefinition.class)
public abstract class PolicyCompositionMixin extends Mixin {
@JsonProperty
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PropertyDefinitionMixin.java b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PropertyDefinitionMixin.java
new file mode 100644
index 0000000000..17dcf96113
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/mixin/PropertyDefinitionMixin.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.mixin;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openecomp.sdc.be.datatypes.elements.Annotation;
+import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.view.Mixin;
+import org.openecomp.sdc.be.view.MixinTarget;
+
+import java.util.List;
+
+@MixinTarget(target = PropertyDefinition.class)
+public abstract class PropertyDefinitionMixin extends Mixin {
+
+ @JsonProperty
+ abstract List<Annotation> getAnnotations();
+ @JsonProperty
+ abstract String getDefaultValue();
+ @JsonProperty
+ abstract String getDescription();
+ @JsonProperty
+ abstract List<GetInputValueDataDefinition> getGetInputValues();
+ @JsonProperty
+ abstract String getInputId();
+ @JsonProperty
+ abstract String getInputPath();
+ @JsonProperty
+ abstract String getInstanceUniqueId();
+ @JsonProperty
+ abstract String getLabel();
+ @JsonProperty
+ abstract String getName();
+ @JsonProperty
+ abstract String getParentUniqueId();
+ @JsonProperty
+ abstract String getPropertyId();
+ @JsonProperty
+ abstract SchemaDefinition getSchema();
+ @JsonProperty
+ abstract SchemaDefinition getSchemaProperty();
+ @JsonProperty
+ abstract String getSchemaType();
+ @JsonProperty
+ abstract String getStatus();
+ @JsonProperty
+ abstract String getType();
+ @JsonProperty
+ abstract String getUniqueId();
+ @JsonProperty
+ abstract String getValue();
+ @JsonProperty
+ abstract boolean isGetInputProperty();
+ @JsonProperty
+ abstract List<PropertyConstraint> getConstraints();
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java b/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java
deleted file mode 100644
index bfda04e4e7..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/monitoring/EsGateway.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*-
- * ============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.sdc.be.monitoring;
-
-import org.eclipse.jetty.proxy.ProxyServlet;
-import org.openecomp.sdc.be.components.impl.MonitoringBusinessLogic;
-import org.openecomp.sdc.be.impl.WebAppContextWrapper;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.web.context.WebApplicationContext;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-
-public class EsGateway extends ProxyServlet {
-
- private static final long serialVersionUID = 1L;
- private static final Logger log = Logger.getLogger(EsGateway.class);
-
- @Override
- public String rewriteTarget(HttpServletRequest request) {
-
- String originalUrl = request.getRequestURI();
- String redirectedUrl = getModifiedUrl(request);
-
- log.debug("EsGateway Redirecting request from: {} , to: {}", originalUrl, redirectedUrl);
- return redirectedUrl;
- }
-
- public String getModifiedUrl(HttpServletRequest request) {
- String esHost = null;
- String esPort = null;
- MonitoringBusinessLogic monitoringBL = getMonitoringBL(request.getSession().getServletContext());
- if (monitoringBL == null) {
- log.error("failed to retrieve monitoringBL.");
- } else {
- esHost = monitoringBL.getEsHost();
- esPort = monitoringBL.getEsPort();
- }
-
- //String scheme = request.getScheme(); esGateway HTTP
- String scheme = "http";
- String contextPath = request.getContextPath(); // /mywebapp
- String servletPath = request.getServletPath(); // /servlet/MyServlet
- String pathInfo = request.getPathInfo(); // /a/b;c=123
- String queryString = request.getQueryString(); // d=789
-
- StringBuilder url = new StringBuilder();
- url.append(scheme).append("://").append(esHost);
- url.append(":").append(esPort);
- url.append(contextPath).append(servletPath);
-
- if (pathInfo != null) {
- url.append(pathInfo);
- }
- if (queryString != null) {
- url.append("?").append(queryString);
- }
-
- return url.toString().replace("/sdc2/esGateway/", "/");
-
- }
-
- protected MonitoringBusinessLogic getMonitoringBL(ServletContext context) {
-
- WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
- WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
-
- return webApplicationContext.getBean(MonitoringBusinessLogic.class);
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
index 3606b010ce..c0f75311f7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java
@@ -7,9 +7,9 @@
* 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.
@@ -26,20 +26,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import fj.data.Either;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Supplier;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.IOUtils;
@@ -51,7 +37,9 @@ import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -64,7 +52,6 @@ import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.servlets.ResourceUploadServlet.ResourceAuthorityTypeEnum;
-import org.openecomp.sdc.be.user.IUserBusinessLogic;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.be.utils.TypeUtils;
@@ -79,6 +66,21 @@ import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
import org.yaml.snakeyaml.Yaml;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+
public abstract class AbstractValidationsServlet extends BeGenericServlet {
private static final Logger log = Logger.getLogger(AbstractValidationsServlet.class);
@@ -122,16 +124,16 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
else {
- IUserBusinessLogic userAdmin = getServletUtils().getUserAdmin();
- Either<User, ActionStatus> eitherCreator = userAdmin.getUser(userUserId, false);
- if (eitherCreator.isRight()) {
+ UserBusinessLogic userAdmin = getServletUtils().getUserAdmin();
+ try {
+ User user = userAdmin.getUser(userUserId);
+ userWrapper.setInnerElement(user);
+ } catch (ComponentException ce) {
log.info("user is not listed. userId={}", userUserId);
User user = new User();
user.setUserId(userUserId);
Response response = returnMissingInformation(user);
responseWrapper.setInnerElement(response);
- } else {
- userWrapper.setInnerElement(eitherCreator.left().value());
}
}
}
@@ -358,7 +360,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
if (!isValid) {
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE);
Response errorResponse = buildErrorResponse(responseFormat);
- getComponentsUtils().auditResource(responseFormat, user, uploadResourceInfo.getName(), AuditingActionEnum.IMPORT_RESOURCE);
+ getComponentsUtils().auditResource(responseFormat, user, uploadResourceInfo.getName(), AuditingActionEnum.IMPORT_RESOURCE);
responseWrapper.setInnerElement(errorResponse);
}
@@ -371,7 +373,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
if (!isYamlValid) {
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_YAML_FILE);
Response errorResponse = buildErrorResponse(responseFormat);
- getComponentsUtils().auditResource(responseFormat, user, uploadResourceInfo.getName(), AuditingActionEnum.IMPORT_RESOURCE);
+ getComponentsUtils().auditResource(responseFormat, user, uploadResourceInfo.getName(), AuditingActionEnum.IMPORT_RESOURCE);
responseWrapper.setInnerElement(errorResponse);
}
}
@@ -390,7 +392,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
if (!isValid) {
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_RESOURCE_NAMESPACE);
Response errorResponse = buildErrorResponse(responseFormat);
- getComponentsUtils().auditResource(responseFormat, user, resourceInfo.getName(), AuditingActionEnum.IMPORT_RESOURCE);
+ getComponentsUtils().auditResource(responseFormat, user, resourceInfo.getName(), AuditingActionEnum.IMPORT_RESOURCE);
responseWrapper.setInnerElement(errorResponse);
} else {
String str1 = nameSpace.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
@@ -405,7 +407,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
- protected void validatePayloadIsSingleResource(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user, String toscaPayload) {
+ private void validatePayloadIsSingleResource(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user, String toscaPayload) {
log.debug("checking payload contains single resource");
boolean isValid;
Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(toscaPayload);
@@ -419,13 +421,13 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
if (!isValid) {
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NOT_SINGLE_RESOURCE);
Response errorResponse = buildErrorResponse(responseFormat);
- getComponentsUtils().auditResource(responseFormat, user, uploadResourceInfo.getName(), AuditingActionEnum.IMPORT_RESOURCE);
+ getComponentsUtils().auditResource(responseFormat, user, uploadResourceInfo.getName(), AuditingActionEnum.IMPORT_RESOURCE);
responseWrapper.setInnerElement(errorResponse);
}
}
- protected void validatePayloadIsNotService(Wrapper<Response> responseWrapper, User user, UploadResourceInfo uploadResourceInfo, String toscaPayload) {
+ private void validatePayloadIsNotService(Wrapper<Response> responseWrapper, User user, UploadResourceInfo uploadResourceInfo, String toscaPayload) {
log.debug("checking payload is not a tosca service");
Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(toscaPayload);
Either<Object, ResultStatusEnum> toscaElement = ImportUtils.findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL);
@@ -439,7 +441,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
- protected void validateToscaTemplatePayloadName(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user) {
+ private void validateToscaTemplatePayloadName(Wrapper<Response> responseWrapper, UploadResourceInfo uploadResourceInfo, User user) {
String toscaTemplatePayloadName = uploadResourceInfo.getPayloadName();
boolean isValidSuffix = false;
if (toscaTemplatePayloadName != null && !toscaTemplatePayloadName.isEmpty()) {
@@ -456,7 +458,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
- protected void validateMD5(Wrapper<Response> responseWrapper, User user, UploadResourceInfo resourceInfo, HttpServletRequest request, String resourceInfoJsonString) {
+ private void validateMD5(Wrapper<Response> responseWrapper, User user, UploadResourceInfo resourceInfo, HttpServletRequest request, String resourceInfoJsonString) {
boolean isValid;
String recievedMD5 = request.getHeader(Constants.MD5_HEADER);
if (recievedMD5 == null) {
@@ -473,35 +475,26 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- protected void validateComponentType(Wrapper<Response> responseWrapper, Wrapper<ComponentTypeEnum> componentTypeWrapper, String componentType) {
- boolean isValid;
+ ComponentTypeEnum validateComponentType(String componentType) {
if (componentType == null) {
- isValid = false;
- } else {
- if (ComponentTypeEnum.RESOURCE_PARAM_NAME.equalsIgnoreCase(componentType)) {
- isValid = true;
- componentTypeWrapper.setInnerElement(ComponentTypeEnum.RESOURCE);
- } else if (ComponentTypeEnum.SERVICE_PARAM_NAME.equalsIgnoreCase(componentType)) {
- isValid = true;
- componentTypeWrapper.setInnerElement(ComponentTypeEnum.SERVICE);
- } else {
- isValid = false;
- }
+ throw new ByActionStatusComponentException(ActionStatus.UNSUPPORTED_ERROR);
}
- if (!isValid) {
- log.debug("Invalid componentType:{}", componentType);
- responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, componentType)));
+ if (ComponentTypeEnum.RESOURCE_PARAM_NAME.equalsIgnoreCase(componentType)) {
+ return ComponentTypeEnum.RESOURCE;
+ }
+ if (ComponentTypeEnum.SERVICE_PARAM_NAME.equalsIgnoreCase(componentType)) {
+ return ComponentTypeEnum.SERVICE;
}
+ log.debug("Invalid componentType:{}", componentType);
+ throw new ByActionStatusComponentException(ActionStatus.UNSUPPORTED_ERROR, componentType);
}
- protected Either<ComponentTypeEnum, ResponseFormat> convertToComponentType(String componentType) {
- Wrapper<Response> errorWrapper = new Wrapper<>();
- Wrapper<ComponentTypeEnum> componentWrapper = new Wrapper<>();
- validateComponentType(errorWrapper, componentWrapper, componentType);
- return errorWrapper.isEmpty() ? Either.left(componentWrapper.getInnerElement()) : Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+
+ ComponentTypeEnum convertToComponentType(String componentType) {
+ return validateComponentType(componentType);
}
- protected void fillToscaTemplateFromJson(Wrapper<Response> responseWrapper, Wrapper<String> yamlStringWrapper, User user, UploadResourceInfo resourceInfo) {
+ private void fillToscaTemplateFromJson(Wrapper<Response> responseWrapper, Wrapper<String> yamlStringWrapper, User user, UploadResourceInfo resourceInfo) {
if (resourceInfo.getPayloadData() == null || resourceInfo.getPayloadData().isEmpty()) {
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_RESOURCE_PAYLOAD);
Response errorResponse = buildErrorResponse(responseFormat);
@@ -515,7 +508,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
- protected void fillPayload(Wrapper<Response> responseWrapper, Wrapper<UploadResourceInfo> uploadResourceInfoWrapper, Wrapper<String> yamlStringWrapper, User user, String resourceInfoJsonString, ResourceAuthorityTypeEnum resourceAuthorityEnum,
+ void fillPayload(Wrapper<Response> responseWrapper, Wrapper<UploadResourceInfo> uploadResourceInfoWrapper, Wrapper<String> yamlStringWrapper, User user, String resourceInfoJsonString, ResourceAuthorityTypeEnum resourceAuthorityEnum,
File file) throws ZipException {
if (responseWrapper.isEmpty()) {
@@ -579,11 +572,11 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- protected void commonGeneralValidations(Wrapper<Response> responseWrapper, Wrapper<User> userWrapper, Wrapper<UploadResourceInfo> uploadResourceInfoWrapper, ResourceAuthorityTypeEnum resourceAuthorityEnum, String userUserId,
- String resourceInfoJsonString) {
+ void commonGeneralValidations(Wrapper<Response> responseWrapper, Wrapper<User> userWrapper, Wrapper<UploadResourceInfo> uploadResourceInfoWrapper, ResourceAuthorityTypeEnum resourceAuthorityEnum, String userId,
+ String resourceInfoJsonString) {
if (responseWrapper.isEmpty()) {
- validateUserExist(responseWrapper, userWrapper, userUserId);
+ validateUserExist(responseWrapper, userWrapper, userId);
}
if (responseWrapper.isEmpty()) {
@@ -613,7 +606,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- protected void importUIValidations(Wrapper<Response> responseWrapper, UploadResourceInfo resourceInfo, User user, HttpServletRequest request, String resourceInfoJsonString) {
+ private void importUIValidations(Wrapper<Response> responseWrapper, UploadResourceInfo resourceInfo, User user, HttpServletRequest request, String resourceInfoJsonString) {
if (responseWrapper.isEmpty()) {
validateMD5(responseWrapper, user, resourceInfo, request, resourceInfoJsonString);
}
@@ -622,7 +615,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- protected void commonPayloadValidations(Wrapper<Response> responseWrapper, Wrapper<String> yamlStringWrapper, User user, UploadResourceInfo uploadResourceInfo) {
+ void commonPayloadValidations(Wrapper<Response> responseWrapper, Wrapper<String> yamlStringWrapper, User user, UploadResourceInfo uploadResourceInfo) {
if (responseWrapper.isEmpty()) {
validatePayloadIsYml(responseWrapper, user, uploadResourceInfo, yamlStringWrapper.getInnerElement());
@@ -639,8 +632,8 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
- protected void handleImport(Wrapper<Response> responseWrapper, User user, UploadResourceInfo resourceInfoObject, String yamlAsString, ResourceAuthorityTypeEnum authority, boolean createNewVersion, String resourceUniqueId) {
- Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> createOrUpdateResponse = null;
+ void handleImport(Wrapper<Response> responseWrapper, User user, UploadResourceInfo resourceInfoObject, String yamlAsString, ResourceAuthorityTypeEnum authority, boolean createNewVersion, String resourceUniqueId) {
+ ImmutablePair<Resource, ActionStatus> createOrUpdateResponse = null;
Response response = null;
Object representation = null;
ImmutablePair<Resource, ActionStatus> importedResourceStatus = null;
@@ -655,11 +648,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
createOrUpdateResponse = resourceImportManager.importUserDefinedResource(yamlAsString, resourceInfoObject, user, false);
}
if (createOrUpdateResponse!= null){
- if(createOrUpdateResponse.isRight()){
- response = buildErrorResponse(createOrUpdateResponse.right().value());
- }else {
- importedResourceStatus = createOrUpdateResponse.left().value();
- }
+ importedResourceStatus = createOrUpdateResponse;
}
if(importedResourceStatus != null){
try {
@@ -675,18 +664,12 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
private ImmutablePair<Resource, ActionStatus> importResourceFromUICsar(UploadResourceInfo resourceInfoObject, User user, String resourceUniqueId) {
Resource newResource;
- ImmutablePair<Resource, ActionStatus> result = null;
ActionStatus actionStatus;
Resource resource = new Resource();
String payloadName = resourceInfoObject.getPayloadName();
fillResourceFromResourceInfoObject(resource, resourceInfoObject);
- Either<Map<String, byte[]>, ResponseFormat> csarUIPayloadRes = getCsarFromPayload(resourceInfoObject);
- if (csarUIPayloadRes.isRight()) {
- throw new ByResponseFormatComponentException(csarUIPayloadRes.right().value());
- }
- Map<String, byte[]> csarUIPayload = csarUIPayloadRes.left().value();
-
+ Map<String, byte[]> csarUIPayload = getCsarFromPayload(resourceInfoObject);
getAndValidateCsarYaml(csarUIPayload, resource, user, payloadName);
if (resourceUniqueId == null || resourceUniqueId.isEmpty()) {
@@ -772,18 +755,18 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- private Either<Map<String, byte[]>, ResponseFormat> getCsarFromPayload(UploadResourceInfo innerElement) {
+ private Map<String, byte[]> getCsarFromPayload(UploadResourceInfo innerElement) {
String csarUUID = innerElement.getPayloadName();
String payloadData = innerElement.getPayloadData();
if (payloadData == null) {
log.info("Failed to decode received csar {}", csarUUID);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_NOT_FOUND, csarUUID));
+ throw new ByActionStatusComponentException(ActionStatus.CSAR_NOT_FOUND, csarUUID);
}
byte[] decodedPayload = Base64.decodeBase64(payloadData.getBytes(StandardCharsets.UTF_8));
if (decodedPayload == null) {
log.info("Failed to decode received csar {}", csarUUID);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_NOT_FOUND, csarUUID));
+ throw new ByActionStatusComponentException(ActionStatus.CSAR_NOT_FOUND, csarUUID);
}
Map<String, byte[]> csar = null;
@@ -793,12 +776,11 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
log.info("Failed to unzip received csar {}", csarUUID, e);
}
if (MapUtils.isEmpty(csar)) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID, csarUUID));
}
- return Either.left(csar);
+ return csar;
}
- protected void validateInputStream(final HttpServletRequest request, Wrapper<String> dataWrapper, Wrapper<ResponseFormat> errorWrapper) throws IOException {
+ void validateInputStream(final HttpServletRequest request, Wrapper<String> dataWrapper, Wrapper<ResponseFormat> errorWrapper) throws IOException {
InputStream inputStream = request.getInputStream();
byte[] bytes = IOUtils.toByteArray(inputStream);
if (bytes == null || bytes.length == 0) {
@@ -810,7 +792,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
- protected <T> void validateClassParse(String data, Wrapper<T> parsedClassWrapper, Supplier<Class<T>> classGen, Wrapper<ResponseFormat> errorWrapper) {
+ <T> void validateClassParse(String data, Wrapper<T> parsedClassWrapper, Supplier<Class<T>> classGen, Wrapper<ResponseFormat> errorWrapper) {
try {
T parsedClass = gson.fromJson(data, classGen.get());
if (parsedClass == null) {
@@ -824,17 +806,18 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- protected void validateComponentInstanceBusinessLogic(HttpServletRequest request, String containerComponentType, Wrapper<ComponentInstanceBusinessLogic> blWrapper, Wrapper<ResponseFormat> errorWrapper) {
+ void validateComponentInstanceBusinessLogic(HttpServletRequest request, String containerComponentType, Wrapper<ComponentInstanceBusinessLogic> blWrapper, Wrapper<ResponseFormat> errorWrapper) {
ServletContext context = request.getSession().getServletContext();
- if (componentInstanceBusinessLogic == null) {
+ ComponentInstanceBusinessLogic componentInstanceLogic = getComponentInstanceBL(context);
+ if (componentInstanceLogic == null) {
log.debug("Unsupported component type {}", containerComponentType);
errorWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
} else {
- blWrapper.setInnerElement(componentInstanceBusinessLogic);
+ blWrapper.setInnerElement(componentInstanceLogic);
}
}
- protected <T> Response buildResponseFromElement(Wrapper<ResponseFormat> errorWrapper, Wrapper<T> attributeWrapper) throws IOException {
+ <T> Response buildResponseFromElement(Wrapper<ResponseFormat> errorWrapper, Wrapper<T> attributeWrapper) throws IOException {
Response response;
if (errorWrapper.isEmpty()) {
ObjectMapper mapper = new ObjectMapper();
@@ -864,14 +847,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- /**
- * Convert json to Object object
- * @param <T>
- * @param classSupplier
- * @param json
- * @return
- */
- public <T> Either<T, ResponseFormat> parseToObject(String json, Supplier<Class<T>> classSupplier) {
+ <T> Either<T, ResponseFormat> parseToObject(String json, Supplier<Class<T>> classSupplier) {
try {
T object = RepresentationUtils.fromRepresentation(json, classSupplier.get());
@@ -883,13 +859,6 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
}
}
- /**
- * Convert json to Object object
- * @param <T>
- * @param json
- * @param type
- * @return
- */
public <T> Either<List<T>, ResponseFormat> parseListOfObjects(String json, Type type) {
try {
List<T> listOfObjects = gson.fromJson(json, type);
@@ -900,4 +869,9 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet {
return Either.right(responseFormat);
}
}
+ protected void validateNotEmptyBody(String data) {
+ if (StringUtils.isEmpty(data)) {
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_BODY);
+ }
+ }
}
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 c137e6f072..b776f7ecf7 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
@@ -1,609 +1,637 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.AdditionalInformationBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Additional Information Servlet", description = "Additional Information Servlet"))
-@Singleton
-public class AdditionalInformationServlet extends BeGenericServlet {
-
- private static final Logger log = Logger.getLogger(AdditionalInformationServlet.class);
- private final AdditionalInformationBusinessLogic businessLogic;
-
- @Inject
- public AdditionalInformationServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- AdditionalInformationBusinessLogic businessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.businessLogic = businessLogic;
- }
-
- /**
- *
- * @param resourceId
- * @param data
- * @param request
- * @param userUserId
- * @return
- */
- @POST
- @Path("/resources/{resourceId}/additionalinfo")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Additional Information Label and Value", method = "POST",
- summary = "Returns created Additional Inforamtion property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Additional information created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response createResourceAdditionalInformationLabel(
- @Parameter(description = "resource id to update with new property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "Additional information key value to be created", required = true) String data,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userUserId) {
-
- 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)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Additional Information Label and Value", method = "POST",
- summary = "Returns created Additional Inforamtion property",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Additional information created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response createServiceAdditionalInformationLabel(
- @Parameter(description = "service id to update with new property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Parameter(description = "Additional information key value to be created", required = true) String data,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userUserId) {
-
- 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)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Additional Information Label and Value", method = "PUT",
- summary = "Returns updated Additional Inforamtion property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Additional information updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response updateResourceAdditionalInformationLabel(
- @Parameter(description = "resource id to update with new property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
- @Parameter(description = "Additional information key value to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- 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)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Additional Information Label and Value", method = "PUT",
- summary = "Returns updated Additional Inforamtion property",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Additional information updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response updateServiceAdditionalInformationLabel(
- @Parameter(description = "service id to update with new property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
- @Parameter(description = "Additional information key value to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- 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)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Additional Information Label and Value", method = "DELETE",
- summary = "Returns deleted Additional Inforamtion property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Additional information deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response updateResourceAdditionalInformationLabel(
- @Parameter(description = "resource id to update with new property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- 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)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Additional Information Label and Value", method = "DELETE",
- summary = "Returns deleted Additional Inforamtion property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Additional information deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response deleteServiceAdditionalInformationLabel(
- @Parameter(description = "service id to update with new property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- 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)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Additional Information by id", method = "GET",
- summary = "Returns Additional Inforamtion property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "fetched additional information"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response getResourceAdditionalInformationLabel(
- @Parameter(description = "resource id to update with new property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- 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)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Additional Information by id", method = "GET",
- summary = "Returns Additional Inforamtion property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "fetched additional information"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response getServiceAdditionalInformationLabel(
- @Parameter(description = "service id to update with new property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return getAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, labelId, request, userId);
-
- }
-
- /**
- *
- * @param resourceId
- * @param request
- * @param userId
- * @return
- */
- @GET
- @Path("/resources/{resourceId}/additionalinfo")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get all Additional Information under resource", method = "GET",
- summary = "Returns Additional Inforamtion property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "list of additional information"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response getAllResourceAdditionalInformationLabel(
- @Parameter(description = "resource id to update with new property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return getAllAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, request, userId);
-
- }
-
- /**
- *
- * @param serviceId
- * @param request
- * @param userId
- * @return
- */
- @GET
- @Path("/services/{serviceId}/additionalinfo")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get all Additional Information under service", method = "GET",
- summary = "Returns Additional Inforamtion property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "list of additional information"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
- public Response getAllServiceAdditionalInformationLabel(
- @Parameter(description = "service id to update with new property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return getAllAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, request, userId);
-
- }
-
- /**
- *
- * Create additional information property under given resource/service
- *
- * @param nodeType
- * @param uniqueId
- * @param request
- * @param userId
- * @param data
- * @return
- */
- protected Response createAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, HttpServletRequest request, String userId, String data) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- log.debug("modifier id is {}", userId);
- log.debug("data is {}", data);
-
- try {
- // convert json to AdditionalInfoParameterInfo
- AdditionalInfoParameterInfo additionalInfoParameterInfo = gson.fromJson(data, AdditionalInfoParameterInfo.class);
-
- Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.createAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId);
-
- if (either.isRight()) {
- ResponseFormat responseFormat = either.right().value();
- log.info("Failed to create additional information {}. Reason - {}", additionalInfoParameterInfo, responseFormat);
- return buildErrorResponse(responseFormat);
- }
-
- AdditionalInfoParameterInfo createdAI = either.left().value();
-
- log.debug("Additional information {}={} created successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
-
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
- return buildOkResponse(responseFormat, createdAI);
-
- } catch (Exception e) {
- log.debug("Create additional information failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
-
- }
-
- /**
- * Update additional information property by id under given resource/service
- *
- * @param nodeType
- * @param uniqueId
- * @param labelId
- * @param request
- * @param userId
- * @param data
- * @return
- */
- protected Response updateAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId, String data) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- log.debug("modifier id is {}", userId);
- log.debug("data is {}", data);
-
- try {
- // convert json to AdditionalInfoParameterInfo
- AdditionalInfoParameterInfo additionalInfoParameterInfo = gson.fromJson(data, AdditionalInfoParameterInfo.class);
-
- additionalInfoParameterInfo.setUniqueId(labelId);
-
- Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.updateAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId);
-
- if (either.isRight()) {
- ResponseFormat responseFormat = either.right().value();
- log.info("Failed to update additional information property. Reason - {}", responseFormat);
- return buildErrorResponse(responseFormat);
- }
-
- AdditionalInfoParameterInfo createdAI = either.left().value();
-
- log.debug("Additional information {}={} updated successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
-
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- return buildOkResponse(responseFormat, createdAI);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Additional Information");
- log.debug("Update additional information failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
-
- }
-
- /**
- *
- * Delete an additional information property by id under given resource/service
- *
- * @param nodeType
- * @param uniqueId
- * @param labelId
- * @param request
- * @param userId
- * @return
- */
- protected Response deleteAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- log.debug("modifier id is {}", userId);
-
- try {
-
- AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
- additionalInfoParameterInfo.setUniqueId(labelId);
-
- Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.deleteAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId);
-
- if (either.isRight()) {
- ResponseFormat responseFormat = either.right().value();
- log.info("Failed to update additional information property. Reason - {}", responseFormat);
- return buildErrorResponse(responseFormat);
- }
-
- AdditionalInfoParameterInfo createdAI = either.left().value();
-
- log.debug("Additional information {}={} deleted successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
-
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- return buildOkResponse(responseFormat, createdAI);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Additional Information");
- log.debug("Delete additional information failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
-
- }
-
- /**
- * Get a specific additional information property by a given id under given resource/service
- *
- * @param nodeType
- * @param uniqueId
- * @param labelId
- * @param request
- * @param userId
- * @return
- */
- protected Response getAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- log.debug("modifier id is {}", userId);
-
- try {
-
- AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
- additionalInfoParameterInfo.setUniqueId(labelId);
-
- Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.getAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId);
-
- if (either.isRight()) {
- ResponseFormat responseFormat = either.right().value();
- log.info("Failed to update additional information property. Reason - {}", responseFormat);
- return buildErrorResponse(responseFormat);
- }
-
- AdditionalInfoParameterInfo createdAI = either.left().value();
-
- log.debug("Additional information {}={} fetched successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
-
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- return buildOkResponse(responseFormat, createdAI);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Additional Information");
-
- log.debug("get additional information failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
-
- }
-
- /**
- * Get all additional information properties under given resource/service
- *
- * @param nodeType
- * @param uniqueId
- * @param request
- * @param userId
- * @return
- */
- protected Response getAllAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, HttpServletRequest request, String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- log.debug("modifier id is {}", userId);
-
- try {
- Either<AdditionalInformationDefinition, ResponseFormat> either = businessLogic.getAllAdditionalInformation(nodeType, uniqueId, userId);
- if (either.isRight()) {
- ResponseFormat responseFormat = either.right().value();
- log.info("Failed to update additional information property. Reason - {}", responseFormat);
- return buildErrorResponse(responseFormat);
- }
-
- AdditionalInformationDefinition additionalInformationDefinition = either.left().value();
-
- log.debug("All Additional information retrieved for component {} is {}", uniqueId, additionalInformationDefinition);
-
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- return buildOkResponse(responseFormat, additionalInformationDefinition);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Additional Information");
- log.debug("Get all addiotanl information properties failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
-
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.AdditionalInformationBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.AdditionalInformationDefinition;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Additional Information Servlet", description = "Additional Information Servlet"))
+@Controller
+public class AdditionalInformationServlet extends BeGenericServlet {
+
+ private static final Logger log = Logger.getLogger(AdditionalInformationServlet.class);
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final String MODIFIER_ID_IS = "modifier id is {}";
+ private static final String FAILED_TO_UPDATE_ADDITIONAL_INFO_PROPERTY = "Failed to update additional information property. Reason - {}";
+
+ private final AdditionalInformationBusinessLogic businessLogic;
+
+ @Inject
+ public AdditionalInformationServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ AdditionalInformationBusinessLogic businessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.businessLogic = businessLogic;
+ }
+
+ /**
+ *
+ * @param resourceId
+ * @param data
+ * @param request
+ * @param userUserId
+ * @return
+ */
+ @POST
+ @Path("/resources/{resourceId}/additionalinfo")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Additional Information Label and Value", method = "POST",
+ summary = "Returns created Additional Inforamtion property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Additional information created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createResourceAdditionalInformationLabel(
+ @Parameter(description = "resource id to update with new property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "Additional information key value to be created", required = true) String data,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userUserId) {
+
+ 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)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Additional Information Label and Value", method = "POST",
+ summary = "Returns created Additional Inforamtion property",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Additional information created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createServiceAdditionalInformationLabel(
+ @Parameter(description = "service id to update with new property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Parameter(description = "Additional information key value to be created", required = true) String data,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userUserId) {
+
+ 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)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Additional Information Label and Value", method = "PUT",
+ summary = "Returns updated Additional Inforamtion property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Additional information updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateResourceAdditionalInformationLabel(
+ @Parameter(description = "resource id to update with new property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
+ @Parameter(description = "Additional information key value to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ 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)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Additional Information Label and Value", method = "PUT",
+ summary = "Returns updated Additional Inforamtion property",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Additional information updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateServiceAdditionalInformationLabel(
+ @Parameter(description = "service id to update with new property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
+ @Parameter(description = "Additional information key value to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ 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)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Additional Information Label and Value", method = "DELETE",
+ summary = "Returns deleted Additional Inforamtion property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Additional information deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateResourceAdditionalInformationLabel(
+ @Parameter(description = "resource id to update with new property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ 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)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Additional Information Label and Value", method = "DELETE",
+ summary = "Returns deleted Additional Inforamtion property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Additional information deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteServiceAdditionalInformationLabel(
+ @Parameter(description = "service id to update with new property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ 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)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Additional Information by id", method = "GET",
+ summary = "Returns Additional Inforamtion property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "fetched additional information"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getResourceAdditionalInformationLabel(
+ @Parameter(description = "resource id to update with new property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ 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)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Additional Information by id", method = "GET",
+ summary = "Returns Additional Inforamtion property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "fetched additional information"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getServiceAdditionalInformationLabel(
+ @Parameter(description = "service id to update with new property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Parameter(description = "label id", required = true) @PathParam("labelId") final String labelId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, labelId, request, userId);
+
+ }
+
+ /**
+ *
+ * @param resourceId
+ * @param request
+ * @param userId
+ * @return
+ */
+ @GET
+ @Path("/resources/{resourceId}/additionalinfo")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get all Additional Information under resource", method = "GET",
+ summary = "Returns Additional Inforamtion property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "list of additional information"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getAllResourceAdditionalInformationLabel(
+ @Parameter(description = "resource id to update with new property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getAllAdditionalInformationLabelForComponent(NodeTypeEnum.Resource, resourceId, request, userId);
+
+ }
+
+ /**
+ *
+ * @param serviceId
+ * @param request
+ * @param userId
+ * @return
+ */
+ @GET
+ @Path("/services/{serviceId}/additionalinfo")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get all Additional Information under service", method = "GET",
+ summary = "Returns Additional Inforamtion property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "list of additional information"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Additional information key already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getAllServiceAdditionalInformationLabel(
+ @Parameter(description = "service id to update with new property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getAllAdditionalInformationLabelForComponent(NodeTypeEnum.Service, serviceId, request, userId);
+
+ }
+
+ /**
+ *
+ * Create additional information property under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param request
+ * @param userId
+ * @param data
+ * @return
+ */
+ protected Response createAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, HttpServletRequest request, String userId, String data) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ log.debug(MODIFIER_ID_IS, userId);
+ log.debug("data is {}", data);
+
+ try {
+ // convert json to AdditionalInfoParameterInfo
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = gson.fromJson(data, AdditionalInfoParameterInfo.class);
+
+ // create the new property
+
+ Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.createAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId);
+
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info("Failed to create additional information {}. Reason - {}", additionalInfoParameterInfo, responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInfoParameterInfo createdAI = either.left().value();
+
+ log.debug("Additional information {}={} created successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, createdAI);
+
+ } catch (Exception e) {
+ log.debug("Create additional information failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ /**
+ * Update additional information property by id under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param labelId
+ * @param request
+ * @param userId
+ * @param data
+ * @return
+ */
+ protected Response updateAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId, String data) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ log.debug(MODIFIER_ID_IS, userId);
+ log.debug("data is {}", data);
+
+ try {
+ // convert json to AdditionalInfoParameterInfo
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = gson.fromJson(data, AdditionalInfoParameterInfo.class);
+
+ // create the new property
+
+ additionalInfoParameterInfo.setUniqueId(labelId);
+
+ Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.updateAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId);
+
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info(FAILED_TO_UPDATE_ADDITIONAL_INFO_PROPERTY, responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInfoParameterInfo createdAI = either.left().value();
+
+ log.debug("Additional information {}={} updated successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, createdAI);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Additional Information");
+ log.debug("Update additional information failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ /**
+ *
+ * Delete an additional information property by id under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param labelId
+ * @param request
+ * @param userId
+ * @return
+ */
+ protected Response deleteAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ try {
+
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
+ additionalInfoParameterInfo.setUniqueId(labelId);
+
+ Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.deleteAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId);
+
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info(FAILED_TO_UPDATE_ADDITIONAL_INFO_PROPERTY, responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInfoParameterInfo createdAI = either.left().value();
+
+ log.debug("Additional information {}={} deleted successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, createdAI);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Additional Information");
+ log.debug("Delete additional information failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ /**
+ * Get a specific additional information property by a given id under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param labelId
+ * @param request
+ * @param userId
+ * @return
+ */
+ protected Response getAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, String labelId, HttpServletRequest request, String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ try {
+
+ // create the new property
+
+
+ AdditionalInfoParameterInfo additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
+ additionalInfoParameterInfo.setUniqueId(labelId);
+
+ Either<AdditionalInfoParameterInfo, ResponseFormat> either = businessLogic.getAdditionalInformation(nodeType, uniqueId, additionalInfoParameterInfo, userId);
+
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info(FAILED_TO_UPDATE_ADDITIONAL_INFO_PROPERTY, responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInfoParameterInfo createdAI = either.left().value();
+
+ log.debug("Additional information {}={} fetched successfully with id {}", createdAI.getKey(), createdAI.getValue(), createdAI.getUniqueId());
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, createdAI);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Additional Information");
+
+ log.debug("get additional information failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ /**
+ * Get all additional information properties under given resource/service
+ *
+ * @param nodeType
+ * @param uniqueId
+ * @param request
+ * @param userId
+ * @return
+ */
+ protected Response getAllAdditionalInformationLabelForComponent(NodeTypeEnum nodeType, String uniqueId, HttpServletRequest request, String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ try {
+
+
+
+ Either<AdditionalInformationDefinition, ResponseFormat> either = businessLogic.getAllAdditionalInformation(nodeType, uniqueId, userId);
+ if (either.isRight()) {
+ ResponseFormat responseFormat = either.right().value();
+ log.info(FAILED_TO_UPDATE_ADDITIONAL_INFO_PROPERTY, responseFormat);
+ return buildErrorResponse(responseFormat);
+ }
+
+ AdditionalInformationDefinition additionalInformationDefinition = either.left().value();
+
+ log.debug("All Additional information retrieved for component {} is {}", uniqueId, additionalInformationDefinition);
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ return buildOkResponse(responseFormat, additionalInformationDefinition);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Additional Information");
+ log.debug("Get all addiotanl information properties failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java
index 3dd582c07e..8c3ca37524 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArchiveEndpoint.java
@@ -1,186 +1,219 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import com.jcabi.aspects.Loggable;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import javax.inject.Inject;
-import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.catalog.CatalogComponent;
-import org.openecomp.sdc.common.api.Constants;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestBody;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Archive Endpoint"))
-@Controller
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class ArchiveEndpoint {
-
- private final ArchiveBusinessLogic archiveBusinessLogic;
-
- @Inject
- public ArchiveEndpoint(ArchiveBusinessLogic archiveBusinessLogic) {
- this.archiveBusinessLogic = archiveBusinessLogic;
- }
-
- @POST
- @Path("/resources/{componentId}/archive")
- @Operation(description = "Archive Resource", method = "POST", summary = "Marks a resource as archived. Can be restored with restore action", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Archive successful"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Resource not found"),
- @ApiResponse(responseCode = "500", description = "Internal Error")
- })
- public Response archiveResources(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- archiveBusinessLogic.archiveComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
- return Response.ok().build();
- }
-
- @POST
- @Path("/resources/{componentId}/restore")
- @Operation(description = "Restore Resource", method = "POST", summary = "Restores a resource from archive.", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Restore successful"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Resource not found"),
- @ApiResponse(responseCode = "500", description = "Internal Error")
- })
- public Response restoreResource(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- archiveBusinessLogic.restoreComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
- return Response.ok().build();
- }
-
- @POST
- @Path("/services/{componentId}/archive")
- @Operation(description = "Archive Service", method = "POST", summary = "Marks a service as archived. Can be restored with restore action",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Archive successful"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found"),
- @ApiResponse(responseCode = "500", description = "Internal Error")
- })
- public Response archiveService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- archiveBusinessLogic.archiveComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
- return Response.ok().build();
- }
-
-
- @POST
- @Path("/services/{componentId}/restore")
- @Operation(description = "Restore Service", method = "POST", summary = "Restores a service from archive.", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Restore successful"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found"),
- @ApiResponse(responseCode = "500", description = "Internal Error")
- })
- public Response restoreService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- archiveBusinessLogic.restoreComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
- return Response.ok().build();
- }
-
- @GET
- @Path("/archive")
- @Operation(description = "Get all Archived Components", method = "GET", summary = "Get all Archived Components", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Success"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "Internal Error")
- })
- public Map<String, List<CatalogComponent>> getArchivedComponents(@HeaderParam(value = Constants.USER_ID_HEADER) String userId){
- return this.archiveBusinessLogic.getArchiveComponents(userId, new LinkedList<>());
- }
-
- @POST
- @Path("/notif/vsp/archived")
- @Operation(description = "Notify about an archived VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=true", method = "POST")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Success"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "Internal Error. A list of the failed CSAR IDs may be returned.")
- })
- public Response onVspArchived(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
- List<String> failedCsarIds = this.archiveBusinessLogic.onVspArchive(userId, csarIds);
- if (!failedCsarIds.isEmpty()){
- //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
- Map<String, List<String>> entity = new HashMap<>();
- entity.put("failedIds", failedCsarIds);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
- .entity(entity)
- .build();
- }
- return Response.ok().build();
- }
-
- @POST
- @Path("/notif/vsp/restored")
- @Operation(description = "Notify about a restored VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=false", method = "POST")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Success"),
- @ApiResponse(responseCode = "400", description = "Bad request"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "Internal Error. A list of the failed CSAR IDs may be returned.")
- })
- public Response onVspRestored(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
- List<String> failedCsarIds = this.archiveBusinessLogic.onVspRestore(userId, csarIds);
- if (!failedCsarIds.isEmpty()){
- //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
- Map<String, List<String>> entity = new HashMap<>();
- entity.put("failedIds", failedCsarIds);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
- .entity(entity)
- .build();
- }
- return Response.ok().build();
- }
-
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.catalog.CatalogComponent;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Archive Endpoint"))
+@Controller
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class ArchiveEndpoint extends BeGenericServlet{
+
+ private static final String COMPONENT_ID = "Component ID= ";
+ private final ArchiveBusinessLogic archiveBusinessLogic;
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ArchiveEndpoint.class.getName());
+
+ @Inject
+ public ArchiveEndpoint(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils, ArchiveBusinessLogic archiveBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.archiveBusinessLogic = archiveBusinessLogic;
+ }
+
+ @POST
+ @Path("/resources/{componentId}/archive")
+ @Operation(description = "Archive Resource", method = "POST", summary = "Marks a resource as archived. Can be restored with restore action", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Archive successful"),
+ @ApiResponse(responseCode = "400", description = "Bad request"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Resource not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")
+ })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response archiveResources(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ loggerSupportability.log(LoggerSupportabilityActions.ARCHIVE,StatusCode.STARTED,"Archive Resource " + COMPONENT_ID + " " + componentId + " by "+ userId);
+ archiveBusinessLogic.archiveComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
+ loggerSupportability.log(LoggerSupportabilityActions.ARCHIVE,StatusCode.COMPLETE,"Archive Resource " + COMPONENT_ID + " " + componentId + " by "+ userId);
+ return Response.ok().build();
+ }
+
+ @POST
+ @Path("/resources/{componentId}/restore")
+ @Operation(description = "Restore Resource", method = "POST", summary = "Restores a resource from archive.", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Restore successful"),
+ @ApiResponse(responseCode = "400", description = "Bad request"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Resource not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")
+ })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response restoreResource(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ loggerSupportability.log(LoggerSupportabilityActions.RESTORE_FROM_ARCHIVE,StatusCode.STARTED,"Restore resource from archive " + COMPONENT_ID + " " + componentId + " by "+ userId);
+ archiveBusinessLogic.restoreComponent(ComponentTypeEnum.RESOURCE_PARAM_NAME, userId, componentId);
+ loggerSupportability.log(LoggerSupportabilityActions.RESTORE_FROM_ARCHIVE,StatusCode.COMPLETE,"Restore resource from archive " + COMPONENT_ID + " " + componentId + " by "+ userId);
+ return Response.ok().build();
+ }
+
+ @POST
+ @Path("/services/{componentId}/archive")
+ @Operation(description = "Archive Service", method = "POST", summary = "Marks a service as archived. Can be restored with restore action",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Archive successful"),
+ @ApiResponse(responseCode = "400", description = "Bad request"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")
+ })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response archiveService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ loggerSupportability.log(LoggerSupportabilityActions.ARCHIVE, StatusCode.STARTED, "Archive Service for " + COMPONENT_ID + " " + componentId + " by " + userId);
+ archiveBusinessLogic.archiveComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
+ loggerSupportability.log(LoggerSupportabilityActions.ARCHIVE,StatusCode.COMPLETE, "Archive Service for " + COMPONENT_ID + " " + componentId + " by " + userId);
+ return Response.ok().build();
+ }
+
+
+ @POST
+ @Path("/services/{componentId}/restore")
+ @Operation(description = "Restore Service", method = "POST", summary = "Restores a service from archive.", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Restore successful"),
+ @ApiResponse(responseCode = "400", description = "Bad request"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")
+ })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response restoreService(@PathParam("componentId") final String componentId, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ loggerSupportability.log(LoggerSupportabilityActions.RESTORE_FROM_ARCHIVE,StatusCode.STARTED,"Restore service from archive " + COMPONENT_ID + " " + componentId + " by "+ userId);
+ archiveBusinessLogic.restoreComponent(ComponentTypeEnum.SERVICE_PARAM_NAME, userId, componentId);
+ loggerSupportability.log(LoggerSupportabilityActions.RESTORE_FROM_ARCHIVE,StatusCode.COMPLETE,"Restore service from archive " + COMPONENT_ID + " " + componentId + " by "+ userId);
+ return Response.ok().build();
+ }
+
+ @GET
+ @Path("/archive")
+ @Operation(description = "Get all Archived Components", method = "GET", summary = "Get all Archived Components", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Success"),
+ @ApiResponse(responseCode = "400", description = "Bad request"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")
+ })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Map<String, List<CatalogComponent>> getArchivedComponents(@HeaderParam(value = Constants.USER_ID_HEADER) String userId){
+ return this.archiveBusinessLogic.getArchiveComponents(userId, new LinkedList<>());
+ }
+
+ @POST
+ @Path("/notif/vsp/archived")
+ @Operation(description = "Notify about an archived VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=true", method = "POST")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Success"),
+ @ApiResponse(responseCode = "400", description = "Bad request"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "500", description = "Internal Error. A list of the failed CSAR IDs may be returned.")
+ })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response onVspArchived(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
+ List<String> failedCsarIds = this.archiveBusinessLogic.onVspArchive(userId, csarIds);
+ if (!failedCsarIds.isEmpty()){
+ //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
+ Map<String, List<String>> entity = new HashMap<>();
+ entity.put("failedIds", failedCsarIds);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+ .entity(entity)
+ .build();
+ }
+ return Response.ok().build();
+ }
+
+ @POST
+ @Path("/notif/vsp/restored")
+ @Operation(description = "Notify about a restored VSP. All VFs with relation to the given CSAR IDs will be martked as vspArchived=false", method = "POST")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Success"),
+ @ApiResponse(responseCode = "400", description = "Bad request"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "500", description = "Internal Error. A list of the failed CSAR IDs may be returned.")
+ })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response onVspRestored(@HeaderParam(value = Constants.USER_ID_HEADER) String userId, @RequestBody List<String> csarIds){
+ List<String> failedCsarIds = this.archiveBusinessLogic.onVspRestore(userId, csarIds);
+ if (!failedCsarIds.isEmpty()){
+ //There are some failed CSAR IDs, return 500 and the list of failed CSAR IDs
+ Map<String, List<String>> entity = new HashMap<>();
+ entity.put("failedIds", failedCsarIds);
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+ .entity(entity)
+ .build();
+ }
+ return Response.ok().build();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java
index 2b55ffa2c8..ebb576fd6c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ArtifactServlet.java
@@ -1,796 +1,816 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.util.Map;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-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;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
-import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * Root resource (exposed at "/" path)
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Resource Artifact Servlet", description = "Resource Artifact Servlet"))
-@Singleton
-public class ArtifactServlet extends BeGenericServlet {
-
- private final ArtifactsBusinessLogic artifactsBusinessLogic;
-
- @Inject
- public ArtifactServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils, ArtifactsBusinessLogic artifactsBusinessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.artifactsBusinessLogic = artifactsBusinessLogic;
- }
-
- private static final Logger log = Logger.getLogger(ArtifactServlet.class);
-
- // *************** Resources
- @POST
- @Path("/resources/{resourceId}/artifacts")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Create Artifact", method = "POST", summary = "Returns created ArtifactDefinition",
- responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Artifact already exist")})
- public Response loadArtifact(@PathParam("resourceId") final String resourceId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleUploadRequest(data, request, resourceId, ComponentTypeEnum.RESOURCE);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadArtifact");
- log.debug("loadArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/resources/{resourceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Update Artifact", method = "POST", summary = "Returns updated artifact",
- responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateArtifact(@PathParam("resourceId") final String resourceId,
- @PathParam("artifactId") final String artifactId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
- try {
- return handleUpdateRequest(data, request, resourceId, artifactId, ComponentTypeEnum.RESOURCE);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifact");
- log.debug("updateArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @DELETE
- @Path("/resources/{resourceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Delete Artifact", method = "DELETE",
- summary = "Returns delete artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteArtifact(@PathParam("resourceId") final String resourceId,
- @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
- try {
- return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, null, null);
- } catch (Exception e) {
- log.debug("deleteArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- // *************** Services
- @POST
- @Path("/services/{serviceId}/artifacts")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Create Artifact", method = "POST",
- summary = "Returns created ArtifactDefinition", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Artifact already exist")})
- public Response loadInformationArtifact(@PathParam("serviceId") final String serviceId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleUploadRequest(data, request, serviceId, ComponentTypeEnum.SERVICE);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadInformationArtifact");
- log.debug("loadInformationArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/services/{serviceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Update Artifact", method = "POST",
- summary = "Returns updated artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service artifact created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateInformationArtifact(@PathParam("serviceId") final String serviceId,
- @PathParam("artifactId") final String artifactId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateInformationArtifact");
- log.debug("updateInformationArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- // *************** Services api artifacts
- @POST
- @Path("/services/{serviceId}/artifacts/api/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Update Api Artifact", method = "POST",
- summary = "Returns created ArtifactDefinition", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Api Artifact Updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateApiArtifact(@PathParam("serviceId") final String serviceId,
- @PathParam("artifactId") final String artifactId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateApiArtifact");
- log.debug("updateApiArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @DELETE
- @Path("/services/{serviceId}/artifacts/api/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Delete Api Artifact", method = "DELETE",
- summary = "Returns Deleted ArtifactDefinition", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Api Artifact deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation")})
- public Response deleteApiArtifact(@PathParam("serviceId") final String serviceId,
- @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteApiArtifact");
- log.debug("deleteApiArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @DELETE
- @Path("/services/{serviceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Delete Artifact", method = "DELETE",
- summary = "Returns delete artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service artifact deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteInformationalArtifact(@PathParam("serviceId") final String serviceId,
- @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteInformationalArtifact");
- log.debug("deleteInformationalArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /*
- * DOWNLOAD Artifacts by json body in base 64 (because of userId problem with href)
- */
-
- @GET
- @Path("/services/{serviceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Download service Artifact in Base64", method = "GET",
- summary = "Returns downloaded artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service artifact downloaded"),
- @ApiResponse(responseCode = "404", description = "Service/Artifact not found")})
- public Response downloadServiceArtifactBase64(@PathParam("serviceId") final String serviceId,
- @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleDownloadRequest(request, serviceId, artifactId, null, ComponentTypeEnum.SERVICE, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadServiceArtifactBase64");
- log.debug("downloadServiceArtifactBase64 unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Path("/resources/{resourceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Download resource Artifact in Base64", method = "GET",
- summary = "Returns downloaded artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource artifact downloaded"),
- @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
- public Response downloadResourceArtifactBase64(@PathParam("resourceId") final String resourceId,
- @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleDownloadRequest(request, resourceId, artifactId, null, ComponentTypeEnum.RESOURCE, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceArtifactBase64");
- log.debug("downloadResourceArtifactBase64 unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Download component Artifact in Base64", method = "GET",
- summary = "Returns downloaded artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "ResourceInstance artifact downloaded"),
- @ApiResponse(responseCode = "404", description = "ResourceInstance/Artifact not found")})
- public Response downloadResourceInstanceArtifactBase64(@Parameter(
- description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleDownloadRequest(request, componentInstanceId, artifactId, componentId,
- ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentType);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceInstanceArtifactBase64");
- log.debug("downloadResourceInstanceArtifactBase64 unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- // *************** Resource lifecycle ( interfces )
-
- @POST
- @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Create Artifact and Attach to interface", method = "POST",
- summary = "Returns created resource", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Artifact already exist")})
- public Response loadArtifactToInterface(@PathParam("resourceId") final String resourceId,
- @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleArtifactRequest(data, request, resourceId, interfaceType, operation, null,
- ComponentTypeEnum.RESOURCE, ArtifactOperationEnum.CREATE, null, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadArtifactToInterface");
- log.debug("loadArtifactToInterface unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @DELETE
- @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "delete Artifact from interface", method = "delete",
- summary = "delete matching artifact from interface", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "delete artifact under interface deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Artifact already exist")})
- public Response deleteArtifactToInterface(@PathParam("resourceId") final String resourceId,
- @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
- @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, interfaceType,
- operation);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteArtifactToInterface");
- log.debug("deleteArtifactToInterface unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "update Artifact Attach to interface", method = "post",
- summary = "updates artifact by interface", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "delete artifact under interface deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Artifact already exist")})
- public Response updateArtifactToInterface(@PathParam("resourceId") final String resourceId,
- @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
- @PathParam("artifactId") final String artifactId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @HeaderParam(value = Constants.MD5_HEADER) String origMd5, @Context final HttpServletRequest request,
- @Parameter(description = "json describe the artifact", required = true) String data) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleArtifactRequest(data, request, resourceId, interfaceType, operation, artifactId,
- ComponentTypeEnum.RESOURCE, ArtifactOperationEnum.UPDATE, null, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifactToInterface");
- log.debug("updateArtifactToInterface unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}/heatParams")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Update Resource Instance HEAT_ENV parameters",
- method = "POST", summary = "Returns updated artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateRIArtifact(@Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @PathParam("artifactId") final String artifactId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId,
- ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.UPDATE, componentId,
- containerComponentType);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateRIArtifact");
- log.debug("updateRIArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Update Resource Instance artifact payload", method = "POST",
- summary = "Returns updated artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @PathParam("artifactId") final String artifactId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId,
- ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.UPDATE, componentId,
- containerComponentType);
- } catch (Exception e) {
- log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Load Resource Instance artifact payload", method = "POST",
- summary = "Returns updated artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response loadComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleArtifactRequest(data, request, componentInstanceId, null, null, null,
- ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.CREATE, componentId,
- containerComponentType);
- } catch (Exception e) {
- log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @DELETE
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Delete Resource Instance artifact", method = "POST",
- summary = "Returns deleted artifact", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @PathParam("artifactId") final String artifactId,
- @Parameter(description = "json describe the artifact", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleDeleteRequest(request, componentInstanceId, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE,
- null, null, componentId);
- } catch (Exception e) {
- log.debug("deleteArtifact unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
-
- @GET
- @Path("/{containerComponentType}/{componentId}/artifactsByType/{artifactGroupType}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Get component Artifacts", method = "GET",
- summary = "Returns artifacts", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component artifacts"),
- @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
- public Response getComponentArtifacts(@Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @PathParam("artifactGroupType") final String artifactGroupType, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleGetArtifactsRequest(request, componentId, null, artifactGroupType, containerComponentType);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceInstanceArtifactBase64");
- log.debug("downloadResourceInstanceArtifactBase64 unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifactsByType/{artifactGroupType}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Get component Artifacts", method = "GET",
- summary = "Returns artifacts", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component artifacts"),
- @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
- public Response getComponentInstanceArtifacts(@Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @PathParam("artifactGroupType") final String artifactGroupType, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- try {
- return handleGetArtifactsRequest(request, componentInstanceId, componentId, artifactGroupType,
- containerComponentType);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceInstanceArtifactBase64");
- log.debug("downloadResourceInstanceArtifactBase64 unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
-
- @POST
- @Path("/{assetType}/{uuid}/interfaces/{interfaceUUID}/operations/{operationUUID}/artifacts/{artifactUUID}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "uploads of artifact to component operation workflow", method = "POST", summary = "uploads of artifact to component operation workflow")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Artifact uploaded",content = @Content(array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
- @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
- @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
- @ApiResponse(responseCode = "400", description = "Artifact type (mandatory field) is missing in request - SVC4124"),
- @ApiResponse(responseCode = "400", description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
- @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
- @ApiResponse(responseCode = "400", description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
- @ApiResponse(responseCode = "400", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
- //@ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
- public Response uploadInterfaceOperationArtifact(
- @Parameter(description = "Asset type") @PathParam("assetType") String assetType,
- @Parameter(description = "The uuid of the asset as published in the metadata", required = true)@PathParam("uuid") final String uuid,
- @Parameter(description = "The uuid of the interface", required = true)@PathParam("interfaceUUID") final String interfaceUUID,
- @Parameter(description = "The uuid of the operation", required = true)@PathParam("operationUUID") final String operationUUID,
- @Parameter(description = "The uuid of the artifact", required = true)@PathParam("artifactUUID") final String artifactUUID,
- @Parameter( hidden = true) String data,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
-
- try {
- Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
- artifactsBusinessLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request,
- ComponentTypeEnum.findByParamName(assetType), uuid, interfaceUUID, operationUUID, artifactUUID,
- new ResourceCommonInfo(assetType), artifactsBusinessLogic.new ArtifactOperationInfo(true,
- false, ArtifactOperationEnum.UPDATE));
- if (uploadArtifactEither.isRight()) {
- log.debug("failed to update artifact");
- return buildErrorResponse(uploadArtifactEither.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uploadArtifactEither.left().value());
- }
- catch (Exception e) {
- final String message = "failed to update artifact on a resource or service";
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
- log.debug(message, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- // ////////// API END ///////////////////////////
-
- // ************ private *********************
-
- private Response handleUploadRequest(String data, HttpServletRequest request, String componentId, ComponentTypeEnum componentType) {
- return handleArtifactRequest(data, componentId, null, componentType, ArtifactOperationEnum.CREATE);
- }
-
- private Response handleUpdateRequest(String data, HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType) {
- return handleArtifactRequest(data, componentId, artifactId, componentType, ArtifactOperationEnum.UPDATE);
- }
-
- private Response handleDownloadRequest(HttpServletRequest request, String componentId, String artifactId, String parentId, ComponentTypeEnum componentType, String containerComponentType) {
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- ServletContext context = request.getSession().getServletContext();
- Either<ImmutablePair<String, byte[]>, ResponseFormat> actionResult = artifactsBusinessLogic
- .handleDownloadRequestById(componentId, artifactId, userId, componentType, parentId, containerComponentType);
-
- Response response;
- if (actionResult.isRight()) {
- response = buildErrorResponse(actionResult.right().value());
- } else {
- byte[] file = actionResult.left().value().getRight();
- String base64Contents = new String(Base64.encodeBase64(file));
- String artifactName = actionResult.left().value().getLeft();
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- ArtifactUiDownloadData artifactUiDownloadData = new ArtifactUiDownloadData();
- artifactUiDownloadData.setArtifactName(artifactName);
- artifactUiDownloadData.setBase64Contents(base64Contents);
- response = buildOkResponse(responseFormat, artifactUiDownloadData);
- }
- return response;
- }
-
- private Response handleGetArtifactsRequest(HttpServletRequest request, String componentId, String parentId, String artifactGroupType, String containerComponentType) {
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- ComponentTypeEnum componentTypeEnum = parentId == null || parentId.isEmpty()? ComponentTypeEnum.findByParamName(containerComponentType): ComponentTypeEnum.RESOURCE_INSTANCE;
- Either<Map<String, ArtifactDefinition>, ResponseFormat> actionResult = artifactsBusinessLogic.handleGetArtifactsByType(containerComponentType, parentId, componentTypeEnum, componentId, artifactGroupType, userId);
-
- Response response;
- if (actionResult.isRight()) {
- response = buildErrorResponse(actionResult.right().value());
- } else {
-
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResult.left().value());
- }
-
- return response;
- }
-
-
- private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName) {
- return handleDeleteRequest(request, componentId, artifactId, componentType, interfaceType, operationName, null);
- }
-
- private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName, String parentId) {
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- ServletContext context = request.getSession().getServletContext();
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType, artifactsBusinessLogic.new ArtifactOperationInfo (false, false, ArtifactOperationEnum.DELETE), artifactId, null, null, null, interfaceType, operationName,
- parentId, null);
- Response response;
- if (actionResult.isRight()) {
- response = buildErrorResponse(actionResult.right().value());
- } else {
- Either<ArtifactDefinition, Operation> result = actionResult.left().value();
- if (result.isLeft()) {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
- } else {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
- }
- }
- return response;
-
- }
-
- private Response handleArtifactRequest(String data, HttpServletRequest request, String componentId, String interfaceName, String operationName, String artifactId, ComponentTypeEnum componentType, ArtifactOperationEnum operationEnum, String parentId,
- String containerComponentType) {
- ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class);
- String origMd5 = request.getHeader(Constants.MD5_HEADER);
-
- String userId = request.getHeader(Constants.USER_ID_HEADER);
-
- Either<Either<ArtifactDefinition, Operation>, ResponseFormat> actionResult = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType,
- artifactsBusinessLogic.new ArtifactOperationInfo (false, false,operationEnum), artifactId, artifactInfo, origMd5, data, interfaceName, operationName, parentId,
- containerComponentType);
- Response response;
- if (actionResult.isRight()) {
- response = buildErrorResponse(actionResult.right().value());
- } else {
- Either<ArtifactDefinition, Operation> result = actionResult.left().value();
- if (result.isLeft()) {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
- } else {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
- }
- }
- return response;
-
- }
-
- private Response handleArtifactRequest(String data, String componentId, String artifactId, ComponentTypeEnum componentType, ArtifactOperationEnum operation) {
- return handleArtifactRequest(data, servletRequest, componentId, null, null, artifactId, componentType, operation, null, null);
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.Map;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Resource Artifact Servlet", description = "Resource Artifact Servlet"))
+@Controller
+public class ArtifactServlet extends BeGenericServlet {
+
+ private final ArtifactsBusinessLogic artifactsBusinessLogic;
+
+ @Inject
+ public ArtifactServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils, ArtifactsBusinessLogic artifactsBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.artifactsBusinessLogic = artifactsBusinessLogic;
+ }
+
+ private static final Logger log = Logger.getLogger(ArtifactServlet.class);
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ArtifactServlet.class.getName());
+
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final String DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64 = "downloadResourceInstanceArtifactBase64";
+ private static final String DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION = "downloadResourceInstanceArtifactBase64 unexpected exception";
+
+ // *************** Resources
+ @POST
+ @Path("/resources/{resourceId}/artifacts")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Artifact", method = "POST", summary = "Returns created ArtifactDefinition",
+ responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Artifact already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response loadArtifact(@PathParam("resourceId") final String resourceId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ return handleUploadRequest(data, request, resourceId, ComponentTypeEnum.RESOURCE);
+ }
+
+ @POST
+ @Path("/resources/{resourceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Artifact", method = "POST", summary = "Returns updated artifact",
+ responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateArtifact(@PathParam("resourceId") final String resourceId,
+ @PathParam("artifactId") final String artifactId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleUpdateRequest(data, request, resourceId, artifactId, ComponentTypeEnum.RESOURCE);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifact");
+ log.debug("updateArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/resources/{resourceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete Artifact", method = "DELETE",
+ summary = "Returns delete artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteArtifact(@PathParam("resourceId") final String resourceId,
+ @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, null, null);
+ } catch (Exception e) {
+ log.debug("deleteArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ // *************** Services
+ @POST
+ @Path("/services/{serviceId}/artifacts")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Artifact", method = "POST",
+ summary = "Returns created ArtifactDefinition", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Artifact already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response loadInformationArtifact(@PathParam("serviceId") final String serviceId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleUploadRequest(data, request, serviceId, ComponentTypeEnum.SERVICE);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadInformationArtifact");
+ log.debug("loadInformationArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/services/{serviceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Artifact", method = "POST",
+ summary = "Returns updated artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service artifact created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ public Response updateInformationArtifact(@PathParam("serviceId") final String serviceId,
+ @PathParam("artifactId") final String artifactId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateInformationArtifact");
+ log.debug("updateInformationArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ // *************** Services api artifacts
+ @POST
+ @Path("/services/{serviceId}/artifacts/api/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Api Artifact", method = "POST",
+ summary = "Returns created ArtifactDefinition", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Api Artifact Updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateApiArtifact(@PathParam("serviceId") final String serviceId,
+ @PathParam("artifactId") final String artifactId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleUpdateRequest(data, request, serviceId, artifactId, ComponentTypeEnum.SERVICE);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateApiArtifact");
+ log.debug("updateApiArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/services/{serviceId}/artifacts/api/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete Api Artifact", method = "DELETE",
+ summary = "Returns Deleted ArtifactDefinition", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Api Artifact deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteApiArtifact(@PathParam("serviceId") final String serviceId,
+ @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteApiArtifact");
+ log.debug("deleteApiArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/services/{serviceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete Artifact", method = "DELETE",
+ summary = "Returns delete artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service artifact deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteInformationalArtifact(@PathParam("serviceId") final String serviceId,
+ @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleDeleteRequest(request, serviceId, artifactId, ComponentTypeEnum.SERVICE, null, null);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteInformationalArtifact");
+ log.debug("deleteInformationalArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ /*
+ * DOWNLOAD Artifacts by json body in base 64 (because of userId problem with href)
+ */
+
+ @GET
+ @Path("/services/{serviceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Download service Artifact in Base64", method = "GET",
+ summary = "Returns downloaded artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service artifact downloaded"),
+ @ApiResponse(responseCode = "404", description = "Service/Artifact not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response downloadServiceArtifactBase64(@PathParam("serviceId") final String serviceId,
+ @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ Response response;
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ response = handleDownloadRequest(request, serviceId, artifactId, null, ComponentTypeEnum.SERVICE, null);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadServiceArtifactBase64");
+ log.debug("downloadServiceArtifactBase64 unexpected exception", e);
+ throw e;
+ }
+ finally {
+ loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS,StatusCode.COMPLETE,"Ended download Service Artifact ");
+ }
+ return response;
+ }
+
+ @GET
+ @Path("/resources/{resourceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Download resource Artifact in Base64", method = "GET",
+ summary = "Returns downloaded artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource artifact downloaded"),
+ @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
+ public Response downloadResourceArtifactBase64(@PathParam("resourceId") final String resourceId,
+ @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ Response response;
+ try {
+ response = handleDownloadRequest(request, resourceId, artifactId, null, ComponentTypeEnum.RESOURCE, null);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("downloadResourceArtifactBase64");
+ log.debug("downloadResourceArtifactBase64 unexpected exception", e);
+ throw e;
+ }
+ finally {
+ loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS,null, StatusCode.COMPLETE,"Ended download artifact {}", artifactId);
+
+ }
+ return response;
+ }
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Download component Artifact in Base64", method = "GET",
+ summary = "Returns downloaded artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "ResourceInstance artifact downloaded"),
+ @ApiResponse(responseCode = "404", description = "ResourceInstance/Artifact not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response downloadResourceInstanceArtifactBase64(@Parameter(
+ description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ Response response;
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS, StatusCode.STARTED," Starting to download Resource Instance Artifact for component {} ", componentId);
+ try {
+ response = handleDownloadRequest(request, componentInstanceId, artifactId, componentId, ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentType);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64);
+ log.debug(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION, e);
+ throw e;
+ }
+ finally {
+ loggerSupportability.log(LoggerSupportabilityActions.DOWNLOAD_ARTIFACTS, StatusCode.COMPLETE,"Ended download Resource Instance Artifact for component {} ", componentId);
+ }
+ return response;
+ }
+
+ // *************** Resource lifecycle ( interfces )
+
+ @POST
+ @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Artifact and Attach to interface", method = "POST",
+ summary = "Returns created resource", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Artifact already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response loadArtifactToInterface(@PathParam("resourceId") final String resourceId,
+ @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleArtifactRequest(data, request, resourceId, interfaceType, operation, null, ComponentTypeEnum.RESOURCE, ArtifactOperationEnum.CREATE, null, null, false);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("loadArtifactToInterface");
+ log.debug("loadArtifactToInterface unexpected exception", e);
+ throw e;
+ }
+
+ }
+
+ @DELETE
+ @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "delete Artifact from interface", method = "delete",
+ summary = "delete matching artifact from interface", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "delete artifact under interface deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Artifact already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteArtifactToInterface(@PathParam("resourceId") final String resourceId,
+ @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
+ @PathParam("artifactId") final String artifactId, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleDeleteRequest(request, resourceId, artifactId, ComponentTypeEnum.RESOURCE, interfaceType, operation);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("deleteArtifactToInterface");
+ log.debug("deleteArtifactToInterface unexpected exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/resources/{resourceId}/{interfaceType}/{operation}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "update Artifact Attach to interface", method = "post",
+ summary = "updates artifact by interface", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "delete artifact under interface deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Artifact already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateArtifactToInterface(@PathParam("resourceId") final String resourceId,
+ @PathParam("interfaceType") final String interfaceType, @PathParam("operation") final String operation,
+ @PathParam("artifactId") final String artifactId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5, @Context final HttpServletRequest request,
+ @Parameter(description = "json describe the artifact", required = true) String data) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleArtifactRequest(data, request, resourceId, interfaceType, operation, artifactId, ComponentTypeEnum.RESOURCE, ArtifactOperationEnum.UPDATE, null, null, false);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateArtifactToInterface");
+ log.debug("updateArtifactToInterface unexpected exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}/heatParams")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Resource Instance HEAT_ENV parameters",
+ method = "POST", summary = "Returns updated artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateRIArtifact(@Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @PathParam("artifactId") final String artifactId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_HEAT, StatusCode.STARTED,"Starting update RI Artifact {}" ,artifactId);
+ Response response;
+ try {
+ response = handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.UPDATE, componentId, containerComponentType, false);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("updateRIArtifact");
+ log.debug("updateRIArtifact unexpected exception", e);
+ throw e;
+ }
+ finally {
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_HEAT, StatusCode.COMPLETE,"Ending update RI Artifact {}" , artifactId);
+ }
+ return response;
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Resource Instance artifact payload", method = "POST",
+ summary = "Returns updated artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @PathParam("artifactId") final String artifactId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleArtifactRequest(data, request, componentInstanceId, null, null, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.UPDATE, componentId, containerComponentType, true);
+ } catch (Exception e) {
+ log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Load Resource Instance artifact payload", method = "POST",
+ summary = "Returns updated artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response loadComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleArtifactRequest(data, request, componentInstanceId, null, null, null, ComponentTypeEnum.RESOURCE_INSTANCE, ArtifactOperationEnum.CREATE, componentId, containerComponentType, false);
+ } catch (Exception e) {
+ log.debug("loadResourceInstanceHeatEnvArtifact unexpected exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/artifacts/{artifactId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete Resource Instance artifact", method = "POST",
+ summary = "Returns deleted artifact", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Artifact updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteComponentInstanceArtifact(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @PathParam("artifactId") final String artifactId,
+ @Parameter(description = "json describe the artifact", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE_ARTIFACT,null, StatusCode.STARTED,"Starting delete component instance artifact {}" ,artifactId);
+ Response response;
+ try {
+ response = handleDeleteRequest(request, componentInstanceId, artifactId, ComponentTypeEnum.RESOURCE_INSTANCE, null, null, componentId);
+ } catch (Exception e) {
+ log.debug("deleteArtifact unexpected exception", e);
+ throw e;
+ }
+ finally {
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE_ARTIFACT,null, StatusCode.COMPLETE,"Ending delete component instance artifact {}" ,artifactId);
+ }
+ return response;
+
+ }
+
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/artifactsByType/{artifactGroupType}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get component Artifacts", method = "GET",
+ summary = "Returns artifacts", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component artifacts"),
+ @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentArtifacts(@Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("artifactGroupType") final String artifactGroupType, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleGetArtifactsRequest(request, componentId, null, artifactGroupType, containerComponentType);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64);
+ log.debug(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION, e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/resourceInstances/{componentInstanceId}/artifactsByType/{artifactGroupType}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get component Artifacts", method = "GET",
+ summary = "Returns artifacts", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component artifacts"),
+ @ApiResponse(responseCode = "404", description = "Resource/Artifact not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentInstanceArtifacts(@Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @PathParam("artifactGroupType") final String artifactGroupType, @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+ return handleGetArtifactsRequest(request, componentInstanceId, componentId, artifactGroupType, containerComponentType);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64);
+ log.debug(DOWNLOAD_RESOURCE_INSTANCE_ARTIFACT_BASE64_EXCEPTION, e);
+ throw e;
+ }
+ }
+
+
+ @POST
+ @Path("/{assetType}/{uuid}/interfaces/{interfaceUUID}/operations/{operationUUID}/artifacts/{artifactUUID}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "uploads of artifact to component operation workflow", method = "POST", summary = "uploads of artifact to component operation workflow")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Artifact uploaded",content = @Content(array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
+ @ApiResponse(responseCode = "404", description = "Specified resource is not found - SVC4063"),
+ @ApiResponse(responseCode = "400", description = "Invalid artifactType was defined as input - SVC4122"),
+ @ApiResponse(responseCode = "400", description = "Artifact type (mandatory field) is missing in request - SVC4124"),
+ @ApiResponse(responseCode = "400", description = "Artifact name given in input already exists in the context of the asset - SVC4125"),
+ @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
+ @ApiResponse(responseCode = "400", description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
+ @ApiResponse(responseCode = "400", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
+ //@ApiImplicitParams({@ApiImplicitParam(required = true, dataType = "org.openecomp.sdc.be.model.ArtifactDefinition", paramType = "body", value = "json describe the artifact")})
+ public Response uploadInterfaceOperationArtifact(
+ @Parameter(description = "Asset type") @PathParam("assetType") String assetType,
+ @Parameter(description = "The uuid of the asset as published in the metadata", required = true)@PathParam("uuid") final String uuid,
+ @Parameter(description = "The uuid of the interface", required = true)@PathParam("interfaceUUID") final String interfaceUUID,
+ @Parameter(description = "The uuid of the operation", required = true)@PathParam("operationUUID") final String operationUUID,
+ @Parameter(description = "The uuid of the artifact", required = true)@PathParam("artifactUUID") final String artifactUUID,
+ @Parameter( hidden = true) String data,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam(value = Constants.MD5_HEADER) String origMd5,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}" , url);
+
+ try {
+ Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither =
+ artifactsBusinessLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request,
+ ComponentTypeEnum.findByParamName(assetType), uuid, interfaceUUID, operationUUID, artifactUUID,
+ new ResourceCommonInfo(assetType), artifactsBusinessLogic.new ArtifactOperationInfo(true,
+ false, ArtifactOperationEnum.UPDATE));
+ if (uploadArtifactEither.isRight()) {
+ log.debug("failed to update artifact");
+ return buildErrorResponse(uploadArtifactEither.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), uploadArtifactEither.left().value());
+ }
+ catch (Exception e) {
+ final String message = "failed to update artifact on a resource or service";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(message);
+ log.debug(message, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ // ////////// API END ///////////////////////////
+
+ // ************ private *********************
+
+ private Response handleUploadRequest(String data, HttpServletRequest request, String componentId, ComponentTypeEnum componentType) {
+ return handleArtifactRequest(data, componentId, null, componentType, ArtifactOperationEnum.CREATE);
+ }
+
+ private Response handleUpdateRequest(String data, HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType) {
+ return handleArtifactRequest(data, componentId, artifactId, componentType, ArtifactOperationEnum.UPDATE);
+ }
+
+ private Response handleDownloadRequest(HttpServletRequest request, String componentId, String artifactId, String parentId, ComponentTypeEnum componentType, String containerComponentType) {
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ ImmutablePair<String, byte[]> actionResult = artifactsBusinessLogic.handleDownloadRequestById(componentId, artifactId, userId, componentType, parentId, containerComponentType);
+
+ Response response;
+ byte[] file = actionResult.getRight();
+ String base64Contents = new String(Base64.encodeBase64(file));
+ String artifactName = actionResult.getLeft();
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ ArtifactUiDownloadData artifactUiDownloadData = new ArtifactUiDownloadData();
+ artifactUiDownloadData.setArtifactName(artifactName);
+ artifactUiDownloadData.setBase64Contents(base64Contents);
+ response = buildOkResponse(responseFormat, artifactUiDownloadData);
+ return response;
+ }
+
+ private Response handleGetArtifactsRequest(HttpServletRequest request, String componentId, String parentId, String artifactGroupType, String containerComponentType) {
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ ComponentTypeEnum componentTypeEnum = parentId == null || parentId.isEmpty() ? ComponentTypeEnum.findByParamName(containerComponentType) : ComponentTypeEnum.RESOURCE_INSTANCE;
+ Map<String, ArtifactDefinition> actionResult = artifactsBusinessLogic.handleGetArtifactsByType(containerComponentType, parentId, componentTypeEnum, componentId, artifactGroupType, userId);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResult);
+ }
+
+
+ private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName) {
+ return handleDeleteRequest(request, componentId, artifactId, componentType, interfaceType, operationName, null);
+ }
+
+ private Response handleDeleteRequest(HttpServletRequest request, String componentId, String artifactId, ComponentTypeEnum componentType, String interfaceType, String operationName, String parentId) {
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> actionResult = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType, artifactsBusinessLogic.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.DELETE), artifactId, null, null, null, interfaceType, operationName,
+ parentId, null);
+ Response response;
+
+ Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> result = actionResult;
+ if (result.isLeft()) {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
+ }
+ return response;
+
+ }
+
+ private Response handleArtifactRequest(String data, HttpServletRequest request, String componentId, String interfaceName, String operationName, String artifactId, ComponentTypeEnum componentType, ArtifactOperationEnum operationEnum, String parentId,
+ String containerComponentType, boolean validateTimeout) {
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_ARTIFACT, StatusCode.STARTED,"Starting to update artifact {} " ,artifactId + " for component " + componentId);
+ ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class, validateTimeout);
+ String origMd5 = request.getHeader(Constants.MD5_HEADER);
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> result = artifactsBusinessLogic.handleArtifactRequest(componentId, userId, componentType,
+ artifactsBusinessLogic.new ArtifactOperationInfo(false, false, operationEnum), artifactId, artifactInfo, origMd5, data, interfaceName, operationName, parentId,
+ containerComponentType);
+ Response response;
+ if (result.isLeft()) {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.left().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result.right().value());
+ }
+
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_ARTIFACT, StatusCode.COMPLETE,"Ended update artifact {} " ,artifactId + " for component " + componentId);
+ return response;
+
+ }
+
+ private Response handleArtifactRequest(String data, String componentId, String artifactId, ComponentTypeEnum componentType, ArtifactOperationEnum operation) {
+ return handleArtifactRequest(data, servletRequest, componentId, null, null, artifactId, componentType, operation, null, null, false);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java
index 1ed1e404da..aad7f1a8bf 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java
@@ -1,320 +1,314 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.AttributeBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * Web Servlet for actions on Attributes
- *
- * @author mshitrit
- *
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Resource Attribute Servlet", description = "Resource Attribute Servlet"))
-@Singleton
-public class AttributeServlet extends AbstractValidationsServlet {
- private static final Logger log = Logger.getLogger(AttributeServlet.class);
-
- @Inject
- public AttributeServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- }
-
- /**
- * Creates new Attribute on a resource with given resource ID
- *
- * @param resourceId
- * @param data
- * @param request
- * @param userId
- * @return
- */
- @POST
- @Path("resources/{resourceId}/attributes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Resource Attribute", method = "POST",
- summary = "Returns created resource attribute", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource property created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Resource attribute already exist")})
- public Response createAttribute(
- @Parameter(description = "resource id to update with new attribute",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "Resource attribute to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
-
- try {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Wrapper<PropertyDefinition> attributesWrapper = new Wrapper<>();
- // convert json to AttributeDefinition
-
- buildAttributeFromString(data, attributesWrapper, errorWrapper);
- if (errorWrapper.isEmpty()) {
- AttributeBusinessLogic businessLogic =
- getClassFromWebAppContext(context, () -> AttributeBusinessLogic.class);
- Either<PropertyDefinition, ResponseFormat> createAttribute =
- businessLogic.createAttribute(resourceId, attributesWrapper.getInnerElement(), userId);
- if (createAttribute.isRight()) {
- errorWrapper.setInnerElement(createAttribute.right().value());
- } else {
- attributesWrapper.setInnerElement(createAttribute.left().value());
- }
- }
-
- Response response;
- if (!errorWrapper.isEmpty()) {
- log.info("Failed to create Attribute. Reason - ", errorWrapper.getInnerElement());
- response = buildErrorResponse(errorWrapper.getInnerElement());
- } else {
- PropertyDefinition createdAttDef = attributesWrapper.getInnerElement();
- log.debug("Attribute {} created successfully with id {}", createdAttDef.getName(),
- createdAttDef.getUniqueId());
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
- response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(createdAttDef));
- }
-
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Attribute");
- log.debug("create property failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
-
- }
- }
-
- /**
- * Updates existing Attribute with given attributeID on a resource with given resourceID
- *
- * @param resourceId
- * @param attributeId
- * @param data
- * @param request
- * @param userId
- * @return
- */
- @PUT
- @Path("resources/{resourceId}/attributes/{attributeId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Resource Attribute", method = "PUT", summary = "Returns updated attribute",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource attribute updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateAttribute(
- @Parameter(description = "resource id to update with new attribute",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "attribute id to update",
- required = true) @PathParam("attributeId") final String attributeId,
- @Parameter(description = "Resource attribute to update", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- try {
- // convert json to PropertyDefinition
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Wrapper<PropertyDefinition> attributesWrapper = new Wrapper<>();
- // convert json to AttributeDefinition
-
- buildAttributeFromString(data, attributesWrapper, errorWrapper);
-
- if (errorWrapper.isEmpty()) {
- AttributeBusinessLogic businessLogic =
- getClassFromWebAppContext(context, () -> AttributeBusinessLogic.class);
- Either<PropertyDefinition, ResponseFormat> eitherUpdateAttribute = businessLogic
- .updateAttribute(resourceId, attributeId, attributesWrapper.getInnerElement(), userId);
- // update property
- if (eitherUpdateAttribute.isRight()) {
- errorWrapper.setInnerElement(eitherUpdateAttribute.right().value());
- } else {
- attributesWrapper.setInnerElement(eitherUpdateAttribute.left().value());
- }
- }
-
- Response response;
- if (!errorWrapper.isEmpty()) {
- log.info("Failed to update Attribute. Reason - ", errorWrapper.getInnerElement());
- response = buildErrorResponse(errorWrapper.getInnerElement());
- } else {
- PropertyDefinition updatedAttribute = attributesWrapper.getInnerElement();
- log.debug("Attribute id {} updated successfully ", updatedAttribute.getUniqueId());
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(updatedAttribute));
- }
-
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Attribute");
- log.debug("update attribute failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
-
- }
- }
-
- /**
- * Deletes existing Attribute with given attributeID on a resource with given resourceID
- *
- * @param resourceId
- * @param attributeId
- * @param request
- * @param userId
- * @return
- */
- @DELETE
- @Path("resources/{resourceId}/attributes/{attributeId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Resource Attribute", method = "DELETE", summary = "Returns deleted attribute",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "deleted attribute"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Resource property not found")})
- public Response deleteAttribute(
- @Parameter(description = "resource id of attribute",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "Attribute id to delete",
- required = true) @PathParam("attributeId") final String attributeId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- log.debug("modifier id is {}", userId);
-
- try {
-
- // delete the property
- AttributeBusinessLogic businessLogic =
- getClassFromWebAppContext(context, () -> AttributeBusinessLogic.class);
- Either<PropertyDefinition, ResponseFormat> eitherAttribute =
- businessLogic.deleteAttribute(resourceId, attributeId, userId);
- if (eitherAttribute.isRight()) {
- log.debug("Failed to delete Attribute. Reason - ", eitherAttribute.right().value());
- return buildErrorResponse(eitherAttribute.right().value());
- }
- PropertyDefinition attributeDefinition = eitherAttribute.left().value();
- String name = attributeDefinition.getName();
-
- log.debug("Attribute {} deleted successfully with id {}", name, attributeDefinition.getUniqueId());
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
- return buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(attributeDefinition));
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Attribute");
- log.debug("delete attribute failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
-
- }
- }
-
- private void buildAttributeFromString(String data, Wrapper<PropertyDefinition> attributesWrapper,
- Wrapper<ResponseFormat> errorWrapper) {
- try {
- Gson gson = new GsonBuilder().setPrettyPrinting().create();
- final PropertyDefinition attribute = gson.fromJson(data, PropertyDefinition.class);
- if (attribute == null) {
- log.info("Attribute content is invalid - {}", data);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- errorWrapper.setInnerElement(responseFormat);
- } else {
- attributesWrapper.setInnerElement(attribute);
- }
-
- } catch (Exception e) {
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- errorWrapper.setInnerElement(responseFormat);
- log.debug("Attribute content is invalid - {}", data, e);
- log.info("Attribute content is invalid - {}", data);
- }
- }
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.AttributeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+/**
+ * Web Servlet for actions on Attributes
+ *
+ * @author mshitrit
+ *
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Resource Attribute Servlet", description = "Resource Attribute Servlet"))
+@Controller
+public class AttributeServlet extends AbstractValidationsServlet {
+ private static final Logger log = Logger.getLogger(AttributeServlet.class);
+ private static final String ATTRIBUTE_CONTENT_IS_INVALID = "Attribute content is invalid - {}";
+ @Inject
+ public AttributeServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ }
+
+ /**
+ * Creates new Attribute on a resource with given resource ID
+ *
+ * @param resourceId
+ * @param data
+ * @param request
+ * @param userId
+ * @return
+ */
+ @POST
+ @Path("resources/{resourceId}/attributes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Resource Attribute", method = "POST",
+ summary = "Returns created resource attribute", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource property created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Resource attribute already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createAttribute(
+ @Parameter(description = "resource id to update with new attribute",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "Resource attribute to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
+
+ try {
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Wrapper<PropertyDefinition> attributesWrapper = new Wrapper<>();
+ // convert json to AttributeDefinition
+
+ buildAttributeFromString(data, attributesWrapper, errorWrapper);
+ if (errorWrapper.isEmpty()) {
+ AttributeBusinessLogic businessLogic = getClassFromWebAppContext(context, () -> AttributeBusinessLogic.class);
+ Either<PropertyDefinition, ResponseFormat> createAttribute = businessLogic.createAttribute(resourceId, attributesWrapper.getInnerElement(), userId);
+ if (createAttribute.isRight()) {
+ errorWrapper.setInnerElement(createAttribute.right().value());
+ } else {
+ attributesWrapper.setInnerElement(createAttribute.left().value());
+ }
+ }
+
+ Response response;
+ if (!errorWrapper.isEmpty()) {
+ log.info("Failed to create Attribute. Reason - ", errorWrapper.getInnerElement());
+ response = buildErrorResponse(errorWrapper.getInnerElement());
+ } else {
+ PropertyDefinition createdAttDef = attributesWrapper.getInnerElement();
+ log.debug("Attribute {} created successfully with id {}", createdAttDef.getName(), createdAttDef.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(createdAttDef));
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Attribute");
+ log.debug("create property failed with exception", e);
+ throw e;
+ }
+ }
+
+ /**
+ * Updates existing Attribute with given attributeID on a resource with given resourceID
+ *
+ * @param resourceId
+ * @param attributeId
+ * @param data
+ * @param request
+ * @param userId
+ * @return
+ */
+ @PUT
+ @Path("resources/{resourceId}/attributes/{attributeId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Resource Attribute", method = "PUT", summary = "Returns updated attribute",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource attribute updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateAttribute(
+ @Parameter(description = "resource id to update with new attribute",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "attribute id to update",
+ required = true) @PathParam("attributeId") final String attributeId,
+ @Parameter(description = "Resource attribute to update", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ try {
+ // convert json to PropertyDefinition
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Wrapper<PropertyDefinition> attributesWrapper = new Wrapper<>();
+ // convert json to AttributeDefinition
+
+ buildAttributeFromString(data, attributesWrapper, errorWrapper);
+
+ if (errorWrapper.isEmpty()) {
+ AttributeBusinessLogic businessLogic = getClassFromWebAppContext(context, () -> AttributeBusinessLogic.class);
+ Either<PropertyDefinition, ResponseFormat> eitherUpdateAttribute = businessLogic.updateAttribute(resourceId, attributeId, attributesWrapper.getInnerElement(), userId);
+ // update property
+ if (eitherUpdateAttribute.isRight()) {
+ errorWrapper.setInnerElement(eitherUpdateAttribute.right().value());
+ } else {
+ attributesWrapper.setInnerElement(eitherUpdateAttribute.left().value());
+ }
+ }
+
+ Response response;
+ if (!errorWrapper.isEmpty()) {
+ log.info("Failed to update Attribute. Reason - ", errorWrapper.getInnerElement());
+ response = buildErrorResponse(errorWrapper.getInnerElement());
+ } else {
+ PropertyDefinition updatedAttribute = attributesWrapper.getInnerElement();
+ log.debug("Attribute id {} updated successfully ", updatedAttribute.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(updatedAttribute));
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Attribute");
+ log.debug("update attribute failed with exception", e);
+ throw e;
+ }
+ }
+
+ /**
+ * Deletes existing Attribute with given attributeID on a resource with given resourceID
+ *
+ * @param resourceId
+ * @param attributeId
+ * @param request
+ * @param userId
+ * @return
+ */
+ @DELETE
+ @Path("resources/{resourceId}/attributes/{attributeId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Resource Attribute", method = "DELETE", summary = "Returns deleted attribute",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "deleted attribute"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Resource property not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteAttribute(
+ @Parameter(description = "resource id of attribute",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "Attribute id to delete",
+ required = true) @PathParam("attributeId") final String attributeId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ log.debug("modifier id is {}", userId);
+
+ try {
+
+ // delete the property
+ AttributeBusinessLogic businessLogic = getClassFromWebAppContext(context, () -> AttributeBusinessLogic.class);
+ Either<PropertyDefinition, ResponseFormat> eitherAttribute = businessLogic.deleteAttribute(resourceId, attributeId, userId);
+ if (eitherAttribute.isRight()) {
+ log.debug("Failed to delete Attribute. Reason - ", eitherAttribute.right().value());
+ return buildErrorResponse(eitherAttribute.right().value());
+ }
+ PropertyDefinition attributeDefinition = eitherAttribute.left().value();
+ String name = attributeDefinition.getName();
+
+ log.debug("Attribute {} deleted successfully with id {}", name, attributeDefinition.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(attributeDefinition));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Attribute");
+ log.debug("delete attribute failed with exception", e);
+ throw e;
+ }
+ }
+
+ private void buildAttributeFromString(String data, Wrapper<PropertyDefinition> attributesWrapper,
+ Wrapper<ResponseFormat> errorWrapper) {
+ try {
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ final PropertyDefinition attribute = gson.fromJson(data, PropertyDefinition.class);
+ if (attribute == null) {
+ log.info(ATTRIBUTE_CONTENT_IS_INVALID, data);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ errorWrapper.setInnerElement(responseFormat);
+ } else {
+ attributesWrapper.setInnerElement(attribute);
+ }
+
+ } catch (Exception e) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ errorWrapper.setInnerElement(responseFormat);
+ log.debug(ATTRIBUTE_CONTENT_IS_INVALID, data, e);
+ log.info(ATTRIBUTE_CONTENT_IS_INVALID, data);
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java
index ce4dfdd3d0..440b72a907 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AutomatedUpgradeEndpoint.java
@@ -1,137 +1,142 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.List;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-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;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic;
-import org.openecomp.sdc.be.components.upgrade.UpgradeRequest;
-import org.openecomp.sdc.be.components.upgrade.UpgradeStatus;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.stereotype.Controller;
-import com.jcabi.aspects.Loggable;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "policy types resource"))
-@Controller
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class AutomatedUpgradeEndpoint extends BeGenericServlet {
- private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
-
- private final UpgradeBusinessLogic businessLogic;
-
- @Inject
- public AutomatedUpgradeEndpoint(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- UpgradeBusinessLogic businessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.businessLogic = businessLogic;
- }
-
- @POST
- @Path("/{componentType}/{componentId}/automatedupgrade")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Autometed upgrade", method = "POST", summary = "....", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response autometedUpgrade(@PathParam("componentType") final String componentType,
- @Context final HttpServletRequest request, @PathParam("componentId") final String componentId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "json describes upgrade request", required = true) String data) {
-
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(POST) Start handle request of {}", url);
-
- try {
-
- List<UpgradeRequest> inputsToUpdate = JsonParserUtils.toList(data, UpgradeRequest.class);
-
- if (log.isDebugEnabled()) {
- log.debug("Received upgrade requests size is {}", inputsToUpdate == null ? 0 : inputsToUpdate.size());
- }
- UpgradeStatus actionResponse = businessLogic.automatedUpgrade(componentId, inputsToUpdate, userId);
-
- return actionResponse.getStatus() == ActionStatus.OK ? buildOkResponse(actionResponse) : buildErrorResponse(actionResponse.getError());
-
- } catch (Exception e) {
- log.error("#autometedUpgrade - Exception occurred during autometed Upgrade", e);
- return buildGeneralErrorResponse();
- }
- }
-
- @GET
- @Path("/{componentType}/{componentId}/dependencies")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Autometed upgrade", method = "POST", summary = "....", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getComponentDependencies(@PathParam("componentType") final String componentType,
- @Context final HttpServletRequest request, @PathParam("componentId") final String componentId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "Consumer Object to be created", required = true) List<String> data) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(GET) Start handle request of {}", url);
-
- try {
- return businessLogic.getComponentDependencies(componentId, userId)
- .either(this::buildOkResponse, this::buildErrorResponse);
- } catch (Exception e) {
- log.error("#getServicesForComponent - Exception occurred during autometed Upgrade", e);
- return buildGeneralErrorResponse();
- }
-
-
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic;
+import org.openecomp.sdc.be.components.upgrade.UpgradeRequest;
+import org.openecomp.sdc.be.components.upgrade.UpgradeStatus;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "policy types resource"))
+@Controller
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class AutomatedUpgradeEndpoint extends BeGenericServlet {
+ private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
+
+ private final UpgradeBusinessLogic businessLogic;
+
+ @Inject
+ public AutomatedUpgradeEndpoint(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ UpgradeBusinessLogic businessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.businessLogic = businessLogic;
+ }
+
+ @POST
+ @Path("/{componentType}/{componentId}/automatedupgrade")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Autometed upgrade", method = "POST", summary = "....", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response autometedUpgrade(@PathParam("componentType") final String componentType,
+ @Context final HttpServletRequest request, @PathParam("componentId") final String componentId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "json describes upgrade request", required = true) String data) {
+
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(POST) Start handle request of {}", url);
+
+ try {
+
+ List<UpgradeRequest> inputsToUpdate = JsonParserUtils.toList(data, UpgradeRequest.class);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Received upgrade requests size is {}", inputsToUpdate == null ? 0 : inputsToUpdate.size());
+ }
+ UpgradeStatus actionResponse = businessLogic.automatedUpgrade(componentId, inputsToUpdate, userId);
+
+ return actionResponse.getStatus() == ActionStatus.OK ? buildOkResponse(actionResponse) : buildErrorResponse(actionResponse.getError());
+
+ } catch (Exception e) {
+ log.error("#autometedUpgrade - Exception occurred during autometed Upgrade", e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/dependencies")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Autometed upgrade", method = "POST", summary = "....", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentDependencies(@PathParam("componentType") final String componentType,
+ @Context final HttpServletRequest request, @PathParam("componentId") final String componentId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "Consumer Object to be created", required = true) List<String> data) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(GET) Start handle request of {}", url);
+
+ try {
+ return businessLogic.getComponentDependencies(componentId, userId)
+ .either(this::buildOkResponse, this::buildErrorResponse);
+ } catch (Exception e) {
+ log.error("#getServicesForComponent - Exception occurred during autometed Upgrade", e);
+ throw e;
+ }
+
+
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
index f7bb744a98..39733c9986 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
@@ -23,36 +23,43 @@ package org.openecomp.sdc.be.servlets;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import fj.data.Either;
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Set;
-import java.util.function.Supplier;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
+import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.RelationshipTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.RequirementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
+import org.openecomp.sdc.be.components.upgrade.UpgradeBusinessLogic;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.ComponentInstInputsMap;
@@ -65,12 +72,27 @@ import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.servlets.BasicServlet;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.web.context.WebApplicationContext;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
+import java.util.function.Supplier;
+
public class BeGenericServlet extends BasicServlet {
public BeGenericServlet(UserBusinessLogic userAdminManager,
@@ -110,6 +132,13 @@ public class BeGenericServlet extends BasicServlet {
.build();
}
+ public HttpServletRequest getServletRequest() {
+ return servletRequest;
+ }
+
+ @VisibleForTesting
+ public void setRequestServlet(HttpServletRequest request) {this.servletRequest = request;}
+
protected Response buildOkResponse(ResponseFormat errorResponseWrapper, Object entity) {
return buildOkResponse(errorResponseWrapper, entity, null);
}
@@ -136,17 +165,74 @@ public class BeGenericServlet extends BasicServlet {
/*******************************************************************************************************/
protected Either<User, ResponseFormat> getUser(final HttpServletRequest request, String userId) {
- Either<User, ActionStatus> eitherCreator = userAdminManager.getUser(userId, false);
- if (eitherCreator.isRight()) {
+ User user;
+ try {
+ user = getUserAdminManager(request.getSession().getServletContext()).getUser(userId, false);
+ return Either.left(user);
+ } catch (ComponentException ce) {
log.info("createResource method - user is not listed. userId= {}", userId);
- ResponseFormat errorResponse = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_INFORMATION);
- User user = new User("", "", userId, "", null, null);
-
+ ResponseFormat errorResponse = getComponentsUtils().getResponseFormat(ce);
+ user = new User("", "", userId, "", null, null);
getComponentsUtils().auditResource(errorResponse, user, "", AuditingActionEnum.CHECKOUT_RESOURCE);
return Either.right(errorResponse);
}
- return Either.left(eitherCreator.left().value());
+ }
+
+ UserBusinessLogic getUserAdminManager(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> UserBusinessLogic.class);
+ }
+
+ protected GenericArtifactBrowserBusinessLogic getGenericArtifactBrowserBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> GenericArtifactBrowserBusinessLogic.class);
+ }
+
+ protected ResourceBusinessLogic getResourceBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> ResourceBusinessLogic.class);
+ }
+ InterfaceOperationBusinessLogic getInterfaceOperationBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> InterfaceOperationBusinessLogic.class);
+ }
+
+ protected CapabilitiesBusinessLogic getCapabilitiesBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> CapabilitiesBusinessLogic.class);
+ }
+
+ protected RelationshipTypeBusinessLogic getRelationshipTypeBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> RelationshipTypeBusinessLogic.class);
+ }
+ protected RequirementBusinessLogic getRequirementBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> RequirementBusinessLogic.class);
+ }
+ ComponentsCleanBusinessLogic getComponentCleanerBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> ComponentsCleanBusinessLogic.class);
+ }
+
+ protected ServiceBusinessLogic getServiceBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> ServiceBusinessLogic.class);
+ }
+
+ ProductBusinessLogic getProductBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> ProductBusinessLogic.class);
+ }
+
+ protected ArtifactsBusinessLogic getArtifactBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> ArtifactsBusinessLogic.class);
+ }
+ protected UpgradeBusinessLogic getUpgradeBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> UpgradeBusinessLogic.class);
+ }
+
+ protected ElementBusinessLogic getElementBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> ElementBusinessLogic.class);
+ }
+
+ protected AssetMetadataConverter getAssetUtils(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> AssetMetadataConverter.class);
+ }
+
+ protected LifecycleBusinessLogic getLifecycleBL(ServletContext context) {
+ return getClassFromWebAppContext(context, () -> LifecycleBusinessLogic.class);
}
<T> T getClassFromWebAppContext(ServletContext context, Supplier<Class<T>> businessLogicClassGen) {
@@ -155,8 +241,25 @@ public class BeGenericServlet extends BasicServlet {
return webApplicationContext.getBean(businessLogicClassGen.get());
}
+ GroupBusinessLogic getGroupBL(ServletContext context) {
+
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(GroupBusinessLogic.class);
+ }
+
+ protected ComponentInstanceBusinessLogic getComponentInstanceBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(ComponentInstanceBusinessLogic.class);
+ }
+
protected ComponentsUtils getComponentsUtils() {
- return componentsUtils;
+ ServletContext context = this.servletRequest.getSession().getServletContext();
+
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(ComponentsUtils.class);
}
/**
@@ -179,7 +282,31 @@ public class BeGenericServlet extends BasicServlet {
return new StringBuilder().append("attachment; filename=\"").append(artifactFileName).append("\"").toString();
}
- <T> void convertJsonToObjectOfClass(String json, Wrapper<T> policyWrapper, Class<T> clazz, Wrapper<Response> errorWrapper) {
+
+
+ protected ComponentBusinessLogic getComponentBL(ComponentTypeEnum componentTypeEnum, ServletContext context) {
+ ComponentBusinessLogic businessLogic;
+ switch (componentTypeEnum) {
+ case RESOURCE:
+ businessLogic = getResourceBL(context);
+ break;
+ case SERVICE:
+ businessLogic = getServiceBL(context);
+ break;
+ case PRODUCT:
+ businessLogic = getProductBL(context);
+ break;
+ case RESOURCE_INSTANCE:
+ businessLogic = getResourceBL(context);
+ break;
+ default:
+ BeEcompErrorManager.getInstance().logBeSystemError("getComponentBL");
+ throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue());
+ }
+ return businessLogic;
+ }
+
+ <T> T convertJsonToObjectOfClass(String json, Class<T> clazz) {
T object = null;
ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
@@ -193,16 +320,16 @@ public class BeGenericServlet extends BasicServlet {
object = mapper.readValue(json, clazz);
if (object != null) {
- policyWrapper.setInnerElement(object);
+ return object;
} else {
BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
log.debug("The object of class {} is null after converting from json. ", clazz);
- errorWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
- } catch (Exception e) {
+ } catch (IOException e) {
BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
- log.debug("The exception {} occured upon json to object convertation. Json=\n{}", e, json);
- errorWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)));
+ log.debug("The exception {} occurred upon json to object convertation. Json=\n{}", e, json);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
}
@@ -360,6 +487,13 @@ public class BeGenericServlet extends BasicServlet {
}
+ protected PropertyBusinessLogic getPropertyBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ PropertyBusinessLogic propertytBl = webApplicationContext.getBean(PropertyBusinessLogic.class);
+ return propertytBl;
+ }
+
protected InputsBusinessLogic getInputBL(ServletContext context) {
WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java
index 5433bd5be3..e34034671e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeMonitoringServlet.java
@@ -1,194 +1,156 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.util.List;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.tuple.Pair;
-import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic;
-import org.openecomp.sdc.be.components.impl.MonitoringBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.api.HealthCheckInfo;
-import org.openecomp.sdc.common.api.HealthCheckWrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.monitoring.MonitoringEvent;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.TRACE, trim = false)
-@Path("/")
-@OpenAPIDefinition(info = @Info(title = "BE Monitoring", description = "BE Monitoring"))
-@Singleton
-public class BeMonitoringServlet extends BeGenericServlet {
-
- Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
-
- private static final Logger log = Logger.getLogger(ConfigServlet.class);
- private final HealthCheckBusinessLogic healthCheckBusinessLogic;
- private final MonitoringBusinessLogic monitoringBusinessLogic;
-
- @Inject
- public BeMonitoringServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- HealthCheckBusinessLogic healthCheckBusinessLogic,
- MonitoringBusinessLogic monitoringBusinessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.healthCheckBusinessLogic = healthCheckBusinessLogic;
- this.monitoringBusinessLogic = monitoringBusinessLogic;
- }
-
- @GET
- @Path("/healthCheck")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Return aggregate BE health check of SDC BE components", summary = "return BE health check",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "SDC BE components are all up"),
- @ApiResponse(responseCode = "500", description = "One or more SDC BE components are down")})
- public Response getHealthCheck(@Context final HttpServletRequest request) {
- try {
- Pair<Boolean, List<HealthCheckInfo>> beHealthCheckInfosStatus =
- healthCheckBusinessLogic.getBeHealthCheckInfosStatus();
- Boolean aggregateStatus = beHealthCheckInfosStatus.getLeft();
- ActionStatus status = aggregateStatus ? ActionStatus.OK : ActionStatus.GENERAL_ERROR;
- String sdcVersion = getVersionFromContext(request);
- if (sdcVersion == null || sdcVersion.isEmpty()) {
- sdcVersion = "UNKNOWN";
- }
- String siteMode = healthCheckBusinessLogic.getSiteMode();
- HealthCheckWrapper healthCheck =
- new HealthCheckWrapper(beHealthCheckInfosStatus.getRight(), sdcVersion, siteMode);
- // The response can be either with 200 or 500 aggregate status - the
- // body of individual statuses is returned either way
-
- String healthCheckStr = prettyGson.toJson(healthCheck);
- return buildOkResponse(getComponentsUtils().getResponseFormat(status), healthCheckStr);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeHealthCheckError("BeHealthCheck");
- log.debug("BE health check unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/monitoring")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response processMonitoringMetrics(@Context final HttpServletRequest request, String json) {
- try {
- MonitoringEvent monitoringEvent = convertContentToJson(json, MonitoringEvent.class);
- if (monitoringEvent == null) {
- return buildErrorResponse(getComponentsUtils().getResponseFormatAdditionalProperty(ActionStatus.GENERAL_ERROR));
- }
- log.trace("Received monitoring metrics: {}", monitoringEvent);
- Either<Boolean, ResponseFormat> result = monitoringBusinessLogic.logMonitoringEvent(monitoringEvent);
- if (result.isRight()) {
- return buildErrorResponse(result.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
-
- } catch (Exception e) {
- log.debug("BE system metrics unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormatAdditionalProperty(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Path("/version")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "return the ASDC application version", summary = "return the ASDC application version",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "return ASDC version"),
- @ApiResponse(responseCode = "500", description = "Internal Error")})
- public Response getSdcVersion(@Context final HttpServletRequest request) {
- try {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- String version = getVersionFromContext(request);
- log.debug("asdc version from manifest is: {}", version);
- if (version == null || version.isEmpty()) {
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.ASDC_VERSION_NOT_FOUND));
- }
-
- HealthCheckInfo versionInfo = new HealthCheckInfo();
- versionInfo.setVersion(version);
-
- // The response can be either with 200 or 500 aggregate status - the
- // body of individual statuses is returned either way
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), versionInfo);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getSDCVersion");
- log.debug("BE get ASDC version unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private String getVersionFromContext(HttpServletRequest request) {
- ServletContext servletContext = request.getSession().getServletContext();
- return (String) servletContext.getAttribute(Constants.ASDC_RELEASE_VERSION_ATTR);
- }
-
- protected MonitoringEvent convertContentToJson(String content, Class<MonitoringEvent> clazz) {
-
- MonitoringEvent object = null;
- try {
- object = gson.fromJson(content, clazz);
- object.setFields(null);
- } catch (Exception e) {
- log.debug("Failed to convert the content {} to object.", content.substring(0, Math.min(50, content.length())), e);
- }
-
- return object;
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.tuple.Pair;
+import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.api.HealthCheckInfo;
+import org.openecomp.sdc.common.api.HealthCheckWrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.context.WebApplicationContext;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+
+@Loggable(prepend = true, value = Loggable.TRACE, trim = false)
+@Path("/")
+@OpenAPIDefinition(info = @Info(title = "BE Monitoring", description = "BE Monitoring"))
+@Controller
+public class BeMonitoringServlet extends BeGenericServlet {
+
+ Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
+
+ private static final Logger log = Logger.getLogger(ConfigServlet.class);
+ private final HealthCheckBusinessLogic healthCheckBusinessLogic;
+
+ @Inject
+ public BeMonitoringServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ HealthCheckBusinessLogic healthCheckBusinessLogic){
+ super(userBusinessLogic, componentsUtils);
+ this.healthCheckBusinessLogic = healthCheckBusinessLogic;
+ }
+
+ @GET
+ @Path("/healthCheck")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Return aggregate BE health check of SDC BE components", summary = "return BE health check",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "SDC BE components are all up"),
+ @ApiResponse(responseCode = "500", description = "One or more SDC BE components are down")})
+ public Response getHealthCheck(@Context final HttpServletRequest request) {
+ try {
+ Pair<Boolean, List<HealthCheckInfo>> beHealthCheckInfosStatus = healthCheckBusinessLogic.getBeHealthCheckInfosStatus();
+ Boolean aggregateStatus = beHealthCheckInfosStatus.getLeft();
+ ActionStatus status = aggregateStatus ? ActionStatus.OK : ActionStatus.GENERAL_ERROR;
+ String sdcVersion = getVersionFromContext(request);
+ if (sdcVersion == null || sdcVersion.isEmpty()) {
+ sdcVersion = "UNKNOWN";
+ }
+ String siteMode = healthCheckBusinessLogic.getSiteMode();
+ HealthCheckWrapper healthCheck = new HealthCheckWrapper(beHealthCheckInfosStatus.getRight(), sdcVersion, siteMode);
+ // The response can be either with 200 or 500 aggregate status - the
+ // body of individual statuses is returned either way
+
+ String healthCheckStr = prettyGson.toJson(healthCheck);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(status), healthCheckStr);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeHealthCheckError("BeHealthCheck");
+ log.debug("BE health check unexpected exception", e);
+ throw e;
+ }
+ }
+
+
+ //TODO remove after UI alignment and tests after API consolidation ASDC-191
+ /*@GET
+ @Path("/version")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "return the ASDC application version", notes = "return the ASDC application version", response = String.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "return ASDC version"), @ApiResponse(code = 500, message = "Internal Error") })
+ public Response getSdcVersion(@Context final HttpServletRequest request) {
+ try {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ String version = getVersionFromContext(request);
+ log.debug("asdc version from manifest is: {}", version);
+ if (version == null || version.isEmpty()) {
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.ASDC_VERSION_NOT_FOUND));
+ }
+
+ HealthCheckInfo versionInfo = new HealthCheckInfo();
+ versionInfo.setVersion(version);
+
+ // The response can be either with 200 or 500 aggregate status - the
+ // body of individual statuses is returned either way
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), versionInfo);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getSDCVersion");
+ log.debug("BE get ASDC version unexpected exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }*/
+
+ private String getVersionFromContext(HttpServletRequest request) {
+ ServletContext servletContext = request.getSession().getServletContext();
+ return (String) servletContext.getAttribute(Constants.ASDC_RELEASE_VERSION_ATTR);
+ }
+
+ private HealthCheckBusinessLogic getHealthCheckBL(ServletContext context) {
+ WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR);
+ WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context);
+ return webApplicationContext.getBean(HealthCheckBusinessLogic.class);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java
index 0e00e017d8..e576337c4d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CapabilityServlet.java
@@ -1,342 +1,357 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.List;
-import java.util.Optional;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-@OpenAPIDefinition(info = @Info(title = "Capability Servlet", description = "Capability Servlet"))
-@Singleton
-public class CapabilityServlet extends AbstractValidationsServlet {
- private static final Logger LOGGER = Logger.getLogger(CapabilityServlet.class);
- private final CapabilitiesBusinessLogic capabilitiesBusinessLogic;
-
- @Inject
- public CapabilityServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- CapabilitiesBusinessLogic capabilitiesBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.capabilitiesBusinessLogic = capabilitiesBusinessLogic;
- }
-
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/capabilities")
- @Operation(description = "Create Capabilities on resource", method = "POST",
- summary = "Create Capabilities on resource", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Capabilities"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Capability already exist")})
- public Response createCapabilitiesOnResource(
- @Parameter(description = "Capability to create", required = true) String data,
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, "resources" , resourceId,
- request, userId, false, "createCapabilities");
- }
-
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/capabilities")
- @Operation(description = "Update Capabilities on resource", method = "PUT",
- summary = "Update Capabilities on resource",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Capabilities"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateCapabilitiesOnResource(
- @Parameter(description = "Capabilities to update", required = true) String data,
- @Parameter(description = "Component Id") @PathParam("resourceId") String resourceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, "resources", resourceId,
- request, userId, true, "updateCapabilities");
- }
-
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/capabilities/{capabilityId}")
- @Operation(description = "Get Capability from resource", method = "GET",
- summary = "GET Capability from resource", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "GET Capability"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response getCapabilityOnResource(
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @Parameter(description = "Capability Id") @PathParam("capabilityId") String capabilityId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return get(capabilityId, resourceId, request, userId);
- }
-
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/capabilities/{capabilityId}")
- @Operation(description = "Delete capability from resource", method = "DELETE",
- summary = "Delete capability from resource", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete capability"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteCapabilityOnResource(
- @Parameter(description = "capability Id") @PathParam("capabilityId") String capabilityId,
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return delete(capabilityId, resourceId, request, userId);
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/capabilities")
- @Operation(description = "Create Capabilities on service", method = "POST",
- summary = "Create Capabilities on service", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Capabilities"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Capability already exist")})
- public Response createCapabilitiesOnService(
- @Parameter(description = "Capability to create", required = true) String data,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, "services" , serviceId,
- request, userId, false, "createCapabilities");
- }
-
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/capabilities")
- @Operation(description = "Update Capabilities on service", method = "PUT",
- summary = "Update Capabilities on service",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Capabilities"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateCapabilitiesOnService(
- @Parameter(description = "Capabilities to update", required = true) String data,
- @Parameter(description = "Component Id") @PathParam("serviceId") String serviceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, "services", serviceId,
- request, userId, true, "updateCapabilities");
- }
-
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/capabilities/{capabilityId}")
- @Operation(description = "Get Capability from service", method = "GET",
- summary = "GET Capability from service", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "GET Capability"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response getCapabilityOnService(
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Capability Id") @PathParam("capabilityId") String capabilityId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return get(capabilityId, serviceId, request, userId);
- }
-
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/capabilities/{capabilityId}")
- @Operation(description = "Delete capability from service", method = "DELETE",
- summary = "Delete capability from service",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete capability"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteCapabilityOnService(
- @Parameter(description = "capability Id") @PathParam("capabilityId") String capabilityId,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return delete(capabilityId, serviceId, request, userId);
- }
-
- private Response createOrUpdate (String data, String componentType, String componentId,
- HttpServletRequest request,
- String userId,
- boolean isUpdate,
- String errorContext) {
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- LOGGER.debug("Start create or update request of {} with modifier id {}", url, userId);
- try {
- String componentIdLower = componentId.toLowerCase();
-
- Either<List<CapabilityDefinition>, ResponseFormat> mappedCapabilitiesDataEither
- = getMappedCapabilitiesData(data, modifier, ComponentTypeEnum.findByParamName(componentType));
- if(mappedCapabilitiesDataEither.isRight()) {
- LOGGER.error("Failed to create or update capabilities");
- buildErrorResponse(mappedCapabilitiesDataEither.right().value());
- }
- List<CapabilityDefinition> mappedCapabilitiesData = mappedCapabilitiesDataEither.left().value();
- Either<List<CapabilityDefinition>, ResponseFormat> actionResponse;
- if(isUpdate) {
- actionResponse = capabilitiesBusinessLogic.updateCapabilities(componentIdLower,
- mappedCapabilitiesData, modifier, errorContext, true);
- } else {
- actionResponse = capabilitiesBusinessLogic.createCapabilities(componentIdLower,
- mappedCapabilitiesData, modifier, errorContext, true);
- }
- if (actionResponse.isRight()) {
- LOGGER.error("Failed to create or update capabilities");
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- actionResponse.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Capabilities create or update");
- LOGGER.error("Failed to create or update capabilities with an error", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Response get (String capabilityIdToGet, String componentId,
- HttpServletRequest request, String userId){
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- LOGGER.debug("Start get request of {} with modifier id {}", url, userId);
-
- try {
- String componentIdLower = componentId.toLowerCase();
-
- Either<CapabilityDefinition, ResponseFormat> actionResponse = capabilitiesBusinessLogic
- .getCapability(componentIdLower, capabilityIdToGet, modifier, true);
- if (actionResponse.isRight()) {
- LOGGER.error("failed to get capability");
- return buildErrorResponse(actionResponse.right().value());
- }
- Object result = RepresentationUtils.toFilteredRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get capability");
- LOGGER.error("get capabilities failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Response delete (String capabilityId, String componentId, HttpServletRequest
- request, String userId){
-
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- LOGGER.debug("Start delete request of {} with modifier id {}", url, userId);
-
- try {
- String componentIdLower = componentId.toLowerCase();
-
- Either<CapabilityDefinition, ResponseFormat> actionResponse = capabilitiesBusinessLogic
- .deleteCapability(componentIdLower, capabilityId, modifier, true);
- if (actionResponse.isRight()) {
- LOGGER.error("failed to delete capability");
- return buildErrorResponse(actionResponse.right().value());
- }
- Object result = RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete capability");
- LOGGER.error("Delete capability failed with an error", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Either<List<CapabilityDefinition>, ResponseFormat> getMappedCapabilitiesData(String inputJson, User user,
- ComponentTypeEnum componentTypeEnum){
- Either<UiComponentDataTransfer, ResponseFormat> mappedData = getComponentsUtils()
- .convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class,
- AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
- Optional<List<CapabilityDefinition>> capabilityDefinitionList =
- mappedData.left().value().getCapabilities().values().stream().findFirst();
- return capabilityDefinitionList.<Either<List<CapabilityDefinition>, ResponseFormat>>
- map(Either::left).orElseGet(() -> Either.right(getComponentsUtils()
- .getResponseFormat(ActionStatus.GENERAL_ERROR)));
- }
-}
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.Optional;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@OpenAPIDefinition(info = @Info(title = "Capability Servlet", description = "Capability Servlet"))
+@Controller
+public class CapabilityServlet extends AbstractValidationsServlet {
+ private static final Logger LOGGER = Logger.getLogger(CapabilityServlet.class);
+ private final CapabilitiesBusinessLogic capabilitiesBusinessLogic;
+
+ @Inject
+ public CapabilityServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ CapabilitiesBusinessLogic capabilitiesBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.capabilitiesBusinessLogic = capabilitiesBusinessLogic;
+ }
+
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/capabilities")
+ @Operation(description = "Create Capabilities on resource", method = "POST",
+ summary = "Create Capabilities on resource", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Capabilities"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Capability already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createCapabilitiesOnResource(
+ @Parameter(description = "Capability to create", required = true) String data,
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return createOrUpdate(data, "resources" , resourceId,
+ request, userId, false, "createCapabilities");
+ }
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/capabilities")
+ @Operation(description = "Update Capabilities on resource", method = "PUT",
+ summary = "Update Capabilities on resource",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Capabilities"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateCapabilitiesOnResource(
+ @Parameter(description = "Capabilities to update", required = true) String data,
+ @Parameter(description = "Component Id") @PathParam("resourceId") String resourceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return createOrUpdate(data, "resources", resourceId,
+ request, userId, true, "updateCapabilities");
+ }
+
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/capabilities/{capabilityId}")
+ @Operation(description = "Get Capability from resource", method = "GET",
+ summary = "GET Capability from resource", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "GET Capability"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getCapabilityOnResource(
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @Parameter(description = "Capability Id") @PathParam("capabilityId") String capabilityId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return get(capabilityId, resourceId, request, userId);
+ }
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/capabilities/{capabilityId}")
+ @Operation(description = "Delete capability from resource", method = "DELETE",
+ summary = "Delete capability from resource", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete capability"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteCapabilityOnResource(
+ @Parameter(description = "capability Id") @PathParam("capabilityId") String capabilityId,
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return delete(capabilityId, resourceId, request, userId);
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/capabilities")
+ @Operation(description = "Create Capabilities on service", method = "POST",
+ summary = "Create Capabilities on service", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Capabilities"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Capability already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createCapabilitiesOnService(
+ @Parameter(description = "Capability to create", required = true) String data,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return createOrUpdate(data, "services" , serviceId,
+ request, userId, false, "createCapabilities");
+ }
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/capabilities")
+ @Operation(description = "Update Capabilities on service", method = "PUT",
+ summary = "Update Capabilities on service",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Capabilities"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateCapabilitiesOnService(
+ @Parameter(description = "Capabilities to update", required = true) String data,
+ @Parameter(description = "Component Id") @PathParam("serviceId") String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return createOrUpdate(data, "services", serviceId,
+ request, userId, true, "updateCapabilities");
+ }
+
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/capabilities/{capabilityId}")
+ @Operation(description = "Get Capability from service", method = "GET",
+ summary = "GET Capability from service", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "GET Capability"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getCapabilityOnService(
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Capability Id") @PathParam("capabilityId") String capabilityId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return get(capabilityId, serviceId, request, userId);
+ }
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/capabilities/{capabilityId}")
+ @Operation(description = "Delete capability from service", method = "DELETE",
+ summary = "Delete capability from service",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = CapabilityDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete capability"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteCapabilityOnService(
+ @Parameter(description = "capability Id") @PathParam("capabilityId") String capabilityId,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return delete(capabilityId, serviceId, request, userId);
+ }
+
+ private Response createOrUpdate (String data, String componentType, String componentId,
+ HttpServletRequest request,
+ String userId,
+ boolean isUpdate,
+ String errorContext) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ LOGGER.debug("Start create or update request of {} with modifier id {}", url, userId);
+ try {
+ String componentIdLower = componentId.toLowerCase();
+
+ Either<List<CapabilityDefinition>, ResponseFormat> mappedCapabilitiesDataEither
+ = getMappedCapabilitiesData(data, modifier, ComponentTypeEnum.findByParamName(componentType));
+ if(mappedCapabilitiesDataEither.isRight()) {
+ LOGGER.error("Failed to create or update capabilities");
+ buildErrorResponse(mappedCapabilitiesDataEither.right().value());
+ }
+ List<CapabilityDefinition> mappedCapabilitiesData = mappedCapabilitiesDataEither.left().value();
+ Either<List<CapabilityDefinition>, ResponseFormat> actionResponse;
+ if(isUpdate) {
+ actionResponse = capabilitiesBusinessLogic.updateCapabilities(componentIdLower,
+ mappedCapabilitiesData, modifier, errorContext, true);
+ } else {
+ actionResponse = capabilitiesBusinessLogic.createCapabilities(componentIdLower,
+ mappedCapabilitiesData, modifier, errorContext, true);
+ }
+ if (actionResponse.isRight()) {
+ LOGGER.error("Failed to create or update capabilities");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Capabilities create or update");
+ LOGGER.error("Failed to create or update capabilities with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Response get (String capabilityIdToGet, String componentId,
+ HttpServletRequest request, String userId){
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ LOGGER.debug("Start get request of {} with modifier id {}", url, userId);
+
+ try {
+ String componentIdLower = componentId.toLowerCase();
+
+ Either<CapabilityDefinition, ResponseFormat> actionResponse = capabilitiesBusinessLogic
+ .getCapability(componentIdLower, capabilityIdToGet, modifier, true);
+ if (actionResponse.isRight()) {
+ LOGGER.error("failed to get capability");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object result = RepresentationUtils.toFilteredRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get capability");
+ LOGGER.error("get capabilities failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Response delete (String capabilityId, String componentId, HttpServletRequest
+ request, String userId){
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ LOGGER.debug("Start delete request of {} with modifier id {}", url, userId);
+
+ try {
+ String componentIdLower = componentId.toLowerCase();
+
+ Either<CapabilityDefinition, ResponseFormat> actionResponse = capabilitiesBusinessLogic
+ .deleteCapability(componentIdLower, capabilityId, modifier, true);
+ if (actionResponse.isRight()) {
+ LOGGER.error("failed to delete capability");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object result = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete capability");
+ LOGGER.error("Delete capability failed with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Either<List<CapabilityDefinition>, ResponseFormat> getMappedCapabilitiesData(String inputJson, User user,
+ ComponentTypeEnum componentTypeEnum){
+ Either<UiComponentDataTransfer, ResponseFormat> mappedData = getComponentsUtils()
+ .convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class,
+ AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
+ Optional<List<CapabilityDefinition>> capabilityDefinitionList =
+ mappedData.left().value().getCapabilities().values().stream().findFirst();
+ return capabilityDefinitionList.<Either<List<CapabilityDefinition>, ResponseFormat>>
+ map(Either::left).orElseGet(() -> Either.right(getComponentsUtils()
+ .getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+}
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 e8e018ef71..6fa16f8681 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
@@ -1,1639 +1,1577 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.io.InputStream;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.ForwardingPaths;
-import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
-import org.openecomp.sdc.be.info.GroupDefinitionInfo;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.ComponentInstanceInput;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.PropertyConstraint;
-import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.reflect.TypeToken;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * Root resource (exposed at "/" path) .json
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Resource Instance Servlet"))
-@Singleton
-public class ComponentInstanceServlet extends AbstractValidationsServlet {
-
- private static final String FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID =
- "Failed to get properties of component instance ID: {} in {} with ID: {}";
- private static final String GET_GROUP_ARTIFACT_BY_ID = "getGroupArtifactById";
- private static final String GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION =
- "getGroupArtifactById unexpected exception";
- private static final String GET_START_HANDLE_REQUEST_OF = "(GET) Start handle request of {}";
- private static final String START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS =
- "Start handle request of updateResourceInstanceProperty. Received property is {}";
- private static final String UPDATE_RESOURCE_INSTANCE = "Update Resource Instance";
- private static final String RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE =
- "Resource Instance - updateResourceInstance";
- private static final String UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION = "update resource instance with exception";
- private static final String FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT =
- "Failed to convert received data to BE format.";
- private static final String EMPTY_BODY_WAS_SENT = "Empty body was sent.";
- private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
- private static final String UNSUPPORTED_COMPONENT_TYPE = "Unsupported component type {}";
- private static final Logger log = Logger.getLogger(ComponentInstanceServlet.class);
- private static final Type PROPERTY_CONSTRAINT_TYPE = new TypeToken<PropertyConstraint>() {}.getType();
- private static final Gson gsonDeserializer = new GsonBuilder()
- .registerTypeAdapter(PROPERTY_CONSTRAINT_TYPE, new PropertyConstraintDeserialiser()).create();
- private final GroupBusinessLogic groupBL;
- private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
- private final ServiceBusinessLogic serviceBusinessLogic;
-
-
- @Inject
- public ComponentInstanceServlet(UserBusinessLogic userBusinessLogic,
- GroupBusinessLogic groupBL, ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- ServiceBusinessLogic serviceBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.groupBL = groupBL;
- this.componentInstanceBusinessLogic = componentInstanceBL;
- this.serviceBusinessLogic = serviceBusinessLogic;
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create ComponentInstance", method = "POST", summary = "Returns created ComponentInstance",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Component created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Component instance already exist")})
- public Response createComponentInstance(@Parameter(description = "RI object to be created", required = true) String data,
- @PathParam("componentId") final String containerComponentId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
-
- try {
-
- ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
- componentInstance.setInvariantName(null);
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic
- .createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED),
- actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Component Instance");
- log.debug("create component instance failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update resource instance", method = "POST", summary = "Returns updated resource instance",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource instance updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateComponentInstanceMetadata(@PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @Parameter(description = "valid values: resources / services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME,
- ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- try {
-
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- InputStream inputStream = request.getInputStream();
-
- byte[] bytes = IOUtils.toByteArray(inputStream);
-
- if (bytes == null || bytes.length == 0) {
- log.info(EMPTY_BODY_WAS_SENT);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- String userId = request.getHeader(Constants.USER_ID_HEADER);
-
- String data = new String(bytes);
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
-
- if (convertResponse.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
- log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
- return buildErrorResponse(convertResponse.right().value());
- }
-
- ComponentInstance resourceInstance = convertResponse.left().value();
- Either<ComponentInstance, ResponseFormat> actionResponse =
- componentInstanceBusinessLogic.updateComponentInstanceMetadata(containerComponentType, componentId,
- componentInstanceId, userId, resourceInstance);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- ComponentInstance resultValue = actionResponse.left().value();
- if (componentTypeEnum.equals(ComponentTypeEnum.SERVICE)) {
- boolean shouldCreateServiceFilter = resourceInstance.getDirectives() != null
- && resourceInstance.getDirectives().contains(DirectivesUtils.SELECTABLE);
-
- if (shouldCreateServiceFilter) {
- Either<CINodeFilterDataDefinition, ResponseFormat> either = serviceBusinessLogic
- .createIfNotAlreadyExistServiceFilter(componentId, componentInstanceId, userId, true);
- if (either.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError(
- "Resource Instance - updateResourceInstance Failed to create service filter.");
- log.debug("Failed to create service filter.");
- return buildErrorResponse(convertResponse.right().value());
- }
- resultValue.setNodeFilter(either.left().value());
- } else {
- Either<String, ResponseFormat> either = serviceBusinessLogic
- .deleteIfNotAlreadyDeletedServiceFilter(componentId, componentInstanceId, userId, true);
- if (either.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError(
- "Resource Instance - updateResourceInstance Failed to delete service filter.");
- log.debug("Failed to delete service filter.");
- return buildErrorResponse(convertResponse.right().value());
- }
- resultValue.setNodeFilter(null);
- }
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
- log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/multipleComponentInstance")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update resource instance multiple component", method = "POST",
- summary = "Returns updated resource instance", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource instance updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateMultipleComponentInstance(@PathParam("componentId") final String componentId, @Parameter(
- description = "valid values: resources / services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME,
- ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Context final HttpServletRequest request, @Parameter(description = "Component Instance JSON Array",
- required = true) final String componentInstanceJsonArray) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- try {
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- if (componentInstanceJsonArray == null || componentInstanceJsonArray.length() == 0) {
- log.info("Empty JSON list was sent.");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- String userId = request.getHeader(Constants.USER_ID_HEADER);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<List<ComponentInstance>, ResponseFormat> convertResponse =
- convertToMultipleResourceInstance(componentInstanceJsonArray);
-
- if (convertResponse.isRight()) {
- // Using both ECOMP error methods, show to Sofer
- BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
- log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
- return buildErrorResponse(convertResponse.right().value());
- }
-
- List<ComponentInstance> componentInstanceList = convertResponse.left().value();
-
- Either<List<ComponentInstance>, ResponseFormat> actionResponse = componentInstanceBusinessLogic
- .updateComponentInstance(containerComponentType, componentId, userId, componentInstanceList, true);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
- log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @DELETE
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{resourceInstanceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Delete ResourceInstance", method = "DELETE", summary = "Returns delete resourceInstance",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "ResourceInstance deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteResourceInstance(@PathParam("componentId") final String componentId,
- @PathParam("resourceInstanceId") final String resourceInstanceId,
- @Parameter(description = "valid values: resources / services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME,
- ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- Response response = null;
- try {
- log.debug(START_HANDLE_REQUEST_OF, url);
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic
- .deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId);
-
- if (actionResponse.isRight()) {
- response = buildErrorResponse(actionResponse.right().value());
- } else {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
- }
- return response;
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource Instance");
- log.debug("delete resource instance with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @Parameter(description = "allowed values are resources /services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME,
- ComponentTypeEnum.PRODUCT_PARAM_NAME}),
- required = true)
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/associate")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Associate RI to RI", method = "POST", summary = "Returns created RelationshipInfo",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship created"),
- @ApiResponse(responseCode = "403", description = "Missing information"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Relationship already exist")})
- public Response associateRIToRI(@Parameter(
- description = "unique id of the container component") @PathParam("componentId") final String componentId,
- @Parameter(description = "allowed values are resources /services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME}),
- required = true) @PathParam("containerComponentType") final String containerComponentType,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "RelationshipInfo", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- Response response = null;
-
- try {
-
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
-
- Either<RequirementCapabilityRelDef, ResponseFormat> resultOp;
- if (regInfoW.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - associateRIToRI");
- log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
- resultOp = Either.right(regInfoW.right().value());
- } else {
- RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
- requirementDef.setOriginUI(true);
- resultOp = componentInstanceBusinessLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum);
- }
-
- Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = resultOp;
-
- if (actionResponse.isRight()) {
- response = buildErrorResponse(actionResponse.right().value());
- } else {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
- }
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Associate Resource Instance");
- log.debug("associate resource instance to another RI with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @PUT
- @Path("/{containerComponentType}/{componentId}/resourceInstance/dissociate")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Dissociate RI from RI", method = "PUT", summary = "Returns deleted RelationshipInfo",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship deleted"),
- @ApiResponse(responseCode = "403", description = "Missing information"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response dissociateRIFromRI(
- @Parameter(description = "allowed values are resources /services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME}),
- required = true) @PathParam("containerComponentType") final String containerComponentType,
- @Parameter(
- description = "unique id of the container component") @PathParam("componentId") final String componentId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "RelationshipInfo", required = true) String data,
- @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- try {
-
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<RequirementCapabilityRelDef, ResponseFormat> regInfoW = convertToRequirementCapabilityRelDef(data);
- if (regInfoW.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - dissociateRIFromRI");
- log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
- return buildErrorResponse(regInfoW.right().value());
- }
-
- RequirementCapabilityRelDef requirementDef = regInfoW.left().value();
- Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceBusinessLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Dissociate Resource Instance");
- log.debug("dissociate resource instance from service failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/createAndAssociate")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create RI and associate RI to RI", method = "POST",
- summary = "Returns created RI and RelationshipInfo", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "RI created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Relationship already exist")})
- public Response createAndAssociateRIToRI(@PathParam("componentId") final String componentId, @Parameter(
- description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- try {
-
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- InputStream inputStream = request.getInputStream();
-
- byte[] bytes = IOUtils.toByteArray(inputStream);
-
- if (bytes == null || bytes.length == 0) {
- log.info(EMPTY_BODY_WAS_SENT);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- String userId = request.getHeader(Constants.USER_ID_HEADER);
-
- String data = new String(bytes);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<CreateAndAssotiateInfo, ActionStatus> convertStatus = convertJsonToObject(data, CreateAndAssotiateInfo.class);
- if (convertStatus.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - createAndAssociateRIToRI");
- log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
- Either<Object, ResponseFormat> formattedResponse = Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
- return buildErrorResponse(formattedResponse.right().value());
- }
-
- CreateAndAssotiateInfo createAndAssotiateInfo = convertStatus.left().value();
- RequirementCapabilityRelDef requirementDef = createAndAssotiateInfo.getAssociate();
- requirementDef.setOriginUI(true);
- Either<CreateAndAssotiateInfo, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create and Associate Resource Instance");
- log.debug("create and associate RI failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update resource instance property", method = "POST",
- summary = "Returns updated resource instance property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateResourceInstanceProperties(
- @Parameter(description = "service id") @PathParam("componentId") final String componentId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Parameter(
- description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
- @Parameter(description = "id of user initiating the operation") @HeaderParam(
- value = Constants.USER_ID_HEADER) String userId,
- @Context final HttpServletRequest request,
- @Parameter(description = "Component Instance Properties JSON Array",
- required = true) final String componentInstancePropertiesJsonArray) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- try {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
- if (errorWrapper.isEmpty()) {
- Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(componentInstancePropertiesJsonArray);
- if (propertiesToUpdateEither.isRight()) {
- errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
- } else {
- propertiesToUpdate = propertiesToUpdateEither.left().value();
- }
- }
-
- if (!errorWrapper.isEmpty()) {
- return buildErrorResponse(errorWrapper.getInnerElement());
- }
-
- log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, propertiesToUpdate);
-
- ServletContext context = request.getSession().getServletContext();
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<List<ComponentInstanceProperty>, ResponseFormat> actionResponse =
- componentInstanceBusinessLogic.createOrUpdatePropertiesValues(componentTypeEnum, componentId, componentInstanceId, propertiesToUpdate, userId);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
-
- List<ComponentInstanceProperty> resourceInstanceProperties = actionResponse.left().value();
- ObjectMapper mapper = new ObjectMapper();
- String result = mapper.writeValueAsString(resourceInstanceProperties);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/inputs")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update resource instance property", method = "POST",
- summary = "Returns updated resource instance property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateResourceInstanceInput(
- @Parameter(description = "service id") @PathParam("componentId") final String componentId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Parameter(
- description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
- @Parameter(description = "id of user initiating the operation") @HeaderParam(
- value = Constants.USER_ID_HEADER) String userId,
- @Context final HttpServletRequest request,
- @Parameter(description = "Component Instance Properties JSON Array",
- required = true) final String componentInstanceInputsJsonArray) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- try {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- List<ComponentInstanceInput> inputsToUpdate = new ArrayList<>();
- if (errorWrapper.isEmpty()) {
- Either<List<ComponentInstanceInput>, ResponseFormat> inputsToUpdateEither = convertMultipleInputs(componentInstanceInputsJsonArray);
- if (inputsToUpdateEither.isRight()) {
- errorWrapper.setInnerElement(inputsToUpdateEither.right().value());
- } else {
- inputsToUpdate = inputsToUpdateEither.left().value();
- }
- }
- if (!errorWrapper.isEmpty()) {
- return buildErrorResponse(errorWrapper.getInnerElement());
- }
-
- log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, inputsToUpdate);
-
- ServletContext context = request.getSession().getServletContext();
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<List<ComponentInstanceInput>, ResponseFormat> actionResponse =
- componentInstanceBusinessLogic.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, componentInstanceId, inputsToUpdate, userId);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
-
- List<ComponentInstanceInput> resourceInstanceInput = actionResponse.left().value();
- ObjectMapper mapper = new ObjectMapper();
- String result = mapper.writeValueAsString(resourceInstanceInput);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- /**
- * Updates ResourceInstance Attribute
- *
- * @param componentId
- * @param containerComponentType
- * @param componentInstanceId
- * @param userId
- * @param request
- * @return
- */
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/attribute")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update resource instance attribute", method = "POST",
- summary = "Returns updated resource instance attribute", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateResourceInstanceAttribute(
- @Parameter(description = "service id") @PathParam("componentId") final String componentId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Parameter(
- description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
- @Parameter(description = "id of user initiating the operation") @HeaderParam(
- value = Constants.USER_ID_HEADER) String userId,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- try {
-
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Wrapper<String> dataWrapper = new Wrapper<>();
- Wrapper<ComponentInstanceProperty> attributeWrapper = new Wrapper<>();
- Wrapper<ComponentInstanceBusinessLogic> blWrapper = new Wrapper<>();
-
- validateInputStream(request, dataWrapper, errorWrapper);
-
- if (errorWrapper.isEmpty()) {
- validateClassParse(dataWrapper.getInnerElement(), attributeWrapper,
- () -> ComponentInstanceProperty.class, errorWrapper);
- }
-
- if (errorWrapper.isEmpty()) {
- validateComponentInstanceBusinessLogic(request, containerComponentType, blWrapper, errorWrapper);
- }
-
- if (errorWrapper.isEmpty()) {
- ComponentInstanceBusinessLogic componentInstanceLogic = blWrapper.getInnerElement();
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- log.debug("Start handle request of ComponentInstanceAttribute. Received attribute is {}",
- attributeWrapper.getInnerElement());
- Either<ComponentInstanceProperty, ResponseFormat> eitherAttribute =
- componentInstanceLogic.createOrUpdateAttributeValue(componentTypeEnum, componentId,
- componentInstanceId, attributeWrapper.getInnerElement(), userId);
- if (eitherAttribute.isRight()) {
- errorWrapper.setInnerElement(eitherAttribute.right().value());
- } else {
- attributeWrapper.setInnerElement(eitherAttribute.left().value());
- }
- }
-
- return buildResponseFromElement(errorWrapper, attributeWrapper);
-
- } catch (Exception e) {
- log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @DELETE
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property/{propertyId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update resource instance", method = "DELETE",
- summary = "Returns deleted resource instance property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteResourceInstanceProperty(
- @Parameter(description = "service id") @PathParam("componentId") final String componentId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Parameter(
- description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
- @Parameter(description = "property id") @PathParam("propertyId") final String propertyId,
- @Parameter(description = "id of user initiating the operation") @HeaderParam(
- value = Constants.USER_ID_HEADER) String userId,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- try {
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(
- getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceBusinessLogic
- .deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId);
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
- } catch (Exception e) {
- log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/changeVersion")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update resource instance", method = "POST", summary = "Returns updated resource instance",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response changeResourceInstanceVersion(@PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- try ( InputStream inputStream = request.getInputStream()) {
-
- byte[] bytes = IOUtils.toByteArray(inputStream);
-
- if (bytes == null || bytes.length == 0) {
- log.info(EMPTY_BODY_WAS_SENT);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- String userId = request.getHeader(Constants.USER_ID_HEADER);
-
- String data = new String(bytes);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
-
- if (convertResponse.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
- log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
- return buildErrorResponse(convertResponse.right().value());
- }
-
- ComponentInstance newResourceInstance = convertResponse.left().value();
- Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
- log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}/property")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update resource instance property", method = "POST",
- summary = "Returns updated resource instance property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateGroupInstanceProperty(
- @Parameter(description = "service id") @PathParam("componentId") final String componentId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Parameter(
- description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
- @Parameter(description = "group instance id") @PathParam("groupInstanceId") final String groupInstanceId,
- @Parameter(description = "id of user initiating the operation") @HeaderParam(
- value = Constants.USER_ID_HEADER) String userId,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- try {
- Wrapper<String> dataWrapper = new Wrapper<>();
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
-
- validateInputStream(request, dataWrapper, errorWrapper);
-
- if (errorWrapper.isEmpty()) {
- validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
- }
-
- if (!errorWrapper.isEmpty()) {
- return buildErrorResponse(errorWrapper.getInnerElement());
- }
-
- ComponentInstanceProperty property = propertyWrapper.getInnerElement();
-
- log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, property);
-
- ServletContext context = request.getSession().getServletContext();
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
-
- ComponentInstanceProperty resourceInstanceProperty = actionResponse.left().value();
- ObjectMapper mapper = new ObjectMapper();
- String result = mapper.writeValueAsString(resourceInstanceProperty);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @GET
- @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get group artifacts ", method = "GET",
- summary = "Returns artifacts metadata according to groupInstId", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "group found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Group not found")})
- public Response getGroupArtifactById(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @PathParam("groupInstId") final String groupInstId, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(GET_START_HANDLE_REQUEST_OF, url);
-
- try {
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- Either<GroupDefinitionInfo, ResponseFormat> actionResponse = groupBL
- .getGroupInstWithArtifactsById(componentTypeEnum, componentId, componentInstanceId,
- groupInstId, userId, false);
-
- if (actionResponse.isRight()) {
- log.debug("failed to get all non abstract {}", containerComponentType);
- return buildErrorResponse(actionResponse.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
- log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- // US831698
- @GET
- @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get component instance properties", method = "GET",
- summary = "Returns component instance properties", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component/Component Instance - not found")})
- public Response getInstancePropertiesById(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("containerComponentId") final String containerComponentId,
- @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(GET_START_HANDLE_REQUEST_OF, url);
-
- try {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
-
- Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBusinessLogic.getComponentInstancePropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, userId);
-
- if (componentInstancePropertiesById.isRight()) {
- log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId);
- return buildErrorResponse(componentInstancePropertiesById.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
- log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- // US330353
- @GET
- @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get component instance capability properties", method = "GET",
- summary = "Returns component instance capability properties", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component/Component Instance/Capability - not found")})
- public Response getInstanceCapabilityPropertiesById(
- @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("containerComponentId") final String containerComponentId,
- @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
- @PathParam("capabilityType") final String capabilityType,
- @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(GET_START_HANDLE_REQUEST_OF, url);
-
- try {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
-
- Either<List<ComponentInstanceProperty>, ResponseFormat> componentInstancePropertiesById = componentInstanceBusinessLogic.getComponentInstanceCapabilityPropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId,
- capabilityType, capabilityName, ownerId, userId);
-
- if (componentInstancePropertiesById.isRight()) {
- log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId);
- return buildErrorResponse(componentInstancePropertiesById.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
- log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- //US 331281
- @PUT
- @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Instance Capabilty Property", method = "PUT",
- summary = "Returns updated property", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(
- value = {@ApiResponse(responseCode = "200", description = "Resource instance capabilty property updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Component/Component Instance/Capability - not found")})
- public Response updateInstanceCapabilityProperty(
- @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("containerComponentId") final String containerComponentId,
- @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
- @PathParam("capabilityType") final String capabilityType,
- @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId,
- @Parameter(description = "Instance capabilty property to update", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(PUT) Start handle request of {}", url);
- try {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
- if (errorWrapper.isEmpty()) {
- Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither =
- convertMultipleProperties(data);
- if (propertiesToUpdateEither.isRight()) {
- errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
- } else {
- propertiesToUpdate = propertiesToUpdateEither.left().value();
- }
- }
-
- if (!errorWrapper.isEmpty()) {
- return buildErrorResponse(errorWrapper.getInnerElement());
- }
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
-
- Either<List<ComponentInstanceProperty>, ResponseFormat> updateCICapProperty = componentInstanceBusinessLogic.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, propertiesToUpdate, userId);
-
- if (updateCICapProperty.isRight()) {
- log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId);
- return buildErrorResponse(updateCICapProperty.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updateCICapProperty.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
- log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{containerComponentId}/serviceProxy")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create service proxy", method = "POST", summary = "Returns created service proxy",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Service proxy already exist")})
- public Response createServiceProxy(@Parameter(description = "RI object to be created", required = true) String data,
- @PathParam("containerComponentId") final String containerComponentId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
-
- try {
-
- ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
- componentInstance.setInvariantName(null);
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentTypeEnum != ComponentTypeEnum.SERVICE) {
- log.debug("Unsupported container component type {}", containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createServiceProxy();
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create service proxy");
- log.debug("Create service proxy failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @DELETE
- @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Delete service proxy", method = "DELETE", summary = "Returns delete service proxy",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteServiceProxy(@PathParam("containerComponentId") final String containerComponentId,
- @PathParam("serviceProxyId") final String serviceProxyId,
- @Parameter(description = "valid values: resources / services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- Response response = null;
- try {
- log.debug(START_HANDLE_REQUEST_OF, url);
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.deleteServiceProxy();
-
- if (actionResponse.isRight()) {
- response = buildErrorResponse(actionResponse.right().value());
- } else {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
- }
- return response;
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete service proxy");
- log.debug("Delete service proxy failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}/changeVersion/{newServiceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update service proxy with new version", method = "POST",
- summary = "Returns updated service proxy", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response changeServiceProxyVersion(@PathParam("containerComponentId") final String containerComponentId,
- @PathParam("serviceProxyId") final String serviceProxyId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- try {
-
- String userId = request.getHeader(Constants.USER_ID_HEADER);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.changeServiceProxyVersion();
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update service proxy with new version");
- log.debug("Update service proxy with new version failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
- /**
- * REST API GET relation by Id
- * Allows to get relation contained in specified component according to received Id
- * @param containerComponentType
- * @param componentId
- * @param relationId
- * @param request
- * @param userId
- * @return Response
- */
- @GET
- @Path("/{containerComponentType}/{componentId}/relationId/{relationId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get relation", method = "GET",
- summary = "Returns relation metadata according to relationId",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "relation found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Relation not found")})
- public Response getRelationById(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("relationId") final String relationId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(GET_START_HANDLE_REQUEST_OF, url);
- try {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentTypeEnum == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceBusinessLogic.getRelationById(componentId, relationId, userId, componentTypeEnum);
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getRelationById");
- log.debug("getRelationById unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) {
-
- Either<ComponentInstance, ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), ComponentInstance.class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
- if (convertStatus.isRight()) {
- return Either.right(convertStatus.right().value());
- }
- ComponentInstance resourceInstanceInfo = convertStatus.left().value();
-
- return Either.left(resourceInstanceInfo);
- }
-
- private Either<List<ComponentInstance>, ResponseFormat> convertToMultipleResourceInstance(String dataList) {
-
- Either<ComponentInstance[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstance[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
- if (convertStatus.isRight()) {
- return Either.right(convertStatus.right().value());
- }
-
- return Either.left(Arrays.asList(convertStatus.left().value()));
- }
-
- private Either<List<ComponentInstanceProperty>, ResponseFormat> convertMultipleProperties(String dataList) {
- if (StringUtils.isEmpty(dataList)) {
- return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- Either<ComponentInstanceProperty[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceProperty[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
- if (convertStatus.isRight()) {
- return Either.right(convertStatus.right().value());
- }
- return Either.left(Arrays.asList(convertStatus.left().value()));
- }
-
- private Either<List<ComponentInstanceInput>, ResponseFormat> convertMultipleInputs(String dataList) {
- if (StringUtils.isEmpty(dataList)) {
- return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- Either<ComponentInstanceInput[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceInput[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
- if (convertStatus.isRight()) {
- return Either.right(convertStatus.right().value());
- }
- return Either.left(Arrays.asList(convertStatus.left().value()));
- }
-
-
- private Either<RequirementCapabilityRelDef, ResponseFormat> convertToRequirementCapabilityRelDef(String data) {
-
- Either<RequirementCapabilityRelDef, ActionStatus> convertStatus = convertJsonToObject(data, RequirementCapabilityRelDef.class);
- if (convertStatus.isRight()) {
- return Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
- }
- RequirementCapabilityRelDef requirementCapabilityRelDef = convertStatus.left().value();
- return Either.left(requirementCapabilityRelDef);
- }
-
- public <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
- try {
- log.trace("convert json to object. json=\n {}", data);
- T t;
- t = gsonDeserializer.fromJson(data, clazz);
- if (t == null) {
- BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
- log.debug("object is null after converting from json");
- return Either.right(ActionStatus.INVALID_CONTENT);
- }
- return Either.left(t);
- } catch (Exception e) {
- // INVALID JSON
- BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
- log.debug("failed to convert from json", e);
- return Either.right(ActionStatus.INVALID_CONTENT);
- }
- }
-
-
- @GET
- @Path("/{containerComponentType}/{componentId}/paths-to-delete")
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Check if forwarding path to delete on version change", method = "GET", summary = "Returns forwarding paths to delete",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- public Response changeResourceInstanceVersion( @PathParam("componentId") String componentId,
- @QueryParam("componentInstanceId") final String oldComponentInstanceId,
- @QueryParam("newComponentInstanceId") final String newComponentInstanceId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME}))
- @PathParam("containerComponentType") final String containerComponentType,
- @Context final HttpServletRequest request) {
- if (oldComponentInstanceId == null){
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_OLD_COMPONENT_INSTANCE));
- }
- if (newComponentInstanceId == null){
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_NEW_COMPONENT_INSTANCE));
- }
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
- ComponentInstance newComponentInstance;
- if(StringUtils.isNotEmpty(newComponentInstanceId)){
- newComponentInstance=new ComponentInstance();
- newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,newComponentInstanceId);
- }else{
- log.error("missing component id");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_DATA));
- }
- Either<Set<String>,ResponseFormat> actionResponse= componentInstanceBusinessLogic.forwardingPathOnVersionChange(
- containerComponentType,componentId,oldComponentInstanceId,newComponentInstance);
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
- ForwardingPaths forwardingPaths=new ForwardingPaths();
- forwardingPaths.setForwardingPathToDelete(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), forwardingPaths);
-
- }
-
- @POST
- @Path("/services/{componentId}/copyComponentInstance/{componentInstanceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces((MediaType.APPLICATION_JSON))
- @Operation(description = "Copy Component Instance", method = "POST", summary = "Returns updated service information",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "201", description = "Copy and Paste Success"),
- @ApiResponse(responseCode = "403", description = "Restricted Operation"),
- @ApiResponse(responseCode = "400", description = "Invalid Content / Missing content")})
- public Response copyComponentInstance(
- @Parameter(description = "service unique id in pasted canvas") @PathParam("componentId") final String containerComponentId,
- @Parameter(description = "Data for copying", required = true) String data, @PathParam("componentInstanceId") final String componentInstanceId,
- @Context final HttpServletRequest request) {
- log.info("Start to copy component instance");
- ServletContext context = request.getSession().getServletContext();
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- final String CNTAINER_CMPT_TYPE = "services";
-
- try {
- ComponentInstance inputComponentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
- inputComponentInstance.setInvariantName(null);
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(CNTAINER_CMPT_TYPE);
- if (componentInstanceBusinessLogic == null) {
- log.debug(UNSUPPORTED_COMPONENT_TYPE, componentTypeEnum);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, "services"));
- }
- Either<Map<String, ComponentInstance>, ResponseFormat> copyComponentInstance = componentInstanceBusinessLogic.copyComponentInstance(
- inputComponentInstance, containerComponentId, componentInstanceId, userId);
-
- if (copyComponentInstance.isRight()) {
- log.error("Failed to copy ComponentInstance {}", copyComponentInstance.right().value());
- return buildErrorResponse(copyComponentInstance.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- copyComponentInstance.left().value());
- } catch (Exception e) {
- log.error("Failed to convert json to Map { }", data, e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.USER_DEFINED,
- "Failed to get the copied component instance information"));
- }
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/batchDeleteResourceInstances/")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Batch Delete ResourceInstances", method = "POST")
- @ApiResponses(value = {
- @ApiResponse(responseCode = "203", description = "ResourceInstances deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted Operation"),
- @ApiResponse(responseCode = "400", description = "Invalid Content / Missing Content")
- })
- public Response batchDeleteResourceInstances(
- @Parameter(description = "valid values: resources / services / products", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME,
- ComponentTypeEnum.PRODUCT_PARAM_NAME}))
- @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @Context final HttpServletRequest request,
- @Parameter(description = "Component Instance Id List", required = true) final String componentInstanceIdLisStr) {
- try {
- if (componentInstanceIdLisStr == null || componentInstanceIdLisStr.isEmpty()) {
- log.error("Empty JSON List was sent",componentInstanceIdLisStr);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
-
- if (componentInstanceBusinessLogic == null) {
- log.error("Unsupported component type {}", containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<List<String>, ResponseFormat> convertResponse = convertToStringList(componentInstanceIdLisStr);
-
- if (convertResponse.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - batchDeleteResourceInstances");
- log.error("Failed to convert received data to BE format.");
- return buildErrorResponse(convertResponse.right().value());
- }
-
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- List<String> componentInstanceIdList = convertResponse.left().value();
- log.debug("batchDeleteResourceInstances componentInstanceIdList is {}", componentInstanceIdList);
- Map<String, List<String>> deleteErrorMap = componentInstanceBusinessLogic.batchDeleteComponentInstance(containerComponentType,
- componentId, componentInstanceIdList, userId);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteErrorMap);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Batch Delete ResourceInstances");
- log.error("batch delete resource instances with exception" , e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @PUT
- @Path("/{containerComponentType}/{componentId}/resourceInstance/batchDissociate")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Batch Dissociate RI from RI", method = "PUT",
- summary = "Returns deleted RelationShip Info", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship deleted"),
- @ApiResponse(responseCode = "403", description = "Missing Information"),
- @ApiResponse(responseCode = "400", description = "Invalid Content / Missing Content")})
- public Response batchDissociateRIFromRI(
- @Parameter(description = "allowed values are resources/services/products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME,
- ComponentTypeEnum.PRODUCT_PARAM_NAME}),
- required = true) @PathParam("containerComponentType") final String containerComponentType,
- @Parameter(
- description = "unique id of the container component") @PathParam("componentId") final String componentId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "RelationshipInfo", required = true) String data,
- @Context final HttpServletRequest request) {
-
- try {
- if (data == null || data.length() == 0) {
- log.info("Empty JSON list was sent");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
-
- if (componentInstanceBusinessLogic == null) {
- log.debug("Unsupported component type {}", containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
- }
-
- Either<List<RequirementCapabilityRelDef>, ResponseFormat> regInfoWs = convertToRequirementCapabilityRelDefList(data);
-
- if (regInfoWs.isRight()) {
- BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - batch dissociateRIFromRI");
- log.debug("Failed to convert received data to BE format");
- return buildErrorResponse(regInfoWs.right().value());
- }
-
- List<RequirementCapabilityRelDef> requirementDefList = regInfoWs.left().value();
- List<RequirementCapabilityRelDef> delOkResult = componentInstanceBusinessLogic.batchDissociateRIFromRI(
- componentId, userId, requirementDefList, componentTypeEnum);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), delOkResult);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Batch Dissociate Resource Instance");
- log.debug("batch dissociate resource instance from service failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Either<List<String>, ResponseFormat> convertToStringList(String datalist) {
- Either<String[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(datalist, new User(), String[].class, null, null);
-
- if (convertStatus.isRight()) {
- return Either.right(convertStatus.right().value());
- }
-
- return Either.left(Arrays.asList(convertStatus.left().value()));
- }
-
- private Either<List<RequirementCapabilityRelDef>, ResponseFormat> convertToRequirementCapabilityRelDefList(String data) {
- Either<RequirementCapabilityRelDef[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), RequirementCapabilityRelDef[].class, null, null);
-
- if (convertStatus.isRight()) {
- return Either.right(convertStatus.right().value());
- }
-
- return Either.left(Arrays.asList(convertStatus.left().value()));
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.ForwardingPaths;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
+import org.openecomp.sdc.be.info.GroupDefinitionInfo;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Root resource (exposed at "/" path) .json
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Resource Instance Servlet"))
+@Controller
+public class ComponentInstanceServlet extends AbstractValidationsServlet {
+
+ private static final String FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID = "Failed to get properties of component instance ID: {} in {} with ID: {}";
+ private static final String GET_GROUP_ARTIFACT_BY_ID = "getGroupArtifactById";
+ private static final String GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION = "getGroupArtifactById unexpected exception";
+ private static final String GET_START_HANDLE_REQUEST_OF = "(GET) Start handle request of {}";
+ private static final String START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS = "Start handle request of updateResourceInstanceProperty. Received property is {}";
+ private static final String UPDATE_RESOURCE_INSTANCE = "Update Resource Instance";
+ private static final String RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE = "Resource Instance - updateResourceInstance";
+ private static final String UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION = "update resource instance with exception";
+ private static final String FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT = "Failed to convert received data to BE format.";
+ private static final String EMPTY_BODY_WAS_SENT = "Empty body was sent.";
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final String UNSUPPORTED_COMPONENT_TYPE = "Unsupported component type {}";
+ private static final String CREATE_AND_ASSOCIATE_RI_FAILED_WITH_EXCEPTION = "create and associate RI failed with exception: {}";
+ private static final Logger log = Logger.getLogger(ComponentInstanceServlet.class);
+ private static final Type PROPERTY_CONSTRAINT_TYPE = new TypeToken<PropertyConstraint>() {}.getType();
+ private static final Gson gsonDeserializer = new GsonBuilder().registerTypeAdapter(PROPERTY_CONSTRAINT_TYPE, new PropertyConstraintDeserialiser()).create();
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ComponentInstanceServlet.class.getName());
+
+ private final GroupBusinessLogic groupBL;
+ private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
+ private final ServiceBusinessLogic serviceBusinessLogic;
+
+
+ @Inject
+ public ComponentInstanceServlet(UserBusinessLogic userBusinessLogic,
+ GroupBusinessLogic groupBL, ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ ServiceBusinessLogic serviceBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.groupBL = groupBL;
+ this.componentInstanceBusinessLogic = componentInstanceBL;
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create ComponentInstance", method = "POST", summary = "Returns created ComponentInstance",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Component created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Component instance already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createComponentInstance(@Parameter(description = "RI object to be created", required = true) String data,
+ @PathParam("componentId") final String containerComponentId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Context final HttpServletRequest request) {
+
+ validateNotEmptyBody(data);
+ ComponentInstance componentInstance = null;
+ try {
+ componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
+ componentInstance.setInvariantName(null);
+ componentInstance.setCreatedFrom(CreatedFrom.UI);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Component Instance");
+ log.debug("create component instance failed with exception", e);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
+ }
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INSTANCE, StatusCode.STARTED,"Starting to create component instance by {}",userId);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ ComponentInstance actionResponse = componentInstanceBusinessLogic.createComponentInstance(containerComponentType, containerComponentId, userId, componentInstance);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INSTANCE,actionResponse.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"Ending to create component instance by user {}",userId);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse);
+
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update resource instance", method = "POST", summary = "Returns updated resource instance",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource instance updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateComponentInstanceMetadata(@PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @Parameter(description = "valid values: resources / services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE,StatusCode.STARTED,"update Component Instance Metadata");
+ try {
+
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ InputStream inputStream = request.getInputStream();
+
+ byte[] bytes = IOUtils.toByteArray(inputStream);
+
+ if (bytes == null || bytes.length == 0) {
+ log.info(EMPTY_BODY_WAS_SENT);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ String data = new String(bytes);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
+
+ if (convertResponse.isRight()) {
+ BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
+ log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
+ return buildErrorResponse(convertResponse.right().value());
+ }
+
+ ComponentInstance resourceInstance = convertResponse.left().value();
+ Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.updateComponentInstanceMetadata(containerComponentType, componentId, componentInstanceId, userId, resourceInstance);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE,actionResponse.left().value().getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"update Component Instance Metadata by {}",userId);
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ ComponentInstance resultValue = actionResponse.left().value();
+ if (componentTypeEnum.equals(ComponentTypeEnum.SERVICE)){
+ boolean shouldCreateServiceFilter = resourceInstance.getDirectives() != null && resourceInstance.getDirectives().contains(
+ DirectivesUtils.SELECTABLE);
+
+ if(shouldCreateServiceFilter) {
+ Either<CINodeFilterDataDefinition, ResponseFormat> either =
+ serviceBusinessLogic.createIfNotAlreadyExistServiceFilter(componentId, componentInstanceId, userId,
+ true);
+ if (either.isRight()){
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance Failed to create service filter.");
+ log.debug("Failed to create service filter.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+ resultValue.setNodeFilter(either.left().value());
+ } else {
+ Either<String, ResponseFormat> either = serviceBusinessLogic.deleteIfNotAlreadyDeletedServiceFilter(componentId, componentInstanceId, userId,true);
+ if (either.isRight()){
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - updateResourceInstance Failed to delete service filter.");
+ log.debug("Failed to delete service filter.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+ resultValue.setNodeFilter(null);
+ }
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
+ log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/multipleComponentInstance")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update resource instance multiple component", method = "POST",
+ summary = "Returns updated resource instance", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource instance updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateMultipleComponentInstance(@PathParam("componentId") final String componentId, @Parameter(
+ description = "valid values: resources / services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request, @Parameter(description = "Component Instance JSON Array",
+ required = true) final String componentInstanceJsonArray) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ try {
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ if (componentInstanceJsonArray == null || componentInstanceJsonArray.length() == 0) {
+ log.info("Empty JSON list was sent.");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<List<ComponentInstance>, ResponseFormat> convertResponse = convertToMultipleResourceInstance(componentInstanceJsonArray);
+
+ if (convertResponse.isRight()) {
+ // Using both ECOMP error methods, show to Sofer
+ BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
+ log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
+ return buildErrorResponse(convertResponse.right().value());
+ }
+
+ List<ComponentInstance> componentInstanceList = convertResponse.left().value();
+
+ List<ComponentInstance> actionResponse = componentInstanceBusinessLogic.updateComponentInstance(containerComponentType, null, componentId, userId, componentInstanceList, true);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
+ log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{resourceInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete ResourceInstance", method = "DELETE", summary = "Returns delete resourceInstance",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "ResourceInstance deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteResourceInstance(@PathParam("componentId") final String componentId,
+ @PathParam("resourceInstanceId") final String resourceInstanceId,
+ @Parameter(description = "valid values: resources / services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ try {
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ ComponentInstance actionResponse = componentInstanceBusinessLogic.deleteComponentInstance(containerComponentType, componentId, resourceInstanceId, userId);
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE,actionResponse.getComponentMetadataForSupportLog(),StatusCode.STARTED,"DELETE_COMPONENT_INSTANCE by user {}", userId);
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_COMPONENT_INSTANCE,actionResponse.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"DELETE_COMPONENT_INSTANCE by user {}", userId);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource Instance");
+ log.debug("delete resource instance with exception", e);
+ throw e;
+ }
+ }
+
+ @Parameter(description = "allowed values are resources /services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME}),
+ required = true)
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/associate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Associate RI to RI", method = "POST", summary = "Returns created RelationshipInfo",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship created"),
+ @ApiResponse(responseCode = "403", description = "Missing information"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Relationship already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response associateRIToRI(@Parameter(
+ description = "unique id of the container component") @PathParam("componentId") final String componentId,
+ @Parameter(description = "allowed values are resources /services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME}),
+ required = true) @PathParam("containerComponentType") final String containerComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "RelationshipInfo", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ Response response = null;
+ loggerSupportability.log(LoggerSupportabilityActions.ASSOCIATE_RI_TO_RI, StatusCode.STARTED,"Starting to associate RI To RI for component {} ",componentId + " by " + userId );
+ try {
+
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ RequirementCapabilityRelDef requirementDef = convertToRequirementCapabilityRelDef(data);
+ requirementDef.setOriginUI(true);
+
+ RequirementCapabilityRelDef actionResponse = componentInstanceBusinessLogic.associateRIToRI(componentId, userId, requirementDef, componentTypeEnum);
+ loggerSupportability.log(LoggerSupportabilityActions.ASSOCIATE_RI_TO_RI, StatusCode.COMPLETE,"Ended associate RI To RI for component {} ",componentId + " by " + userId );
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
+
+ } catch (Exception e) {
+ if(!e.getClass().equals(ComponentException.class)) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Associate Resource Instance");
+ log.debug("associate resource instance to another RI with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ throw e;
+ }
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/dissociate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Dissociate RI from RI", method = "PUT", summary = "Returns deleted RelationshipInfo",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship deleted"),
+ @ApiResponse(responseCode = "403", description = "Missing information"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response dissociateRIFromRI(
+ @Parameter(description = "allowed values are resources /services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME}),
+ required = true) @PathParam("containerComponentType") final String containerComponentType,
+ @Parameter(
+ description = "unique id of the container component") @PathParam("componentId") final String componentId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "RelationshipInfo", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ loggerSupportability.log(LoggerSupportabilityActions.UN_ASSOCIATE_RI_TO_RI, StatusCode.STARTED,"Starting to undo associate RI To RI for component {} ",componentId + " by " + userId );
+ try {
+
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ RequirementCapabilityRelDef requirementDef = convertToRequirementCapabilityRelDef(data);
+ RequirementCapabilityRelDef actionResponse = componentInstanceBusinessLogic.dissociateRIFromRI(componentId, userId, requirementDef, componentTypeEnum);
+ loggerSupportability.log(LoggerSupportabilityActions.UN_ASSOCIATE_RI_TO_RI, StatusCode.COMPLETE,"Ended undo associate RI To RI for component {} ",componentId + " by " + userId );
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Dissociate Resource Instance");
+ log.debug("dissociate resource instance from service failed with exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/createAndAssociate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create RI and associate RI to RI", method = "POST",
+ summary = "Returns created RI and RelationshipInfo", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "RI created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Relationship already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createAndAssociateRIToRI(@PathParam("componentId") final String componentId, @Parameter(
+ description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ InputStream inputStream = request.getInputStream();
+
+ byte[] bytes = IOUtils.toByteArray(inputStream);
+
+ if (bytes == null || bytes.length == 0) {
+ log.info(EMPTY_BODY_WAS_SENT);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ String data = new String(bytes);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<CreateAndAssotiateInfo, ActionStatus> convertStatus = convertJsonToObject(data, CreateAndAssotiateInfo.class);
+ if (convertStatus.isRight()) {
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - createAndAssociateRIToRI");
+ log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
+ Either<Object, ResponseFormat> formattedResponse = Either.right(getComponentsUtils().getResponseFormat(convertStatus.right().value()));
+ return buildErrorResponse(formattedResponse.right().value());
+ }
+
+ CreateAndAssotiateInfo createAndAssotiateInfo = convertStatus.left().value();
+ RequirementCapabilityRelDef requirementDef = createAndAssotiateInfo.getAssociate();
+ requirementDef.setOriginUI(true);
+ Either<CreateAndAssotiateInfo, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createAndAssociateRIToRI(containerComponentType, componentId, userId, createAndAssotiateInfo);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create and Associate Resource Instance");
+ log.debug("create and associate RI failed with exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update resource instance property", method = "POST",
+ summary = "Returns updated resource instance property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateResourceInstanceProperties(
+ @Parameter(description = "service id") @PathParam("componentId") final String componentId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Parameter(
+ description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
+ @Parameter(description = "id of user initiating the operation") @HeaderParam(
+ value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request,
+ @Parameter(description = "Component Instance Properties JSON Array",
+ required = true) final String componentInstancePropertiesJsonArray) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE, StatusCode.STARTED,"Starting to update Resource Instance Properties for component {} ",componentId + " by " + userId );
+
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
+ if (errorWrapper.isEmpty()) {
+ Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(componentInstancePropertiesJsonArray);
+ if (propertiesToUpdateEither.isRight()) {
+ errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
+ } else {
+ propertiesToUpdate = propertiesToUpdateEither.left().value();
+ }
+ }
+ if (!errorWrapper.isEmpty()) {
+ return buildErrorResponse(errorWrapper.getInnerElement());
+ }
+ log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, propertiesToUpdate);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ Either<List<ComponentInstanceProperty>, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createOrUpdatePropertiesValues(componentTypeEnum, componentId, componentInstanceId, propertiesToUpdate, userId);
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ List<ComponentInstanceProperty> resourceInstanceProperties = actionResponse.left().value();
+ ObjectMapper mapper = new ObjectMapper();
+ String result;
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE, StatusCode.COMPLETE,"Ended update Resource Instance Properties for component {} ",componentId + " by " + userId );
+ try {
+ result = mapper.writeValueAsString(resourceInstanceProperties);
+ } catch (JsonProcessingException e) {
+ log.error(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e.getMessage(), e);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ }
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_COMPONENT_INSTANCE, StatusCode.COMPLETE,"Ended update Resource Instance Properties for component {} ",componentId + " by user " + userId );
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/inputs")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update resource instance property", method = "POST",
+ summary = "Returns updated resource instance property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateResourceInstanceInput(
+ @Parameter(description = "service id") @PathParam("componentId") final String componentId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Parameter(
+ description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
+ @Parameter(description = "id of user initiating the operation") @HeaderParam(
+ value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request,
+ @Parameter(description = "Component Instance Properties JSON Array",
+ required = true) final String componentInstanceInputsJsonArray) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ List<ComponentInstanceInput> inputsToUpdate = new ArrayList<>();
+ if (errorWrapper.isEmpty()) {
+ Either<List<ComponentInstanceInput>, ResponseFormat> inputsToUpdateEither = convertMultipleInputs(componentInstanceInputsJsonArray);
+ if (inputsToUpdateEither.isRight()) {
+ errorWrapper.setInnerElement(inputsToUpdateEither.right().value());
+ } else {
+ inputsToUpdate = inputsToUpdateEither.left().value();
+ }
+ }
+ if (!errorWrapper.isEmpty()) {
+ return buildErrorResponse(errorWrapper.getInnerElement());
+ }
+ log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, inputsToUpdate);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ Either<List<ComponentInstanceInput>, ResponseFormat> actionResponse =
+ componentInstanceBusinessLogic.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, componentInstanceId, inputsToUpdate, userId);
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ List<ComponentInstanceInput> resourceInstanceInput = actionResponse.left().value();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
+ String result;
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE,"Ending update Resource Instance Input for component {} ",componentId + " by " + userId );
+ try {
+ result = mapper.writeValueAsString(resourceInstanceInput);
+ } catch (JsonProcessingException e) {
+ log.error(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e.getMessage(), e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE, "Ending update Resource Instance Input for component {} ", componentId + " by user " + userId);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ }
+
+ /**
+ * Updates ResourceInstance Attribute
+ *
+ * @param componentId
+ * @param containerComponentType
+ * @param componentInstanceId
+ * @param userId
+ * @param request
+ * @return
+ */
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/attribute")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update resource instance attribute", method = "POST",
+ summary = "Returns updated resource instance attribute", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateResourceInstanceAttribute(
+ @Parameter(description = "service id") @PathParam("componentId") final String componentId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Parameter(
+ description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
+ @Parameter(description = "id of user initiating the operation") @HeaderParam(
+ value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_RESOURCE, StatusCode.STARTED,"Starting to update Resource Instance Attribute for component {} ",componentId + " by " + userId );
+ try {
+
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Wrapper<String> dataWrapper = new Wrapper<>();
+ Wrapper<ComponentInstanceProperty> attributeWrapper = new Wrapper<>();
+ Wrapper<ComponentInstanceBusinessLogic> blWrapper = new Wrapper<>();
+
+ validateInputStream(request, dataWrapper, errorWrapper);
+
+ if (errorWrapper.isEmpty()) {
+ validateClassParse(dataWrapper.getInnerElement(), attributeWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
+ }
+
+ if (errorWrapper.isEmpty()) {
+ validateComponentInstanceBusinessLogic(request, containerComponentType, blWrapper, errorWrapper);
+ }
+
+ if (errorWrapper.isEmpty()) {
+ ComponentInstanceBusinessLogic componentInstanceLogic = blWrapper.getInnerElement();
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ log.debug("Start handle request of ComponentInstanceAttribute. Received attribute is {}", attributeWrapper.getInnerElement());
+ Either<ComponentInstanceProperty, ResponseFormat> eitherAttribute = componentInstanceLogic.createOrUpdateAttributeValue(componentTypeEnum, componentId, componentInstanceId, attributeWrapper.getInnerElement(), userId);
+ if (eitherAttribute.isRight()) {
+ errorWrapper.setInnerElement(eitherAttribute.right().value());
+ } else {
+ attributeWrapper.setInnerElement(eitherAttribute.left().value());
+ }
+ }
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_RESOURCE, StatusCode.COMPLETE,"Ended update Resource Instance Attribute for component {} ",componentId + " by " + userId );
+ return buildResponseFromElement(errorWrapper, attributeWrapper);
+
+ } catch (Exception e) {
+ log.error(CREATE_AND_ASSOCIATE_RI_FAILED_WITH_EXCEPTION, e.getMessage(), e);
+ throw e;
+ }
+
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/property/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update resource instance", method = "DELETE",
+ summary = "Returns deleted resource instance property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteResourceInstanceProperty(
+ @Parameter(description = "service id") @PathParam("componentId") final String componentId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Parameter(
+ description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
+ @Parameter(description = "property id") @PathParam("propertyId") final String propertyId,
+ @Parameter(description = "id of user initiating the operation") @HeaderParam(
+ value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request) {
+
+
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.STARTED,"Starting to delete Resource Instance Property for component {} ",componentId + " by " + userId );
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE,"Ended delete Resource Instance Property for component {} ",componentId + " by " + userId );
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceBusinessLogic.deletePropertyValue(componentTypeEnum, componentId, componentInstanceId, propertyId, userId);
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ } catch (Exception e) {
+ log.error(CREATE_AND_ASSOCIATE_RI_FAILED_WITH_EXCEPTION, e.getMessage(), e);
+ throw e;
+ }
+
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/changeVersion")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update resource instance", method = "POST", summary = "Returns updated resource instance",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response changeResourceInstanceVersion(@PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try (
+ InputStream inputStream = request.getInputStream()) {
+
+ byte[] bytes = IOUtils.toByteArray(inputStream);
+
+ if (bytes == null || bytes.length == 0) {
+ log.info(EMPTY_BODY_WAS_SENT);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ String data = new String(bytes);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<ComponentInstance, ResponseFormat> convertResponse = convertToResourceInstance(data);
+
+ if (convertResponse.isRight()) {
+ BeEcompErrorManager.getInstance().logBeSystemError(RESOURCE_INSTANCE_UPDATE_RESOURCE_INSTANCE);
+ log.debug(FAILED_TO_CONVERT_RECEIVED_DATA_TO_BE_FORMAT);
+ return buildErrorResponse(convertResponse.right().value());
+ }
+
+ ComponentInstance newResourceInstance = convertResponse.left().value();
+ ComponentInstance actionResponse = componentInstanceBusinessLogic.changeComponentInstanceVersion(containerComponentType, componentId, componentInstanceId, userId, newResourceInstance);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(UPDATE_RESOURCE_INSTANCE);
+ log.debug(UPDATE_RESOURCE_INSTANCE_WITH_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}/property")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update resource instance property", method = "POST",
+ summary = "Returns updated resource instance property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource instance created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateGroupInstanceProperty(
+ @Parameter(description = "service id") @PathParam("componentId") final String componentId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Parameter(
+ description = "resource instance id") @PathParam("componentInstanceId") final String componentInstanceId,
+ @Parameter(description = "group instance id") @PathParam("groupInstanceId") final String groupInstanceId,
+ @Parameter(description = "id of user initiating the operation") @HeaderParam(
+ value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ try {
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.STARTED,"Starting update Group Instance Property for component {} ",componentId + " by " + userId );
+ Wrapper<String> dataWrapper = new Wrapper<>();
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ Wrapper<ComponentInstanceProperty> propertyWrapper = new Wrapper<>();
+
+ validateInputStream(request, dataWrapper, errorWrapper);
+
+ if (errorWrapper.isEmpty()) {
+ validateClassParse(dataWrapper.getInnerElement(), propertyWrapper, () -> ComponentInstanceProperty.class, errorWrapper);
+ }
+
+ if (!errorWrapper.isEmpty()) {
+ return buildErrorResponse(errorWrapper.getInnerElement());
+ }
+
+ ComponentInstanceProperty property = propertyWrapper.getInnerElement();
+
+ log.debug(START_HANDLE_REQUEST_OF_UPDATE_RESOURCE_INSTANCE_PROPERTY_RECEIVED_PROPERTY_IS, property);
+
+
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<ComponentInstanceProperty, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, componentInstanceId, groupInstanceId, property, userId);
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ ComponentInstanceProperty resourceInstanceProperty = actionResponse.left().value();
+ ObjectMapper mapper = new ObjectMapper();
+ String result = mapper.writeValueAsString(resourceInstanceProperty);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE,"Ended update Group Instance Property for component {} ",componentId + " by " + userId );
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ log.error(CREATE_AND_ASSOCIATE_RI_FAILED_WITH_EXCEPTION, e.getMessage(), e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get group artifacts ", method = "GET",
+ summary = "Returns artifacts metadata according to groupInstId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "group found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Group not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getGroupArtifactById(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @PathParam("groupInstId") final String groupInstId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(GET_START_HANDLE_REQUEST_OF, url);
+
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ Either<GroupDefinitionInfo, ResponseFormat> actionResponse = groupBL.getGroupInstWithArtifactsById(componentTypeEnum, componentId, componentInstanceId, groupInstId, userId, false);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all non abstract {}", containerComponentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
+ log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ // US831698
+ @GET
+ @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get component instance properties", method = "GET",
+ summary = "Returns component instance properties", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component/Component Instance - not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getInstancePropertiesById(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("containerComponentId") final String containerComponentId,
+ @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(GET_START_HANDLE_REQUEST_OF, url);
+
+ List<ComponentInstanceProperty> componentInstancePropertiesById = componentInstanceBusinessLogic.getComponentInstancePropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId, userId);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById);
+ }
+
+ // US330353
+ @GET
+ @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get component instance capability properties", method = "GET",
+ summary = "Returns component instance capability properties", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component/Component Instance/Capability - not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getInstanceCapabilityPropertiesById(
+ @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("containerComponentId") final String containerComponentId,
+ @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
+ @PathParam("capabilityType") final String capabilityType,
+ @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(GET_START_HANDLE_REQUEST_OF, url);
+
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+
+ List<ComponentInstanceProperty> componentInstancePropertiesById = componentInstanceBusinessLogic.getComponentInstanceCapabilityPropertiesById(containerComponentType, containerComponentId, componentInstanceUniqueId,
+ capabilityType, capabilityName, ownerId, userId);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), componentInstancePropertiesById);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
+ log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ //US 331281
+ @PUT
+ @Path("/{containerComponentType}/{containerComponentId}/componentInstances/{componentInstanceUniqueId}/capability/{capabilityType}/capabilityName/{capabilityName}/ownerId/{ownerId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Instance Capabilty Property", method = "PUT",
+ summary = "Returns updated property", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(
+ value = {@ApiResponse(responseCode = "200", description = "Resource instance capabilty property updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Component/Component Instance/Capability - not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateInstanceCapabilityProperty(
+ @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("containerComponentId") final String containerComponentId,
+ @PathParam("componentInstanceUniqueId") final String componentInstanceUniqueId,
+ @PathParam("capabilityType") final String capabilityType,
+ @PathParam("capabilityName") final String capabilityName, @PathParam("ownerId") final String ownerId,
+ @Parameter(description = "Instance capabilty property to update", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(PUT) Start handle request of {}", url);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_INSTANCE_CAPABILITY_PROPERTY, StatusCode.STARTED," Starting to update Instance Capability Property for component instance {} " , componentInstanceUniqueId + " by " + userId);
+ try {
+ Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ List<ComponentInstanceProperty> propertiesToUpdate = new ArrayList<>();
+ if (errorWrapper.isEmpty()) {
+ Either<List<ComponentInstanceProperty>, ResponseFormat> propertiesToUpdateEither = convertMultipleProperties(data);
+ if (propertiesToUpdateEither.isRight()) {
+ errorWrapper.setInnerElement(propertiesToUpdateEither.right().value());
+ } else {
+ propertiesToUpdate = propertiesToUpdateEither.left().value();
+ }
+ }
+
+ if (!errorWrapper.isEmpty()) {
+ return buildErrorResponse(errorWrapper.getInnerElement());
+ }
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+
+ Either<List<ComponentInstanceProperty>, ResponseFormat> updateCICapProperty = componentInstanceBusinessLogic.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, propertiesToUpdate, userId);
+
+ if (updateCICapProperty.isRight()) {
+ log.debug(FAILED_TO_GET_PROPERTIES_OF_COMPONENT_INSTANCE_ID_IN_WITH_ID, componentInstanceUniqueId, containerComponentType, containerComponentId);
+ return buildErrorResponse(updateCICapProperty.right().value());
+ }
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_INSTANCE_CAPABILITY_PROPERTY, StatusCode.COMPLETE," Ended to update Instance Capability Property for component instance {} " , componentInstanceUniqueId + " by " + userId);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updateCICapProperty.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_GROUP_ARTIFACT_BY_ID);
+ log.debug(GET_GROUP_ARTIFACT_BY_ID_UNEXPECTED_EXCEPTION, e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{containerComponentId}/serviceProxy")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create service proxy", method = "POST", summary = "Returns created service proxy",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Service proxy already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createServiceProxy(@Parameter(description = "RI object to be created", required = true) String data,
+ @PathParam("containerComponentId") final String containerComponentId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Context final HttpServletRequest request) {
+
+ try {
+
+ ComponentInstance componentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
+ componentInstance.setInvariantName(null);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentTypeEnum != ComponentTypeEnum.SERVICE) {
+ log.debug("Unsupported container component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.createServiceProxy();
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create service proxy");
+ log.debug("Create service proxy failed with exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete service proxy", method = "DELETE", summary = "Returns delete service proxy",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteServiceProxy(@PathParam("containerComponentId") final String containerComponentId,
+ @PathParam("serviceProxyId") final String serviceProxyId,
+ @Parameter(description = "valid values: resources / services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ try {
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.deleteServiceProxy();
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete service proxy");
+ log.debug("Delete service proxy failed with exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{containerComponentId}/serviceProxy/{serviceProxyId}/changeVersion/{newServiceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update service proxy with new version", method = "POST",
+ summary = "Returns updated service proxy", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service proxy created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response changeServiceProxyVersion(@PathParam("containerComponentId") final String containerComponentId,
+ @PathParam("serviceProxyId") final String serviceProxyId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) {
+
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ try {
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ Either<ComponentInstance, ResponseFormat> actionResponse = componentInstanceBusinessLogic.changeServiceProxyVersion();
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update service proxy with new version");
+ log.debug("Update service proxy with new version failed with exception", e);
+ throw e;
+ }
+ }
+ /**
+ * REST API GET relation by Id
+ * Allows to get relation contained in specified component according to received Id
+ * @param containerComponentType
+ * @param componentId
+ * @param relationId
+ * @param request
+ * @param userId
+ * @return Response
+ */
+ @GET
+ @Path("/{containerComponentType}/{componentId}/relationId/{relationId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get relation", method = "GET",
+ summary = "Returns relation metadata according to relationId",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "relation found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Relation not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getRelationById(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("relationId") final String relationId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(GET_START_HANDLE_REQUEST_OF, url);
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentTypeEnum == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<RequirementCapabilityRelDef, ResponseFormat> actionResponse = componentInstanceBusinessLogic.getRelationById(componentId, relationId, userId, componentTypeEnum);
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getRelationById");
+ log.debug("getRelationById unexpected exception", e);
+ throw e;
+ }
+ }
+
+ private Either<ComponentInstance, ResponseFormat> convertToResourceInstance(String data) {
+
+ Either<ComponentInstance, ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), ComponentInstance.class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+ ComponentInstance resourceInstanceInfo = convertStatus.left().value();
+
+ return Either.left(resourceInstanceInfo);
+ }
+
+ private Either<List<ComponentInstance>, ResponseFormat> convertToMultipleResourceInstance(String dataList) {
+
+ Either<ComponentInstance[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstance[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+
+ return Either.left(Arrays.asList(convertStatus.left().value()));
+ }
+
+ private Either<List<ComponentInstanceProperty>, ResponseFormat> convertMultipleProperties(String dataList) {
+ if (StringUtils.isEmpty(dataList)) {
+ return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_BODY));
+ }
+ Either<ComponentInstanceProperty[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceProperty[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+ return Either.left(Arrays.asList(convertStatus.left().value()));
+ }
+
+ private Either<List<ComponentInstanceInput>, ResponseFormat> convertMultipleInputs(String dataList) {
+ if (StringUtils.isEmpty(dataList)) {
+ return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_BODY));
+ }
+ Either<ComponentInstanceInput[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(dataList, new User(), ComponentInstanceInput[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+ return Either.left(Arrays.asList(convertStatus.left().value()));
+ }
+
+
+ private RequirementCapabilityRelDef convertToRequirementCapabilityRelDef(String data) {
+
+ Either<RequirementCapabilityRelDef, ActionStatus> convertStatus = convertJsonToObject(data, RequirementCapabilityRelDef.class);
+ if (convertStatus.isRight()) {
+ throw new ByActionStatusComponentException(convertStatus.right().value());
+ }
+ RequirementCapabilityRelDef requirementCapabilityRelDef = convertStatus.left().value();
+ return requirementCapabilityRelDef;
+ }
+
+ public <T> Either<T, ActionStatus> convertJsonToObject(String data, Class<T> clazz) {
+ try {
+ log.trace("convert json to object. json=\n {}", data);
+ T t;
+ t = gsonDeserializer.fromJson(data, clazz);
+ if (t == null) {
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("object is null after converting from json");
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+ return Either.left(t);
+ } catch (Exception e) {
+ // INVALID JSON
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("failed to convert from json", e);
+ return Either.right(ActionStatus.INVALID_CONTENT);
+ }
+ }
+
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/paths-to-delete")
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Check if forwarding path to delete on version change", method = "GET", summary = "Returns forwarding paths to delete",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ public Response changeResourceInstanceVersion( @PathParam("componentId") String componentId,
+ @QueryParam("componentInstanceId") final String oldComponentInstanceId,
+ @QueryParam("newComponentInstanceId") final String newComponentInstanceId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME}))
+ @PathParam("containerComponentType") final String containerComponentType,
+ @Context final HttpServletRequest request) {
+ if (oldComponentInstanceId == null){
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_OLD_COMPONENT_INSTANCE));
+ }
+ if (newComponentInstanceId == null){
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_NEW_COMPONENT_INSTANCE));
+ }
+
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+ ComponentInstance newComponentInstance;
+ if(StringUtils.isNotEmpty(newComponentInstanceId)){
+ newComponentInstance=new ComponentInstance();
+ newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,newComponentInstanceId);
+ }else{
+ log.error("missing component id");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_DATA));
+ }
+ Either<Set<String>,ResponseFormat> actionResponse= componentInstanceBusinessLogic.forwardingPathOnVersionChange(
+ containerComponentType,componentId,oldComponentInstanceId,newComponentInstance);
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ ForwardingPaths forwardingPaths=new ForwardingPaths();
+ forwardingPaths.setForwardingPathToDelete(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), forwardingPaths);
+
+ }
+
+ @POST
+ @Path("/services/{componentId}/copyComponentInstance/{componentInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces((MediaType.APPLICATION_JSON))
+ @Operation(description = "Copy Component Instance", method = "POST", summary = "Returns updated service information",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "201", description = "Copy and Paste Success"),
+ @ApiResponse(responseCode = "403", description = "Restricted Operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid Content / Missing content")})
+ public Response copyComponentInstance(
+ @Parameter(description = "service unique id in pasted canvas") @PathParam("componentId") final String containerComponentId,
+ @Parameter(description = "Data for copying", required = true) String data, @PathParam("componentInstanceId") final String componentInstanceId,
+ @Context final HttpServletRequest request) {
+ log.info("Start to copy component instance");
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ final String CNTAINER_CMPT_TYPE = "services";
+
+ try {
+ ComponentInstance inputComponentInstance = RepresentationUtils.fromRepresentation(data, ComponentInstance.class);
+ inputComponentInstance.setInvariantName(null);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(CNTAINER_CMPT_TYPE);
+ if (componentInstanceBusinessLogic == null) {
+ log.debug(UNSUPPORTED_COMPONENT_TYPE, componentTypeEnum);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, "services"));
+ }
+ Either<Map<String, ComponentInstance>, ResponseFormat> copyComponentInstance = componentInstanceBusinessLogic.copyComponentInstance(
+ inputComponentInstance, containerComponentId, componentInstanceId, userId);
+
+ if (copyComponentInstance.isRight()) {
+ log.error("Failed to copy ComponentInstance {}", copyComponentInstance.right().value());
+ return buildErrorResponse(copyComponentInstance.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ copyComponentInstance.left().value());
+ } catch (Exception e) {
+ log.error("Failed to convert json to Map { }", data, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.USER_DEFINED,
+ "Failed to get the copied component instance information"));
+ }
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/batchDeleteResourceInstances/")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Batch Delete ResourceInstances", method = "POST")
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "203", description = "ResourceInstances deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted Operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid Content / Missing Content")
+ })
+ public Response batchDeleteResourceInstances(
+ @Parameter(description = "valid values: resources / services / products", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME}))
+ @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @Context final HttpServletRequest request,
+ @Parameter(description = "Component Instance Id List", required = true) final String componentInstanceIdLisStr) {
+ try {
+ if (componentInstanceIdLisStr == null || componentInstanceIdLisStr.isEmpty()) {
+ log.error("Empty JSON List was sent",componentInstanceIdLisStr);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+
+ if (componentInstanceBusinessLogic == null) {
+ log.error("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<List<String>, ResponseFormat> convertResponse = convertToStringList(componentInstanceIdLisStr);
+
+ if (convertResponse.isRight()) {
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - batchDeleteResourceInstances");
+ log.error("Failed to convert received data to BE format.");
+ return buildErrorResponse(convertResponse.right().value());
+ }
+
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ List<String> componentInstanceIdList = convertResponse.left().value();
+ log.debug("batchDeleteResourceInstances componentInstanceIdList is {}", componentInstanceIdList);
+ Map<String, List<String>> deleteErrorMap = componentInstanceBusinessLogic.batchDeleteComponentInstance(containerComponentType,
+ componentId, componentInstanceIdList, userId);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteErrorMap);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Batch Delete ResourceInstances");
+ log.error("batch delete resource instances with exception" , e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/resourceInstance/batchDissociate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Batch Dissociate RI from RI", method = "PUT",
+ summary = "Returns deleted RelationShip Info", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship deleted"),
+ @ApiResponse(responseCode = "403", description = "Missing Information"),
+ @ApiResponse(responseCode = "400", description = "Invalid Content / Missing Content")})
+ public Response batchDissociateRIFromRI(
+ @Parameter(description = "allowed values are resources/services/products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME}),
+ required = true) @PathParam("containerComponentType") final String containerComponentType,
+ @Parameter(
+ description = "unique id of the container component") @PathParam("componentId") final String componentId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "RelationshipInfo", required = true) String data,
+ @Context final HttpServletRequest request) {
+
+
+ try {
+ if (data == null || data.length() == 0) {
+ log.info("Empty JSON list was sent");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+
+ if (componentInstanceBusinessLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR, containerComponentType));
+ }
+
+ Either<List<RequirementCapabilityRelDef>, ResponseFormat> regInfoWs = convertToRequirementCapabilityRelDefList(data);
+
+ if (regInfoWs.isRight()) {
+ BeEcompErrorManager.getInstance().logBeSystemError("Resource Instance - batch dissociateRIFromRI");
+ log.debug("Failed to convert received data to BE format");
+ return buildErrorResponse(regInfoWs.right().value());
+ }
+
+ List<RequirementCapabilityRelDef> requirementDefList = regInfoWs.left().value();
+ List<RequirementCapabilityRelDef> delOkResult = componentInstanceBusinessLogic.batchDissociateRIFromRI(
+ componentId, userId, requirementDefList, componentTypeEnum);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), delOkResult);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Batch Dissociate Resource Instance");
+ log.debug("batch dissociate resource instance from service failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Either<List<String>, ResponseFormat> convertToStringList(String datalist) {
+ Either<String[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(datalist, new User(), String[].class, null, null);
+
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+
+ return Either.left(Arrays.asList(convertStatus.left().value()));
+ }
+
+ private Either<List<RequirementCapabilityRelDef>, ResponseFormat> convertToRequirementCapabilityRelDefList(String data) {
+ Either<RequirementCapabilityRelDef[], ResponseFormat> convertStatus = getComponentsUtils().convertJsonToObjectUsingObjectMapper(data, new User(), RequirementCapabilityRelDef[].class, null, null);
+
+ if (convertStatus.isRight()) {
+ return Either.right(convertStatus.right().value());
+ }
+
+ return Either.left(Arrays.asList(convertStatus.left().value()));
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
index 355c3e0bd2..28f73af0f5 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java
@@ -1,467 +1,489 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.List;
-import java.util.Map;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.PropertyValueConstraintValidationUtil;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
-import org.openecomp.sdc.be.resources.data.EntryData;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Component Property Servlet", description = "Component Property Servlet"))
-@Singleton
-public class ComponentPropertyServlet extends BeGenericServlet {
-
- private final PropertyBusinessLogic propertyBusinessLogic;
- private final ApplicationDataTypeCache applicationDataTypeCache;
-
- @Inject
- public ComponentPropertyServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- ApplicationDataTypeCache applicationDataTypeCache,
- PropertyBusinessLogic propertyBusinessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.applicationDataTypeCache = applicationDataTypeCache;
- this.propertyBusinessLogic = propertyBusinessLogic;
- }
-
- private static final Logger log = LoggerFactory.getLogger(ComponentPropertyServlet.class);
- private static final String CREATE_PROPERTY = "Create Property";
- private static final String DEBUG_MESSAGE = "Start handle request of {} modifier id is {}";
-
- @POST
- @Path("services/{serviceId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Service Property", method = "POST", summary = "Returns created service property",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service property created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Service property already exist")})
- public Response createPropertyInService(
- @Parameter(description = "service id to update with new property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Parameter(description = "Service property to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return createProperty(serviceId, data, request, userId);
- }
-
- @POST
- @Path("resources/{resourceId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Resource Property", method = "POST", summary = "Returns created service property",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource property created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Resource property already exist")})
- public Response createPropertyInResource(
- @Parameter(description = "Resource id to update with new property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "Resource property to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return createProperty(resourceId, data, request, userId);
- }
-
-
- @GET
- @Path("services/{serviceId}/properties/{propertyId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Service Property", method = "GET", summary = "Returns property of service",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "property"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Service property not found")})
- public Response getPropertyInService(
- @Parameter(description = "service id of property", required = true) @PathParam("serviceId") final String serviceId,
- @Parameter(description = "property id to get", required = true) @PathParam("propertyId") final String propertyId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return getProperty(serviceId, propertyId, request, userId);
- }
-
- @GET
- @Path("resources/{resourceId}/properties/{propertyId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Resource Property", method = "GET", summary = "Returns property of resource",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "property"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Resource property not found")})
- public Response getPropertyInResource(
- @Parameter(description = "resource id of property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "property id to get", required = true) @PathParam("propertyId") final String propertyId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return getProperty(resourceId, propertyId, request, userId);
- }
-
- @GET
- @Path("services/{serviceId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Service Property", method = "GET", summary = "Returns property list of service",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "property"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Service property not found")})
- public Response getPropertyListInService(
- @Parameter(description = "service id of property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return getPropertyList(serviceId, request, userId);
- }
-
- @GET
- @Path("resources/{resourceId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Resource Property", method = "GET", summary = "Returns property list of resource",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "property"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Resource property not found")})
- public Response getPropertyListInResource(
- @Parameter(description = "resource id of property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return getPropertyList(resourceId, request, userId);
- }
-
- @DELETE
- @Path("services/{serviceId}/properties/{propertyId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Delete Service Property", method = "DELETE", summary = "Returns deleted property",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "deleted property"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Service property not found")})
- public Response deletePropertyInService(
- @Parameter(description = "service id of property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Parameter(description = "Property id to delete",
- required = true) @PathParam("propertyId") final String propertyId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return deleteProperty(serviceId, propertyId, request, userId);
- }
-
- @DELETE
- @Path("resources/{resourceId}/properties/{propertyId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Delete Resource Property", method = "DELETE", summary = "Returns deleted property",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "deleted property"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Resource property not found")})
- public Response deletePropertyInResource(
- @Parameter(description = "resource id of property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "Property id to delete",
- required = true) @PathParam("propertyId") final String propertyId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return deleteProperty(resourceId, propertyId, request, userId);
- }
-
- @PUT
- @Path("services/{serviceId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Service Property", method = "PUT", summary = "Returns updated property",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service property updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updatePropertyInService(
- @Parameter(description = "service id to update with new property",
- required = true) @PathParam("serviceId") final String serviceId,
- @Parameter(description = "Service property to update", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return updateProperty(serviceId, data, request, userId);
- }
-
- @PUT
- @Path("resources/{resourceId}/properties")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Resource Property", method = "PUT", summary = "Returns updated property",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource property updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updatePropertyInResource(
- @Parameter(description = "resource id to update with new property",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "Resource property to update", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return updateProperty(resourceId, data, request, userId);
- }
-
- private Response createProperty(String componentId, String data, HttpServletRequest request,String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
-
- try{
- Either<Map<String, PropertyDefinition>, ActionStatus> propertyDefinition =
- getPropertyModel(componentId, data);
- if (propertyDefinition.isRight()) {
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(propertyDefinition.right().value());
- return buildErrorResponse(responseFormat);
- }
-
- Map<String, PropertyDefinition> properties = propertyDefinition.left().value();
- if (properties == null || properties.size() != 1) {
- log.info("Property content is invalid - {}", data);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- return buildErrorResponse(responseFormat);
- }
-
- Map.Entry<String, PropertyDefinition> entry = properties.entrySet().iterator().next();
- PropertyDefinition newPropertyDefinition = entry.getValue();
- newPropertyDefinition.setParentUniqueId(componentId);
- String propertyName = newPropertyDefinition.getName();
-
- Either<EntryData<String, PropertyDefinition>, ResponseFormat> addPropertyEither =
- propertyBusinessLogic.addPropertyToComponent(componentId, propertyName, newPropertyDefinition, userId);
-
- if(addPropertyEither.isRight()) {
- return buildErrorResponse(addPropertyEither.right().value());
- }
-
- return buildOkResponse(newPropertyDefinition);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
- log.debug("create property failed with exception", e);
- ResponseFormat responseFormat =
- getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
-
-
- private Response updateProperty(String componentId, String data, HttpServletRequest request, String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-//
- try {
- // convert json to PropertyDefinition
-
- Either<Map<String, PropertyDefinition>, ActionStatus> propertiesListEither =
- getPropertiesListForUpdate(data);
- if (propertiesListEither.isRight()) {
- ResponseFormat responseFormat =
- getComponentsUtils().getResponseFormat(propertiesListEither.right().value());
- return buildErrorResponse(responseFormat);
- }
- Map<String, PropertyDefinition> properties = propertiesListEither.left().value();
- if (properties == null) {
- log.info("Property content is invalid - {}", data);
- ResponseFormat responseFormat =
- getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
- return buildErrorResponse(responseFormat);
- }
-
- //Validate value and Constraint of property
- Either<Boolean, ResponseFormat> constraintValidatorResponse =
- PropertyValueConstraintValidationUtil.getInstance().
- validatePropertyConstraints(properties.values(), applicationDataTypeCache);
- if (constraintValidatorResponse.isRight()) {
- log.error("Failed validation value and constraint of property: {}",
- constraintValidatorResponse.right().value());
- return buildErrorResponse(constraintValidatorResponse.right().value());
- }
-
- // update property
-
- for(PropertyDefinition propertyDefinition : properties.values()) {
- Either<EntryData<String, PropertyDefinition>, ResponseFormat> status =
- propertyBusinessLogic.updateComponentProperty(
- componentId, propertyDefinition.getUniqueId(), propertyDefinition, userId);
- if (status.isRight()) {
- log.info("Failed to update Property. Reason - ", status.right().value());
- return buildErrorResponse(status.right().value());
- }
- EntryData<String, PropertyDefinition> property = status.left().value();
- PropertyDefinition updatedPropertyDefinition = property.getValue();
-
- log.debug("Property id {} updated successfully ", updatedPropertyDefinition.getUniqueId());
- }
-
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- return buildOkResponse(responseFormat, properties);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Property");
- log.debug("update property failed with exception", e);
- ResponseFormat responseFormat =
- getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
-
- }
- }
-
- private Response getProperty(String componentId, String propertyId, HttpServletRequest request, String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(DEBUG_MESSAGE, url, userId);
-
- try {
- Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> retrievedPropertyEither =
- propertyBusinessLogic.getComponentProperty(componentId, propertyId, userId);
-
- if(retrievedPropertyEither.isRight()) {
- return buildErrorResponse(retrievedPropertyEither.right().value());
- }
-
- return buildOkResponse(retrievedPropertyEither.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
- log.debug("get property failed with exception", e);
- ResponseFormat responseFormat =
- getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
- private Response getPropertyList(String componentId, HttpServletRequest request, String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(DEBUG_MESSAGE, url, userId);
-
- try {
- Either<List<PropertyDefinition>, ResponseFormat> propertiesListEither =
- propertyBusinessLogic.getPropertiesList(componentId, userId);
-
- if(propertiesListEither.isRight()) {
- return buildErrorResponse(propertiesListEither.right().value());
- }
-
- return buildOkResponse(propertiesListEither.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
- log.debug("get property failed with exception", e);
- ResponseFormat responseFormat =
- getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
- private Response deleteProperty(String componentId, String propertyId, HttpServletRequest request, String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(DEBUG_MESSAGE, url, userId);
-
- try {
-
- // delete the property
- Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> status =
- propertyBusinessLogic.deletePropertyFromComponent(componentId, propertyId, userId);
- if (status.isRight()) {
- log.debug("Failed to delete Property. Reason - ", status.right().value());
- return buildErrorResponse(status.right().value());
- }
- Map.Entry<String, PropertyDefinition> property = status.left().value();
- String name = property.getKey();
- PropertyDefinition propertyDefinition = property.getValue();
-
- log.debug("Property {} deleted successfully with id {}", name, propertyDefinition.getUniqueId());
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
- return buildOkResponse(responseFormat, propertyToJson(property));
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Property");
- log.debug("delete property failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
-
- }
- }
-
-}
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.utils.PropertyValueConstraintValidationUtil;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.resources.data.EntryData;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.Map;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Component Property Servlet", description = "Component Property Servlet"))
+@Singleton
+public class ComponentPropertyServlet extends BeGenericServlet {
+
+ private final PropertyBusinessLogic propertyBusinessLogic;
+ private final ApplicationDataTypeCache applicationDataTypeCache;
+
+ @Inject
+ public ComponentPropertyServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ ApplicationDataTypeCache applicationDataTypeCache,
+ PropertyBusinessLogic propertyBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.applicationDataTypeCache = applicationDataTypeCache;
+ this.propertyBusinessLogic = propertyBusinessLogic;
+ }
+
+ private static final Logger log = LoggerFactory.getLogger(ComponentPropertyServlet.class);
+ private static final String CREATE_PROPERTY = "Create Property";
+ private static final String DEBUG_MESSAGE = "Start handle request of {} modifier id is {}";
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ComponentPropertyServlet.class.getName());
+
+
+ @POST
+ @Path("services/{serviceId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Service Property", method = "POST", summary = "Returns created service property",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service property created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Service property already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createPropertyInService(
+ @Parameter(description = "service id to update with new property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Parameter(description = "Service property to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return createProperty(serviceId, data, request, userId);
+ }
+
+ @POST
+ @Path("resources/{resourceId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Resource Property", method = "POST", summary = "Returns created service property",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource property created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Resource property already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createPropertyInResource(
+ @Parameter(description = "Resource id to update with new property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "Resource property to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return createProperty(resourceId, data, request, userId);
+ }
+
+
+ @GET
+ @Path("services/{serviceId}/properties/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Service Property", method = "GET", summary = "Returns property of service",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "property"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Service property not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getPropertyInService(
+ @Parameter(description = "service id of property", required = true) @PathParam("serviceId") final String serviceId,
+ @Parameter(description = "property id to get", required = true) @PathParam("propertyId") final String propertyId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getProperty(serviceId, propertyId, request, userId);
+ }
+
+ @GET
+ @Path("resources/{resourceId}/properties/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Resource Property", method = "GET", summary = "Returns property of resource",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "property"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Resource property not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getPropertyInResource(
+ @Parameter(description = "resource id of property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "property id to get", required = true) @PathParam("propertyId") final String propertyId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getProperty(resourceId, propertyId, request, userId);
+ }
+
+ @GET
+ @Path("services/{serviceId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Service Property", method = "GET", summary = "Returns property list of service",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "property"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Service property not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getPropertyListInService(
+ @Parameter(description = "service id of property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getPropertyList(serviceId, request, userId);
+ }
+
+ @GET
+ @Path("resources/{resourceId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Resource Property", method = "GET", summary = "Returns property list of resource",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "property"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Resource property not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getPropertyListInResource(
+ @Parameter(description = "resource id of property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return getPropertyList(resourceId, request, userId);
+ }
+
+ @DELETE
+ @Path("services/{serviceId}/properties/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete Service Property", method = "DELETE", summary = "Returns deleted property",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "deleted property"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Service property not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deletePropertyInService(
+ @Parameter(description = "service id of property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Parameter(description = "Property id to delete",
+ required = true) @PathParam("propertyId") final String propertyId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return deleteProperty(serviceId, propertyId, request, userId);
+ }
+
+ @DELETE
+ @Path("resources/{resourceId}/properties/{propertyId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete Resource Property", method = "DELETE", summary = "Returns deleted property",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "deleted property"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Resource property not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deletePropertyInResource(
+ @Parameter(description = "resource id of property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "Property id to delete",
+ required = true) @PathParam("propertyId") final String propertyId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return deleteProperty(resourceId, propertyId, request, userId);
+ }
+
+ @PUT
+ @Path("services/{serviceId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Service Property", method = "PUT", summary = "Returns updated property",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service property updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updatePropertyInService(
+ @Parameter(description = "service id to update with new property",
+ required = true) @PathParam("serviceId") final String serviceId,
+ @Parameter(description = "Service property to update", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return updateProperty(serviceId, data, request, userId);
+ }
+
+ @PUT
+ @Path("resources/{resourceId}/properties")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Resource Property", method = "PUT", summary = "Returns updated property",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource property updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updatePropertyInResource(
+ @Parameter(description = "resource id to update with new property",
+ required = true) @PathParam("resourceId") final String resourceId,
+ @Parameter(description = "Resource property to update", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return updateProperty(resourceId, data, request, userId);
+ }
+
+ private Response createProperty(String componentId, String data, HttpServletRequest request,String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_PROPERTIES, StatusCode.STARTED,"CREATE_PROPERTIES by user {} ", userId);
+
+ try{
+ Either<Map<String, PropertyDefinition>, ActionStatus> propertyDefinition =
+ getPropertyModel(componentId, data);
+ if (propertyDefinition.isRight()) {
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(propertyDefinition.right().value());
+ return buildErrorResponse(responseFormat);
+ }
+
+ Map<String, PropertyDefinition> properties = propertyDefinition.left().value();
+ if (properties == null || properties.size() != 1) {
+ log.info("Property content is invalid - {}", data);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return buildErrorResponse(responseFormat);
+ }
+
+ Map.Entry<String, PropertyDefinition> entry = properties.entrySet().iterator().next();
+ PropertyDefinition newPropertyDefinition = entry.getValue();
+ newPropertyDefinition.setParentUniqueId(componentId);
+ String propertyName = newPropertyDefinition.getName();
+
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> addPropertyEither =
+ propertyBusinessLogic.addPropertyToComponent(componentId, propertyName, newPropertyDefinition, userId);
+
+ if(addPropertyEither.isRight()) {
+ return buildErrorResponse(addPropertyEither.right().value());
+ }
+
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_PROPERTIES, StatusCode.COMPLETE,"CREATE_PROPERTIES by user {} ", userId);
+ return buildOkResponse(newPropertyDefinition);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
+ log.debug("create property failed with exception", e);
+ ResponseFormat responseFormat =
+ getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+
+
+ private Response updateProperty(String componentId, String data, HttpServletRequest request, String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.STARTED,"UPDATE_PROPERTIES by user {} ", userId);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+//
+ try {
+ // convert json to PropertyDefinition
+
+ Either<Map<String, PropertyDefinition>, ActionStatus> propertiesListEither =
+ getPropertiesListForUpdate(data);
+ if (propertiesListEither.isRight()) {
+ ResponseFormat responseFormat =
+ getComponentsUtils().getResponseFormat(propertiesListEither.right().value());
+ return buildErrorResponse(responseFormat);
+ }
+ Map<String, PropertyDefinition> properties = propertiesListEither.left().value();
+ if (properties == null) {
+ log.info("Property content is invalid - {}", data);
+ ResponseFormat responseFormat =
+ getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ return buildErrorResponse(responseFormat);
+ }
+
+ //Validate value and Constraint of property
+ Either<Boolean, ResponseFormat> constraintValidatorResponse =
+ PropertyValueConstraintValidationUtil.getInstance().
+ validatePropertyConstraints(properties.values(), applicationDataTypeCache);
+ if (constraintValidatorResponse.isRight()) {
+ log.error("Failed validation value and constraint of property: {}",
+ constraintValidatorResponse.right().value());
+ return buildErrorResponse(constraintValidatorResponse.right().value());
+ }
+
+ // update property
+
+ for(PropertyDefinition propertyDefinition : properties.values()) {
+ Either<EntryData<String, PropertyDefinition>, ResponseFormat> status =
+ propertyBusinessLogic.updateComponentProperty(
+ componentId, propertyDefinition.getUniqueId(), propertyDefinition, userId);
+ if (status.isRight()) {
+ log.info("Failed to update Property. Reason - ", status.right().value());
+ return buildErrorResponse(status.right().value());
+ }
+ EntryData<String, PropertyDefinition> property = status.left().value();
+ PropertyDefinition updatedPropertyDefinition = property.getValue();
+
+ log.debug("Property id {} updated successfully ", updatedPropertyDefinition.getUniqueId());
+ }
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_PROPERTIES, StatusCode.COMPLETE,"UPDATE_PROPERTIES by user {} ", userId);
+ return buildOkResponse(responseFormat, properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Property");
+ log.debug("update property failed with exception", e);
+ ResponseFormat responseFormat =
+ getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ private Response getProperty(String componentId, String propertyId, HttpServletRequest request, String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(DEBUG_MESSAGE, url, userId);
+
+ try {
+ Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> retrievedPropertyEither =
+ propertyBusinessLogic.getComponentProperty(componentId, propertyId, userId);
+
+ if(retrievedPropertyEither.isRight()) {
+ return buildErrorResponse(retrievedPropertyEither.right().value());
+ }
+
+ return buildOkResponse(retrievedPropertyEither.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
+ log.debug("get property failed with exception", e);
+ ResponseFormat responseFormat =
+ getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+ private Response getPropertyList(String componentId, HttpServletRequest request, String userId) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(DEBUG_MESSAGE, url, userId);
+
+ try {
+ Either<List<PropertyDefinition>, ResponseFormat> propertiesListEither =
+ propertyBusinessLogic.getPropertiesList(componentId, userId);
+
+ if(propertiesListEither.isRight()) {
+ return buildErrorResponse(propertiesListEither.right().value());
+ }
+
+ return buildOkResponse(propertiesListEither.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE_PROPERTY);
+ log.debug("get property failed with exception", e);
+ ResponseFormat responseFormat =
+ getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+ private Response deleteProperty(String componentId, String propertyId, HttpServletRequest request, String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(DEBUG_MESSAGE, url, userId);
+
+ try {
+
+ // delete the property
+ Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> status =
+ propertyBusinessLogic.deletePropertyFromComponent(componentId, propertyId, userId);
+ if (status.isRight()) {
+ log.debug("Failed to delete Property. Reason - ", status.right().value());
+ return buildErrorResponse(status.right().value());
+ }
+ Map.Entry<String, PropertyDefinition> property = status.left().value();
+ String name = property.getKey();
+ PropertyDefinition propertyDefinition = property.getValue();
+
+ log.debug("Property {} deleted successfully with id {}", name, propertyDefinition.getUniqueId());
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, propertyToJson(property));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Property");
+ log.debug("delete property failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java
index 98f75dfba3..6311520efb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentServlet.java
@@ -1,466 +1,464 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-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;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.collections.CollectionUtils;
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.mixin.GroupCompositionMixin;
-import org.openecomp.sdc.be.mixin.PolicyCompositionMixin;
-import org.openecomp.sdc.be.model.CapReqDef;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.IComponentInstanceConnectedElement;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.be.view.ResponseView;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.stereotype.Controller;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Component Servlet",description = "Component Servlet"))
-@Controller
-public class ComponentServlet extends BeGenericServlet {
- private static final String GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION = "getCertifiedNotAbstractComponents failed with exception";
-
- private static final String GET_CERTIFIED_NON_ABSTRACT = "Get Certified Non Abstract";
-
- private static final String FAILED_TO_GET_ALL_NON_ABSTRACT = "failed to get all non abstract {}";
-
- private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
-
- private static final Logger log = Logger.getLogger(ComponentServlet.class);
-
- private final ComponentBusinessLogicProvider componentBusinessLogicProvider;
-
- @Inject
- public ComponentServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- ComponentBusinessLogicProvider componentBusinessLogicProvider) {
- super(userBusinessLogic, componentsUtils);
- this.componentBusinessLogicProvider = componentBusinessLogicProvider;
- }
-
- @GET
- @Path("/{componentType}/{componentUuid}/conformanceLevelValidation")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Validate Component Conformance Level", method = "GET",
- summary = "Returns the result according to conformance level in BE config", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response conformanceLevelValidation(@PathParam("componentType") final String componentType,
- @PathParam("componentUuid") final String componentUuid, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- Response response;
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- if (componentTypeEnum != null) {
- ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum);
- Either<Boolean, ResponseFormat> eitherConformanceLevel = compBL.validateConformanceLevel(componentUuid, componentTypeEnum, userId);
- if (eitherConformanceLevel.isRight()) {
- response = buildErrorResponse(eitherConformanceLevel.right().value());
- } else {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), gson.toJson(eitherConformanceLevel.left().value()));
- }
- } else {
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- return response;
- }
-
- @GET
- @Path("/{componentType}/{componentId}/requirmentsCapabilities")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
- summary = "Returns Requirements And Capabilities according to componentId", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getRequirementAndCapabilities(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- Response response;
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- if (componentTypeEnum != null) {
- try {
- ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum);
- Either<CapReqDef, ResponseFormat> eitherRequirementsAndCapabilities = compBL.getRequirementsAndCapabilities(componentId, componentTypeEnum, userId);
- if (eitherRequirementsAndCapabilities.isRight()) {
- response = buildErrorResponse(eitherRequirementsAndCapabilities.right().value());
- } else {
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toRepresentation(eitherRequirementsAndCapabilities.left().value()));
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Capabilities and requirements for " + componentId);
- log.debug("getRequirementAndCapabilities failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- } else {
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- return response;
- }
-
- @GET
- @Path("/{componentType}/latestversion/notabstract")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
- summary = "Returns Requirments And Capabilities according to componentId", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getLatestVersionNotAbstractCheckoutComponents(
- @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
- @QueryParam("internalComponentType") String internalComponentType,
- @QueryParam("componentUids") List<String> componentUids,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
- Response response = null;
-
- try {
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
-
- log.debug("Received componentUids size is {}", componentUids == null ? 0 : componentUids.size());
-
- Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, componentTypeEnum, internalComponentType, componentUids, userId);
-
- if (actionResponse.isRight()) {
- log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
- return buildErrorResponse(actionResponse.right().value());
- }
- Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
- log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
-
- }
-
- @POST
- @Path("/{componentType}/latestversion/notabstract")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
- summary = "Returns Requirments And Capabilities according to componentId", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getLatestVersionNotAbstractCheckoutComponentsByBody(
- @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
- @QueryParam("internalComponentType") String internalComponentType,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "Consumer Object to be created", required = true) List<String> data) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(GET) Start handle request of {}", url);
- Response response = null;
-
- try {
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
- if (log.isDebugEnabled()) {
- log.debug("Received componentUids size is {}", data == null ? 0 : data.size());
- }
-
- Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, componentTypeEnum, internalComponentType, data, userId);
-
- if (actionResponse.isRight()) {
- log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
- return buildErrorResponse(actionResponse.right().value());
-
- }
- Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
-
-
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
- log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
-
- }
-
- @GET
- @Path("/{componentType}/latestversion/notabstract/metadata")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Component uid only", method = "GET", summary = "Returns componentId",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getLatestVersionNotAbstractCheckoutComponentsIdesOnly(
- @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
- @QueryParam("internalComponentType") String internalComponentType,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "uid list", required = true) String data) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
- Response response = null;
- try {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
-
- Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponentsMetadata(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, userId);
- if (actionResponse.isRight()) {
- log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
- return buildErrorResponse(actionResponse.right().value());
- }
- Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
- log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
-
- }
-
- @GET
- @Path("/{componentType}/{componentId}/componentInstances")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get Component instances", method = "GET", summary = "Returns component instances",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getComponentInstancesFilteredByPropertiesAndInputs(
- @PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
- @Context final HttpServletRequest request, @QueryParam("searchText") String searchText,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "uid" + " " + "list", required = true) String data) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(GET) Start handle request of {}", url);
- Response response = null;
- try {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
-
- Either<List<ComponentInstance>, ResponseFormat> actionResponse = businessLogic.getComponentInstancesFilteredByPropertiesAndInputs(componentId, userId);
- if (actionResponse.isRight()) {
- log.debug("failed to get all component instances filtered by properties and inputs", componentType);
- return buildErrorResponse(actionResponse.right().value());
- }
- Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Instances filtered by properties & inputs" + componentType);
- log.debug("getComponentInstancesFilteredByPropertiesAndInputs failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
-
-
- /**
- * This API is a generic api for ui - the api get a list of strings and return the data on the component according to to list.
- * for example: list of the string "properties, inputs" will return component with the list of properties and inputs.
- *
- * @param componentType
- * @param componentId
- * @param dataParamsToReturn
- * @param request
- * @param userId
- * @return
- */
-
- @GET
- @Path("/{componentType}/{componentId}/filteredDataByParams")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve Resource", method = "GET", summary = "Returns resource according to resourceId",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ResponseView(mixin = {GroupCompositionMixin.class, PolicyCompositionMixin.class})
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Resource not found")})
- public Response getComponentDataFilteredByParams(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId,
- @QueryParam("include") final List<String> dataParamsToReturn, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF , url);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}" , userId);
-
- Response response;
-
- try {
- String resourceIdLower = componentId.toLowerCase();
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
-
- log.trace("get component with id {} filtered by ui params", componentId);
- Either<UiComponentDataTransfer, ResponseFormat> actionResponse = businessLogic.getComponentDataFilteredByParams(resourceIdLower, modifier, dataParamsToReturn);
-
- if (actionResponse.isRight()) {
- log.debug("failed to get component data filtered by ui params");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
- RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get component filtered by ui params");
- log.debug("get resource failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
-
- @GET
- @Path("/{componentType}/{componentId}/filteredproperties/{propertyNameFragment}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(
- description = "Retrieve properties belonging to component instances of specific component by name and optionally resource type",
- method = "GET",
- summary = "Returns properties belonging to component instances of specific component by name and optionally resource type",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Map.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getFilteredComponentInstanceProperties(
- @PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId,
- @PathParam("propertyNameFragment") final String propertyNameFragment,
- @QueryParam("resourceType") List<String> resourceTypes,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- User user = new User();
- user.setUserId(userId);
- log.debug("User Id is {}" , userId);
- Response response;
- try {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
- Map<FilterKeyEnum, List<String>> filters = new EnumMap<>(FilterKeyEnum.class);
- List<String> propertyNameFragments = new ArrayList<>();
- propertyNameFragments.add(propertyNameFragment);
- filters.put(FilterKeyEnum.NAME_FRAGMENT, propertyNameFragments);
- if(CollectionUtils.isNotEmpty(resourceTypes)){
- filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypes);
- }
- Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> actionResponse = businessLogic.getFilteredComponentInstanceProperties(componentId, filters, userId);
- if (actionResponse.isRight()) {
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
- Object resource = RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resource);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Filtered Component Instance Properties");
- log.debug("Getting of filtered component instance properties failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogicProvider;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.mixin.GroupCompositionMixin;
+import org.openecomp.sdc.be.mixin.PolicyCompositionMixin;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.IComponentInstanceConnectedElement;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.be.view.ResponseView;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.openecomp.sdc.common.util.GeneralUtility.getCategorizedComponents;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Component Servlet",description = "Component Servlet"))
+@Controller
+public class ComponentServlet extends BeGenericServlet {
+ private static final String GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION = "getCertifiedNotAbstractComponents failed with exception";
+
+ private static final String GET_CERTIFIED_NON_ABSTRACT = "Get Certified Non Abstract";
+
+ private static final String FAILED_TO_GET_ALL_NON_ABSTRACT = "failed to get all non abstract {}";
+
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+
+ private static final Logger log = Logger.getLogger(ComponentServlet.class);
+
+ private final ComponentBusinessLogicProvider componentBusinessLogicProvider;
+
+ @Inject
+ public ComponentServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ ComponentBusinessLogicProvider componentBusinessLogicProvider) {
+ super(userBusinessLogic, componentsUtils);
+ this.componentBusinessLogicProvider = componentBusinessLogicProvider;
+ }
+
+ @GET
+ @Path("/{componentType}/{componentUuid}/conformanceLevelValidation")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Validate Component Conformance Level", method = "GET",
+ summary = "Returns the result according to conformance level in BE config", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response conformanceLevelValidation(@PathParam("componentType") final String componentType,
+ @PathParam("componentUuid") final String componentUuid, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ Response response;
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ if (componentTypeEnum != null) {
+ ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+ Either<Boolean, ResponseFormat> eitherConformanceLevel = compBL.validateConformanceLevel(componentUuid, componentTypeEnum, userId);
+ if (eitherConformanceLevel.isRight()) {
+ response = buildErrorResponse(eitherConformanceLevel.right().value());
+ } else {
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), gson.toJson(eitherConformanceLevel.left().value()));
+ }
+ } else {
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ return response;
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/requirmentsCapabilities")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
+ summary = "Returns Requirements And Capabilities according to componentId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getRequirementAndCapabilities(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+ Response response;
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ if (componentTypeEnum != null) {
+ try {
+ ComponentBusinessLogic compBL = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ RepresentationUtils.toRepresentation(compBL.getRequirementsAndCapabilities(componentId, componentTypeEnum, userId)));
+ } catch (IOException e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Capabilities and requirements for " + componentId);
+ log.debug("getRequirementAndCapabilities failed with exception", e);
+ throw e;
+ }
+ } else {
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ return response;
+ }
+
+ @GET
+ @Path("/{componentType}/latestversion/notabstract")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
+ summary = "Returns Requirments And Capabilities according to componentId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getLatestVersionNotAbstractCheckoutComponents(
+ @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
+ @QueryParam("internalComponentType") String internalComponentType,
+ @QueryParam("componentUids") List<String> componentUids,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+
+ log.debug("Received componentUids size is {}", componentUids == null ? 0 : componentUids.size());
+
+ Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, componentTypeEnum, internalComponentType, componentUids, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
+ log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
+ throw e;
+
+ }
+ }
+
+ @POST
+ @Path("/{componentType}/latestversion/notabstract")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component Requirments And Capabilities", method = "GET",
+ summary = "Returns Requirments And Capabilities according to componentId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getLatestVersionNotAbstractCheckoutComponentsByBody(
+ @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
+ @QueryParam("internalComponentType") String internalComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "Consumer Object to be created", required = true) List<String> data) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(GET) Start handle request of {}", url);
+ Response response;
+
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+ if (log.isDebugEnabled()) {
+ log.debug("Received componentUids size is {}", data == null ? 0 : data.size());
+ }
+
+ Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponents(false, componentTypeEnum, internalComponentType, data, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
+ return buildErrorResponse(actionResponse.right().value());
+
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
+ log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ @GET
+ @Path("/{componentType}/latestversion/notabstract/metadata")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component uid only", method = "GET", summary = "Returns componentId",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getLatestVersionNotAbstractCheckoutComponentsIdesOnly(
+ @PathParam("componentType") final String componentType, @Context final HttpServletRequest request,
+ @QueryParam("internalComponentType") String internalComponentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "uid list", required = true) String data) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+
+ Either<List<Component>, ResponseFormat> actionResponse = businessLogic.getLatestVersionNotAbstractComponentsMetadata(false, HighestFilterEnum.HIGHEST_ONLY, componentTypeEnum, internalComponentType, userId);
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ List<UiLeftPaletteComponent> uiLeftPaletteComponents = getComponentsUtils().convertComponentToUiLeftPaletteComponentObject(actionResponse.left().value());
+ Map<String, Map<String, List<UiLeftPaletteComponent>>> categorizedComponents = getCategorizedComponents(uiLeftPaletteComponents);
+ Object components = RepresentationUtils.toRepresentation(categorizedComponents);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(GET_CERTIFIED_NON_ABSTRACT + componentType);
+ log.debug(GET_CERTIFIED_NOT_ABSTRACT_COMPONENTS_FAILED_WITH_EXCEPTION, e);
+ throw e;
+ }
+
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/componentInstances")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get Component instances", method = "GET", summary = "Returns component instances",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentInstancesFilteredByPropertiesAndInputs(
+ @PathParam("componentType") final String componentType, @PathParam("componentId") final String componentId,
+ @Context final HttpServletRequest request, @QueryParam("searchText") String searchText,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "uid" + " " + "list", required = true) String data) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(GET) Start handle request of {}", url);
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+
+ Either<List<ComponentInstance>, ResponseFormat> actionResponse = businessLogic.getComponentInstancesFilteredByPropertiesAndInputs(componentId, userId);
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all component instances filtered by properties and inputs", componentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object components = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), components);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Instances filtered by properties & inputs" + componentType);
+ log.debug("getComponentInstancesFilteredByPropertiesAndInputs failed with exception", e);
+ throw e;
+ }
+ }
+
+
+
+ /**
+ * This API is a generic api for ui - the api get a list of strings and return the data on the component according to to list.
+ * for example: list of the string "properties, inputs" will return component with the list of properties and inputs.
+ *
+ * @param componentType
+ * @param componentId
+ * @param dataParamsToReturn
+ * @param request
+ * @param userId
+ * @return
+ */
+
+
+ @GET
+ @Path("/{componentType}/{componentId}/filteredDataByParams")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve Resource", method = "GET", summary = "Returns resource according to resourceId",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ResponseView(mixin = {GroupCompositionMixin.class, PolicyCompositionMixin.class})
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Resource not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentDataFilteredByParams(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId,
+ @QueryParam("include") final List<String> dataParamsToReturn, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF , url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}" , userId);
+
+ try {
+ String resourceIdLower = componentId.toLowerCase();
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+
+ log.trace("get component with id {} filtered by ui params", componentId);
+ Either<UiComponentDataTransfer, ResponseFormat> actionResponse = businessLogic.getComponentDataFilteredByParams(resourceIdLower, modifier, dataParamsToReturn);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get component data filtered by ui params");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get component filtered by ui params");
+ log.debug("get resource failed with exception", e);
+ throw e;
+ }
+ }
+
+
+ @GET
+ @Path("/{componentType}/{componentId}/filteredproperties/{propertyNameFragment}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(
+ description = "Retrieve properties belonging to component instances of specific component by name and optionally resource type",
+ method = "GET",
+ summary = "Returns properties belonging to component instances of specific component by name and optionally resource type",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Map.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getFilteredComponentInstanceProperties(
+ @PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("propertyNameFragment") final String propertyNameFragment,
+ @QueryParam("resourceType") List<String> resourceTypes,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ User user = new User();
+ user.setUserId(userId);
+ log.debug("User Id is {}" , userId);
+ Response response;
+ try {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentBusinessLogic businessLogic = componentBusinessLogicProvider.getInstance(componentTypeEnum);
+ Map<FilterKeyEnum, List<String>> filters = new EnumMap<>(FilterKeyEnum.class);
+ List<String> propertyNameFragments = new ArrayList<>();
+ propertyNameFragments.add(propertyNameFragment);
+ filters.put(FilterKeyEnum.NAME_FRAGMENT, propertyNameFragments);
+ if(CollectionUtils.isNotEmpty(resourceTypes)){
+ filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypes);
+ }
+ Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> actionResponse = businessLogic.getFilteredComponentInstanceProperties(componentId, filters, userId);
+ if (actionResponse.isRight()) {
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ Object resource = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), resource);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Filtered Component Instance Properties");
+ log.debug("Getting of filtered component instance properties failed with exception", e);
+ throw e;
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java
index 5b21e7de74..a3365c5ea2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigMgrServlet.java
@@ -21,6 +21,8 @@
package org.openecomp.sdc.be.servlets;
import com.jcabi.aspects.Loggable;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.common.api.Constants;
@@ -29,7 +31,13 @@ import org.openecomp.sdc.common.servlets.BasicServlet;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
@@ -45,6 +53,7 @@ public class ConfigMgrServlet extends BasicServlet {
@GET
@Path("/get")
@Produces(MediaType.APPLICATION_JSON)
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public String getConfig(@Context final HttpServletRequest request, @QueryParam("type") String type) {
String result = null;
@@ -74,6 +83,7 @@ public class ConfigMgrServlet extends BasicServlet {
@Path("/set1")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public String setConfig1(@Context final HttpServletRequest request, Configuration configuration) {
log.debug("{}", configuration);
@@ -86,6 +96,7 @@ public class ConfigMgrServlet extends BasicServlet {
@Path("/set2")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public void setConfig2(@Context final HttpServletRequest request, Configuration configuration) {
log.debug("{}", configuration);
@@ -96,6 +107,7 @@ public class ConfigMgrServlet extends BasicServlet {
@Path("/setput1")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public String setConfig3(@Context final HttpServletRequest request, Configuration configuration) {
log.debug("{}", configuration);
@@ -108,6 +120,7 @@ public class ConfigMgrServlet extends BasicServlet {
@Path("/setput2")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_JSON)
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public void setConfig4(@Context final HttpServletRequest request, Configuration configuration) {
log.debug("{}", configuration);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java
index ac4381f65f..0735b9de33 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConfigServlet.java
@@ -21,6 +21,12 @@
package org.openecomp.sdc.be.servlets;
import com.jcabi.aspects.Loggable;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.api.Constants;
@@ -40,6 +46,7 @@ import javax.ws.rs.core.MediaType;
*/
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/config")
+@Api(value = "Get configuration", description = "Get configuration")
public class ConfigServlet extends BasicServlet {
private static final Logger log = Logger.getLogger(ConfigServlet.class);
@@ -47,6 +54,9 @@ public class ConfigServlet extends BasicServlet {
@GET
@Path("/get")
@Produces(MediaType.APPLICATION_JSON)
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ @ApiOperation(value = "Retrieve configuration", httpMethod = "GET", notes = "Returns configuration", response = String.class)
+ @ApiResponses(value = { @ApiResponse(code = 200, message = "OK") })
public String getConfig(@Context final HttpServletRequest request) {
String result = null;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java
index 2ecbab765e..44b22a50f9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java
@@ -1,233 +1,235 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-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;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.ConsumerDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.google.gson.Gson;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/consumers")
-@OpenAPIDefinition(info = @Info(title = "Consumer Servlet",description = "Consumer Servlet"))
-@Singleton
-public class ConsumerServlet extends BeGenericServlet {
-
- private static final String MODIFIER_ID_IS = "modifier id is {}";
- private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
- private static final Logger log = Logger.getLogger(ConsumerServlet.class);
- private final ConsumerBusinessLogic businessLogic;
-
- @Inject
- public ConsumerServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- ConsumerBusinessLogic businessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.businessLogic = businessLogic;
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Consumer credentials", method = "POST",
- summary = "Returns created ECOMP consumer credentials",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Consumer credentials created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response createConsumer(@Parameter(description = "Consumer Object to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug(MODIFIER_ID_IS, userId);
-
- try {
- Either<ConsumerDefinition, ResponseFormat> convertionResponse = convertJsonToObject(data, modifier, AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS);
-
- if (convertionResponse.isRight()) {
- log.debug("failed to create Consumer");
- return buildErrorResponse(convertionResponse.right().value());
- }
-
- ConsumerDefinition consumer = convertionResponse.left().value();
-
- Either<ConsumerDefinition, ResponseFormat> actionResult = businessLogic.createConsumer(modifier, consumer);
-
- if (actionResult.isRight()) {
- log.debug("failed to create Consumer");
- return buildErrorResponse(actionResult.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResult.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create consumer");
- log.debug("create consumer failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
-
- }
- }
-
- @GET
- @Path("/{consumerId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve Consumer", method = "GET", summary = "Returns consumer according to ConsumerID",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConsumerDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Consumer found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Consumer not found")})
- public Response getConsumer(@PathParam("consumerId") final String consumerId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug(MODIFIER_ID_IS, userId);
-
- Response response = null;
- try {
- Either<ConsumerDefinition, ResponseFormat> actionResponse = businessLogic.getConsumer(consumerId, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("failed to get consumer");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Consumer");
- log.debug("get consumer failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- @DELETE
- @Path("/{consumerId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Deletes Consumer", method = "DELETE",
- summary = "Returns deleted consumer according to ConsumerID", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConsumerDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Consumer deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Consumer not found")})
- public Response deleteConsumer(@PathParam("consumerId") final String consumerId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug(MODIFIER_ID_IS, userId);
-
- Response response = null;
- try {
- Either<ConsumerDefinition, ResponseFormat> actionResponse = businessLogic.deleteConsumer(consumerId, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("failed to delete consumer");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Consumer");
- log.debug("delete consumer failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- public Either<ConsumerDefinition, ResponseFormat> convertJsonToObject(String data, User user, AuditingActionEnum actionEnum) {
- ConsumerDefinition consumer;
- Gson gson = new Gson();
- try {
- log.trace("convert json to object. json=\n {}", data);
- consumer = gson.fromJson(data, ConsumerDefinition.class);
- if (consumer == null) {
- BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
- log.debug("object is null after converting from json");
- ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorForConsumerAndAudit(user, null, actionEnum);
- return Either.right(responseFormat);
- }
- } catch (Exception e) {
- // INVALID JSON
- BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
- log.debug("failed to convert from json {}", data, e);
- ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorForConsumerAndAudit(user, null, actionEnum);
- return Either.right(responseFormat);
- }
- return Either.left(consumer);
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.google.gson.Gson;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.ConsumerBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ConsumerDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/consumers")
+@OpenAPIDefinition(info = @Info(title = "Consumer Servlet",description = "Consumer Servlet"))
+@Singleton
+public class ConsumerServlet extends BeGenericServlet {
+
+ private static final String MODIFIER_ID_IS = "modifier id is {}";
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final Logger log = Logger.getLogger(ConsumerServlet.class);
+ private final ConsumerBusinessLogic businessLogic;
+
+ @Inject
+ public ConsumerServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ ConsumerBusinessLogic businessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.businessLogic = businessLogic;
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Consumer credentials", method = "POST",
+ summary = "Returns created ECOMP consumer credentials",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Consumer credentials created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ public Response createConsumer(@Parameter(description = "Consumer Object to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ try {
+ Either<ConsumerDefinition, ResponseFormat> convertionResponse = convertJsonToObject(data, modifier, AuditingActionEnum.ADD_ECOMP_USER_CREDENTIALS);
+
+ if (convertionResponse.isRight()) {
+ log.debug("failed to create Consumer");
+ return buildErrorResponse(convertionResponse.right().value());
+ }
+
+ ConsumerDefinition consumer = convertionResponse.left().value();
+
+ Either<ConsumerDefinition, ResponseFormat> actionResult = businessLogic.createConsumer(modifier, consumer);
+
+ if (actionResult.isRight()) {
+ log.debug("failed to create Consumer");
+ return buildErrorResponse(actionResult.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResult.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create consumer");
+ log.debug("create consumer failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+
+ }
+ }
+
+ @GET
+ @Path("/{consumerId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve Consumer", method = "GET", summary = "Returns consumer according to ConsumerID",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConsumerDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Consumer found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Consumer not found")})
+ public Response getConsumer(@PathParam("consumerId") final String consumerId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+ try {
+ Either<ConsumerDefinition, ResponseFormat> actionResponse = businessLogic.getConsumer(consumerId, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get consumer");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Consumer");
+ log.debug("get consumer failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ @DELETE
+ @Path("/{consumerId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Deletes Consumer", method = "DELETE",
+ summary = "Returns deleted consumer according to ConsumerID", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConsumerDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Consumer deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Consumer not found")})
+ public Response deleteConsumer(@PathParam("consumerId") final String consumerId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+ try {
+ Either<ConsumerDefinition, ResponseFormat> actionResponse = businessLogic.deleteConsumer(consumerId, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to delete consumer");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Consumer");
+ log.debug("delete consumer failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+
+ }
+ }
+
+ public Either<ConsumerDefinition, ResponseFormat> convertJsonToObject(String data, User user, AuditingActionEnum actionEnum) {
+ ConsumerDefinition consumer;
+ Gson gson = new Gson();
+ try {
+ log.trace("convert json to object. json=\n {}", data);
+ consumer = gson.fromJson(data, ConsumerDefinition.class);
+ if (consumer == null) {
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("object is null after converting from json");
+ ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorForConsumerAndAudit(user, null, actionEnum);
+ return Either.right(responseFormat);
+ }
+ } catch (Exception e) {
+ // INVALID JSON
+ BeEcompErrorManager.getInstance().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("failed to convert from json {}", data, e);
+ ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorForConsumerAndAudit(user, null, actionEnum);
+ return Either.right(responseFormat);
+ }
+ return Either.left(consumer);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java
deleted file mode 100644
index 8c5a2247f9..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/CsarBuildServlet.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import com.jcabi.aspects.Loggable;
-import javax.inject.Inject;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
-import org.openecomp.sdc.be.resources.api.IResourceUploader;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/services")
-public class CsarBuildServlet extends ToscaDaoServlet {
-
- private static final Logger log = Logger.getLogger(CsarBuildServlet.class);
-
- @Inject
- public CsarBuildServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- IResourceUploader resourceUploader,
- DownloadArtifactLogic logic) {
- super(userBusinessLogic, componentsUtils, resourceUploader, logic);
- }
-
- @GET
- @Path("/{serviceName}/{serviceVersion}")
- public Response getDefaultTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
-
- return null;// buildToscaCsar(request, serviceName, serviceVersion);
-
- }
-
- @GET
- @Path("/{serviceName}/{serviceVersion}/csar")
- public Response getToscaCsarTemplate(@Context final HttpServletRequest request, @PathParam("serviceName") final String serviceName, @PathParam("serviceVersion") final String serviceVersion) {
-
- return null; // buildToscaCsar(request, serviceName, serviceVersion);
-
- }
-
-
- public static final String TOSCA_META_PATH = "TOSCA-Metadata/TOSCA.meta";
-
- protected String[] prepareToscaMetaHeader(String serviceName) {
- return new String[] { "TOSCA-Meta-File-Version: 1.0\n", "CSAR-Version: 1.1\n", "Created-By: INTERWISE\n", "\n", "Entry-Definitions: Definitions/" + serviceName + ".yaml\n", "\n", "Name: Definitions/" + serviceName + ".yaml\n",
- "Content-Type: application/vnd.oasis.tosca.definitions.yaml\n" };
- }
-
- protected String getAppliactionMime(String fileName) {
- String mimeType;
- if (fileName.contains(".sh")) {
- mimeType = "x-sh";
- } else if (fileName.contains(".yang")) {
- mimeType = "yang";
- }
-
- else if (fileName.contains(".rar")) {
- mimeType = "x-rar-compressed";
- }
-
- else if (fileName.contains(".zip")) {
- mimeType = "zip";
- }
-
- else if (fileName.contains(".tar")) {
- mimeType = "x-tar";
- }
-
- else if (fileName.contains(".7z")) {
- mimeType = "x-7z-compressed";
- }
-
- else {
- // Undefined
- mimeType = "undefined";
- }
- return mimeType;
- }
-
- protected String getArtifactPath(String nodeTamplateName, ESArtifactData artifactData) {
- return "Scripts/" + nodeTamplateName + "/" + artifactData.getId();
- }
-
- protected String getResourcePath(String resourceName) {
- return "Definitions/" + resourceName + ".yaml";
- }
-
- @Override
- public Logger getLogger() {
- return log;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java
index fc6c28c8cd..a5a2768199 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java
@@ -1,169 +1,168 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-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;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.info.DistributionStatusListResponse;
-import org.openecomp.sdc.be.info.DistributionStatusOfServiceListResponce;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * Root resource (exposed at "/" path)
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Distribution Service Servlet",description = "Distribution Service Servlet"))
-@Singleton
-public class DistributionServiceServlet extends BeGenericServlet {
- private static final Logger log = Logger.getLogger(DistributionServiceServlet.class);
-
- @Inject
- public DistributionServiceServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- DistributionMonitoringBusinessLogic distributionMonitoringLogic) {
- super(userBusinessLogic, componentsUtils);
- this.distributionMonitoringLogic = distributionMonitoringLogic;
- }
-
- private DistributionMonitoringBusinessLogic distributionMonitoringLogic;
-
- @GET
- @Path("/services/{serviceUUID}/distribution")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve Distributions", method = "GET",
- summary = "Returns list bases on the information extracted from Auditing Records according to service uuid",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = DistributionStatusListResponse.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found")})
- public Response getServiceById(@PathParam("serviceUUID") final String serviceUUID,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- Response response = null;
- ResponseFormat responseFormat = null;
-
- try {
- Either<DistributionStatusOfServiceListResponce, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionServiceStatus(serviceUUID, userId);
-
- if (actionResponse.isRight()) {
-
- responseFormat = actionResponse.right().value();
- response = buildErrorResponse(responseFormat);
- } else {
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- response = buildOkResponse(responseFormat, actionResponse.left().value());
-
- }
-
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution list for Service");
- log.debug("failed to get service distribution statuses", e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
-
- response = buildErrorResponse(responseFormat);
- return response;
- }
-
- }
-
- @GET
- @Path("/services/distribution/{did}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve Distributions", method = "GET",
- summary = "Return the list of distribution status objects",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = DistributionStatusListResponse.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Status not found")})
- public Response getListOfDistributionStatuses(@PathParam("did") final String did,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- Response response = null;
- ResponseFormat responseFormat = null;
-
- try {
- Either<DistributionStatusListResponse, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionStatus(did, userId);
-
- if (actionResponse.isRight()) {
-
- responseFormat = actionResponse.right().value();
- log.debug("failed to fount statuses for did {} {}", did, responseFormat);
- response = buildErrorResponse(responseFormat);
- } else {
-
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- log.debug("success to fount statuses for did {} {}", did, actionResponse.left().value());
- response = buildOkResponse(responseFormat, actionResponse.left().value());
-
- }
-
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution Status");
- log.debug("failed to get distribution status ", e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
-
- response = buildErrorResponse(responseFormat);
- return response;
- }
-
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.DistributionMonitoringBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.info.DistributionStatusListResponse;
+import org.openecomp.sdc.be.info.DistributionStatusOfServiceListResponce;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+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;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Distribution Service Servlet",description = "Distribution Service Servlet"))
+@Controller
+public class DistributionServiceServlet extends BeGenericServlet {
+ private static final Logger log = Logger.getLogger(DistributionServiceServlet.class);
+
+ @Inject
+ public DistributionServiceServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ DistributionMonitoringBusinessLogic distributionMonitoringLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.distributionMonitoringLogic = distributionMonitoringLogic;
+ }
+
+ private DistributionMonitoringBusinessLogic distributionMonitoringLogic;
+
+ @GET
+ @Path("/services/{serviceUUID}/distribution")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve Distributions", method = "GET",
+ summary = "Returns list bases on the information extracted from Auditing Records according to service uuid",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = DistributionStatusListResponse.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getServiceById(@PathParam("serviceUUID") final String serviceUUID,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Response response = null;
+ ResponseFormat responseFormat = null;
+
+ try {
+ Either<DistributionStatusOfServiceListResponce, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionServiceStatus(serviceUUID, userId);
+
+ if (actionResponse.isRight()) {
+
+ responseFormat = actionResponse.right().value();
+ response = buildErrorResponse(responseFormat);
+ } else {
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ response = buildOkResponse(responseFormat, actionResponse.left().value());
+
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution list for Service");
+ log.debug("failed to get service distribution statuses", e);
+ throw e;
+ }
+
+ }
+
+ @GET
+ @Path("/services/distribution/{did}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve Distributions", method = "GET",
+ summary = "Return the list of distribution status objects",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = DistributionStatusListResponse.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Status not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getListOfDistributionStatuses(@PathParam("did") final String did,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Response response = null;
+ ResponseFormat responseFormat = null;
+
+ try {
+ Either<DistributionStatusListResponse, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionStatus(did, userId);
+
+ if (actionResponse.isRight()) {
+
+ responseFormat = actionResponse.right().value();
+ log.debug("failed to fount statuses for did {} {}", did, responseFormat);
+ response = buildErrorResponse(responseFormat);
+ } else {
+
+ responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+ log.debug("success to fount statuses for did {} {}", did, actionResponse.left().value());
+ response = buildOkResponse(responseFormat, actionResponse.left().value());
+
+ }
+
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution Status");
+ log.debug("failed to get distribution status ", e);
+ throw e;
+ }
+
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
index 0c81ad3cab..4245fc813e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java
@@ -1,735 +1,780 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-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;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
-import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.info.ArtifactTypesInfo;
-import org.openecomp.sdc.be.model.ArtifactType;
-import org.openecomp.sdc.be.model.Category;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.PropertyScope;
-import org.openecomp.sdc.be.model.Tag;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.catalog.CatalogComponent;
-import org.openecomp.sdc.be.model.category.CategoryDefinition;
-import org.openecomp.sdc.be.model.category.GroupingDefinition;
-import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
-import org.openecomp.sdc.be.ui.model.UiCategories;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Path("/v1/")
-
-/****
- *
- * UI oriented servlet - to return elements in specific format UI needs
- *
- *
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@OpenAPIDefinition(info = @Info(title = "Element Servlet",description = "Element Servlet"))
-@Singleton
-public class ElementServlet extends BeGenericServlet {
-
- private static final Logger log = Logger.getLogger(ElementServlet.class);
- private final ComponentsCleanBusinessLogic componentsCleanBusinessLogic;
- private final ElementBusinessLogic elementBusinessLogic;
- private final UserBusinessLogic userBusinessLogic;
-
- @Inject
- public ElementServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- ComponentsCleanBusinessLogic componentsCleanBusinessLogic,
- ElementBusinessLogic elementBusinessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.componentsCleanBusinessLogic = componentsCleanBusinessLogic;
- this.elementBusinessLogic = elementBusinessLogic;
- this.userBusinessLogic = userBusinessLogic;
- }
-
- /*
- ******************************************************************************
- * NEW CATEGORIES category / \ subcategory subcategory / grouping
- ******************************************************************************/
-
- /*
- *
- *
- * CATEGORIES
- */
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // retrieve all component categories
- @GET
- @Path("/categories/{componentType}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve the list of all resource/service/product categories/sub-categories/groupings",
- method = "GET",
- summary = "Retrieve the list of all resource/service/product categories/sub-categories/groupings.",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns categories Ok"),
- @ApiResponse(responseCode = "403", description = "Missing information"),
- @ApiResponse(responseCode = "400", description = "Invalid component type"),
- @ApiResponse(responseCode = "409", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getComponentCategories(
- @Parameter(description = "allowed values are resources / services/ products", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME,ComponentTypeEnum.PRODUCT_PARAM_NAME}),required = true)
- @PathParam(value = "componentType") final String componentType,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
-
- try {
- Either<List<CategoryDefinition>, ResponseFormat> either =
- elementBusinessLogic.getAllCategories(componentType, userId);
- if (either.isRight()) {
- log.debug("No categories were found for type {}", componentType);
- return buildErrorResponse(either.right().value());
- } else {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Categories");
- log.debug("getComponentCategories failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Path("/categories")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve the all resource, service and product categories", method = "GET",
- summary = "Retrieve the all resource, service and product categories", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns categories Ok"),
- @ApiResponse(responseCode = "403", description = "Missing information"),
- @ApiResponse(responseCode = "409", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getAllCategories(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- try {
- Either<UiCategories, ResponseFormat> either = elementBusinessLogic.getAllCategories(userId);
- if (either.isRight()) {
- log.debug("No categories were found");
- return buildErrorResponse(either.right().value());
- } else {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Categories");
- log.debug("getAllCategories failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
-
- @POST
- @Path("/category/{componentType}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create new component category", method = "POST",
- summary = "Create new component category")
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Category created"),
- @ApiResponse(responseCode = "400", description = "Invalid category data"),
- @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
- @ApiResponse(responseCode = "409",
- description = "Category already exists / User not permitted to perform the action"),
- @ApiResponse(responseCode = "500", description = "General Error")})
- public Response createComponentCategory(
- @Parameter(description = "allowed values are resources /services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME,ComponentTypeEnum.PRODUCT_PARAM_NAME}),
- required = true) @PathParam(value = "componentType") final String componentType,
- @Parameter(description = "Category to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- try {
- CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class);
-
- Either<CategoryDefinition, ResponseFormat> createResourceCategory =
- elementBusinessLogic.createCategory(category, componentType, userId);
- if (createResourceCategory.isRight()) {
- return buildErrorResponse(createResourceCategory.right().value());
- }
-
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
- return buildOkResponse(responseFormat, createResourceCategory.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
- log.debug("createResourceCategory failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- @DELETE
- @Path("/category/{componentType}/{categoryUniqueId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
- @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
- @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
- @ApiResponse(responseCode = "404", description = "Category not found"),
- @ApiResponse(responseCode = "500", description = "General Error")})
- public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
- @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- try {
- Either<CategoryDefinition, ResponseFormat> createResourceCategory =
- elementBusinessLogic.deleteCategory(categoryUniqueId, componentType, userId);
-
- if (createResourceCategory.isRight()) {
- return buildErrorResponse(createResourceCategory.right().value());
- }
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
- return buildOkResponse(responseFormat, null);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
- log.debug("createResourceCategory failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- /*
- *
- *
- * SUBCATEGORIES
- *
- */
-
- @POST
- @Path("/category/{componentType}/{categoryId}/subCategory")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create new component sub-category", method = "POST",
- summary = "Create new component sub-category for existing category")
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Subcategory created"),
- @ApiResponse(responseCode = "400", description = "Invalid subcategory data"),
- @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
- @ApiResponse(responseCode = "404", description = "Parent category wasn't found"),
- @ApiResponse(responseCode = "409",
- description = "Subcategory already exists / User not permitted to perform the action"),
- @ApiResponse(responseCode = "500", description = "General Error")})
- public Response createComponentSubCategory(
- @Parameter(description = "allowed values are resources / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.PRODUCT_PARAM_NAME}),
- required = true) @PathParam(value = "componentType") final String componentType,
- @Parameter(description = "Parent category unique ID",
- required = true) @PathParam(value = "categoryId") final String categoryId,
- @Parameter(description = "Subcategory to be created. \ne.g. {\"name\":\"Resource-subcat\"}",
- required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- try {
- SubCategoryDefinition subCategory =
- RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class);
-
- Either<SubCategoryDefinition, ResponseFormat> createSubcategory =
- elementBusinessLogic.createSubCategory(subCategory, componentType, categoryId, userId);
- if (createSubcategory.isRight()) {
- return buildErrorResponse(createSubcategory.right().value());
- }
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
- return buildOkResponse(responseFormat, createSubcategory.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create sub-category");
- log.debug("createComponentSubCategory failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- @DELETE
- @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
- @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
- @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
- @ApiResponse(responseCode = "404", description = "Category not found"),
- @ApiResponse(responseCode = "500", description = "General Error")})
- public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
- @PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
- @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- try {
- Either<SubCategoryDefinition, ResponseFormat> deleteSubResourceCategory =
- elementBusinessLogic.deleteSubCategory(subCategoryUniqueId, componentType, userId);
- if (deleteSubResourceCategory.isRight()) {
- return buildErrorResponse(deleteSubResourceCategory.right().value());
- }
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
- return buildOkResponse(responseFormat, null);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component category");
- log.debug("deleteComponentSubCategory failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- /*
- * GROUPINGS
- */
- @POST
- @Path("/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create new component grouping", method = "POST",
- summary = "Create new component grouping for existing sub-category")
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Grouping created"),
- @ApiResponse(responseCode = "400", description = "Invalid grouping data"),
- @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
- @ApiResponse(responseCode = "404", description = "Parent category or subcategory were not found"),
- @ApiResponse(responseCode = "409",
- description = "Grouping already exists / User not permitted to perform the action"),
- @ApiResponse(responseCode = "500", description = "General Error")})
- public Response createComponentGrouping(
- @Parameter(description = "allowed values are products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.PRODUCT_PARAM_NAME}),
- required = true) @PathParam(value = "componentType") final String componentType,
- @Parameter(description = "Parent category unique ID",
- required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
- @Parameter(description = "Parent sub-category unique ID",
- required = true) @PathParam(value = "subCategoryId") final String parentSubCategoryId,
- @Parameter(description = "Subcategory to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- try {
- GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class);
-
- Either<GroupingDefinition, ResponseFormat> createGrouping = elementBusinessLogic.createGrouping(grouping,
- componentType, grandParentCategoryId, parentSubCategoryId, userId);
- if (createGrouping.isRight()) {
- return buildErrorResponse(createGrouping.right().value());
- }
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
- return buildOkResponse(responseFormat, createGrouping.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create grouping");
- log.debug("createComponentGrouping failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- @DELETE
- @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
- @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
- @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
- @ApiResponse(responseCode = "404", description = "Category not found"),
- @ApiResponse(responseCode = "500", description = "General Error")})
- public Response deleteComponentGrouping(
- @PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId,
- @PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
- @PathParam(value = "groupingUniqueId") final String groupingUniqueId,
- @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- try {
- Either<GroupingDefinition, ResponseFormat> deleteGrouping =
- elementBusinessLogic.deleteGrouping(groupingUniqueId, componentType, userId);
- if (deleteGrouping.isRight()) {
- return buildErrorResponse(deleteGrouping.right().value());
- }
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
- return buildOkResponse(responseFormat, null);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component grouping");
- log.debug("deleteGrouping failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // retrieve all tags
- @GET
- @Path("/tags")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve all tags", method = "GET", summary = "Retrieve all tags",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns tags Ok"),
- @ApiResponse(responseCode = "404", description = "No tags were found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getTags(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(getTags) Start handle request of {}", url);
-
- try {
- Either<List<Tag>, ActionStatus> either = elementBusinessLogic.getAllTags(userId);
- if (either.isRight() || either.left().value() == null) {
- log.debug("No tags were found");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
- } else {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Tags");
- log.debug("getAllTags failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // retrieve all property scopes
- @GET
- @Path("/propertyScopes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve all propertyScopes", method = "GET", summary = "Retrieve all propertyScopes",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns propertyScopes Ok"),
- @ApiResponse(responseCode = "404", description = "No propertyScopes were found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getPropertyScopes(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(getPropertyScopes) Start handle request of {}", url);
-
- try {
- Either<List<PropertyScope>, ActionStatus> either = elementBusinessLogic.getAllPropertyScopes(userId);
- if (either.isRight() || either.left().value() == null) {
- log.debug("No property scopes were found");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
- } else {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property Scopes Categories");
- log.debug("getPropertyScopes failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // retrieve all artifact types
- @GET
- @Path("/artifactTypes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve all artifactTypes", method = "GET", summary = "Retrieve all artifactTypes",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns artifactTypes Ok"),
- @ApiResponse(responseCode = "404", description = "No artifactTypes were found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getArtifactTypes(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(GET - getArtifactTypes) Start handle request of {}", url);
-
- try {
- Either<List<ArtifactType>, ActionStatus> either = elementBusinessLogic.getAllArtifactTypes(userId);
- if (either.isRight() || either.left().value() == null) {
- log.debug("No artifact types were found");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
- } else {
-
- Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getDefaultHeatArtifactTimeoutMinutes();
- ArtifactTypesInfo typesResponse = new ArtifactTypesInfo();
- typesResponse.setArtifactTypes(either.left().value());
- typesResponse.setHeatDefaultTimeout(defaultHeatTimeout);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), typesResponse);
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
- log.debug("getArtifactTypes failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // retrieve all artifact types
- @GET
- @Path("/configuration/ui")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve all artifactTypes", method = "GET", summary = "Retrieve all artifactTypes",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns artifactTypes Ok"),
- @ApiResponse(responseCode = "404", description = "No artifactTypes were found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getConfiguration(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(getConfiguration) Start handle request of {}", url);
-
- try {
- Either<List<ArtifactType>, ActionStatus> otherEither = elementBusinessLogic.getAllArtifactTypes(userId);
- Either<Integer, ActionStatus> defaultHeatTimeout = elementBusinessLogic.getDefaultHeatTimeout();
- Either<Map<String, Object>, ActionStatus> deploymentEither =
- elementBusinessLogic.getAllDeploymentArtifactTypes();
- Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBusinessLogic.getResourceTypesMap();
-
- if (otherEither.isRight() || otherEither.left().value() == null) {
- log.debug("No other artifact types were found");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
- } else if (deploymentEither.isRight() || deploymentEither.left().value() == null) {
- log.debug("No deployment artifact types were found");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
- } else if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
- log.debug("heat default timeout was not found");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
- } else if (resourceTypesMap.isRight() || resourceTypesMap.left().value() == null) {
- log.debug("No resource types were found");
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
- } else {
- Map<String, Object> artifacts = new HashMap<>();
- Map<String, Object> configuration = new HashMap<>();
-
- artifacts.put("other", otherEither.left().value());
- artifacts.put("deployment", deploymentEither.left().value());
- configuration.put("artifacts", artifacts);
- configuration.put("defaultHeatTimeout", defaultHeatTimeout.left().value());
- configuration.put("componentTypes", elementBusinessLogic.getAllComponentTypesParamNames());
- configuration.put("roles", elementBusinessLogic.getAllSupportedRoles());
- configuration.put("resourceTypes", resourceTypesMap.left().value());
- configuration.put("environmentContext",
- ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext());
- configuration.put("gab",
- ConfigurationManager.getConfigurationManager().getConfiguration().getGabConfig());
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), configuration);
- }
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
- log.debug("getArtifactTypes failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // retrieve all followed resources and services
- @GET
- @Path("/followed")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve all followed", method = "GET", summary = "Retrieve all followed",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns followed Ok"),
- @ApiResponse(responseCode = "404", description = "No followed were found"),
- @ApiResponse(responseCode = "404", description = "User not found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getFollowedResourcesServices(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- Response res = null;
- User userData = null;
- try {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // Getting the user
- Either<User, ActionStatus> either = userBusinessLogic.getUser(userId, false);
- if (either.isRight()) {
- // Couldn't find or otherwise fetch the user
- return buildErrorResponse(
- getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
- }
-
- if (either.left().value() != null) {
- userData = either.left().value();
- Either<Map<String, List<? extends Component>>, ResponseFormat> followedResourcesServices =
- elementBusinessLogic.getFollowed(userData);
- if (followedResourcesServices.isRight()) {
- log.debug("failed to get followed resources services ");
- return buildErrorResponse(followedResourcesServices.right().value());
- }
- Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
- res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
- } else {
- res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
- log.debug("Getting followed resources/services failed with exception", e);
- res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- return res;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // retrieve all certified resources and services and their last version
- @GET
- @Path("/screen")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve catalog resources and services", method = "GET",
- summary = "Retrieve catalog resources and services", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns resources and services Ok"),
- @ApiResponse(responseCode = "404", description = "No resources and services were found"),
- @ApiResponse(responseCode = "404", description = "User not found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getCatalogComponents(@Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) {
-
- Response res = null;
- try {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData =
- elementBusinessLogic.getCatalogComponents(userId, excludeTypes);
-
- if (catalogData.isRight()) {
- log.debug("failed to get catalog data");
- return buildErrorResponse(catalogData.right().value());
- }
- Object data = RepresentationUtils.toRepresentation(catalogData.left().value());
- res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components");
- log.debug("Getting catalog components failed with exception", e);
- res = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- return res;
- }
-
- @DELETE
- @Path("/inactiveComponents/{componentType}")
- public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
-
- NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType);
- if (nodeType == null) {
- log.info("componentType is not valid: {}", componentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- List<NodeTypeEnum> componentsList = new ArrayList<>();
- componentsList.add(nodeType);
- try {
- Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponentsResult = componentsCleanBusinessLogic.cleanComponents(componentsList);
- Either<List<String>, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType);
-
- if (cleanResult.isRight()) {
- log.debug("failed to delete marked components of type {}", nodeType);
- response = buildErrorResponse(cleanResult.right().value());
- return response;
- }
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value());
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components");
- log.debug("delete marked components failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @GET
- @Path("/ecompPortalMenu")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve ecomp portal menu - MOC", method = "GET", summary = "Retrieve ecomp portal menu", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Retrieve ecomp portal menu") })
- public Response getListOfCsars(@Context final HttpServletRequest request) {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- "[{\"menuId\":1,\"column\":2,\"text\":\"Design\",\"parentMenuId\":null,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":11,\"column\":1,\"text\":\"ProductDesign\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":12,\"column\":2,\"text\":\"Service\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":21,\"column\":1,\"text\":\"ViewPolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":90,\"column\":1,\"text\":\"4thLevelApp1aR16\",\"parentMenuId\":21,\"url\":\"http://google.com\",\"appid\":null,\"roles\":null}]},{\"menuId\":22,\"column\":2,\"text\":\"UpdatePolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":91,\"column\":1,\"text\":\"4thLevelApp1bR16\",\"parentMenuId\":22,\"url\":\"http://jsonlint.com/\",\"appid\":null,\"roles\":null}]},{\"menuId\":23,\"column\":3,\"text\":\"UpdateRules\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":24,\"column\":4,\"text\":\"CreateSignatures?\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":25,\"column\":5,\"text\":\"Definedata\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null}]}]}]");
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.ElementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.info.ArtifactTypesInfo;
+import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
+import org.openecomp.sdc.be.model.Category;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.PropertyScope;
+import org.openecomp.sdc.be.model.Tag;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.catalog.CatalogComponent;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.GroupingDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.ui.model.UiCategories;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Path("/v1/")
+
+/****
+ *
+ * UI oriented servlet - to return elements in specific format UI needs
+ *
+ *
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@OpenAPIDefinition(info = @Info(title = "Element Servlet",description = "Element Servlet"))
+@Controller
+public class ElementServlet extends BeGenericServlet {
+
+ private static final Logger log = Logger.getLogger(ElementServlet.class);
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private final ComponentsCleanBusinessLogic componentsCleanBusinessLogic;
+ private final ElementBusinessLogic elementBusinessLogic;
+ private final UserBusinessLogic userBusinessLogic;
+
+ @Inject
+ public ElementServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ ComponentsCleanBusinessLogic componentsCleanBusinessLogic,
+ ElementBusinessLogic elementBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.componentsCleanBusinessLogic = componentsCleanBusinessLogic;
+ this.elementBusinessLogic = elementBusinessLogic;
+ this.userBusinessLogic = userBusinessLogic;
+ }
+
+ /*
+ ******************************************************************************
+ * NEW CATEGORIES category / \ subcategory subcategory / grouping
+ ******************************************************************************/
+
+ /*
+ *
+ *
+ * CATEGORIES
+ */
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all component categories
+ @GET
+ @Path("/categories/{componentType}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve the list of all resource/service/product categories/sub-categories/groupings",
+ method = "GET",
+ summary = "Retrieve the list of all resource/service/product categories/sub-categories/groupings.",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns categories Ok"),
+ @ApiResponse(responseCode = "403", description = "Missing information"),
+ @ApiResponse(responseCode = "400", description = "Invalid component type"),
+ @ApiResponse(responseCode = "409", description = "Restricted operation"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentCategories(
+ @Parameter(description = "allowed values are resources / services/ products", schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME,ComponentTypeEnum.PRODUCT_PARAM_NAME}),required = true)
+ @PathParam(value = "componentType") final String componentType,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<CategoryDefinition>, ResponseFormat> either = elementBL.getAllCategories(componentType, userId);
+ if (either.isRight()) {
+ log.debug("No categories were found for type {}", componentType);
+ return buildErrorResponse(either.right().value());
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component Categories");
+ log.debug("getComponentCategories failed with exception", e);
+ throw e;
+ }
+ }
+
+ //TODO remove after UI alignment and tests after API consolidation ASDC-191
+ /* @GET
+ @Path("/categories")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Retrieve the all resource, service and product categories", httpMethod = "GET", notes = "Retrieve the all resource, service and product categories", response = Response.class)
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "Returns categories Ok"), @ApiResponse(code = 403, message = "Missing information"),
+ @ApiResponse(code = 409, message = "Restricted operation"), @ApiResponse(code = 500, message = "Internal Server Error")})
+ public Response getAllCategories(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<UiCategories, ResponseFormat> either = elementBL.getAllCategories(userId);
+ if (either.isRight()) {
+ log.debug("No categories were found");
+ return buildErrorResponse(either.right().value());
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Categories");
+ log.debug("getAllCategories failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }*/
+
+
+ @POST
+ @Path("/category/{componentType}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create new component category", method = "POST",
+ summary = "Create new component category")
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Category created"),
+ @ApiResponse(responseCode = "400", description = "Invalid category data"),
+ @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
+ @ApiResponse(responseCode = "409",
+ description = "Category already exists / User not permitted to perform the action"),
+ @ApiResponse(responseCode = "500", description = "General Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createComponentCategory(
+ @Parameter(description = "allowed values are resources /services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME,ComponentTypeEnum.PRODUCT_PARAM_NAME}),
+ required = true) @PathParam(value = "componentType") final String componentType,
+ @Parameter(description = "Category to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ CategoryDefinition category = RepresentationUtils.fromRepresentation(data, CategoryDefinition.class);
+
+ Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.createCategory(category, componentType, userId);
+ if (createResourceCategory.isRight()) {
+ return buildErrorResponse(createResourceCategory.right().value());
+ }
+
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, createResourceCategory.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
+ log.debug("createResourceCategory failed with exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/category/{componentType}/{categoryUniqueId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
+ @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
+ @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
+ @ApiResponse(responseCode = "404", description = "Category not found"),
+ @ApiResponse(responseCode = "500", description = "General Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteComponentCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
+ @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<CategoryDefinition, ResponseFormat> createResourceCategory = elementBL.deleteCategory(categoryUniqueId, componentType, userId);
+
+ if (createResourceCategory.isRight()) {
+ return buildErrorResponse(createResourceCategory.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, null);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create resource category");
+ log.debug("createResourceCategory failed with exception", e);
+ throw e;
+ }
+ }
+
+ /*
+ *
+ *
+ * SUBCATEGORIES
+ *
+ */
+
+ @POST
+ @Path("/category/{componentType}/{categoryId}/subCategory")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create new component sub-category", method = "POST",
+ summary = "Create new component sub-category for existing category")
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Subcategory created"),
+ @ApiResponse(responseCode = "400", description = "Invalid subcategory data"),
+ @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
+ @ApiResponse(responseCode = "404", description = "Parent category wasn't found"),
+ @ApiResponse(responseCode = "409",
+ description = "Subcategory already exists / User not permitted to perform the action"),
+ @ApiResponse(responseCode = "500", description = "General Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createComponentSubCategory(
+ @Parameter(description = "allowed values are resources / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME}),
+ required = true) @PathParam(value = "componentType") final String componentType,
+ @Parameter(description = "Parent category unique ID",
+ required = true) @PathParam(value = "categoryId") final String categoryId,
+ @Parameter(description = "Subcategory to be created. \ne.g. {\"name\":\"Resource-subcat\"}",
+ required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ SubCategoryDefinition subCategory = RepresentationUtils.fromRepresentation(data, SubCategoryDefinition.class);
+
+ Either<SubCategoryDefinition, ResponseFormat> createSubcategory = elementBL.createSubCategory(subCategory, componentType, categoryId, userId);
+ if (createSubcategory.isRight()) {
+ return buildErrorResponse(createSubcategory.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, createSubcategory.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create sub-category");
+ log.debug("createComponentSubCategory failed with exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
+ @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
+ @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
+ @ApiResponse(responseCode = "404", description = "Category not found"),
+ @ApiResponse(responseCode = "500", description = "General Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteComponentSubCategory(@PathParam(value = "categoryUniqueId") final String categoryUniqueId,
+ @PathParam(value = "subCategoryUniqueId") final String subCategoryUniqueId,
+ @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<SubCategoryDefinition, ResponseFormat> deleteSubResourceCategory = elementBL.deleteSubCategory(subCategoryUniqueId, componentType, userId);
+ if (deleteSubResourceCategory.isRight()) {
+ return buildErrorResponse(deleteSubResourceCategory.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, null);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component subcategory");
+ log.debug("deleteComponentSubCategory failed with exception", e);
+ throw e;
+ }
+ }
+
+ /*
+ * GROUPINGS
+ */
+ @POST
+ @Path("/category/{componentType}/{categoryId}/subCategory/{subCategoryId}/grouping")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create new component grouping", method = "POST",
+ summary = "Create new component grouping for existing sub-category")
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Grouping created"),
+ @ApiResponse(responseCode = "400", description = "Invalid grouping data"),
+ @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
+ @ApiResponse(responseCode = "404", description = "Parent category or subcategory were not found"),
+ @ApiResponse(responseCode = "409",
+ description = "Grouping already exists / User not permitted to perform the action"),
+ @ApiResponse(responseCode = "500", description = "General Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createComponentGrouping(
+ @Parameter(description = "allowed values are products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.PRODUCT_PARAM_NAME}),
+ required = true) @PathParam(value = "componentType") final String componentType,
+ @Parameter(description = "Parent category unique ID",
+ required = true) @PathParam(value = "categoryId") final String grandParentCategoryId,
+ @Parameter(description = "Parent sub-category unique ID",
+ required = true) @PathParam(value = "subCategoryId") final String parentSubCategoryId,
+ @Parameter(description = "Subcategory to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ GroupingDefinition grouping = RepresentationUtils.fromRepresentation(data, GroupingDefinition.class);
+
+ Either<GroupingDefinition, ResponseFormat> createGrouping = elementBL.createGrouping(grouping, componentType, grandParentCategoryId, parentSubCategoryId, userId);
+ if (createGrouping.isRight()) {
+ return buildErrorResponse(createGrouping.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
+ return buildOkResponse(responseFormat, createGrouping.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create grouping");
+ log.debug("createComponentGrouping failed with exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/category/{componentType}/{categoryUniqueId}/subCategory/{subCategoryUniqueId}/grouping/{groupingUniqueId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete component category", method = "DELETE", summary = "Delete component category",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Category.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Category deleted"),
+ @ApiResponse(responseCode = "403", description = "USER_ID header is missing"),
+ @ApiResponse(responseCode = "409", description = "User not permitted to perform the action"),
+ @ApiResponse(responseCode = "404", description = "Category not found"),
+ @ApiResponse(responseCode = "500", description = "General Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteComponentGrouping(
+ @PathParam(value = "categoryUniqueId") final String grandParentCategoryUniqueId,
+ @PathParam(value = "subCategoryUniqueId") final String parentSubCategoryUniqueId,
+ @PathParam(value = "groupingUniqueId") final String groupingUniqueId,
+ @PathParam(value = "componentType") final String componentType, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<GroupingDefinition, ResponseFormat> deleteGrouping = elementBL.deleteGrouping(groupingUniqueId, componentType, userId);
+ if (deleteGrouping.isRight()) {
+ return buildErrorResponse(deleteGrouping.right().value());
+ }
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT);
+ return buildOkResponse(responseFormat, null);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete component grouping");
+ log.debug("deleteGrouping failed with exception", e);
+ throw e;
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all tags
+ @GET
+ @Path("/tags")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve all tags", method = "GET", summary = "Retrieve all tags",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns tags Ok"),
+ @ApiResponse(responseCode = "404", description = "No tags were found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getTags(@Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getTags) Start handle request of {}", url);
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<Tag>, ActionStatus> either = elementBL.getAllTags(userId);
+ if (either.isRight() || either.left().value() == null) {
+ log.debug("No tags were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Tags");
+ log.debug("getAllTags failed with exception", e);
+ throw e;
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all property scopes
+ @GET
+ @Path("/propertyScopes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve all propertyScopes", method = "GET", summary = "Retrieve all propertyScopes",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns propertyScopes Ok"),
+ @ApiResponse(responseCode = "404", description = "No propertyScopes were found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getPropertyScopes(@Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getPropertyScopes) Start handle request of {}", url);
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<PropertyScope>, ActionStatus> either = elementBL.getAllPropertyScopes(userId);
+ if (either.isRight() || either.left().value() == null) {
+ log.debug("No property scopes were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property Scopes Categories");
+ log.debug("getPropertyScopes failed with exception", e);
+ throw e;
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all artifact types
+ @GET
+ @Path("/artifactTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve all artifactTypes", method = "GET", summary = "Retrieve all artifactTypes",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns artifactTypes Ok"),
+ @ApiResponse(responseCode = "404", description = "No artifactTypes were found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getArtifactTypes(@Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(GET - getArtifactTypes) Start handle request of {}", url);
+
+ try {
+ ElementBusinessLogic elementBL = getElementBL(request.getSession().getServletContext());
+ Either<List<ArtifactType>, ActionStatus> either = elementBL.getAllArtifactTypes(userId);
+ if (either.isRight() || either.left().value() == null) {
+ log.debug("No artifact types were found");
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ } else {
+
+ Integer defaultHeatTimeout = ConfigurationManager.getConfigurationManager().getConfiguration().getHeatArtifactDeploymentTimeout().getDefaultMinutes();
+ ArtifactTypesInfo typesResponse = new ArtifactTypesInfo();
+ typesResponse.setArtifactTypes(either.left().value());
+ typesResponse.setHeatDefaultTimeout(defaultHeatTimeout);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), typesResponse);
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Artifact Types");
+ log.debug("getArtifactTypes failed with exception", e);
+ throw e;
+ }
+ }
+
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all followed resources and services
+ @GET
+ @Path("/followed")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve all followed", method = "GET", summary = "Retrieve all followed",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns followed Ok"),
+ @ApiResponse(responseCode = "404", description = "No followed were found"),
+ @ApiResponse(responseCode = "404", description = "User not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getFollowedResourcesServices(@Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ Response res = null;
+ try {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ UserBusinessLogic userAdminManager = getUserAdminManager(request.getSession().getServletContext());
+ User userData = userAdminManager.getUser(userId, false);
+ Either<Map<String, List<? extends Component>>, ResponseFormat> followedResourcesServices = getElementBL(request.getSession().getServletContext()).getFollowed(userData);
+ if (followedResourcesServices.isRight()) {
+ log.debug("failed to get followed resources services ");
+ return buildErrorResponse(followedResourcesServices.right().value());
+ }
+ Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value());
+ res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories");
+ log.debug("Getting followed resources/services failed with exception", e);
+ throw e;
+ }
+ return res;
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all certified resources and services and their last version
+ @GET
+ @Path("/screen")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve catalog resources and services", method = "GET",
+ summary = "Retrieve catalog resources and services", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns resources and services Ok"),
+ @ApiResponse(responseCode = "404", description = "No resources and services were found"),
+ @ApiResponse(responseCode = "404", description = "User not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getCatalogComponents(@Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) throws IOException {
+
+ Response res = null;
+ try {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ Either<Map<String, List<CatalogComponent>>, ResponseFormat> catalogData = getElementBL(request.getSession().getServletContext()).getCatalogComponents(userId, excludeTypes);
+
+ if (catalogData.isRight()) {
+ log.debug("failed to get catalog data");
+ return buildErrorResponse(catalogData.right().value());
+ }
+ Object data = RepresentationUtils.toRepresentation(catalogData.left().value());
+ res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components");
+ log.debug("Getting catalog components failed with exception", e);
+ throw e;
+ }
+ return res;
+ }
+
+ @DELETE
+ @Path("/inactiveComponents/{componentType}")
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteMarkedResources(@PathParam("componentType") final String componentType, @Context final HttpServletRequest request) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType);
+ if (nodeType == null) {
+ log.info("componentType is not valid: {}", componentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+
+ List<NodeTypeEnum> componentsList = new ArrayList<>();
+ componentsList.add(nodeType);
+ try {
+ Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponentsResult = componentsCleanBusinessLogic.cleanComponents(componentsList);
+ Either<List<String>, ResponseFormat> cleanResult = cleanComponentsResult.get(nodeType);
+
+ if (cleanResult.isRight()) {
+ log.debug("failed to delete marked components of type {}", nodeType);
+ response = buildErrorResponse(cleanResult.right().value());
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value());
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components");
+ log.debug("delete marked components failed with exception", e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/ecompPortalMenu")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve ecomp portal menu - MOC", method = "GET", summary = "Retrieve ecomp portal menu", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Retrieve ecomp portal menu") })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getListOfCsars(@Context final HttpServletRequest request) {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ "[{\"menuId\":1,\"column\":2,\"text\":\"Design\",\"parentMenuId\":null,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":11,\"column\":1,\"text\":\"ProductDesign\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":12,\"column\":2,\"text\":\"Service\",\"parentMenuId\":1,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":21,\"column\":1,\"text\":\"ViewPolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":90,\"column\":1,\"text\":\"4thLevelApp1aR16\",\"parentMenuId\":21,\"url\":\"http://google.com\",\"appid\":null,\"roles\":null}]},{\"menuId\":22,\"column\":2,\"text\":\"UpdatePolicies\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null,\"children\":[{\"menuId\":91,\"column\":1,\"text\":\"4thLevelApp1bR16\",\"parentMenuId\":22,\"url\":\"http://jsonlint.com/\",\"appid\":null,\"roles\":null}]},{\"menuId\":23,\"column\":3,\"text\":\"UpdateRules\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":24,\"column\":4,\"text\":\"CreateSignatures?\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null},{\"menuId\":25,\"column\":5,\"text\":\"Definedata\",\"parentMenuId\":12,\"url\":\"\",\"appid\":null,\"roles\":null}]}]}]");
+ }
+
+ @GET
+ @Path("/catalogUpdateTime")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve previus and current catalog update time", method = "GET", summary = "Retrieve previus and current catalog update time", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Retrieve previus and current catalog update time")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getCatalogUpdateTime(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(post) Start handle request of {}", url);
+ CatalogUpdateTimestamp catalogUpdateTimestamp = getElementBL(request.getSession().getServletContext()).getCatalogUpdateTime(userId);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ catalogUpdateTimestamp);
+ }
+
+
+ // retrieve all artifact types, ui configuration and sdc version
+ @GET
+ @Path("/setup/ui")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve all artifactTypes, ui configuration and sdc version", method = "GET", summary = "Retrieve all artifactTypes, ui configuration and sdc version", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns artifactTypes, ui configuration and sdc version Ok"),
+ @ApiResponse(responseCode = "404", description = "No artifactTypes were found/no ui configuration were found/no sdc version were found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getConfCategoriesAndVersion(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getConsolidated) Start handle request of {}", url);
+
+ Map<String, Object> consolidatedObject = new HashMap<>();
+
+ try {
+ ServletContext servletContext = request.getSession().getServletContext();
+ Map<String, Object> configuration = getConfigurationUi(elementBusinessLogic, userId);
+ if (!configuration.isEmpty()) {
+ consolidatedObject.put("configuration", configuration);
+ } else {
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT));
+ }
+
+ Either<UiCategories, ResponseFormat> either = elementBusinessLogic.getAllCategories(userId);
+ if (either.isRight()) {
+ log.debug("No categories were found");
+ return buildErrorResponse(either.right().value());
+ }
+ consolidatedObject.put("categories", either.left().value());
+
+ consolidatedObject.put("version", getVersion(servletContext));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getSDCVersion");
+ log.debug("method getConfCategoriesAndVersion failed with unexpected exception", e);
+ throw e;
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), consolidatedObject);
+ }
+
+ private String getVersion(ServletContext servletContext) {
+ String version = (String) servletContext.getAttribute(Constants.ASDC_RELEASE_VERSION_ATTR);
+ log.debug("sdc version from manifest is: {}", version);
+ return version;
+ }
+
+ private Map<String, Object> getConfigurationUi(ElementBusinessLogic elementBL, String userId) {
+ Either<Configuration.HeatDeploymentArtifactTimeout, ActionStatus> defaultHeatTimeout = elementBL.getDefaultHeatTimeout();
+ Either<Map<String, Object>, ActionStatus> deploymentEither = elementBL.getAllDeploymentArtifactTypes();
+ Either<Map<String, String>, ActionStatus> resourceTypesMap = elementBL.getResourceTypesMap();
+ Either<List<ArtifactType>, ActionStatus> otherEither = elementBL.getAllArtifactTypes(userId);
+
+ Map<String, Object> configuration = new HashMap<>();
+
+ if (otherEither.isRight() || otherEither.left().value() == null) {
+ log.debug("No other artifact types were found");
+ return configuration;
+ }
+ if (deploymentEither.isRight() || deploymentEither.left().value() == null) {
+ log.debug("No deployment artifact types were found");
+ return configuration;
+ }
+ if (defaultHeatTimeout.isRight() || defaultHeatTimeout.left().value() == null) {
+ log.debug("heat default timeout was not found");
+ return configuration;
+ }
+ if (resourceTypesMap.isRight() || resourceTypesMap.left().value() == null) {
+ log.debug("No resource types were found");
+ return configuration;
+ }
+ Map<String, Object> artifacts = new HashMap<>();
+ artifacts.put("other", otherEither.left().value());
+ artifacts.put("deployment", deploymentEither.left().value());
+ configuration.put("artifacts", artifacts);
+ configuration.put("heatDeploymentTimeout", defaultHeatTimeout.left().value());
+ configuration.put("componentTypes", elementBL.getAllComponentTypesParamNames());
+ configuration.put("roles", elementBL.getAllSupportedRoles());
+ configuration.put("resourceTypes", resourceTypesMap.left().value());
+ configuration.put("environmentContext", ConfigurationManager.getConfigurationManager().getConfiguration().getEnvironmentContext());
+ configuration.put("gab", ConfigurationManager.getConfigurationManager().getConfiguration().getGabConfig());
+
+ return configuration;
+ }
+
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ExceptionHandlerEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ExceptionHandlerEndpoint.java
new file mode 100644
index 0000000000..0a87cddd97
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ExceptionHandlerEndpoint.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.jcabi.aspects.Loggable;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "ExceptionHandling Endpoint")
+@Produces(MediaType.APPLICATION_JSON)
+@Controller
+public class ExceptionHandlerEndpoint {
+ private static final Logger log = Logger.getLogger(ExceptionHandlerEndpoint.class);
+ private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ private final ComponentsUtils componentsUtils;
+
+ ExceptionHandlerEndpoint(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @GET
+ @Path("/handleException")
+ @ApiOperation(value = "Handle exception", httpMethod = "GET", response = Response.class)
+ @ApiResponses(value = {@ApiResponse(code = 500, message = "Internal Error")})
+ public Response sendError() {
+ log.debug("Request is received");
+
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Response.status(responseFormat.getStatus())
+ .entity(gson.toJson(responseFormat.getRequestError()))
+ .build();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java
index 580362c00d..045b5065eb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GenericArtifactBrowserServlet.java
@@ -1,112 +1,110 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.io.IOException;
-import java.util.Set;
-import java.util.stream.Collectors;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.onap.sdc.gab.model.GABQuery;
-import org.onap.sdc.gab.model.GABQuery.GABQueryType;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.info.GenericArtifactQueryInfo;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.owasp.esapi.ESAPI;
-import org.springframework.stereotype.Controller;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog/gab")
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-@OpenAPIDefinition(info = @Info(title = "Generic Artifact Browser"))
-@Controller
-public class GenericArtifactBrowserServlet extends BeGenericServlet {
-
- private static final Logger LOGGER = Logger.getLogger(GenericArtifactBrowserServlet.class);
- private final GenericArtifactBrowserBusinessLogic gabLogic;
- private final ArtifactsBusinessLogic artifactsBusinessLogic;
-
- @Inject
- public GenericArtifactBrowserServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- ArtifactsBusinessLogic artifactsBusinessLogic,
- GenericArtifactBrowserBusinessLogic gabLogic) {
- super(userBusinessLogic, componentsUtils);
- this.artifactsBusinessLogic = artifactsBusinessLogic;
- this.gabLogic = gabLogic;
- }
-
- @POST
- @Path("/searchFor")
- @Operation(description = "Search json paths inside the yaml", method = "POST", summary = "Returns found entries of json paths",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Returned yaml entries"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response searchFor(
- @Parameter(description = "Generic Artifact search model", required = true) GenericArtifactQueryInfo query,
- @Context final HttpServletRequest request) {
- try {
- Either<ImmutablePair<String, byte[]>, ResponseFormat> immutablePairResponseFormatEither = artifactsBusinessLogic
- .downloadArtifact(ESAPI.encoder().canonicalize(query.getParentId()), ESAPI.encoder().canonicalize(query.getArtifactUniqueId()));
- if (immutablePairResponseFormatEither.isLeft()){
- GABQuery gabQuery = prepareGabQuery(query, immutablePairResponseFormatEither);
- return buildOkResponse(gabLogic.searchFor(gabQuery));
- }else{
- throw new IOException(immutablePairResponseFormatEither.right().value().getFormattedMessage());
- }
- } catch (IOException e) {
- LOGGER.error("Cannot search for a given queries in the yaml file", e);
- return buildGeneralErrorResponse();
- }
- }
-
- private GABQuery prepareGabQuery(GenericArtifactQueryInfo query,
- Either<ImmutablePair<String, byte[]>, ResponseFormat> immutablePairResponseFormatEither) {
- byte[] content = immutablePairResponseFormatEither.left().value().getRight();
- Set<String> queryFields = query.getFields().stream().map(ESAPI.encoder()::canonicalize).collect(Collectors.toSet());
- return new GABQuery(queryFields, new String(content), GABQueryType.CONTENT);
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.onap.sdc.gab.model.GABQuery;
+import org.onap.sdc.gab.model.GABQuery.GABQueryType;
+import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GenericArtifactBrowserBusinessLogic;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.info.GenericArtifactQueryInfo;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.owasp.esapi.ESAPI;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog/gab")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@OpenAPIDefinition(info = @Info(title = "Generic Artifact Browser"))
+@Controller
+public class GenericArtifactBrowserServlet extends BeGenericServlet {
+
+ private static final Logger LOGGER = Logger.getLogger(GenericArtifactBrowserServlet.class);
+ private final GenericArtifactBrowserBusinessLogic gabLogic;
+ private final ArtifactsBusinessLogic artifactsBusinessLogic;
+
+ @Inject
+ public GenericArtifactBrowserServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ ArtifactsBusinessLogic artifactsBusinessLogic,
+ GenericArtifactBrowserBusinessLogic gabLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.artifactsBusinessLogic = artifactsBusinessLogic;
+ this.gabLogic = gabLogic;
+ }
+
+ @POST
+ @Path("/searchFor")
+ @Operation(description = "Search json paths inside the yaml", method = "POST", summary = "Returns found entries of json paths",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Returned yaml entries"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ public Response searchFor(
+ @Parameter(description = "Generic Artifact search model", required = true) GenericArtifactQueryInfo query,
+ @Context final HttpServletRequest request) {
+ try {
+ ServletContext context = request.getSession().getServletContext();
+ ImmutablePair<String, byte[]> immutablePairResponseFormatEither = getArtifactBL(context)
+ .downloadArtifact(ESAPI.encoder().canonicalize(query.getParentId()), ESAPI.encoder().canonicalize(query.getArtifactUniqueId()));
+ GABQuery gabQuery = prepareGabQuery(query, immutablePairResponseFormatEither);
+ return buildOkResponse(getGenericArtifactBrowserBL(context).searchFor(gabQuery));
+ } catch (IOException e) {
+ LOGGER.error("Cannot search for a given queries in the yaml file", e);
+ return buildGeneralErrorResponse();
+ }
+ }
+
+ private GABQuery prepareGabQuery(GenericArtifactQueryInfo query,
+ ImmutablePair<String, byte[]> immutablePairResponseFormatEither) {
+ byte[] content = immutablePairResponseFormatEither.getRight();
+ Set<String> queryFields = query.getFields().stream().map(ESAPI.encoder()::canonicalize).collect(Collectors.toSet());
+ return new GABQuery(queryFields, new String(content), GABQueryType.CONTENT);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java
index 387faae3ab..dd56b47286 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupEndpoint.java
@@ -1,120 +1,136 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.List;
-import javax.inject.Inject;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogicNew;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.GroupProperty;
-import org.openecomp.sdc.common.api.Constants;
-import org.springframework.stereotype.Controller;
-import com.jcabi.aspects.Loggable;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * Here new APIs for group will be written in an attempt to gradually clean BL code
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Group Servlet"))
-@Controller
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class GroupEndpoint {
-
- private final GroupBusinessLogicNew groupBusinessLogic;
-
- @Inject
- public GroupEndpoint(GroupBusinessLogicNew groupBusinessLogic) {
- this.groupBusinessLogic = groupBusinessLogic;
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/members")
- @Operation(description = "Update group members ", method = "POST",
- summary = "Updates list of members and returns it", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group members updated"), @ApiResponse(
- responseCode = "400",
- description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found"),
- @ApiResponse(responseCode = "500", description = "Internal Error")})
- public List<String> updateGroupMembers(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
- @Parameter(description = "List of members unique ids", required = true) List<String> members,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- return groupBusinessLogic.updateMembers(componentId, componentTypeEnum, userId, groupUniqueId, members);
- }
-
- @GET
- @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
- @Operation(description = "Get List of properties on a group", method = "GET",
- summary = "Returns list of properties", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public List<PropertyDataDefinition> getGroupProperties(
- @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return groupBusinessLogic.getProperties(containerComponentType, userId, componentId, groupUniqueId);
- }
-
- @PUT
- @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
- @Operation(description = "Updates List of properties on a group (only values)", method = "PUT",
- summary = "Returns updated list of properties", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public List<GroupProperty> updateGroupProperties(
- @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
- @Parameter(description = "Group Properties to be Updated", required = true) List<GroupProperty> properties,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- return groupBusinessLogic.updateProperties(componentId, componentTypeEnum, userId, groupUniqueId, properties);
- }
-
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogicNew;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.GroupProperty;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import java.util.List;
+
+/**
+ * Here new APIs for group will be written in an attempt to gradually clean BL code
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Group Servlet"))
+@Controller
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class GroupEndpoint extends BeGenericServlet{
+
+ private final GroupBusinessLogicNew groupBusinessLogic;
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(GroupEndpoint.class.getName());
+
+ @Inject
+ public GroupEndpoint(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils, GroupBusinessLogicNew groupBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.groupBusinessLogic = groupBusinessLogic;
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/members")
+ @Operation(description = "Update group members ", method = "POST",
+ summary = "Updates list of members and returns it", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group members updated"), @ApiResponse(
+ responseCode = "400",
+ description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public List<String> updateGroupMembers(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
+ @Parameter(description = "List of members unique ids", required = true) List<String> members,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_GROUP_MEMBERS, StatusCode.STARTED," Starting to update Group Members for component {} " , componentId );
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_GROUP_MEMBERS, StatusCode.COMPLETE," Ended update Group Members for component {} " , componentId );
+ return groupBusinessLogic.updateMembers(componentId, componentTypeEnum, userId, groupUniqueId, members);
+ }
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
+ @Operation(description = "Get List of properties on a group", method = "GET",
+ summary = "Returns list of properties", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public List<PropertyDataDefinition> getGroupProperties(
+ @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return groupBusinessLogic.getProperties(containerComponentType, userId, componentId, groupUniqueId);
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/properties")
+ @Operation(description = "Updates List of properties on a group (only values)", method = "PUT",
+ summary = "Returns updated list of properties", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupProperty.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public List<GroupProperty> updateGroupProperties(
+ @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
+ @Parameter(description = "Group Properties to be Updated", required = true) List<GroupProperty> properties,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ return groupBusinessLogic.updateProperties(componentId, componentTypeEnum, userId, groupUniqueId, properties);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java
index bbc41f2ffb..3eaf9376c8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java
@@ -1,247 +1,256 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.info.GroupDefinitionInfo;
-import org.openecomp.sdc.be.model.GroupDefinition;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-/**
- * Root resource (exposed at "/" path)
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Group Servlet"))
-@Singleton
-public class GroupServlet extends AbstractValidationsServlet {
-
- private static final Logger log = Logger.getLogger(GroupServlet.class);
- public static final String START_HANDLE_REQUEST = "Start handle request of {}";
- private final GroupBusinessLogic groupBL;
-
- @Inject
- public GroupServlet(UserBusinessLogic userBusinessLogic, GroupBusinessLogic groupBL,
- ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils,
- ServletUtils servletUtils, ResourceImportManager resourceImportManager) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.groupBL = groupBL;
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/groups/{groupType}")
- @Operation(description = "Create group ", method = "POST",
- summary = "Creates new group in component and returns it", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Group created"), @ApiResponse(
- responseCode = "400",
- description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found"),
- @ApiResponse(responseCode = "500", description = "Internal Error")})
- public Response createGroup(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("groupType") final String type,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(post) Start handle request of {}", url);
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- GroupDefinition groupDefinition = groupBL.createGroup(componentId, componentTypeEnum, type, userId);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), groupDefinition);
- }
-
- @GET
- @Path("/{containerComponentType}/{componentId}/groups/{groupId}")
- @Operation(description = "Get group artifacts ", method = "GET",
- summary = "Returns artifacts metadata according to groupId", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "group found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Group not found")})
- public Response getGroupById(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("groupId") final String groupId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
-
- try {
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- Either<GroupDefinitionInfo, ResponseFormat> actionResponse =
- groupBL.getGroupWithArtifactsById(componentTypeEnum, componentId, groupId, userId, false);
-
- if (actionResponse.isRight()) {
- log.debug("failed to get all non abstract {}", containerComponentType);
- return buildErrorResponse(actionResponse.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- actionResponse.left().value());
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
- log.debug("getGroupArtifactById unexpected exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- @DELETE
- @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}")
- @Operation(description = "Delete Group", method = "DELETE", summary = "Returns deleted group id",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "ResourceInstance deleted"), @ApiResponse(
- responseCode = "400",
- description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found"),
- @ApiResponse(responseCode = "500", description = "Internal Error")})
- public Response deleteGroup(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST, url);
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- GroupDefinition groupDefinition = groupBL.deleteGroup(componentId, componentTypeEnum, groupId, userId);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT),
- groupDefinition.getUniqueId());
- }
-
- @PUT
- @Path("/{containerComponentType}/{componentId}/groups/{groupId}")
- @Operation(description = "Update Group metadata", method = "PUT", summary = "Returns updated Group",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "component / group Not found")})
- public Response updateGroup(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("groupId") final String groupId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "GroupDefinition", required = true) GroupDefinition groupData,
- @Context final HttpServletRequest request) {
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- GroupDefinition updatedGroup = groupBL.updateGroup(componentId, componentTypeEnum, groupId, userId, groupData);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updatedGroup);
- }
-
- @PUT
- @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/metadata")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Group Metadata", method = "PUT", summary = "Returns updated group definition",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateGroupMetadata(@PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
- @Parameter(description = "Service object to be Updated", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST, url);
-
- User user = new User();
- user.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
-
- try {
- Either<GroupDefinition, ResponseFormat> convertResponse = parseToObject(data, () -> GroupDefinition.class);
- if (convertResponse.isRight()) {
- log.debug("failed to parse group");
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
- GroupDefinition updatedGroup = convertResponse.left().value();
-
- // Update GroupDefinition
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
- Either<GroupDefinition, ResponseFormat> actionResponse = groupBL.validateAndUpdateGroupMetadata(componentId,
- user, componentTypeEnum, updatedGroup, true, true);
-
- if (actionResponse.isRight()) {
- log.debug("failed to update GroupDefinition");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- GroupDefinition group = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(group);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Group Metadata");
- log.debug("update group metadata failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.info.GroupDefinitionInfo;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+/**
+ * Root resource (exposed at "/" path)
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Group Servlet"))
+@Controller
+public class GroupServlet extends AbstractValidationsServlet {
+
+ private static final Logger log = Logger.getLogger(GroupServlet.class);
+ public static final String START_HANDLE_REQUEST = "Start handle request of {}";
+ private final GroupBusinessLogic groupBL;
+
+ @Inject
+ public GroupServlet(UserBusinessLogic userBusinessLogic, GroupBusinessLogic groupBL,
+ ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils,
+ ServletUtils servletUtils, ResourceImportManager resourceImportManager) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.groupBL = groupBL;
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/groups/{groupType}")
+ @Operation(description = "Create group ", method = "POST",
+ summary = "Creates new group in component and returns it", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Group created"), @ApiResponse(
+ responseCode = "400",
+ description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createGroup(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("groupType") final String type,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(post) Start handle request of {}", url);
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ GroupDefinition groupDefinition = groupBL
+ .createGroup(componentId, componentTypeEnum, type, userId);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED),
+ groupDefinition);
+ }
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/groups/{groupId}")
+ @Operation(description = "Get group artifacts ", method = "GET",
+ summary = "Returns artifacts metadata according to groupId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "group found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Group not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getGroupById(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("groupId") final String groupId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+
+ try {
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ Either<GroupDefinitionInfo, ResponseFormat> actionResponse =
+ groupBL.getGroupWithArtifactsById(componentTypeEnum, componentId, groupId, userId, false);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get all non abstract {}", containerComponentType);
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ actionResponse.left().value());
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("getGroupArtifactById");
+ log.debug("getGroupArtifactById unexpected exception", e);
+ throw e;
+ }
+
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}")
+ @Operation(description = "Delete Group", method = "DELETE", summary = "Returns deleted group id",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "ResourceInstance deleted"), @ApiResponse(
+ responseCode = "400",
+ description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteGroup(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST, url);
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ GroupDefinition groupDefinition = groupBL
+ .deleteGroup(componentId, componentTypeEnum, groupId, userId);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), groupDefinition.getUniqueId());
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/groups/{groupId}")
+ @Operation(description = "Update Group metadata", method = "PUT", summary = "Returns updated Group",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "component / group Not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateGroup(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("groupId") final String groupId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "GroupDefinition", required = true) GroupDefinition groupData,
+ @Context final HttpServletRequest request) {
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ GroupDefinition updatedGroup = groupBL.updateGroup(componentId, componentTypeEnum, groupId, userId, groupData);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updatedGroup);
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/groups/{groupUniqueId}/metadata")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Group Metadata", method = "PUT", summary = "Returns updated group definition",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = GroupDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateGroupMetadata(@PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId, @PathParam("groupUniqueId") final String groupUniqueId,
+ @Parameter(description = "Service object to be Updated", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST, url);
+
+ User user = new User();
+ user.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Response response = null;
+
+ try {
+ Either<GroupDefinition, ResponseFormat> convertResponse = parseToObject(data, () -> GroupDefinition.class);
+ if (convertResponse.isRight()) {
+ log.debug("failed to parse group");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ GroupDefinition updatedGroup = convertResponse.left().value();
+
+ // Update GroupDefinition
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(containerComponentType);
+ Either<GroupDefinition, ResponseFormat> actionResponse = groupBL
+ .validateAndUpdateGroupMetadata(componentId, user, componentTypeEnum, updatedGroup, true ,true);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to update GroupDefinition");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ GroupDefinition group = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(group);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Group Metadata");
+ log.debug("update group metadata failed with exception", e);
+ throw e;
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java
index 79a8208978..7373c58cd7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupTypesEndpoint.java
@@ -1,79 +1,87 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.List;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
-import org.openecomp.sdc.be.mixin.GroupTypeMixin;
-import org.openecomp.sdc.be.model.GroupTypeDefinition;
-import org.openecomp.sdc.be.view.ResponseView;
-import org.openecomp.sdc.common.api.Constants;
-import org.springframework.stereotype.Controller;
-import com.jcabi.aspects.Loggable;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "group types resource"))
-@Controller
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class GroupTypesEndpoint {
-
- private final GroupTypeBusinessLogic groupTypeBusinessLogic;
-
- public GroupTypesEndpoint(GroupTypeBusinessLogic groupTypeBusinessLogic) {
- this.groupTypeBusinessLogic = groupTypeBusinessLogic;
- }
-
- @GET
- @Path("/groupTypes")
- @Operation(description = "Get group types ", method = "GET", summary = "Returns group types",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = GroupTypeDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "group types found"), @ApiResponse(
- responseCode = "400",
- description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "Internal Error")})
- @ResponseView(mixin = {GroupTypeMixin.class})
- public List<GroupTypeDefinition> getGroupTypes(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(
- description = "An optional parameter to indicate the type of the container from where this call is executed") @QueryParam("internalComponentType") String internalComponentType) {
- return groupTypeBusinessLogic.getAllGroupTypes(userId, internalComponentType);
- }
-
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.mixin.GroupTypeMixin;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.be.view.ResponseView;
+import org.openecomp.sdc.common.api.Constants;
+import org.springframework.stereotype.Controller;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import java.util.List;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "group types resource"))
+@Controller
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class GroupTypesEndpoint extends BeGenericServlet{
+
+ private final GroupTypeBusinessLogic groupTypeBusinessLogic;
+
+ public GroupTypesEndpoint(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils, GroupTypeBusinessLogic groupTypeBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.groupTypeBusinessLogic = groupTypeBusinessLogic;
+ }
+
+ @GET
+ @Path("/groupTypes")
+ @Operation(description = "Get group types ", method = "GET", summary = "Returns group types",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = GroupTypeDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "group types found"), @ApiResponse(
+ responseCode = "400",
+ description = "field name invalid type/length, characters; mandatory field is absent, already exists (name)"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "500", description = "Internal Error")})
+ @ResponseView(mixin = {GroupTypeMixin.class})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public List<GroupTypeDefinition> getGroupTypes(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(
+ description = "An optional parameter to indicate the type of the container from where this call is executed") @QueryParam("internalComponentType") String internalComponentType) {
+ return groupTypeBusinessLogic.getAllGroupTypes(userId, internalComponentType);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java
index df061ad3b1..bc5cd8e6f0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java
@@ -1,580 +1,574 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.util.Arrays;
-import java.util.List;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-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;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;
-import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.ComponentInstInputsMap;
-import org.openecomp.sdc.be.model.ComponentInstListInput;
-import org.openecomp.sdc.be.model.ComponentInstanceInput;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@OpenAPIDefinition(info = @Info(title = "Input Catalog", description = "Input Servlet"))
-@Path("/v1/catalog")
-@Singleton
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class InputsServlet extends AbstractValidationsServlet {
-
- private static final Logger log = Logger.getLogger(InputsServlet.class);
-
- private final DataTypeBusinessLogic businessLogic;
- private final InputsBusinessLogic inputsBusinessLogic;
-
- @Inject
- public InputsServlet(UserBusinessLogic userBusinessLogic,
- InputsBusinessLogic inputsBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- DataTypeBusinessLogic dataTypeBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.inputsBusinessLogic = inputsBusinessLogic;
- this.businessLogic = dataTypeBusinessLogic;
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/update/inputs")
- @Operation(description = "Update resource inputs", method = "POST", summary = "Returns updated input",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Input updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateComponentInputs(@Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("componentId") final String componentId,
- @Parameter(description = "json describe the input", required = true) String data,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- String userId = request.getHeader(Constants.USER_ID_HEADER);
-
- try {
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Either<InputDefinition[], ResponseFormat> inputsEither = getComponentsUtils()
- .convertJsonToObjectUsingObjectMapper(data, modifier, InputDefinition[].class,
- AuditingActionEnum.UPDATE_RESOURCE_METADATA, ComponentTypeEnum.SERVICE);
- if(inputsEither.isRight()){
- log.debug("Failed to convert data to input definition. Status is {}", inputsEither.right().value());
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- List<InputDefinition> inputsToUpdate = Arrays.asList(inputsEither.left().value());
-
- log.debug("Start handle request of updateComponentInputs. Received inputs are {}", inputsToUpdate);
-
- ServletContext context = request.getSession().getServletContext();
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(containerComponentType);
-
- if (businessLogic == null) {
- log.debug("Unsupported component type {}", containerComponentType);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR));
- }
-
- Either<List<InputDefinition>, ResponseFormat> actionResponse = inputsBusinessLogic.updateInputsValue(componentType, componentId, inputsToUpdate, userId, true, false);
-
- if (actionResponse.isRight()) {
- return buildErrorResponse(actionResponse.right().value());
- }
-
- List<InputDefinition> componentInputs = actionResponse.left().value();
- ObjectMapper mapper = new ObjectMapper();
- String result = mapper.writeValueAsString(componentInputs);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- }
- catch (Exception e) {
- log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
-
- @GET
- @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{originComponentUid}/inputs")
- @Operation(description = "Get Inputs only", method = "GET", summary = "Returns Inputs list",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getComponentInstanceInputs(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
- @PathParam("originComponentUid") final String originComponentUid, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
- Response response;
-
- try {
- Either<List<ComponentInstanceInput>, ResponseFormat> inputsResponse = inputsBusinessLogic.getComponentInstanceInputs(userId, componentId, instanceId);
- if (inputsResponse.isRight()) {
- log.debug("failed to get component instance inputs {}", componentType);
- return buildErrorResponse(inputsResponse.right().value());
- }
- Object inputs = RepresentationUtils.toRepresentation(inputsResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputs);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Inputs " + componentType);
- log.debug("getInputs failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @GET
- @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{inputId}/properties")
- @Operation(description = "Get properties", method = "GET", summary = "Returns properties list",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getInputPropertiesForComponentInstance(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
- @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(GET) Start handle request of {}", url);
- Response response = null;
-
- try {
- Either<List<ComponentInstanceProperty>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
- .getComponentInstancePropertiesByInputId(userId, componentId, instanceId, inputId);
- if (inputPropertiesRes.isRight()) {
- log.debug("failed to get properties of input: {}, with instance id: {}", inputId, instanceId);
- return buildErrorResponse(inputPropertiesRes.right().value());
- }
- Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(
- "Get Properites by input id: " + inputId + " for instance with id: " + instanceId);
- log.debug("getInputPropertiesForComponentInstance failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @GET
- @Path("/{componentType}/{componentId}/inputs/{inputId}/inputs")
- @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getInputsForComponentInput(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
- Response response;
- try {
- Either<List<ComponentInstanceInput>, ResponseFormat> inputsRes =
- inputsBusinessLogic.getInputsForComponentInput(userId, componentId, inputId);
-
- if (inputsRes.isRight()) {
- log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
- return buildErrorResponse(inputsRes.right().value());
- }
- Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(
- "Get inputs by input id: " + inputId + " for component with id: " + componentId);
- log.debug("getInputsForComponentInput failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @GET
- @Path("/{componentType}/{componentId}/inputs/{inputId}")
- @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getInputsAndPropertiesForComponentInput(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
- Response response;
-
- try {
- Either<InputDefinition, ResponseFormat> inputsRes =
- inputsBusinessLogic.getInputsAndPropertiesForComponentInput(userId, componentId, inputId, false);
-
- if (inputsRes.isRight()) {
- log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
- return buildErrorResponse(inputsRes.right().value());
- }
- Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(
- "Get inputs by input id: " + inputId + " for component with id: " + componentId);
- log.debug("getInputsForComponentInput failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- private Either<ComponentInstInputsMap, ResponseFormat> parseToComponentInstanceMap(String serviceJson, User user) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, ComponentInstInputsMap.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
- }
-
- private Either<ComponentInstListInput, ResponseFormat> parseToComponentInstListInput(String json, User user) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(json, user, ComponentInstListInput.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
- }
-
- @POST
- @Path("/{componentType}/{componentId}/create/inputs")
- @Operation(description = "Create inputs on service", method = "POST", summary = "Return inputs list",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response createMultipleInputs(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "ComponentIns Inputs Object to be created",
- required = true) String componentInstInputsMapObj) {
-
- return super.declareProperties(userId, componentId, componentType, componentInstInputsMapObj,
- DeclarationTypeEnum.INPUT, request);
- }
-
-
- /**
- * Creates a "list input" and updates given list of properties to get value from the input.
- * also a data type which has same properties is created.
- * the data type will be the entry_schema of the list input.
- * @param componentType the container type (service, resource, ...)
- * @param componentId the container ID
- * @param request HttpServletRequest object
- * @param userId the User ID
- * @param componentInstInputsMapObj the list of properties to be declared and the "list input" to be created.
- * the type of the input must be "list".
- * schema.type of the input will be the name of new data type.
- * @return the created input
- */
- @POST
- @Path("/{componentType}/{componentId}/create/listInput")
- @Operation(description = "Create a list input on service", method = "POST", summary = "Return input",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response createListInput(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "ComponentIns Inputs Object to be created",
- required = true) String componentInstInputsMapObj) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("#createListInput: Start handle request of {}", url);
- Response response = null;
-
- try {
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Either<ComponentInstListInput, ResponseFormat> componentInstInputsMapRes =
- parseToComponentInstListInput(componentInstInputsMapObj, modifier);
- if (componentInstInputsMapRes.isRight()) {
- log.debug("failed to parse componentInstInputsMap");
- response = buildErrorResponse(componentInstInputsMapRes.right().value());
- return response;
- }
-
- ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
- ComponentInstListInput componentInstInputsMap = componentInstInputsMapRes.left().value();
- if (log.isDebugEnabled()) {
- // for inspection on debug
- log.debug("parsed componentInstInputsMap={}",
- ReflectionToStringBuilder.toString(componentInstInputsMap));
- }
-
- Either<List<InputDefinition>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
- .createListInput(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
- if (inputPropertiesRes.isRight()) {
- log.debug("failed to create list input for service: {}", componentId);
- return buildErrorResponse(inputPropertiesRes.right().value());
- }
- Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance()
- .logBeRestApiGeneralError("Create list input for service with id: " + componentId);
- log.debug("createListInput failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
-
- @DELETE
- @Path("/{componentType}/{componentId}/delete/{inputId}/input")
- @Operation(description = "Delete input from service", method = "DELETE", summary = "Delete service input",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Input deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Input not found")})
- public Response deleteInput(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "Service Input to be deleted", required = true) String componentInstInputsMapObj) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
- Response response = null;
-
- try {
- Either<InputDefinition, ResponseFormat> deleteInput =
- inputsBusinessLogic.deleteInput(componentId, userId, inputId);
- if (deleteInput.isRight()) {
- ResponseFormat deleteResponseFormat = deleteInput.right().value();
- response = buildErrorResponse(deleteResponseFormat);
- return response;
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteInput.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance()
- .logBeRestApiGeneralError("Delete input for service + " + componentId + " + with id: " + inputId);
- log.debug("Delete input failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- /**
- * Gets a specific data type associated with a component.
- * @param componentType the container type (service, resource, ...)
- * @param componentId the container ID
- * @param dataTypeName the data type name
- * @param request HttpServletRequest object
- * @return the data type info
- */
- @GET
- @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
- @Operation(description = "Get data type in service", method = "GET", summary = "Get data type in service",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = DataTypeDefinition.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Data type found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Data type not found")})
- public Response getDataType(
- @PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId,
- @PathParam("dataTypeName") final String dataTypeName,
- @Context final HttpServletRequest request
- ) {
- ComponentsUtils componentsUtils = getComponentsUtils();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(getDataType) Start handle request of {}", url);
- Response response;
-
- try {
- Either<DataTypeDefinition, StorageOperationStatus> getResult = businessLogic.getPrivateDataType(componentId, dataTypeName);
- if (getResult.isRight()) {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
- return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
- }
- Object json = RepresentationUtils.toRepresentation(getResult.left().value());
- return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId + " + with name: " + dataTypeName);
- log.debug("Get data type failed with exception", e);
- response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- /**
- * Gets a list of data types which a component has.
- * @param componentType the container type (service, resource, ...)
- * @param componentId the container ID
- * @param request HttpServletRequest object
- * @return the list of data types in the component
- */
- @GET
- @Path("/{componentType}/{componentId}/dataTypes")
- @Operation(description = "Get data types that service has", method = "GET", summary = "Get data types in service",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Data type found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response getDataTypes(
- @PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId,
- @Context final HttpServletRequest request
- ) {
- ServletContext context = request.getSession().getServletContext();
- ComponentsUtils componentsUtils = getComponentsUtils();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(getDataType) Start handle request of {}", url);
- Response response;
-
- try {
- Either<List<DataTypeDefinition>, StorageOperationStatus> getResult = businessLogic.getPrivateDataTypes(componentId);
- if (getResult.isRight()) {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
- return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
- }
- Object json = RepresentationUtils.toRepresentation(getResult.left().value());
- return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId);
- log.debug("Get data type failed with exception", e);
- response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- /**
- * Deletes a data type from a component.
- * @param componentType the container type (service, resource, ...)
- * @param componentId the container ID
- * @param dataTypeName the data type name to be deleted
- * @param request HttpServletRequest object
- * @return operation result
- */
- @DELETE
- @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
- @Operation(description = "Delete data type from service", method = "DELETE", summary = "Delete service input",
- responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Data type deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Data type not found")})
- public Response deleteDataType(
- @PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId,
- @PathParam("dataTypeName") final String dataTypeName,
- @Context final HttpServletRequest request
- ) {
- ServletContext context = request.getSession().getServletContext();
- ComponentsUtils componentsUtils = getComponentsUtils();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
- Response response;
-
- try {
- Either<DataTypeDefinition, StorageOperationStatus> deleteResult = businessLogic.deletePrivateDataType(componentId, dataTypeName);
- if (deleteResult.isRight()) {
- ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteResult.right().value());
- return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
- }
- Object json = RepresentationUtils.toRepresentation(deleteResult.left().value());
- return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete data type for service + " + componentId + " + with name: " + dataTypeName);
- log.debug("Delete data type failed with exception", e);
- response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.ComponentInstInputsMap;
+import org.openecomp.sdc.be.model.ComponentInstListInput;
+import org.openecomp.sdc.be.model.ComponentInstanceInput;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@OpenAPIDefinition(info = @Info(title = "Input Catalog", description = "Input Servlet"))
+@Path("/v1/catalog")
+@Controller
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class InputsServlet extends AbstractValidationsServlet {
+
+ private static final Logger log = Logger.getLogger(InputsServlet.class);
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(InputsServlet.class.getName());
+ private static final String START_HANDLE_REQUEST_OF = "(get) Start handle request of {}";
+
+ private final DataTypeBusinessLogic businessLogic;
+ private final InputsBusinessLogic inputsBusinessLogic;
+
+ @Inject
+ public InputsServlet(UserBusinessLogic userBusinessLogic,
+ InputsBusinessLogic inputsBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ DataTypeBusinessLogic dataTypeBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.inputsBusinessLogic = inputsBusinessLogic;
+ this.businessLogic = dataTypeBusinessLogic;
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/update/inputs")
+ @Operation(description = "Update resource inputs", method = "POST", summary = "Returns updated input",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Input updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ public Response updateComponentInputs(@Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("componentId") final String componentId,
+ @Parameter(description = "json describe the input", required = true) String data,
+ @Context final HttpServletRequest request) throws JsonProcessingException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+
+ try {
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Either<InputDefinition[], ResponseFormat> inputsEither = getComponentsUtils()
+ .convertJsonToObjectUsingObjectMapper(data, modifier, InputDefinition[].class,
+ AuditingActionEnum.UPDATE_RESOURCE_METADATA, ComponentTypeEnum.SERVICE);
+ if(inputsEither.isRight()){
+ log.debug("Failed to convert data to input definition. Status is {}", inputsEither.right().value());
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ List<InputDefinition> inputsToUpdate = Arrays.asList(inputsEither.left().value());
+
+ log.debug("Start handle request of updateComponentInputs. Received inputs are {}", inputsToUpdate);
+
+ ServletContext context = request.getSession().getServletContext();
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(containerComponentType);
+
+ if (businessLogic == null) {
+ log.debug("Unsupported component type {}", containerComponentType);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.UNSUPPORTED_ERROR));
+ }
+
+ Either<List<InputDefinition>, ResponseFormat> actionResponse = inputsBusinessLogic.updateInputsValue(componentType, componentId, inputsToUpdate, userId, true, false);
+
+ if (actionResponse.isRight()) {
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ List<InputDefinition> componentInputs = actionResponse.left().value();
+ ObjectMapper mapper = new ObjectMapper();
+ String result = mapper.writeValueAsString(componentInputs);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ }
+ catch (Exception e) {
+ log.error("create and associate RI failed with exception: {}", e.getMessage(), e);
+ throw e;
+ }
+ }
+
+
+ @GET
+ @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{originComponentUid}/inputs")
+ @Operation(description = "Get Inputs only", method = "GET", summary = "Returns Inputs list",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ public Response getComponentInstanceInputs(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
+ @PathParam("originComponentUid") final String originComponentUid, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ Response response;
+
+ try {
+ Either<List<ComponentInstanceInput>, ResponseFormat> inputsResponse = inputsBusinessLogic.getComponentInstanceInputs(userId, componentId, instanceId);
+ if (inputsResponse.isRight()) {
+ log.debug("failed to get component instance inputs {}", componentType);
+ return buildErrorResponse(inputsResponse.right().value());
+ }
+ Object inputs = RepresentationUtils.toRepresentation(inputsResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), inputs);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Inputs " + componentType);
+ log.debug("getInputs failed with exception", e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/componentInstances/{instanceId}/{inputId}/properties")
+ @Operation(description = "Get properties", method = "GET", summary = "Returns properties list",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ public Response getInputPropertiesForComponentInstance(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @PathParam("instanceId") final String instanceId,
+ @PathParam("inputId") final String inputId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ Response response = null;
+
+ try {
+ Either<List<ComponentInstanceProperty>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
+ .getComponentInstancePropertiesByInputId(userId, componentId, instanceId, inputId);
+ if (inputPropertiesRes.isRight()) {
+ log.debug("failed to get properties of input: {}, with instance id: {}", inputId, instanceId);
+ return buildErrorResponse(inputPropertiesRes.right().value());
+ }
+ Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Properites by input id: " + inputId + " for instance with id: " + instanceId);
+ log.debug("getInputPropertiesForComponentInstance failed with exception", e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/inputs/{inputId}/inputs")
+ @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ public Response getInputsForComponentInput(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ Response response;
+ try {
+ Either<List<ComponentInstanceInput>, ResponseFormat> inputsRes =
+ inputsBusinessLogic.getInputsForComponentInput(userId, componentId, inputId);
+
+ if (inputsRes.isRight()) {
+ log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
+ return buildErrorResponse(inputsRes.right().value());
+ }
+ Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
+ log.debug("getInputsForComponentInput failed with exception", e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/{componentType}/{componentId}/inputs/{inputId}")
+ @Operation(description = "Get inputs", method = "GET", summary = "Returns inputs list", responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ public Response getInputsAndPropertiesForComponentInput(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ Response response;
+
+ try {
+ Either<InputDefinition, ResponseFormat> inputsRes =
+ inputsBusinessLogic.getInputsAndPropertiesForComponentInput(userId, componentId, inputId, false);
+
+ if (inputsRes.isRight()) {
+ log.debug("failed to get inputs of input: {}, with instance id: {}", inputId, componentId);
+ return buildErrorResponse(inputsRes.right().value());
+ }
+ Object properties = RepresentationUtils.toRepresentation(inputsRes.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get inputs by input id: " + inputId + " for component with id: " + componentId);
+ log.debug("getInputsForComponentInput failed with exception", e);
+ throw e;
+ }
+ }
+
+ private Either<ComponentInstInputsMap, ResponseFormat> parseToComponentInstanceMap(String serviceJson, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, ComponentInstInputsMap.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ }
+
+ private Either<ComponentInstListInput, ResponseFormat> parseToComponentInstListInput(String json, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(json, user, ComponentInstListInput.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ }
+
+ @POST
+ @Path("/{componentType}/{componentId}/create/inputs")
+ @Operation(description = "Create inputs on service", method = "POST", summary = "Return inputs list",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ public Response createMultipleInputs(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "ComponentIns Inputs Object to be created",
+ required = true) String componentInstInputsMapObj) {
+
+ return super.declareProperties(userId, componentId, componentType, componentInstInputsMapObj,
+ DeclarationTypeEnum.INPUT, request);
+ }
+
+
+ /**
+ * Creates a "list input" and updates given list of properties to get value from the input.
+ * also a data type which has same properties is created.
+ * the data type will be the entry_schema of the list input.
+ * @param componentType the container type (service, resource, ...)
+ * @param componentId the container ID
+ * @param request HttpServletRequest object
+ * @param userId the User ID
+ * @param componentInstInputsMapObj the list of properties to be declared and the "list input" to be created.
+ * the type of the input must be "list".
+ * schema.type of the input will be the name of new data type.
+ * @return the created input
+ */
+ @POST
+ @Path("/{componentType}/{componentId}/create/listInput")
+ @Operation(description = "Create a list input on service", method = "POST", summary = "Return input",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ public Response createListInput(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "ComponentIns Inputs Object to be created",
+ required = true) String componentInstInputsMapObj) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("#createListInput: Start handle request of {}", url);
+ Response response = null;
+
+ try {
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("modifier id is {}", userId);
+
+ Either<ComponentInstListInput, ResponseFormat> componentInstInputsMapRes =
+ parseToComponentInstListInput(componentInstInputsMapObj, modifier);
+ if (componentInstInputsMapRes.isRight()) {
+ log.debug("failed to parse componentInstInputsMap");
+ response = buildErrorResponse(componentInstInputsMapRes.right().value());
+ return response;
+ }
+
+ ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
+ ComponentInstListInput componentInstInputsMap = componentInstInputsMapRes.left().value();
+ if (log.isDebugEnabled()) {
+ // for inspection on debug
+ log.debug("parsed componentInstInputsMap={}",
+ ReflectionToStringBuilder.toString(componentInstInputsMap));
+ }
+
+ Either<List<InputDefinition>, ResponseFormat> inputPropertiesRes = inputsBusinessLogic
+ .createListInput(userId, componentId, componentTypeEnum, componentInstInputsMap, true, false);
+ if (inputPropertiesRes.isRight()) {
+ log.debug("failed to create list input for service: {}", componentId);
+ return buildErrorResponse(inputPropertiesRes.right().value());
+ }
+ Object properties = RepresentationUtils.toRepresentation(inputPropertiesRes.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), properties);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance()
+ .logBeRestApiGeneralError("Create list input for service with id: " + componentId);
+ log.debug("createListInput failed with exception", e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+
+ @DELETE
+ @Path("/{componentType}/{componentId}/delete/{inputId}/input")
+ @Operation(description = "Delete input from service", method = "DELETE", summary = "Delete service input",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Input deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Input not found")})
+ public Response deleteInput(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @PathParam("inputId") final String inputId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "Service Input to be deleted", required = true) String componentInstInputsMapObj) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_INPUTS, StatusCode.STARTED,"Starting to delete Inputs for component {} ",componentId + " by " + userId );
+
+ try {
+ InputDefinition deleteInput = inputsBusinessLogic.deleteInput(componentId, userId, inputId);
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_INPUTS, StatusCode.COMPLETE,"Ended delete Inputs for component {} ",componentId + " by " + userId );
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deleteInput);
+ } catch (ComponentException e){
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete input for service + " + componentId + " + with id: " + inputId);
+ log.debug("Delete input failed with exception", e);
+ throw e;
+ }
+ }
+
+ /**
+ * Gets a specific data type associated with a component.
+ * @param componentType the container type (service, resource, ...)
+ * @param componentId the container ID
+ * @param dataTypeName the data type name
+ * @param request HttpServletRequest object
+ * @return the data type info
+ */
+ @GET
+ @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
+ @Operation(description = "Get data type in service", method = "GET", summary = "Get data type in service",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = DataTypeDefinition.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Data type found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Data type not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getDataType(
+ @PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("dataTypeName") final String dataTypeName,
+ @Context final HttpServletRequest request
+ ) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getDataType) Start handle request of {}", url);
+ Response response;
+
+ try {
+ Either<DataTypeDefinition, StorageOperationStatus> getResult = businessLogic.getPrivateDataType(componentId, dataTypeName);
+ if (getResult.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
+ return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
+ }
+ Object json = RepresentationUtils.toRepresentation(getResult.left().value());
+ return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId + " + with name: " + dataTypeName);
+ log.debug("Get data type failed with exception", e);
+ response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ /**
+ * Gets a list of data types which a component has.
+ * @param componentType the container type (service, resource, ...)
+ * @param componentId the container ID
+ * @param request HttpServletRequest object
+ * @return the list of data types in the component
+ */
+ @GET
+ @Path("/{componentType}/{componentId}/dataTypes")
+ @Operation(description = "Get data types that service has", method = "GET", summary = "Get data types in service",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Resource.class)))) )
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Data type found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getDataTypes(
+ @PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId,
+ @Context final HttpServletRequest request
+ ) {
+ ServletContext context = request.getSession().getServletContext();
+ ComponentsUtils componentsUtils = getComponentsUtils();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(getDataType) Start handle request of {}", url);
+ Response response;
+
+ try {
+ Either<List<DataTypeDefinition>, StorageOperationStatus> getResult = businessLogic.getPrivateDataTypes(componentId);
+ if (getResult.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getResult.right().value());
+ return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
+ }
+ Object json = RepresentationUtils.toRepresentation(getResult.left().value());
+ return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get data type from service + " + componentId);
+ log.debug("Get data type failed with exception", e);
+ response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+
+ /**
+ * Deletes a data type from a component.
+ * @param componentType the container type (service, resource, ...)
+ * @param componentId the container ID
+ * @param dataTypeName the data type name to be deleted
+ * @param request HttpServletRequest object
+ * @return operation result
+ */
+ @DELETE
+ @Path("/{componentType}/{componentId}/dataType/{dataTypeName}")
+ @Operation(description = "Delete data type from service", method = "DELETE", summary = "Delete service input",
+ responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Data type deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Data type not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteDataType(
+ @PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId,
+ @PathParam("dataTypeName") final String dataTypeName,
+ @Context final HttpServletRequest request
+ ) {
+ ServletContext context = request.getSession().getServletContext();
+ ComponentsUtils componentsUtils = getComponentsUtils();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("(get) Start handle request of {}", url);
+ Response response;
+
+ try {
+ Either<DataTypeDefinition, StorageOperationStatus> deleteResult = businessLogic.deletePrivateDataType(componentId, dataTypeName);
+ if (deleteResult.isRight()) {
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(deleteResult.right().value());
+ return buildErrorResponse(componentsUtils.getResponseFormat(actionStatus));
+ }
+ Object json = RepresentationUtils.toRepresentation(deleteResult.left().value());
+ return buildOkResponse(componentsUtils.getResponseFormat(ActionStatus.OK), json);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete data type for service + " + componentId + " + with name: " + dataTypeName);
+ log.debug("Delete data type failed with exception", e);
+ response = buildErrorResponse(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+ }
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java
index f6531f7873..ff31f54b99 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java
@@ -1,348 +1,355 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableMap;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-@OpenAPIDefinition(info = @Info(title = "Interface Operation Servlet", description = "Interface Operation Servlet"))
-@Singleton
-public class InterfaceOperationServlet extends AbstractValidationsServlet {
-
- private static final Logger log = LoggerFactory.getLogger(InterfaceOperationServlet.class);
- private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
-
- @Inject
- public InterfaceOperationServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/interfaceOperations")
- @Operation(description = "Create Interface Operations on Resource", method = "POST",
- summary = "Create Interface Operations on Resource",responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Interface Operations on Resource"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Resource not found"),
- @ApiResponse(responseCode = "409", description = "Interface Operation already exist")})
- public Response createInterfaceOperationsOnResource(
- @Parameter(description = "Interface Operations to create", required = true) String data,
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
- return createOrUpdate(data, ComponentTypeEnum.RESOURCE, resourceId, request, userId, false);
- }
-
- private Response createOrUpdate(String data, ComponentTypeEnum componentType, String componentId,
- HttpServletRequest request, String userId, boolean isUpdate) {
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("Start create or update request of {} with modifier id {}", url, userId);
-
- try {
- String componentIdLower = componentId.toLowerCase();
-
- List<InterfaceDefinition> mappedInterfaceData = getMappedInterfaceData(data, modifier, componentType);
- Either<List<InterfaceDefinition>, ResponseFormat> actionResponse;
- if (isUpdate) {
- actionResponse =
- interfaceOperationBusinessLogic
- .updateInterfaceOperation(componentIdLower, mappedInterfaceData, modifier, true);
- } else {
- actionResponse =
- interfaceOperationBusinessLogic
- .createInterfaceOperation(componentIdLower, mappedInterfaceData, modifier, true);
- }
-
- if (actionResponse.isRight()) {
- log.error("failed to create or update interface operation");
- return buildErrorResponse(actionResponse.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- getFormattedResponse(actionResponse.left().value()));
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Interface Operation Creation or update");
- log.error("create or update interface Operation with an error", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private List<InterfaceDefinition> getMappedInterfaceData(String inputJson, User user,
- ComponentTypeEnum componentTypeEnum) {
- Either<UiComponentDataTransfer, ResponseFormat> uiComponentEither =
- getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user,
- UiComponentDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
- return new ArrayList<>(uiComponentEither.left().value().getInterfaces().values());
- }
-
- private Object getFormattedResponse(List<InterfaceDefinition> interfaceDefinitions) throws IOException {
- Map<String, List<InterfaceDefinition>> allInterfaces =
- ImmutableMap.of(JsonPresentationFields.INTERFACES.getPresentation(), interfaceDefinitions);
- return RepresentationUtils.toFilteredRepresentation(allInterfaces);
- }
-
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/interfaceOperations")
- @Operation(description = "Update Interface Operations on Resource", method = "PUT",
- summary = "Update Interface Operations on Resource",responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Interface Operations on Resource"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Resource not found")})
- public Response updateInterfaceOperationsOnResource(
- @Parameter(description = "Interface Operations to update", required = true) String data,
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
- return createOrUpdate(data, ComponentTypeEnum.RESOURCE, resourceId, request, userId, true);
- }
-
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/interfaces/{interfaceId}/operations/{operationId}")
- @Operation(description = "Delete Interface Operation from Resource", method = "DELETE",
- summary = "Delete Interface Operation from Resource", responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Interface Operation from Resource"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Resource not found")})
- public Response deleteInterfaceOperationsFromResource(
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @Parameter(description = "Interface Id") @PathParam("interfaceId") String interfaceId,
- @Parameter(description = "Operation Id") @PathParam("operationId") String operationId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
- return delete(interfaceId, operationId, resourceId, request, userId);
- }
-
- private Response delete(String interfaceId, String operationId, String componentId, HttpServletRequest request,
- String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("Start delete request of {} with modifier id {}", url, userId);
-
- try {
- String componentIdLower = componentId.toLowerCase();
- Either<List<InterfaceDefinition>, ResponseFormat> actionResponse =
- interfaceOperationBusinessLogic.deleteInterfaceOperation(
- componentIdLower, interfaceId, Collections.singletonList(operationId), modifier, true);
- if (actionResponse.isRight()) {
- log.error("failed to delete interface operation");
- return buildErrorResponse(actionResponse.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- getFormattedResponse(actionResponse.left().value()));
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Operation");
- log.error("Delete interface operation with an error", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/interfaces/{interfaceId}/operations/{operationId}")
- @Operation(description = "Get Interface Operation from Resource", method = "GET",
- summary = "GET Interface Operation from Resource",responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Interface Operation from Resource"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Resource not found")})
- public Response getInterfaceOperationsFromResource(
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @Parameter(description = "Interface Id") @PathParam("interfaceId") String interfaceId,
- @Parameter(description = "Operation Id") @PathParam("operationId") String operationId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
- return get(interfaceId, operationId, resourceId, request, userId);
- }
-
- private Response get(String interfaceId, String operationId, String componentId, HttpServletRequest request,
- String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("Start get request of {} with modifier id {}", url, userId);
-
- try {
- String componentIdLower = componentId.toLowerCase();
- Either<List<InterfaceDefinition>, ResponseFormat> actionResponse =
- interfaceOperationBusinessLogic.getInterfaceOperation(
- componentIdLower, interfaceId, Collections.singletonList(operationId), modifier, true);
- if (actionResponse.isRight()) {
- log.error("failed to get interface operation");
- return buildErrorResponse(actionResponse.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- getFormattedResponse(actionResponse.left().value()));
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component interface operations");
- log.error("get component interface operations failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/interfaceOperations")
- @Operation(description = "Create Interface Operations on Service", method = "POST",
- summary = "Create Interface Operations on Service", responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Interface Operations on Service"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found"),
- @ApiResponse(responseCode = "409", description = "Interface Operation already exist")})
- public Response createInterfaceOperationsOnService(
- @Parameter(description = "Interface Operations to create", required = true) String data,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
- return createOrUpdate(data, ComponentTypeEnum.SERVICE, serviceId, request, userId, false);
- }
-
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/interfaceOperations")
- @Operation(description = "Update Interface Operations on Service", method = "PUT",
- summary = "Update Interface Operations on Service",responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Interface Operations on Service"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found")})
- public Response updateInterfaceOperationsOnService(
- @Parameter(description = "Interface Operations to update", required = true) String data,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
- return createOrUpdate(data, ComponentTypeEnum.SERVICE, serviceId, request, userId, true);
- }
-
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/interfaces/{interfaceId}/operations/{operationId}")
- @Operation(description = "Delete Interface Operation from Service", method = "DELETE",
- summary = "Delete Interface Operation from Service",responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Interface Operation from Service"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found")})
- public Response deleteInterfaceOperationsFromService(
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Interface Id") @PathParam("interfaceId") String interfaceId,
- @Parameter(description = "Operation Id") @PathParam("operationId") String operationId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
- return delete(interfaceId, operationId, serviceId, request, userId);
- }
-
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/interfaces/{interfaceId}/operations/{operationId}")
- @Operation(description = "Get Interface Operation from Service", method = "GET",
- summary = "GET Interface Operation from Service",responses = @ApiResponse(content = @Content(
- array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Get Interface Operation from Service"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found")})
- public Response getInterfaceOperationsFromService(
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Interface Id") @PathParam("interfaceId") String interfaceId,
- @Parameter(description = "Operation Id") @PathParam("operationId") String operationId,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
- return get(interfaceId, operationId, serviceId, request, userId);
- }
-
-}
-
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.google.common.collect.ImmutableMap;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@OpenAPIDefinition(info = @Info(title = "Interface Operation Servlet", description = "Interface Operation Servlet"))
+@Controller
+public class InterfaceOperationServlet extends AbstractValidationsServlet {
+
+ private static final Logger log = LoggerFactory.getLogger(InterfaceOperationServlet.class);
+ private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+
+ @Inject
+ public InterfaceOperationServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ InterfaceOperationBusinessLogic interfaceOperationBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/interfaceOperations")
+ @Operation(description = "Create Interface Operations on Resource", method = "POST",
+ summary = "Create Interface Operations on Resource",responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Interface Operations on Resource"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Resource not found"),
+ @ApiResponse(responseCode = "409", description = "Interface Operation already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createInterfaceOperationsOnResource(
+ @Parameter(description = "Interface Operations to create", required = true) String data,
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+ return createOrUpdate(data, ComponentTypeEnum.RESOURCE, resourceId, request, userId, false);
+ }
+
+ private Response createOrUpdate(String data, ComponentTypeEnum componentType, String componentId,
+ HttpServletRequest request, String userId, boolean isUpdate) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("Start create or update request of {} with modifier id {}", url, userId);
+
+ try {
+ String componentIdLower = componentId.toLowerCase();
+
+ List<InterfaceDefinition> mappedInterfaceData = getMappedInterfaceData(data, modifier, componentType);
+ Either<List<InterfaceDefinition>, ResponseFormat> actionResponse;
+ if (isUpdate) {
+ actionResponse =
+ interfaceOperationBusinessLogic.updateInterfaceOperation(componentIdLower, mappedInterfaceData, modifier, true);
+ } else {
+ actionResponse =
+ interfaceOperationBusinessLogic.createInterfaceOperation(componentIdLower, mappedInterfaceData, modifier, true);
+ }
+
+ if (actionResponse.isRight()) {
+ log.error("failed to create or update interface operation");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ getFormattedResponse(actionResponse.left().value()));
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Interface Operation Creation or update");
+ log.error("create or update interface Operation with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private List<InterfaceDefinition> getMappedInterfaceData(String inputJson, User user,
+ ComponentTypeEnum componentTypeEnum) {
+ Either<UiComponentDataTransfer, ResponseFormat> uiComponentEither =
+ getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user,
+ UiComponentDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
+ return new ArrayList<>(uiComponentEither.left().value().getInterfaces().values());
+ }
+
+ private Object getFormattedResponse(List<InterfaceDefinition> interfaceDefinitions) throws IOException {
+ Map<String, List<InterfaceDefinition>> allInterfaces =
+ ImmutableMap.of(JsonPresentationFields.INTERFACES.getPresentation(), interfaceDefinitions);
+ return RepresentationUtils.toFilteredRepresentation(allInterfaces);
+ }
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/interfaceOperations")
+ @Operation(description = "Update Interface Operations on Resource", method = "PUT",
+ summary = "Update Interface Operations on Resource",responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Interface Operations on Resource"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Resource not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateInterfaceOperationsOnResource(
+ @Parameter(description = "Interface Operations to update", required = true) String data,
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+ return createOrUpdate(data, ComponentTypeEnum.RESOURCE, resourceId, request, userId, true);
+ }
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/interfaces/{interfaceId}/operations/{operationId}")
+ @Operation(description = "Delete Interface Operation from Resource", method = "DELETE",
+ summary = "Delete Interface Operation from Resource", responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Interface Operation from Resource"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Resource not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteInterfaceOperationsFromResource(
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @Parameter(description = "Interface Id") @PathParam("interfaceId") String interfaceId,
+ @Parameter(description = "Operation Id") @PathParam("operationId") String operationId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+ return delete(interfaceId, operationId, resourceId, request, userId);
+ }
+
+ private Response delete(String interfaceId, String operationId, String componentId, HttpServletRequest request,
+ String userId) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("Start delete request of {} with modifier id {}", url, userId);
+
+ try {
+ String componentIdLower = componentId.toLowerCase();
+ Either<List<InterfaceDefinition>, ResponseFormat> actionResponse = interfaceOperationBusinessLogic.deleteInterfaceOperation(
+ componentIdLower, interfaceId, Collections.singletonList(operationId), modifier, true);
+ if (actionResponse.isRight()) {
+ log.error("failed to delete interface operation");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ getFormattedResponse(actionResponse.left().value()));
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Interface Operation");
+ log.error("Delete interface operation with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/interfaces/{interfaceId}/operations/{operationId}")
+ @Operation(description = "Get Interface Operation from Resource", method = "GET",
+ summary = "GET Interface Operation from Resource",responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Interface Operation from Resource"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Resource not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getInterfaceOperationsFromResource(
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @Parameter(description = "Interface Id") @PathParam("interfaceId") String interfaceId,
+ @Parameter(description = "Operation Id") @PathParam("operationId") String operationId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+ return get(interfaceId, operationId, resourceId, request, userId);
+ }
+
+ private Response get(String interfaceId, String operationId, String componentId, HttpServletRequest request,
+ String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug("Start get request of {} with modifier id {}", url, userId);
+
+ try {
+ String componentIdLower = componentId.toLowerCase();
+ Either<List<InterfaceDefinition>, ResponseFormat> actionResponse = interfaceOperationBusinessLogic.getInterfaceOperation(
+ componentIdLower, interfaceId, Collections.singletonList(operationId), modifier, true);
+ if (actionResponse.isRight()) {
+ log.error("failed to get interface operation");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ getFormattedResponse(actionResponse.left().value()));
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component interface operations");
+ log.error("get component interface operations failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/interfaceOperations")
+ @Operation(description = "Create Interface Operations on Service", method = "POST",
+ summary = "Create Interface Operations on Service", responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Interface Operations on Service"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found"),
+ @ApiResponse(responseCode = "409", description = "Interface Operation already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createInterfaceOperationsOnService(
+ @Parameter(description = "Interface Operations to create", required = true) String data,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+ return createOrUpdate(data, ComponentTypeEnum.SERVICE, serviceId, request, userId, false);
+ }
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/interfaceOperations")
+ @Operation(description = "Update Interface Operations on Service", method = "PUT",
+ summary = "Update Interface Operations on Service",responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Interface Operations on Service"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateInterfaceOperationsOnService(
+ @Parameter(description = "Interface Operations to update", required = true) String data,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+ return createOrUpdate(data, ComponentTypeEnum.SERVICE, serviceId, request, userId, true);
+ }
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/interfaces/{interfaceId}/operations/{operationId}")
+ @Operation(description = "Delete Interface Operation from Service", method = "DELETE",
+ summary = "Delete Interface Operation from Service",responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Interface Operation from Service"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteInterfaceOperationsFromService(
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Interface Id") @PathParam("interfaceId") String interfaceId,
+ @Parameter(description = "Operation Id") @PathParam("operationId") String operationId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+ return delete(interfaceId, operationId, serviceId, request, userId);
+ }
+
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/interfaces/{interfaceId}/operations/{operationId}")
+ @Operation(description = "Get Interface Operation from Service", method = "GET",
+ summary = "GET Interface Operation from Service",responses = @ApiResponse(content = @Content(
+ array = @ArraySchema(schema = @Schema(implementation = InterfaceDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Get Interface Operation from Service"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getInterfaceOperationsFromService(
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Interface Id") @PathParam("interfaceId") String interfaceId,
+ @Parameter(description = "Operation Id") @PathParam("operationId") String operationId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @Context final HttpServletRequest request) {
+ return get(interfaceId, operationId, serviceId, request, userId);
+ }
+
+}
+
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java
index 753ae13873..cb883f20fe 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/LifecycleServlet.java
@@ -1,197 +1,198 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
-import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoBase;
-import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.ui.model.UiComponentMetadata;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Lifecycle Actions Servlet", description = "Lifecycle Actions Servlet"))
-@Singleton
-public class LifecycleServlet extends BeGenericServlet {
-
- private static final Logger log = Logger.getLogger(LifecycleServlet.class);
- private final LifecycleBusinessLogic lifecycleBusinessLogic;
-
- @Inject
- public LifecycleServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- LifecycleBusinessLogic lifecycleBusinessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.lifecycleBusinessLogic = lifecycleBusinessLogic;
- }
-
-
- @POST
- @Path("/{componentCollection}/{componentId}/lifecycleState/{lifecycleOperation}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Change Resource lifecycle State", method = "POST", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource state changed"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "409", description = "Resource already exist")})
- public Response changeResourceState(
- @Parameter(
- description = "LifecycleChangeInfo - relevant for checkin, failCertification, cancelCertification",
- required = false) String jsonChangeInfo,
- @Parameter(description = "validValues: resources / services / products",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam(
- value = "componentCollection") final String componentCollection,
- @Parameter(schema = @Schema(allowableValues = {
- "checkout, undoCheckout, checkin, certificationRequest, startCertification, failCertification, cancelCertification, certify"}),
- required = true) @PathParam(value = "lifecycleOperation") final String lifecycleTransition,
- @Parameter(description = "id of component to be changed") @PathParam(
- value = "componentId") final String componentId,
- @Context final HttpServletRequest request,
- @Parameter(description = "id of user initiating the operation") @HeaderParam(
- value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- Response response = null;
-
- // get modifier from graph
- log.debug("get modifier properties");
- Either<User, ResponseFormat> eitherGetUser = getUser(request, userId);
- if (eitherGetUser.isRight()) {
- return buildErrorResponse(eitherGetUser.right().value());
- }
- User user = eitherGetUser.left().value();
-
- String resourceIdLower = componentId.toLowerCase();
- log.debug("perform {} operation to resource with id {} ", lifecycleTransition, resourceIdLower);
- Either<LifeCycleTransitionEnum, Response> validateEnum = validateTransitionEnum(lifecycleTransition, user);
- if (validateEnum.isRight()) {
- return validateEnum.right().value();
- }
-
- 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().logBeInvalidJsonInput("convertJsonToObject");
- log.debug("failed to convert from json {}", jsonChangeInfo, e);
- ResponseFormat responseFormat = getComponentsUtils().getInvalidContentErrorAndAudit(user, componentId,
- AuditingActionEnum.CHECKOUT_RESOURCE);
- return buildErrorResponse(responseFormat);
- }
-
- try {
- LifeCycleTransitionEnum transitionEnum = validateEnum.left().value();
- ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(componentCollection);
- if (componentType != null) {
- Either<? extends Component, ResponseFormat> actionResponse =
- lifecycleBusinessLogic.changeComponentState(componentType, componentId, user, transitionEnum,
- changeInfo, false, true);
-
- if (actionResponse.isRight()) {
- log.info("failed to change resource state");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- log.debug("change state successful !!!");
- UiComponentMetadata componentMetatdata =
- UiComponentDataConverter.convertToUiComponentMetadata(actionResponse.left().value());
- Object value = RepresentationUtils.toRepresentation(componentMetatdata);
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), value);
- return response;
- } else {
- log.info(
- "componentCollection \"{}\" is not valid. Supported componentCollection values are \"{}\", \"{}\" or \"{}\"",
- componentCollection, ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME);
- ResponseFormat error = getComponentsUtils().getInvalidContentErrorAndAudit(user, componentId,
- AuditingActionEnum.CHECKOUT_RESOURCE);
- return buildErrorResponse(error);
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Change Lifecycle State");
- log.debug("change lifecycle state failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- private Either<LifeCycleTransitionEnum, Response> validateTransitionEnum(final String lifecycleTransition, User user) {
- LifeCycleTransitionEnum transitionEnum = LifeCycleTransitionEnum.CHECKOUT;
- try {
- transitionEnum = LifeCycleTransitionEnum.getFromDisplayName(lifecycleTransition);
- } catch (IllegalArgumentException e) {
- log.info("state operation is not valid. operations allowed are: {}", LifeCycleTransitionEnum.valuesAsString(), e);
- ResponseFormat error = getComponentsUtils().getInvalidContentErrorAndAudit(user, "", AuditingActionEnum.CHECKOUT_RESOURCE);
- return Either.right(buildErrorResponse(error));
- }
- return Either.left(transitionEnum);
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoBase;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.ui.model.UiComponentMetadata;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Lifecycle Actions Servlet", description = "Lifecycle Actions Servlet"))
+@Controller
+public class LifecycleServlet extends BeGenericServlet {
+
+ private static final Logger log = Logger.getLogger(LifecycleServlet.class);
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(LifecycleServlet.class.getName());
+ private LifecycleBusinessLogic lifecycleBusinessLogic;
+
+ @Inject
+ public LifecycleServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils,
+ LifecycleBusinessLogic lifecycleBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.lifecycleBusinessLogic = lifecycleBusinessLogic;
+ }
+
+
+ @POST
+ @Path("/{componentCollection}/{componentId}/lifecycleState/{lifecycleOperation}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Change Resource lifecycle State", method = "POST", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource state changed"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "409", description = "Resource already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response changeResourceState(
+ @Parameter(
+ description = "LifecycleChangeInfo - relevant for checkin, failCertification, cancelCertification",
+ required = false) String jsonChangeInfo,
+ @Parameter(description = "validValues: resources / services / products",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME, ComponentTypeEnum.PRODUCT_PARAM_NAME})) @PathParam(
+ value = "componentCollection") final String componentCollection,
+ @Parameter(schema = @Schema(allowableValues = {
+ "checkout, undoCheckout, checkin, certificationRequest, startCertification, failCertification, cancelCertification, certify"}),
+ required = true) @PathParam(value = "lifecycleOperation") final String lifecycleTransition,
+ @Parameter(description = "id of component to be changed") @PathParam(
+ value = "componentId") final String componentId,
+ @Context final HttpServletRequest request,
+ @Parameter(description = "id of user initiating the operation") @HeaderParam(
+ value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ loggerSupportability.log(LoggerSupportabilityActions.CHANGELIFECYCLESTATE, StatusCode.STARTED,"Starting to change lifecycle state to " + lifecycleTransition + " by user " + userId);
+
+ Response response = null;
+
+ // get modifier from graph
+ log.debug("get modifier properties");
+ Either<User, ResponseFormat> eitherGetUser = getUser(request, userId);
+ if (eitherGetUser.isRight()) {
+ return buildErrorResponse(eitherGetUser.right().value());
+ }
+ User user = eitherGetUser.left().value();
+
+ String resourceIdLower = componentId.toLowerCase();
+ log.debug("perform {} operation to resource with id {} ", lifecycleTransition, resourceIdLower);
+ Either<LifeCycleTransitionEnum, Response> validateEnum = validateTransitionEnum(lifecycleTransition, user);
+ if (validateEnum.isRight()) {
+ return validateEnum.right().value();
+ }
+
+ 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().logBeInvalidJsonInput("convertJsonToObject");
+ log.debug("failed to convert from json {}", jsonChangeInfo, e);
+ getComponentsUtils().getInvalidContentErrorAndAudit(user, componentId, AuditingActionEnum.CHECKOUT_RESOURCE);
+ throw e;
+ }
+
+ LifeCycleTransitionEnum transitionEnum = validateEnum.left().value();
+ ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(componentCollection);
+ if (componentType != null) {
+ Either<? extends Component, ResponseFormat> actionResponse = lifecycleBusinessLogic.changeComponentState(componentType, componentId, user, transitionEnum, changeInfo, false, true);
+
+ if (actionResponse.isRight()) {
+ log.info("failed to change resource state");
+ loggerSupportability.log(LoggerSupportabilityActions.CHANGELIFECYCLESTATE, StatusCode.ERROR,"failed to change resource state " + lifecycleTransition + " with error " + actionResponse.isRight() + " by user " + userId);
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ log.debug("change state successful !!!");
+ UiComponentMetadata componentMetatdata = UiComponentDataConverter.convertToUiComponentMetadata(actionResponse.left().value());
+ Object value = null;
+ try {
+ value = RepresentationUtils.toRepresentation(componentMetatdata);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), value);
+ loggerSupportability.log(LoggerSupportabilityActions.CHANGELIFECYCLESTATE,actionResponse.left().value().getComponentMetadataForSupportLog(),StatusCode.COMPLETE," change state to " + lifecycleTransition + " was successful by user" + userId);
+ return response;
+ } else {
+ log.info("componentCollection \"{}\" is not valid. Supported componentCollection values are \"{}\", \"{}\" or \"{}\"", componentCollection, ComponentTypeEnum.RESOURCE_PARAM_NAME, ComponentTypeEnum.SERVICE_PARAM_NAME,
+ ComponentTypeEnum.PRODUCT_PARAM_NAME);
+ ResponseFormat error = getComponentsUtils().getInvalidContentErrorAndAudit(user, componentId, AuditingActionEnum.CHECKOUT_RESOURCE);
+ return buildErrorResponse(error);
+ }
+ }
+
+ private Either<LifeCycleTransitionEnum, Response> validateTransitionEnum(final String lifecycleTransition, User user) {
+ LifeCycleTransitionEnum transitionEnum;
+ try {
+ transitionEnum = LifeCycleTransitionEnum.getFromDisplayName(lifecycleTransition);
+ } catch (IllegalArgumentException e) {
+ log.info("state operation is not valid. operations allowed are: {}", LifeCycleTransitionEnum.valuesAsString(), e);
+ ResponseFormat error = getComponentsUtils().getInvalidContentErrorAndAudit(user, "", AuditingActionEnum.CHECKOUT_RESOURCE);
+ return Either.right(buildErrorResponse(error));
+ }
+ return Either.left(transitionEnum);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
index 1ab061fa27..cb91473940 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyServlet.java
@@ -1,480 +1,389 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.StringUtils;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.PolicyDefinition;
-import org.openecomp.sdc.be.model.PolicyTargetDTO;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.stereotype.Controller;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-/**
- * Provides REST API to create, retrieve, update, delete a policy
- */
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Policy Servlet"))
-@Controller
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class PolicyServlet extends AbstractValidationsServlet {
-
- private static final Logger log = Logger.getLogger(PolicyServlet.class);
- private final PolicyBusinessLogic policyBusinessLogic;
-
- @Inject
- public PolicyServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- PolicyBusinessLogic policyBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.policyBusinessLogic = policyBusinessLogic;
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/policies/{policyTypeName}")
- @Operation(description = "Create Policy", method = "POST", summary = "Returns created Policy",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Policy created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Policy already exist"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response createPolicy(@PathParam("componentId") final String containerComponentId, @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("policyTypeName") final String policyTypeName,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Context final HttpServletRequest request) {
- init();
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- try {
- Wrapper<ComponentTypeEnum> componentTypeWrapper =
- validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
- if (responseWrapper.isEmpty()) {
- responseWrapper.setInnerElement(policyBusinessLogic
- .createPolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyTypeName,
- userId, true)
- .either(l -> buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), l),
- this::buildErrorResponse));
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Policy");
- log.error("Failed to create policy. The exception {} occurred. ", e);
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
- }
- return responseWrapper.getInnerElement();
- }
-
- @PUT
- @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
- @Operation(description = "Update Policy metadata", method = "PUT", summary = "Returns updated Policy",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "component / policy Not found")})
- public Response updatePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(
- description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("policyId") final String policyId,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Parameter(description = "PolicyDefinition", required = true) String policyData,
- @Context final HttpServletRequest request) {
- init();
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- try {
- Wrapper<ComponentTypeEnum> componentTypeWrapper =
- validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
- Wrapper<PolicyDefinition> policyWrapper = new Wrapper<>();
- if (responseWrapper.isEmpty()) {
- convertJsonToObjectOfClass(policyData, policyWrapper, PolicyDefinition.class, responseWrapper);
- if (policyWrapper.isEmpty()) {
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)));
- }
- }
- if (!policyWrapper.isEmpty()) {
- policyWrapper.getInnerElement().setUniqueId(policyId);
- responseWrapper.setInnerElement(policyBusinessLogic
- .updatePolicy(componentTypeWrapper.getInnerElement(), containerComponentId,
- policyWrapper.getInnerElement(), userId, true)
- .either(this::buildOkResponse, this::buildErrorResponse));
- }
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Policy");
- log.error("Failed to update policy. The exception {} occurred. ", e);
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
- }
- return responseWrapper.getInnerElement();
- }
-
- @GET
- @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
- @Operation(description = "Get Policy", method = "GET", summary = "Returns Policy", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy was found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "component / policy Not found")})
- public Response getPolicy(@PathParam("componentId") final String containerComponentId, @Parameter(
- description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("policyId") final String policyId,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Context final HttpServletRequest request) {
- init();
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- try {
- Wrapper<ComponentTypeEnum> componentTypeWrapper =
- validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
- if (responseWrapper.isEmpty()) {
- responseWrapper.setInnerElement(policyBusinessLogic
- .getPolicy(componentTypeWrapper.getInnerElement(), containerComponentId, policyId, userId)
- .either(this::buildOkResponse, this::buildErrorResponse));
- }
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Policy");
- log.error("Failed to retrieve policy. The exception {} occurred. ", e);
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
- }
- return responseWrapper.getInnerElement();
- }
-
- @DELETE
- @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
- @Operation(description = "Delete Policy", method = "DELETE", summary = "No body", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Policy was deleted"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "component / policy Not found")})
- public Response deletePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(
- description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("policyId") final String policyId,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Context final HttpServletRequest request) {
- init();
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- try {
- Wrapper<ComponentTypeEnum> componentTypeWrapper =
- validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
- if (responseWrapper.isEmpty()) {
- responseWrapper
- .setInnerElement(
- policyBusinessLogic
- .deletePolicy(componentTypeWrapper.getInnerElement(), containerComponentId,
- policyId, userId, true)
- .either(this::buildOkResponse, this::buildErrorResponse));
- }
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Policy");
- log.error("Failed to delete policy. The exception {} occurred. ", e);
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
- }
- return responseWrapper.getInnerElement();
- }
-
- @PUT
- @Path("/{containerComponentType}/{componentId}/policies/{policyId}/undeclare")
- @Operation(description = "undeclare Policy", method = "PUT", summary = "No body",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Policy was undeclared"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "component / policy Not found")})
- public Response undeclarePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(
- description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("policyId") final String policyId,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Context final HttpServletRequest request) {
- init();
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- try {
- Wrapper<ComponentTypeEnum> componentTypeWrapper =
- validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
- if (responseWrapper.isEmpty()) {
- responseWrapper
- .setInnerElement(
- policyBusinessLogic
- .undeclarePolicy(componentTypeWrapper.getInnerElement(), containerComponentId,
- policyId, userId, true)
- .either(this::buildOkResponse, this::buildErrorResponse));
- }
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Undeclare Policy");
- log.error("Failed to undeclare policy. The exception {} occurred. ", e);
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
- }
- return responseWrapper.getInnerElement();
- }
-
- @GET
- @Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")
- @Operation(description = "Get component policy properties", method = "GET",
- summary = "Returns component policy properties",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = PropertyDataDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),
- @ApiResponse(responseCode = "400",
- description = "invalid content - Error: containerComponentType is invalid"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Componentorpolicy not found"),
- @ApiResponse(responseCode = "500", description = "The GET request failed due to internal SDC problem.")})
- public Response getPolicyProperties(@Parameter(
- description = "the id of the component which is the container of the policy") @PathParam("componentId") final String containerComponentId,
- @Parameter(description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @Parameter(
- description = "the id of the policy which its properties are to return") @PathParam("policyId") final String policyId,
- @Parameter(description = "the userid",
- required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Context final HttpServletRequest request) {
- init();
- try {
- return convertToComponentType(containerComponentType).left().bind(cmptType -> policyBusinessLogic
- .getPolicyProperties(cmptType, containerComponentId, policyId, userId))
- .either(this::buildOkResponse, this::buildErrorResponse);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("get Policy properties");
- log.debug("#getPolicyProperties - get Policy properties has failed.", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
-
- }
-
- @PUT
- @Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")
- @Operation(description = "Update Policy properties", method = "PUT", summary = "Returns updated Policy",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy properties updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "component / policy Not found")})
- public Response updatePolicyProperties(@PathParam("componentId") final String containerComponentId, @Parameter(
- description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("policyId") final String policyId,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Parameter(description = "PolicyDefinition", required = true) String policyData,
- @Context final HttpServletRequest request) {
- init();
- Wrapper<Response> responseWrapper = new Wrapper<>();
- try {
- Wrapper<ComponentTypeEnum> componentTypeWrapper =
- validateComponentTypeAndUserId(containerComponentType, userId, responseWrapper);
- Wrapper<PropertyDataDefinition[]> propertiesWrapper = new Wrapper<>();
- if (responseWrapper.isEmpty()) {
- convertJsonToObjectOfClass(policyData, propertiesWrapper, PropertyDataDefinition[].class,
- responseWrapper);
- if (propertiesWrapper.isEmpty()) {
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)));
- }
- }
- if (!propertiesWrapper.isEmpty()) {
- responseWrapper.setInnerElement(policyBusinessLogic
- .updatePolicyProperties(componentTypeWrapper.getInnerElement(), containerComponentId, policyId,
- propertiesWrapper.getInnerElement(), userId, true)
- .either(this::buildOkResponse, this::buildErrorResponse));
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Policy");
- log.error("Failed to update policy. The exception {} occurred. ", e);
- responseWrapper.setInnerElement(
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)));
- }
- return responseWrapper.getInnerElement();
- }
-
- private Wrapper<ComponentTypeEnum> validateComponentTypeAndUserId(final String containerComponentType, String userId, Wrapper<Response> responseWrapper) {
- Wrapper<ComponentTypeEnum> componentTypeWrapper = new Wrapper<>();
- if (StringUtils.isEmpty(userId)) {
- log.error("Missing userId HTTP header. ");
- responseWrapper.setInnerElement(buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.MISSING_USER_ID)));
- }
- if (responseWrapper.isEmpty()) {
- validateComponentType(responseWrapper, componentTypeWrapper, containerComponentType);
- }
- return componentTypeWrapper;
- }
-
- @POST
- @Path("/{containerComponentType}/{componentId}/policies/{policyId}/targets")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "update policy targets", method = "POST", summary = "Returns updated Policy",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Policy target updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updatePolicyTargets(@PathParam("componentId") final String containerComponentId, @Parameter(
- description = "valid values: resources / services",
- schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
- ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("policyId") final String policyId,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
- required = true) String userId,
- @Context final HttpServletRequest request, List<PolicyTargetDTO> requestJson) {
- try {
-
- return updatePolicyTargetsFromDTO(requestJson).left()
- .bind(policyTarget -> updatePolicyTargetsFromMap(policyTarget, containerComponentType,
- containerComponentId, policyId, userId))
- .either(this::buildOkResponse, this::buildErrorResponse);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Policy");
- log.debug("Policy target update has been failed with the exception{}. ", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @POST
- @Path("/{componentType}/{componentId}/create/policies")
- @Operation(description = "Create policies on service", method = "POST", summary = "Return policies list",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Component not found")})
- public Response declareProperties(@PathParam("componentType") final String componentType,
- @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @Parameter(description = "ComponentIns policies Object to be created",
- required = true) String componentInstPoliciesMapObj) {
-
- return super.declareProperties(userId, componentId, componentType, componentInstPoliciesMapObj,
- DeclarationTypeEnum.POLICY, request);
- }
-
- private Either<PolicyDefinition, ResponseFormat> updatePolicyTargetsFromMap(
- Map<PolicyTargetType, List<String>> policyTarget, String containerComponentType,
- String containerComponentId, String policyId, String userId) {
- return convertToComponentType(containerComponentType).left().bind(cmptType -> policyBusinessLogic
- .updatePolicyTargets(cmptType, containerComponentId, policyId, policyTarget, userId));
- }
-
- private Either<Map<PolicyTargetType, List<String>>, ResponseFormat> updatePolicyTargetsFromDTO(
- List<PolicyTargetDTO> targetDTOList) {
- Map<PolicyTargetType, List<String>> policyTarget = new HashMap<>();
- for (PolicyTargetDTO currentTarget : targetDTOList) {
- if (!addTargetsByType(policyTarget, currentTarget.getType(), currentTarget.getUniqueIds())) {
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.POLICY_TARGET_TYPE_DOES_NOT_EXIST,
- currentTarget.getType()));
- }
- }
- return Either.left(policyTarget);
- }
-
-
- public boolean addTargetsByType(Map<PolicyTargetType, List<String>> policyTarget, String type, List<String> uniqueIds) {
- PolicyTargetType targetTypeEnum = PolicyTargetType.getByNameIgnoreCase(type);
- if(targetTypeEnum != null){
- policyTarget.put(targetTypeEnum, validateUniquenessOfIds(uniqueIds));
- return true;
- }
- else{
- return false;
- }
- }
-
- private List<String> validateUniquenessOfIds(List<String> uniqueIds) {
- return uniqueIds.stream().distinct().collect(Collectors.toList());
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.DeclarationTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PolicyTargetDTO;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+/**
+ * Provides REST API to create, retrieve, update, delete a policy
+ */
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Policy Servlet"))
+@Controller
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class PolicyServlet extends AbstractValidationsServlet {
+
+ private static final Logger log = Logger.getLogger(PolicyServlet.class);
+ private final PolicyBusinessLogic policyBusinessLogic;
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ServiceServlet.class.getName());
+
+ @Inject
+ public PolicyServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ PolicyBusinessLogic policyBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.policyBusinessLogic = policyBusinessLogic;
+ this.servletUtils = servletUtils;
+ this.resourceImportManager = resourceImportManager;
+ this.componentsUtils = componentsUtils;
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/policies/{policyTypeName}")
+ @Operation(description = "Create Policy", method = "POST", summary = "Returns created Policy",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Policy created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Policy already exist"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createPolicy(@PathParam("componentId") final String containerComponentId, @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyTypeName") final String policyTypeName,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Context final HttpServletRequest request) {
+ init();
+
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_POLICIES, StatusCode.STARTED,"Starting to create Policy by user {} containerComponentId={}" , userId , containerComponentId );
+ ComponentTypeEnum componentType = validateComponentTypeAndUserId(containerComponentType, userId);
+ PolicyDefinition policy = policyBusinessLogic.createPolicy(componentType, containerComponentId, policyTypeName, userId, true);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_POLICIES, StatusCode.COMPLETE,"Ended create Policy by user {} containerComponentId={}" , userId , containerComponentId);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), policy);
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
+ @Operation(description = "Update Policy metadata", method = "PUT", summary = "Returns updated Policy",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "component / policy Not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updatePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(
+ description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyId") final String policyId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Parameter(description = "PolicyDefinition", required = true) String policyData,
+ @Context final HttpServletRequest request) {
+ init();
+
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_POLICY_TARGET, StatusCode.STARTED,"Starting to update Policy by user {} containerComponentId={}" , userId , containerComponentId);
+ PolicyDefinition policyDefinition = convertJsonToObjectOfClass(policyData, PolicyDefinition.class);
+ policyDefinition.setUniqueId(policyId);
+ policyDefinition = policyBusinessLogic.updatePolicy(validateComponentTypeAndUserId(containerComponentType, userId), containerComponentId, policyDefinition, userId, true);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_POLICY_TARGET, StatusCode.COMPLETE,"Ended update Policy by user {} containerComponentId={}" , userId , containerComponentId);
+ return buildOkResponse(policyDefinition);
+
+ }
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
+ @Operation(description = "Get Policy", method = "GET", summary = "Returns Policy", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy was found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "component / policy Not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getPolicy(@PathParam("componentId") final String containerComponentId, @Parameter(
+ description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyId") final String policyId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Context final HttpServletRequest request) {
+ init();
+
+ PolicyDefinition policy = policyBusinessLogic.getPolicy(validateComponentTypeAndUserId(containerComponentType,
+ userId), containerComponentId, policyId, userId);
+ return buildOkResponse(policy);
+ }
+
+ @DELETE
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}")
+ @Operation(description = "Delete Policy", method = "DELETE", summary = "No body", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Policy was deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "component / policy Not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deletePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(
+ description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyId") final String policyId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Context final HttpServletRequest request) {
+ init();
+
+ ComponentTypeEnum componentTypeEnum = validateComponentTypeAndUserId(containerComponentType, userId);
+ PolicyDefinition policyDefinition = policyBusinessLogic.deletePolicy(componentTypeEnum, containerComponentId, policyId, userId, true);
+ return buildOkResponse(policyDefinition);
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}/undeclare")
+ @Operation(description = "undeclare Policy", method = "PUT", summary = "No body",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "204", description = "Policy was undeclared"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "component / policy Not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response undeclarePolicy(@PathParam("componentId") final String containerComponentId, @Parameter(
+ description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyId") final String policyId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Context final HttpServletRequest request) {
+ init();
+ Response response = null;
+ try {
+ ComponentTypeEnum componentTypeEnum = validateComponentTypeAndUserId(containerComponentType, userId);
+ Either<PolicyDefinition, ResponseFormat> undeclarePolicy = policyBusinessLogic.undeclarePolicy(componentTypeEnum, containerComponentId, policyId, userId, true);
+ if (undeclarePolicy.isLeft()){
+ response = buildOkResponse(undeclarePolicy.left().value());
+ } else{
+ response = buildErrorResponse(undeclarePolicy.right().value());
+ }
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Undeclare Policy");
+ log.error("Failed to undeclare policy. The exception {} occurred. ", e);
+ }
+ return response;
+ }
+
+ @GET
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")
+ @Operation(description = "Get component policy properties", method = "GET",
+ summary = "Returns component policy properties",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = PropertyDataDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Properties found"),
+ @ApiResponse(responseCode = "400",
+ description = "invalid content - Error: containerComponentType is invalid"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Componentorpolicy not found"),
+ @ApiResponse(responseCode = "500", description = "The GET request failed due to internal SDC problem.")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getPolicyProperties(@Parameter(
+ description = "the id of the component which is the container of the policy") @PathParam("componentId") final String containerComponentId,
+ @Parameter(description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @Parameter(
+ description = "the id of the policy which its properties are to return") @PathParam("policyId") final String policyId,
+ @Parameter(description = "the userid",
+ required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request) {
+ init();
+ List<PropertyDataDefinition> propertyDataDefinitionList = policyBusinessLogic.getPolicyProperties(
+ convertToComponentType(containerComponentType), containerComponentId, policyId, userId);
+ return buildOkResponse(propertyDataDefinitionList);
+ }
+
+ @PUT
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}/properties")
+ @Operation(description = "Update Policy properties", method = "PUT", summary = "Returns updated Policy",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Policy properties updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "component / policy Not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updatePolicyProperties(@PathParam("componentId") final String containerComponentId, @Parameter(
+ description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyId") final String policyId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Parameter(description = "PolicyDefinition", required = true) String policyData,
+ @Context final HttpServletRequest request) {
+ init();
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_POLICIES_PROPERTIES, StatusCode.STARTED,"Starting to update Policy Properties by user {} containerComponentId={}" , userId , containerComponentId);
+
+ ComponentTypeEnum componentTypeEnum = validateComponentTypeAndUserId(containerComponentType, userId);
+ PropertyDataDefinition[] propertyDataDefinitions = convertJsonToObjectOfClass(policyData, PropertyDataDefinition[].class);
+ List<PropertyDataDefinition> propertyDataDefinitionList = policyBusinessLogic.updatePolicyProperties(componentTypeEnum,
+ containerComponentId, policyId, propertyDataDefinitions, userId, true);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_POLICIES_PROPERTIES, StatusCode.STARTED,"Starting to update Policy Properties by user {} containerComponentId={}" , userId , containerComponentId);
+ return buildOkResponse(propertyDataDefinitionList);
+ }
+
+ private ComponentTypeEnum validateComponentTypeAndUserId(final String containerComponentType, String userId) {
+ if (StringUtils.isEmpty(userId)) {
+ log.error("Missing userId HTTP header. ");
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_USER_ID);
+ }
+ return validateComponentType(containerComponentType);
+ }
+
+ @POST
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}/targets")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "update policy targets", method = "POST", summary = "Returns updated Policy",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Policy target updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updatePolicyTargets(@PathParam("componentId") final String containerComponentId, @Parameter(
+ description = "valid values: resources / services",
+ schema = @Schema(allowableValues = {ComponentTypeEnum.RESOURCE_PARAM_NAME ,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyId") final String policyId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user",
+ required = true) String userId,
+ @Context final HttpServletRequest request, List<PolicyTargetDTO> requestJson) {
+ Map<PolicyTargetType, List<String>> policyTargetTypeListMap = updatePolicyTargetsFromDTO(requestJson);
+ PolicyDefinition policyDefinition = updatePolicyTargetsFromMap(policyTargetTypeListMap, containerComponentType, containerComponentId, policyId, userId);
+ return buildOkResponse(policyDefinition);
+
+ }
+
+ @POST
+ @Path("/{componentType}/{componentId}/create/policies")
+ @Operation(description = "Create policies on service", method = "POST", summary = "Return policies list",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Component found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Component not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response declareProperties(@PathParam("componentType") final String componentType,
+ @PathParam("componentId") final String componentId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Parameter(description = "ComponentIns policies Object to be created",
+ required = true) String componentInstPoliciesMapObj) {
+
+ return super.declareProperties(userId, componentId, componentType, componentInstPoliciesMapObj,
+ DeclarationTypeEnum.POLICY, request);
+ }
+
+
+ private PolicyDefinition updatePolicyTargetsFromMap(Map<PolicyTargetType, List<String>> policyTarget, String containerComponentType, String containerComponentId, String policyId, String userId) {
+ ComponentTypeEnum componentTypeEnum = convertToComponentType(containerComponentType);
+ return policyBusinessLogic.updatePolicyTargets(componentTypeEnum, containerComponentId, policyId, policyTarget, userId);
+ }
+
+ private Map<PolicyTargetType, List<String>> updatePolicyTargetsFromDTO(List<PolicyTargetDTO> targetDTOList) {
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_POLICY_TARGET, StatusCode.STARTED,"Starting to update Policy target");
+ Map<PolicyTargetType, List<String>> policyTarget = new HashMap<>();
+ for (PolicyTargetDTO currentTarget : targetDTOList) {
+ if(!addTargetsByType(policyTarget, currentTarget.getType(), currentTarget.getUniqueIds())){
+ throw new ByActionStatusComponentException(ActionStatus.POLICY_TARGET_TYPE_DOES_NOT_EXIST, currentTarget.getType());
+ }
+ }
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_POLICY_TARGET, StatusCode.COMPLETE,"Ended update Policy target");
+ return policyTarget;
+ }
+
+
+ public boolean addTargetsByType(Map<PolicyTargetType, List<String>> policyTarget, String type, List<String> uniqueIds) {
+ PolicyTargetType targetTypeEnum = PolicyTargetType.getByNameIgnoreCase(type);
+ if(targetTypeEnum != null){
+ policyTarget.put(targetTypeEnum, validateUniquenessOfIds(uniqueIds));
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+
+ private List<String> validateUniquenessOfIds(List<String> uniqueIds) {
+ return uniqueIds.stream().distinct().collect(Collectors.toList());
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java
index 8030ef4184..baf246e67a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/PolicyTypesEndpoint.java
@@ -1,80 +1,88 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.List;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
-import org.openecomp.sdc.be.mixin.PolicyTypeMixin;
-import org.openecomp.sdc.be.model.PolicyTypeDefinition;
-import org.openecomp.sdc.be.view.ResponseView;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.stereotype.Controller;
-import com.jcabi.aspects.Loggable;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "policy types resource"))
-@Controller
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-public class PolicyTypesEndpoint {
-
- private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
-
- private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
-
- public PolicyTypesEndpoint(PolicyTypeBusinessLogic policyTypeBusinessLogic) {
- this.policyTypeBusinessLogic = policyTypeBusinessLogic;
- }
-
- @GET
- @Path("/policyTypes")
- @Operation(description = "Get policy types ", method = "GET", summary = "Returns policy types",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = PolicyTypeDefinition.class)))))
- @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "policy types found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "The GET request failed due to internal SDC problem.")})
- @ResponseView(mixin = {PolicyTypeMixin.class})
- public List<PolicyTypeDefinition> getPolicyTypes(@Parameter(description = "An optional parameter to indicate the type of the container from where this call is executed")
- @QueryParam("internalComponentType") String internalComponentType,
- @Parameter(description = "The user id", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- log.debug("(get) Start handle request of GET policyTypes");
- return policyTypeBusinessLogic.getAllPolicyTypes(userId, internalComponentType);
- }
-
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.mixin.PolicyTypeMixin;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.be.view.ResponseView;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Controller;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import java.util.List;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "policy types resource"))
+@Controller
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+public class PolicyTypesEndpoint extends BeGenericServlet{
+
+ private static final Logger log = Logger.getLogger(PolicyTypesEndpoint.class);
+
+ private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
+
+ public PolicyTypesEndpoint(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils, PolicyTypeBusinessLogic policyTypeBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.policyTypeBusinessLogic = policyTypeBusinessLogic;
+ }
+
+ @GET
+ @Path("/policyTypes")
+ @Operation(description = "Get policy types ", method = "GET", summary = "Returns policy types",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = PolicyTypeDefinition.class)))))
+ @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "policy types found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "500", description = "The GET request failed due to internal SDC problem.")})
+ @ResponseView(mixin = {PolicyTypeMixin.class})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public List<PolicyTypeDefinition> getPolicyTypes(@Parameter(description = "An optional parameter to indicate the type of the container from where this call is executed")
+ @QueryParam("internalComponentType") String internalComponentType,
+ @Parameter(description = "The user id", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ log.debug("(get) Start handle request of GET policyTypes");
+ return policyTypeBusinessLogic.getAllPolicyTypes(userId, internalComponentType);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java
deleted file mode 100644
index c6a6571687..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ProductServlet.java
+++ /dev/null
@@ -1,329 +0,0 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.util.Map;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Product;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Product Catalog", description = "Product Catalog"))
-@Singleton
-public class ProductServlet extends BeGenericServlet {
- private static final Logger log = Logger.getLogger(ProductServlet.class);
- private final ProductBusinessLogic productBusinessLogic;
-
- @Inject
- public ProductServlet(UserBusinessLogic userBusinessLogic,
- ProductBusinessLogic productBusinessLogic,
- ComponentsUtils componentsUtils) {
- super(userBusinessLogic, componentsUtils);
- this.productBusinessLogic = productBusinessLogic;
- }
-
- @POST
- @Path("/products")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create product", method = "POST", summary = "Returns created product",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Product.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Product created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation / Empty USER_ID header"),
- @ApiResponse(responseCode = "400", description = "Invalid/missing content"),
- @ApiResponse(responseCode = "409", description = "Product already exists / User not found / Wrong user role")})
- public Response createProduct(@Parameter(description = "Product object to be created", required = true) String data,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of product strategist user",
- required = true) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- Product product = RepresentationUtils.fromRepresentation(data, Product.class);
- Either<Product, ResponseFormat> actionResponse = productBusinessLogic.createProduct(product, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("Failed to create product");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Object result = RepresentationUtils.toRepresentation(actionResponse.left().value());
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), result);
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Product");
- log.debug("create product failed with error ", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- @GET
- @Path("/products/{productId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve product", method = "GET", summary = "Returns product according to productId",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Product.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Product found"),
- @ApiResponse(responseCode = "403", description = "Missing information"),
- @ApiResponse(responseCode = "409", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error"),
- @ApiResponse(responseCode = "404", description = "Product not found"),})
- public Response getProductById(@PathParam("productId") final String productId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
-
- try {
- log.trace("get product with id {}", productId);
- Either<Product, ResponseFormat> actionResponse = productBusinessLogic.getProduct(productId, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("Failed to get product");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Object product = RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), product);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Product");
- log.debug("get product failed with error ", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- @GET
- @Path("/products/productName/{productName}/productVersion/{productVersion}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve Service", method = "GET",
- summary = "Returns product according to name and version",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Product.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Product found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Product not found")})
- public Response getServiceByNameAndVersion(@PathParam("productName") final String productName,
- @PathParam("productVersion") final String productVersion, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- Either<Product, ResponseFormat> actionResponse =
- productBusinessLogic.getProductByNameAndVersion(productName, productVersion, userId);
-
- if (actionResponse.isRight()) {
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Product product = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(product);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get product by name and version");
- log.debug("get product failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- @DELETE
- @Path("/products/{productId}")
- public Response deleteProduct(@PathParam("productId") final String productId, @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
-
- try {
- log.trace("delete product with id {}", productId);
- Either<Product, ResponseFormat> actionResponse = productBusinessLogic.deleteProduct(productId, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("Failed to delete product");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Object product = RepresentationUtils.toRepresentation(actionResponse.left().value());
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), product);
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource");
- log.debug("delete resource failed with error ", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @PUT
- @Path("/products/{productId}/metadata")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Product Metadata", method = "PUT", summary = "Returns updated product",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Product.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Product Updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateProductMetadata(@PathParam("productId") final String productId,
- @Parameter(description = "Product object to be Updated", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
- Response response = null;
-
- try {
- String productIdLower = productId.toLowerCase();
- Product updatedProduct = RepresentationUtils.fromRepresentation(data, Product.class);
- Either<Product, ResponseFormat> actionResponse =
- productBusinessLogic.updateProductMetadata(productIdLower, updatedProduct, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("failed to update product");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Product product = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(product);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- log.debug("update product metadata failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- @GET
- @Path("/products/validate-name/{productName}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "validate product name", method = "GET",
- summary = "checks if the chosen product name is available ",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation")})
- public Response validateServiceName(@PathParam("productName") final String productName,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
- Response response = null;
- try {
- Either<Map<String, Boolean>, ResponseFormat> actionResponse =
- productBusinessLogic.validateProductNameExists(productName, userId);
-
- if (actionResponse.isRight()) {
- log.debug("failed to get validate service name");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- actionResponse.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Product Name");
- log.debug("validate product name failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java
index 0358e67075..f115f77a86 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RepresentationUtils.java
@@ -31,14 +31,11 @@ import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
@@ -47,6 +44,14 @@ import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
public class RepresentationUtils {
private static final Logger log = Logger.getLogger(RepresentationUtils.class);
@@ -120,15 +125,28 @@ public class RepresentationUtils {
return object;
}
- public static ArtifactDefinition convertJsonToArtifactDefinition(String content, Class<ArtifactDefinition> clazz) {
+ public static ArtifactDefinition convertJsonToArtifactDefinition(String content, Class<ArtifactDefinition> clazz, boolean validateTimeout) {
JsonObject jsonElement = new JsonObject();
ArtifactDefinition resourceInfo = null;
+ if (StringUtils.isEmpty(content)) {
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_BODY);
+ }
+
try {
Gson gson = new Gson();
jsonElement = gson.fromJson(content, jsonElement.getClass());
JsonElement artifactGroupValue = jsonElement.get(Constants.ARTIFACT_GROUP_TYPE);
+ HashMap<String, JsonElement> elementsToValidate = new HashMap<>();
+ elementsToValidate.put(Constants.ARTIFACT_GROUP_TYPE, artifactGroupValue);
+ elementsToValidate.put(Constants.ARTIFACT_TYPE, jsonElement.get(Constants.ARTIFACT_TYPE));
+ elementsToValidate.put(Constants.ARTIFACT_LABEL, (jsonElement.get(Constants.ARTIFACT_LABEL)));
+ if (validateTimeout) {
+ elementsToValidate.put(Constants.ARTIFACT_TIMEOUT, jsonElement.get(Constants.ARTIFACT_TIMEOUT));
+ }
+ validateMandatoryProperties(elementsToValidate);
+
if (artifactGroupValue != null && !artifactGroupValue.isJsonNull()) {
String groupValueUpper = artifactGroupValue.getAsString().toUpperCase();
if (!ArtifactGroupTypeEnum.getAllTypes().contains(groupValueUpper)) {
@@ -158,7 +176,12 @@ public class RepresentationUtils {
resourceInfo = mapper.readValue(json, clazz);
resourceInfo.setPayloadData(payload);
- } catch (Exception e) {
+ } catch (ComponentException ce) {
+ BeEcompErrorManager.getInstance().logBeArtifactInformationInvalidError("Artifact Upload / Update");
+ log.debug("Failed to convert the content {} to object.", content.substring(0, Math.min(50, content.length())), ce);
+ throw ce;
+ }
+ catch (Exception e) {
BeEcompErrorManager.getInstance().logBeArtifactInformationInvalidError("Artifact Upload / Update");
log.debug("Failed to convert the content {} to object.", content.substring(0, Math.min(50, content.length())), e);
}
@@ -166,6 +189,17 @@ public class RepresentationUtils {
return resourceInfo;
}
+ private static void validateMandatoryProperties(HashMap<String, JsonElement> elementsByName) {
+ elementsByName.forEach((name, element) -> {
+ if (element == null) {
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_MANDATORY_PROPERTY, name);
+ }
+ if (element.isJsonNull()) {
+ throw new ByActionStatusComponentException(ActionStatus.MANDATORY_PROPERTY_MISSING_VALUE, name);
+ }
+ });
+ }
+
public static <T> Object toFilteredRepresentation(T elementToRepresent) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java
index 5df3404b24..27cd082839 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementServlet.java
@@ -1,344 +1,356 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.List;
-import java.util.Optional;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.RequirementBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.RequirementDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-@OpenAPIDefinition(info = @Info(title = "Requirement Servlet", description = "Requirement Servlet"))
-@Singleton
-public class RequirementServlet extends AbstractValidationsServlet {
- private static final Logger LOGGER = Logger.getLogger(RequirementServlet.class);
- private final RequirementBusinessLogic requirementBusinessLogic;
-
- @Inject
- public RequirementServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- RequirementBusinessLogic requirementBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.requirementBusinessLogic = requirementBusinessLogic;
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/requirements")
- @Operation(description = "Create requirements on resource", method = "POST",
- summary = "Create requirements on resource",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create requirements"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "requirement already exist")})
- public Response createRequirementsOnResource(
- @Parameter(description = "Requirement to create", required = true) String data,
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, "resources" , resourceId, request,
- userId, false, "createRequirements");
- }
-
-
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/requirements")
- @Operation(description = "Update Requirements on resource", method = "PUT",
- summary = "Update Requirements on resource", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Requirements"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateRequirementsOnResource(
- @Parameter(description = "Requirements to update", required = true) String data,
- @Parameter(description = "Component Id") @PathParam("resourceId") String resourceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, "resources", resourceId, request,
- userId, true, "updateRequirements");
- }
-
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/requirements/{requirementId}")
- @Operation(description = "Get Requirement from resource", method = "GET",
- summary = "GET Requirement from resource", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "GET requirement"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response getRequirementsFromResource(
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @Parameter(description = "Requirement Id") @PathParam("requirementId") String requirementId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return get(requirementId, resourceId, request, userId);
- }
-
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/resources/{resourceId}/requirements/{requirementId}")
- @Operation(description = "Delete requirements from resource", method = "DELETE",
- summary = "Delete requirements from resource", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete requirement"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteRequirementsFromResource(
- @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
- @Parameter(description = "requirement Id") @PathParam("requirementId") String requirementId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return delete(requirementId, resourceId, request, userId);
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/requirements")
- @Operation(description = "Create requirements on service", method = "POST",
- summary = "Create requirements on service", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Requirements"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Requirement already exist")})
- public Response createRequirementsOnService(
- @Parameter(description = "Requirements to create", required = true) String data,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, "services" , serviceId, request, userId,
- false , "createRequirements");
- }
-
-
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/requirements")
- @Operation(description = "Update requirements on service", method = "PUT",
- summary = "Update requirements on service", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update requirements"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateRequirementsOnService(
- @Parameter(description = "Requirements to update", required = true) String data,
- @Parameter(description = "Component Id") @PathParam("serviceId") String serviceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, "services", serviceId, request, userId,
- true, "updateRequirements");
- }
-
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/requirements/{requirementId}")
- @Operation(description = "Get requirement from service", method = "GET",
- summary = "GET requirement from service", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "GET Requirements"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response getRequirementsOnService(
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Requirement Id") @PathParam("requirementId") String requirementId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- return get(requirementId, serviceId, request, userId);
- }
-
-
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/services/{serviceId}/requirements/{requirementId}")
- @Operation(description = "Delete requirement from service", method = "DELETE",
- summary = "Delete requirement from service", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Requirements"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteRequirementsOnService(
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Requirement Id") @PathParam("requirementId") String requirementId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return delete(requirementId, serviceId, request, userId);
- }
-
-
- private Response createOrUpdate (String data, String componentType, String componentId,
- HttpServletRequest request, String userId,
- boolean isUpdate, String errorContext) {
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- LOGGER.debug("Start create or update request of {} with modifier id {}", url, userId);
-
- try {
- String componentIdLower = componentId.toLowerCase();
-
- Either<List<RequirementDefinition>, ResponseFormat> mappedRequirementDataEither =
- getMappedRequirementData(data, modifier, ComponentTypeEnum.findByParamName(componentType));
- if(mappedRequirementDataEither.isRight()) {
- LOGGER.error("Failed to create or update requirements");
- return buildErrorResponse(mappedRequirementDataEither.right().value());
- }
- List<RequirementDefinition> mappedRequirementData = mappedRequirementDataEither.left().value();
- Either<List<RequirementDefinition>, ResponseFormat> actionResponse;
- if(isUpdate) {
- actionResponse = requirementBusinessLogic.updateRequirements(componentIdLower, mappedRequirementData, modifier,
- errorContext, true);
- } else {
- actionResponse = requirementBusinessLogic.createRequirements(componentIdLower, mappedRequirementData, modifier,
- errorContext, true);
- }
-
- if (actionResponse.isRight()) {
- LOGGER.error("Failed to create or update requirements");
- return buildErrorResponse(actionResponse.right().value());
- }
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- actionResponse.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("requirements create or update");
- LOGGER.error("Failed to create or update requirements with an error", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Response get (String requirementIdToGet, String componentId,
- HttpServletRequest request, String userId){
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- LOGGER.debug("Start get request of {} with modifier id {}", url, userId);
-
- try {
- String componentIdLower = componentId.toLowerCase();
- Either<RequirementDefinition, ResponseFormat> actionResponse = requirementBusinessLogic
- .getRequirement(componentIdLower, requirementIdToGet, modifier, true);
- if (actionResponse.isRight()) {
- LOGGER.error("failed to get requirements");
- return buildErrorResponse(actionResponse.right().value());
- }
- Object result = RepresentationUtils.toFilteredRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get requirements");
- LOGGER.error("get requirements failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Response delete (String requirementId, String componentId, HttpServletRequest
- request, String userId){
- String url = request.getMethod() + " " + request.getRequestURI();
-
- User modifier = new User();
- modifier.setUserId(userId);
- LOGGER.debug("Start delete request of {} with modifier id {}", url, userId);
-
- try {
- String componentIdLower = componentId.toLowerCase();
-
- Either<RequirementDefinition, ResponseFormat> actionResponse = requirementBusinessLogic
- .deleteRequirement(componentIdLower, requirementId, modifier, true);
- if (actionResponse.isRight()) {
- LOGGER.error("failed to delete requirements");
- return buildErrorResponse(actionResponse.right().value());
- }
- Object result = RepresentationUtils.toRepresentation(actionResponse.left().value());
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete requirements");
- LOGGER.error("Delete requirements failed with an error", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Either<List<RequirementDefinition>, ResponseFormat> getMappedRequirementData(String inputJson, User user,
- ComponentTypeEnum componentTypeEnum){
- Either<UiComponentDataTransfer, ResponseFormat> mappedData = getComponentsUtils()
- .convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class,
- AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
- Optional<List<RequirementDefinition>> requirementDefinitionList = mappedData.left().value()
- .getRequirements().values().stream().findFirst();
- return requirementDefinitionList.<Either<List<RequirementDefinition>, ResponseFormat>>
- map(Either::left).orElseGet(() -> Either.right(getComponentsUtils()
- .getResponseFormat(ActionStatus.GENERAL_ERROR)));
- }
-}
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.RequirementBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.Optional;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@OpenAPIDefinition(info = @Info(title = "Requirement Servlet", description = "Requirement Servlet"))
+@Controller
+public class RequirementServlet extends AbstractValidationsServlet {
+ private static final Logger LOGGER = Logger.getLogger(RequirementServlet.class);
+ private final RequirementBusinessLogic requirementBusinessLogic;
+
+ @Inject
+ public RequirementServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ RequirementBusinessLogic requirementBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.requirementBusinessLogic = requirementBusinessLogic;
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/requirements")
+ @Operation(description = "Create requirements on resource", method = "POST",
+ summary = "Create requirements on resource",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create requirements"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "requirement already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createRequirementsOnResource(
+ @Parameter(description = "Requirement to create", required = true) String data,
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return createOrUpdate(data, "resources" , resourceId, request,
+ userId, false, "createRequirements");
+ }
+
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/requirements")
+ @Operation(description = "Update Requirements on resource", method = "PUT",
+ summary = "Update Requirements on resource", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update Requirements"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateRequirementsOnResource(
+ @Parameter(description = "Requirements to update", required = true) String data,
+ @Parameter(description = "Component Id") @PathParam("resourceId") String resourceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return createOrUpdate(data, "resources", resourceId, request,
+ userId, true, "updateRequirements");
+ }
+
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/requirements/{requirementId}")
+ @Operation(description = "Get Requirement from resource", method = "GET",
+ summary = "GET Requirement from resource", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "GET requirement"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getRequirementsFromResource(
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @Parameter(description = "Requirement Id") @PathParam("requirementId") String requirementId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return get(requirementId, resourceId, request, userId);
+ }
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/resources/{resourceId}/requirements/{requirementId}")
+ @Operation(description = "Delete requirements from resource", method = "DELETE",
+ summary = "Delete requirements from resource", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete requirement"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteRequirementsFromResource(
+ @Parameter(description = "Resource Id") @PathParam("resourceId") String resourceId,
+ @Parameter(description = "requirement Id") @PathParam("requirementId") String requirementId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return delete(requirementId, resourceId, request, userId);
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/requirements")
+ @Operation(description = "Create requirements on service", method = "POST",
+ summary = "Create requirements on service", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Requirements"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Requirement already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createRequirementsOnService(
+ @Parameter(description = "Requirements to create", required = true) String data,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return createOrUpdate(data, "services" , serviceId, request, userId,
+ false , "createRequirements");
+ }
+
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/requirements")
+ @Operation(description = "Update requirements on service", method = "PUT",
+ summary = "Update requirements on service", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Update requirements"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateRequirementsOnService(
+ @Parameter(description = "Requirements to update", required = true) String data,
+ @Parameter(description = "Component Id") @PathParam("serviceId") String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return createOrUpdate(data, "services", serviceId, request, userId,
+ true, "updateRequirements");
+ }
+
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/requirements/{requirementId}")
+ @Operation(description = "Get requirement from service", method = "GET",
+ summary = "GET requirement from service", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "GET Requirements"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getRequirementsOnService(
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Requirement Id") @PathParam("requirementId") String requirementId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ return get(requirementId, serviceId, request, userId);
+ }
+
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/services/{serviceId}/requirements/{requirementId}")
+ @Operation(description = "Delete requirement from service", method = "DELETE",
+ summary = "Delete requirement from service", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = RequirementDefinition.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Requirements"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteRequirementsOnService(
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Requirement Id") @PathParam("requirementId") String requirementId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ return delete(requirementId, serviceId, request, userId);
+ }
+
+
+ private Response createOrUpdate (String data, String componentType, String componentId,
+ HttpServletRequest request, String userId,
+ boolean isUpdate, String errorContext) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ LOGGER.debug("Start create or update request of {} with modifier id {}", url, userId);
+
+ try {
+ String componentIdLower = componentId.toLowerCase();
+
+ Either<List<RequirementDefinition>, ResponseFormat> mappedRequirementDataEither =
+ getMappedRequirementData(data, modifier, ComponentTypeEnum.findByParamName(componentType));
+ if(mappedRequirementDataEither.isRight()) {
+ LOGGER.error("Failed to create or update requirements");
+ return buildErrorResponse(mappedRequirementDataEither.right().value());
+ }
+ List<RequirementDefinition> mappedRequirementData = mappedRequirementDataEither.left().value();
+ Either<List<RequirementDefinition>, ResponseFormat> actionResponse;
+ if(isUpdate) {
+ actionResponse = requirementBusinessLogic.updateRequirements(componentIdLower, mappedRequirementData, modifier,
+ errorContext, true);
+ } else {
+ actionResponse = requirementBusinessLogic.createRequirements(componentIdLower, mappedRequirementData, modifier,
+ errorContext, true);
+ }
+
+ if (actionResponse.isRight()) {
+ LOGGER.error("Failed to create or update requirements");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("requirements create or update");
+ LOGGER.error("Failed to create or update requirements with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Response get (String requirementIdToGet, String componentId,
+ HttpServletRequest request, String userId){
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ LOGGER.debug("Start get request of {} with modifier id {}", url, userId);
+
+ try {
+ String componentIdLower = componentId.toLowerCase();
+
+ Either<RequirementDefinition, ResponseFormat> actionResponse = requirementBusinessLogic
+ .getRequirement(componentIdLower, requirementIdToGet, modifier, true);
+ if (actionResponse.isRight()) {
+ LOGGER.error("failed to get requirements");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object result = RepresentationUtils.toFilteredRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get requirements");
+ LOGGER.error("get requirements failed with exception", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Response delete (String requirementId, String componentId, HttpServletRequest
+ request, String userId){
+ String url = request.getMethod() + " " + request.getRequestURI();
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ LOGGER.debug("Start delete request of {} with modifier id {}", url, userId);
+
+ try {
+ String componentIdLower = componentId.toLowerCase();
+
+ Either<RequirementDefinition, ResponseFormat> actionResponse = requirementBusinessLogic
+ .deleteRequirement(componentIdLower, requirementId, modifier, true);
+ if (actionResponse.isRight()) {
+ LOGGER.error("failed to delete requirements");
+ return buildErrorResponse(actionResponse.right().value());
+ }
+ Object result = RepresentationUtils.toRepresentation(actionResponse.left().value());
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete requirements");
+ LOGGER.error("Delete requirements failed with an error", e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Either<List<RequirementDefinition>, ResponseFormat> getMappedRequirementData(String inputJson, User user,
+ ComponentTypeEnum componentTypeEnum){
+ Either<UiComponentDataTransfer, ResponseFormat> mappedData = getComponentsUtils()
+ .convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class,
+ AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
+ Optional<List<RequirementDefinition>> requirementDefinitionList = mappedData.left().value()
+ .getRequirements().values().stream().findFirst();
+ return requirementDefinitionList.<Either<List<RequirementDefinition>, ResponseFormat>>
+ map(Either::left).orElseGet(() -> Either.right(getComponentsUtils()
+ .getResponseFormat(ActionStatus.GENERAL_ERROR)));
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java
deleted file mode 100644
index efbf730d3a..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/RequirementsServlet.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-public class RequirementsServlet extends BeGenericServlet {
-
- private static final Logger log = Logger.getLogger(RequirementsServlet.class);
-
- @Inject
- public RequirementsServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils) {
- super(userBusinessLogic, componentsUtils);
- }
-
- @PUT
- @Path("resources/{resourceId}/requirements/{requirementId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Resource Requirement", method = "PUT", summary = "Returns updated requirement", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource requirement updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateRequirement(
- @Parameter(description = "resource id to update with new requirement",
- required = true) @PathParam("resourceId") final String resourceId,
- @Parameter(description = "requirement id to update",
- required = true) @PathParam("requirementId") final String requirementId,
- @Parameter(description = "Resource property to update", required = true) String requirementData,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- // Convert RequirementDefinition from JSON
- // TODO: it's going to be another object, probably. This is placeholder
- // for sake of JSON validation
- // RequirementDefinition requirementDefinition;
- ResponseFormat responseFormat;
- try {
- // TODO pass real entity
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
- } catch (Exception e) {
- log.debug("Unexpected error: ", e);
- responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java
deleted file mode 100644
index 932dc51214..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceArtifactDownloadServlet.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import org.apache.http.HttpStatus;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
-import org.openecomp.sdc.be.info.ArtifactAccessInfo;
-import org.openecomp.sdc.be.resources.api.IResourceUploader;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog/resources/available")
-public class ResourceArtifactDownloadServlet extends ToscaDaoServlet {
-
- private static final Logger log = Logger.getLogger(ResourceArtifactDownloadServlet.class);
-
- public ResourceArtifactDownloadServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- IResourceUploader resourceUploader, DownloadArtifactLogic logic) {
- super(userBusinessLogic, componentsUtils, resourceUploader, logic);
- }
-
- @GET
- @Path("/{resourceName}/{resourceVersion}/artifacts/{artifactName}")
- // @Produces(MediaType.APPLICATION_OCTET_STREAM)
- public Response getResourceArtifactByName(@PathParam("resourceName") final String resourceName, @PathParam("resourceVersion") final String resourceVersion, @PathParam("artifactName") final String artifactName,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- Response response = null;
- try {
- // get the artifact data
- String artifactId = String.format(Constants.ARTIFACT_ID_FORMAT, resourceName, resourceVersion, artifactName);
-
- Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = resourceUploader.getArtifact(artifactId);
-
- response = logic.downloadArtifact(artifactName, getArtifactStatus, artifactId);
-
- log.info("Finish handle request of {} | result = {}", url, response.getStatus());
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource Artifact By Name");
- log.debug("getResourceArtifactByName failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- @GET
- @Path("/{resourceName}/{resourceVersion}/artifacts/{artifactName}/metadata")
- @Produces(MediaType.APPLICATION_JSON)
- public Response getResourceArtifactMetadata(@PathParam("resourceName") final String resourceName, @PathParam("resourceVersion") final String resourceVersion, @PathParam("artifactName") final String artifactName,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- Response response = null;
- try {
-
- String artifactId = String.format(Constants.ARTIFACT_ID_FORMAT, resourceName, resourceVersion, artifactName);
- Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = resourceUploader.getArtifact(artifactId);
-
- if (getArtifactStatus.isRight()) {
- ResourceUploadStatus status = getArtifactStatus.right().value();
- if (status == ResourceUploadStatus.COMPONENT_NOT_EXIST) {
- response = Response.status(HttpStatus.SC_NOT_FOUND).build();
- log.debug("Could not find artifact for with id: {}", artifactId);
- } else {
- response = Response.status(HttpStatus.SC_NO_CONTENT).build();
- log.debug("Could not find artifact for with id: {}", artifactId);
- }
- return response;
- } else {
- ESArtifactData artifactData = getArtifactStatus.left().value();
- log.debug("found artifact with id: {}", artifactId);
- ArtifactAccessInfo artifactInfo = new ArtifactAccessInfo(artifactData);
- String artifactDataJson = gson.toJson(artifactInfo);
- response = Response.status(HttpStatus.SC_OK).entity(artifactDataJson).type(MediaType.APPLICATION_JSON_TYPE).build();
-
- log.info("Finish handle request of {} | result = {}", url, response.getStatus());
- return response;
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource Artifact Metadata");
- log.debug("getResourceArtifactMetadata failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
-
- }
-
- @Override
- public Logger getLogger() {
- return log;
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
index bfd7ce720a..303b0104e9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceUploadServlet.java
@@ -20,27 +20,23 @@
package org.openecomp.sdc.be.servlets;
-import java.io.File;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
import org.openecomp.sdc.be.model.UploadResourceInfo;
@@ -49,23 +45,32 @@ import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import com.jcabi.aspects.Loggable;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.openecomp.sdc.common.zip.exception.ZipException;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.FileNotFoundException;
+
/**
* Root resource (exposed at "/" path)
*/
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog/upload")
@OpenAPIDefinition(info = @Info(title = "Resources Catalog Upload", description = "Upload resource yaml"))
-@Singleton
+@Controller
public class ResourceUploadServlet extends AbstractValidationsServlet {
private static final Logger log = Logger.getLogger(ResourceUploadServlet.class);
@@ -83,9 +88,7 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
}
public enum ResourceAuthorityTypeEnum {
- NORMATIVE_TYPE_BE(NORMATIVE_TYPE_RESOURCE, true, false), USER_TYPE_BE(USER_TYPE_RESOURCE, true,
- true), USER_TYPE_UI(USER_TYPE_RESOURCE_UI_IMPORT, false,
- true), CSAR_TYPE_BE(CSAR_TYPE_RESOURCE, true, true);
+ NORMATIVE_TYPE_BE(NORMATIVE_TYPE_RESOURCE, true, false), USER_TYPE_BE(USER_TYPE_RESOURCE, true, true), USER_TYPE_UI(USER_TYPE_RESOURCE_UI_IMPORT, false, true), CSAR_TYPE_BE(CSAR_TYPE_RESOURCE, true, true);
private String urlPath;
private boolean isBackEndImport, isUserTypeResource;
@@ -131,6 +134,7 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
@ApiResponse(responseCode = "409", description = "Resource already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadMultipart(
@Parameter(description = "validValues: normative-resource / user-resource",
schema = @Schema(allowableValues = {NORMATIVE_TYPE_RESOURCE ,
@@ -141,7 +145,7 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
@Parameter(description = "resourceMetadata") @FormDataParam("resourceMetadata") String resourceInfoJsonString,
@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
// updateResourse Query Parameter if false checks if already exist
- @DefaultValue("true") @QueryParam("createNewVersion") boolean createNewVersion) {
+ @DefaultValue("true") @QueryParam("createNewVersion") boolean createNewVersion) throws FileNotFoundException, ZipException {
try {
@@ -164,7 +168,7 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
fillPayload(responseWrapper, uploadResourceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), resourceInfoJsonString, resourceAuthorityEnum, file);
// PayLoad Validations
- if(!resourceAuthorityEnum.equals(ResourceAuthorityTypeEnum.CSAR_TYPE_BE)){
+ if(resourceAuthorityEnum != ResourceAuthorityTypeEnum.CSAR_TYPE_BE){
commonPayloadValidations(responseWrapper, yamlStringWrapper, userWrapper.getInnerElement(), uploadResourceInfoWrapper.getInnerElement());
specificResourceAuthorityValidations(responseWrapper, uploadResourceInfoWrapper, yamlStringWrapper, userWrapper.getInnerElement(), request, resourceInfoJsonString, resourceAuthorityEnum);
@@ -179,7 +183,7 @@ public class ResourceUploadServlet extends AbstractValidationsServlet {
} catch (Exception e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Upload Resource");
log.debug("upload resource failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw e;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java
index fd1fe221ac..6ecc8d69e7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourcesServlet.java
@@ -22,7 +22,15 @@ package org.openecomp.sdc.be.servlets;
import com.jcabi.aspects.Loggable;
import fj.data.Either;
-import javax.inject.Inject;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.apache.http.HttpStatus;
import org.json.JSONException;
import org.json.JSONObject;
@@ -31,6 +39,8 @@ import org.openecomp.sdc.be.components.impl.CsarValidationUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
@@ -46,22 +56,27 @@ import org.openecomp.sdc.be.servlets.ResourceUploadServlet.ResourceAuthorityType
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-import javax.inject.Singleton;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -72,10 +87,13 @@ import java.util.Map;
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog")
@OpenAPIDefinition(info = @Info(title = "Resources Catalog", description = "Resources Servlet"))
-@Singleton
+@Controller
public class ResourcesServlet extends AbstractValidationsServlet {
private static final Logger log = Logger.getLogger(ResourcesServlet.class);
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ResourcesServlet.class.getName());
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final String MODIFIER_ID_IS = "modifier id is {}";
private final ResourceBusinessLogic resourceBusinessLogic;
@Inject
@@ -99,20 +117,20 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
@ApiResponse(responseCode = "409", description = "Resource already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response createResource(@Parameter(description = "Resource object to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException, ZipException {
userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER);
init();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
-
+ log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
User modifier = new User();
modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
+ log.debug(MODIFIER_ID_IS, userId);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE, StatusCode.STARTED,"Starting to create Resource by user {}",userId);
Response response;
try {
@@ -136,13 +154,13 @@ public class ResourcesServlet extends AbstractValidationsServlet {
Object representation = RepresentationUtils.toRepresentation(createdResource);
response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), representation);
responseWrapper.setInnerElement(response);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RESOURCE,resource.getComponentMetadataForSupportLog() ,StatusCode.COMPLETE,"Resource successfully created user {}",userId);
}
return responseWrapper.getInnerElement();
} catch (final IOException | ZipException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Resource");
log.debug("create resource failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
+ throw e;
}
}
@@ -198,19 +216,17 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@DELETE
@Path("/resources/{resourceId}")
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response deleteResource(@PathParam("resourceId") final String resourceId, @Context final HttpServletRequest request) {
- ServletContext context = request.getSession().getServletContext();
-
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
-
+ log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
String userId = request.getHeader(Constants.USER_ID_HEADER);
User modifier = new User();
modifier.setUserId(userId);
- log.debug("modifier id is {}" , userId);
-
+ log.debug(MODIFIER_ID_IS, userId);
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_RESOURCE ,StatusCode.STARTED,"Starting to delete Resource by user {}",userId);
Response response;
try {
@@ -223,34 +239,41 @@ public class ResourcesServlet extends AbstractValidationsServlet {
return response;
}
response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_RESOURCE ,StatusCode.COMPLETE,"Ended delete Resource by user {}",userId);
return response;
} catch (JSONException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Resource");
log.debug("delete resource failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
+ throw e;
}
}
@DELETE
@Path("/resources/{resourceName}/{version}")
+ @Operation(description = "Delete Resource By Name And Version", method = "DELETE", summary = "Returns no content", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = { @ApiResponse(responseCode = "204", description = "Resource deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Resource not found") })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response deleteResourceByNameAndVersion(@PathParam("resourceName") final String resourceName, @PathParam("version") final String version, @Context final HttpServletRequest request) {
ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
String userId = request.getHeader(Constants.USER_ID_HEADER);
User modifier = new User();
modifier.setUserId(userId);
- log.debug("modifier id is {}" , userId);
+ log.debug(MODIFIER_ID_IS, userId);
Response response;
- ResponseFormat actionResponse = resourceBusinessLogic.deleteResourceByNameAndVersion(resourceName, version, modifier);
+ ResourceBusinessLogic businessLogic = getResourceBL(context);
+ ResponseFormat actionResponse = businessLogic.deleteResourceByNameAndVersion(resourceName, version, modifier);
if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
log.debug("failed to delete resource");
@@ -271,18 +294,19 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource found"),
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "404", description = "Resource not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getResourceById(@PathParam("resourceId") final String resourceId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
User modifier = new User();
modifier.setUserId(userId);
- log.debug("modifier id is {}" , userId);
+ log.debug(MODIFIER_ID_IS, userId);
Response response;
@@ -302,8 +326,7 @@ public class ResourcesServlet extends AbstractValidationsServlet {
} catch (IOException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource");
log.debug("get resource failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
+ throw e;
}
}
@@ -317,15 +340,15 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource found"),
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "404", description = "Resource not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getResourceByNameAndVersion(@PathParam("resourceName") final String resourceName,
- @PathParam("resourceVersion") final String resourceVersion, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @PathParam("resourceVersion") final String resourceVersion, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
- ServletContext context = request.getSession().getServletContext();
// get modifier id
User modifier = new User();
modifier.setUserId(userId);
- log.debug("modifier id is {}" , userId);
+ log.debug(MODIFIER_ID_IS, userId);
Response response;
try {
Either<Resource, ResponseFormat> actionResponse = resourceBusinessLogic.getResourceByNameAndVersion(resourceName, resourceVersion, userId);
@@ -339,8 +362,7 @@ public class ResourcesServlet extends AbstractValidationsServlet {
} catch (IOException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource by name and version");
log.debug("get resource failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
+ throw e;
}
}
@@ -353,17 +375,17 @@ public class ResourcesServlet extends AbstractValidationsServlet {
content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource found"),
@ApiResponse(responseCode = "403", description = "Restricted operation")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response validateResourceName(@PathParam("resourceName") final String resourceName,
@QueryParam("subtype") String resourceType, @Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
User modifier = new User();
modifier.setUserId(userId);
- log.debug("modifier id is {}" , userId);
+ log.debug(MODIFIER_ID_IS, userId);
Response response;
if (resourceType != null && !ResourceTypeEnum.containsName(resourceType)) {
@@ -390,7 +412,8 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@Path("/resources/certified/abstract")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Response getCertifiedAbstractResources(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getCertifiedAbstractResources(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("(get) Start handle request of {}" , url);
try {
@@ -401,7 +424,7 @@ public class ResourcesServlet extends AbstractValidationsServlet {
} catch (IOException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Certified Abstract Resources");
log.debug("getCertifiedAbstractResources failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw e;
}
}
@@ -409,7 +432,8 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@Path("/resources/certified/notabstract")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Response getCertifiedNotAbstractResources(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getCertifiedNotAbstractResources(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("(get) Start handle request of {}" , url);
try {
@@ -419,7 +443,7 @@ public class ResourcesServlet extends AbstractValidationsServlet {
} catch (IOException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Certified Non Abstract Resources");
log.debug("getCertifiedNotAbstractResources failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ throw e;
}
}
@@ -434,17 +458,18 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource metadata updated"),
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "400", description = "Invalid content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response updateResourceMetadata(@PathParam("resourceId") final String resourceId,
@Parameter(description = "Resource metadata to be updated", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}" , url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
User modifier = new User();
modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
+ log.debug(MODIFIER_ID_IS, userId);
Response response;
try {
String resourceIdLower = resourceId.toLowerCase();
@@ -460,9 +485,7 @@ public class ResourcesServlet extends AbstractValidationsServlet {
} catch (IOException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource Metadata");
log.debug("Update Resource Metadata failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
+ throw e;
}
}
@@ -477,19 +500,21 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
@ApiResponse(responseCode = "409", description = "Resource already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response updateResource(
@Parameter(description = "Resource object to be updated", required = true) String data,
@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @PathParam(value = "resourceId") String resourceId) {
+ @PathParam(value = "resourceId") String resourceId) throws IOException, ZipException {
userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER);
init();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
// get modifier id
User modifier = new User();
modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
+ log.debug(MODIFIER_ID_IS, userId);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_RESOURCE,StatusCode.STARTED,"Starting to update a resource by user {}",userId);
Response response;
try {
Wrapper<Response> responseWrapper = new Wrapper<>();
@@ -503,19 +528,18 @@ public class ResourcesServlet extends AbstractValidationsServlet {
response = buildErrorResponse(convertResponse.right().value());
return response;
}
- Resource updatedResource = resourceBusinessLogic.validateAndUpdateResourceFromCsar(
- convertResponse.left().value(), modifier, null, null, resourceId);
+ Resource updatedResource = resourceBusinessLogic.validateAndUpdateResourceFromCsar(convertResponse.left().value(), modifier, null, null, resourceId);
Object representation = RepresentationUtils.toRepresentation(updatedResource);
response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation);
responseWrapper.setInnerElement(response);
+ loggerSupportability.log(LoggerSupportabilityActions.UPDATE_RESOURCE,updatedResource.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"Ended update a resource by user {}",userId);
+
}
return responseWrapper.getInnerElement();
} catch (final IOException | ZipException e) {
BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Resource");
log.debug("update resource failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
+ throw e;
}
}
@@ -529,14 +553,15 @@ public class ResourcesServlet extends AbstractValidationsServlet {
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Resource retrieced"),
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response getResourceFromCsar(@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
- @PathParam(value = "csaruuid") String csarUUID) {
+ @PathParam(value = "csaruuid") String csarUUID) throws IOException {
init();
String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
+ log.debug(START_HANDLE_REQUEST_OF, url);
// retrieve user details
userId = (userId != null) ? userId : request.getHeader(Constants.USER_ID_HEADER);
@@ -555,8 +580,7 @@ public class ResourcesServlet extends AbstractValidationsServlet {
// validate response
if (eitherResource.isRight()) {
log.debug("failed to get resource from csarUuid : {}", csarUUID);
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- eitherResource.right().value());
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), eitherResource.right().value());
} else {
Object representation = RepresentationUtils.toRepresentation(eitherResource.left().value());
response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation);
@@ -566,8 +590,7 @@ public class ResourcesServlet extends AbstractValidationsServlet {
} catch (IOException e) {
log.debug("get resource by csar failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
+ throw e;
}
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java
index 3ffef17fbb..d438784122 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceConsumptionServlet.java
@@ -1,261 +1,273 @@
-/*
- * Copyright © 2016-2018 European Support Limited
- *
- * 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.
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-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.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.StringUtils;
-import org.json.simple.JSONArray;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.OperationInput;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.types.ServiceConsumptionData;
-import org.openecomp.sdc.be.types.ServiceConsumptionSource;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import com.google.gson.Gson;
-import com.google.gson.JsonParseException;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Service Consumption Servlet", description = "Service Consumption Servlet"))
-@Singleton
-public class ServiceConsumptionServlet extends BeGenericServlet {
-
- private static final Logger log = LoggerFactory.getLogger(ServiceConsumptionServlet.class);
- private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
- private final ServiceBusinessLogic serviceBusinessLogic;
-
- @Inject
- public ServiceConsumptionServlet(UserBusinessLogic userBusinessLogic, ComponentsUtils componentsUtils,
- InterfaceOperationBusinessLogic interfaceOperationBusinessLogic,
- ServiceBusinessLogic serviceBusinessLogic) {
- super(userBusinessLogic, componentsUtils);
- this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
- this.serviceBusinessLogic = serviceBusinessLogic;
- }
-
- @POST
- @Path("/services/{serviceId}/consumption/{serviceInstanceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @io.swagger.v3.oas.annotations.Operation(description = "Service consumption on operation", method = "POST",
- summary = "Returns consumption data", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service property created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Service property already exist")})
- public Response addInputToServiceOperation(@PathParam("serviceId") final String serviceId,
- @PathParam("serviceInstanceId") final String serviceInstanceId,
- @Parameter(description = "Service Consumption Data", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- ServletContext context = request.getSession().getServletContext();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
- User modifier = new User();
- modifier.setUserId(userId);
-
- try {
-
- Either<Map<String, List<ServiceConsumptionData>>, ResponseFormat> dataFromJson =
- getServiceConsumptionData(data, modifier);
- if (dataFromJson.isRight()) {
- return buildErrorResponse(dataFromJson.right().value());
- }
-
- Map<String, List<ServiceConsumptionData>> serviceConsumptionDataMap = dataFromJson.left().value();
-
- for (Entry<String, List<ServiceConsumptionData>> consumptionEntry : serviceConsumptionDataMap.entrySet()) {
- List<ServiceConsumptionData> consumptionList = consumptionEntry.getValue();
- Either<List<Operation>, ResponseFormat> operationEither =
- serviceBusinessLogic.addServiceConsumptionData(serviceId, serviceInstanceId,
- consumptionEntry.getKey(), consumptionList, userId);
- if (operationEither.isRight()) {
- return buildErrorResponse(operationEither.right().value());
- }
- }
-
- return buildOkResponse(serviceConsumptionDataMap);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Operation Inputs");
- log.debug("Create Operation Inputs failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
-
- }
-
- @GET
- @Path("/services/{serviceId}/consumption/{serviceInstanceId}/interfaces/{interfaceId}/operations/{operationId}/inputs")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response getInputsListOfOperation(@PathParam("serviceId") final String serviceId,
- @PathParam("serviceInstanceId") final String serviceInstanceId,
- @PathParam("interfaceId") final String interfaceId, @PathParam("operationId") final String operationId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} modifier id is {}", url, userId);
- User user = new User();
- user.setUserId(userId);
-
- try {
- Either<List<OperationInputDefinition>, ResponseFormat> inputsEither = interfaceOperationBusinessLogic
- .getInputsListForOperation(serviceId, serviceInstanceId, interfaceId, operationId, user);
-
- if (inputsEither.isRight()) {
- return buildErrorResponse(inputsEither.right().value());
- }
-
- List<OperationInputDefinition> inputs = inputsEither.left().value();
- return buildOkResponse(updateOperationInputListForUi(inputs, interfaceOperationBusinessLogic));
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Operation Inputs");
- log.debug("Get Operation Inputs failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
-
- private List<OperationInput> updateOperationInputListForUi(List<OperationInputDefinition> inputsList,
- InterfaceOperationBusinessLogic interfaceOperationBL) {
- List<OperationInput> operationInputs = new ArrayList<>();
- for (OperationInputDefinition input : inputsList) {
-
- String value = input.getValue();
-
- // Additional UI mapping needed for other sources
- if (StringUtils.isNotBlank(value)
- && !ServiceConsumptionSource.STATIC.getSource().equals(input.getSource())) {
- uiMappingForOtherSources(value, input);
- }
-
- // Add Constraint for UI
- OperationInput operationInput = new OperationInput(input);
- operationInput.setConstraints(interfaceOperationBL.setInputConstraint(input));
- operationInputs.add(operationInput);
- }
-
- return operationInputs;
- }
-
- private void uiMappingForOtherSources(String value, OperationInputDefinition input) {
- try {
- Map<String, Object> valueAsMap = (new Gson()).fromJson(value, Map.class);
- String toscaFunction = valueAsMap.keySet().iterator().next();
- Object consumptionValueName = valueAsMap.values().iterator().next();
- if (consumptionValueName instanceof List) {
- List<Object> toscaFunctionList = (List<Object>) consumptionValueName;
- String consumptionInputValue = null;
- if (ToscaFunctions.GET_PROPERTY.getFunctionName().equals(toscaFunction)) {
- String propertyValue = toscaFunctionList.stream().map(Object::toString)
- .filter(val -> !val.equals(SELF)).collect(Collectors.joining("_"));
- consumptionInputValue = String.valueOf(propertyValue);
- } else if (ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName().equals(toscaFunction)) {
- // Return full output name
- consumptionInputValue =
- toscaFunctionList.get(1) + "." + toscaFunctionList.get(2) + "." + toscaFunctionList.get(3);
- }
- input.setValue(consumptionInputValue);
- } else {
- input.setValue(String.valueOf(consumptionValueName));
- }
- } catch (JsonParseException ex) {
- log.info("This means it is static value for which no changes are needed");
- }
- }
-
- private Either<Map<String, List<ServiceConsumptionData>>, ResponseFormat> getServiceConsumptionData(String data,
- User user) {
- JSONParser parser = new JSONParser();
- Map<String, List<ServiceConsumptionData>> serviceConsumptionDataMap = new HashMap<>();
-
- try {
- JSONArray operationsArray = (JSONArray) parser.parse(data);
- Iterator iterator = operationsArray.iterator();
- while (iterator.hasNext()) {
- Map next = (Map) iterator.next();
- Entry consumptionEntry = (Entry) next.entrySet().iterator().next();
- String operationId = (String) consumptionEntry.getKey();
- Object value = consumptionEntry.getValue();
-
- JSONArray inputsArray = (JSONArray) parser.parse(value.toString());
- serviceConsumptionDataMap.putIfAbsent(operationId, new ArrayList<>());
- for (Object consumptionObject : inputsArray) {
- Either<ServiceConsumptionData, ResponseFormat> serviceDataEither =
- getComponentsUtils().convertJsonToObjectUsingObjectMapper(consumptionObject.toString(),
- user, ServiceConsumptionData.class, AuditingActionEnum.CREATE_RESOURCE,
- ComponentTypeEnum.SERVICE);
- if (serviceDataEither.isRight()) {
- return Either.right(serviceDataEither.right().value());
- }
-
- serviceConsumptionDataMap.get(operationId).add(serviceDataEither.left().value());
- }
- }
- } catch (ParseException e) {
- log.info("Conetnt is invalid - {}", data);
- return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- return Either.left(serviceConsumptionDataMap);
- }
-}
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * 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.
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonParseException;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.StringUtils;
+import org.json.simple.JSONArray;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Operation;
+import org.openecomp.sdc.be.model.OperationInput;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.types.ServiceConsumptionData;
+import org.openecomp.sdc.be.types.ServiceConsumptionSource;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil.SELF;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Service Consumption Servlet", description = "Service Consumption Servlet"))
+@Singleton
+public class ServiceConsumptionServlet extends BeGenericServlet {
+
+ private static final Logger log = LoggerFactory.getLogger(ServiceConsumptionServlet.class);
+ private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+ private final ServiceBusinessLogic serviceBusinessLogic;
+
+ @Inject
+ public ServiceConsumptionServlet(UserBusinessLogic userBusinessLogic, ComponentsUtils componentsUtils,
+ InterfaceOperationBusinessLogic interfaceOperationBusinessLogic,
+ ServiceBusinessLogic serviceBusinessLogic) {
+ super(userBusinessLogic, componentsUtils);
+ this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ }
+
+ @POST
+ @Path("/services/{serviceId}/consumption/{serviceInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @io.swagger.v3.oas.annotations.Operation(description = "Service consumption on operation", method = "POST",
+ summary = "Returns consumption data", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service property created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Service property already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response addInputToServiceOperation(@PathParam("serviceId") final String serviceId,
+ @PathParam("serviceInstanceId") final String serviceInstanceId,
+ @Parameter(description = "Service Consumption Data", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
+ User modifier = new User();
+ modifier.setUserId(userId);
+
+ try {
+
+ Either<Map<String, List<ServiceConsumptionData>>, ResponseFormat> dataFromJson =
+ getServiceConsumptionData(data, modifier);
+ if(dataFromJson.isRight()) {
+ return buildErrorResponse(dataFromJson.right().value());
+ }
+
+ Map<String, List<ServiceConsumptionData>> serviceConsumptionDataMap = dataFromJson.left().value();
+
+ for(Entry<String, List<ServiceConsumptionData>> consumptionEntry : serviceConsumptionDataMap.entrySet()) {
+ List<ServiceConsumptionData> consumptionList = consumptionEntry.getValue();
+ Either<List<Operation>, ResponseFormat> operationEither =
+ serviceBusinessLogic.addServiceConsumptionData(serviceId, serviceInstanceId,
+ consumptionEntry.getKey(), consumptionList, userId);
+ if (operationEither.isRight()) {
+ return buildErrorResponse(operationEither.right().value());
+ }
+ }
+
+ return buildOkResponse(serviceConsumptionDataMap);
+
+ }
+ catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Operation Inputs");
+ log.debug("Create Operation Inputs failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+
+ }
+
+ @GET
+ @Path("/services/{serviceId}/consumption/{serviceInstanceId}/interfaces/{interfaceId}/operations/{operationId}/inputs")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getInputsListOfOperation(@PathParam("serviceId") final String serviceId,
+ @PathParam("serviceInstanceId") final String serviceInstanceId,
+ @PathParam("interfaceId") final String interfaceId, @PathParam("operationId") final String operationId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} modifier id is {}", url, userId);
+ User user = new User();
+ user.setUserId(userId);
+
+ try {
+ Either<List<OperationInputDefinition>, ResponseFormat> inputsEither =
+ interfaceOperationBusinessLogic.getInputsListForOperation(serviceId, serviceInstanceId, interfaceId, operationId, user);
+
+ if(inputsEither.isRight()) {
+ return buildErrorResponse(inputsEither.right().value());
+ }
+
+ List<OperationInputDefinition> inputs = inputsEither.left().value();
+ return buildOkResponse(updateOperationInputListForUi(inputs, interfaceOperationBusinessLogic));
+ }
+ catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Operation Inputs");
+ log.debug("Get Operation Inputs failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+
+ private List<OperationInput> updateOperationInputListForUi(List<OperationInputDefinition> inputsList,
+ InterfaceOperationBusinessLogic interfaceOperationBL) {
+ List<OperationInput> operationInputs = new ArrayList<>();
+ for(OperationInputDefinition input : inputsList) {
+
+ String value = input.getValue();
+
+ // Additional UI mapping needed for other sources
+ if (StringUtils.isNotBlank(value)
+ && !ServiceConsumptionSource.STATIC.getSource().equals(input.getSource())) {
+ uiMappingForOtherSources(value, input);
+ }
+
+ // Add Constraint for UI
+ OperationInput operationInput = new OperationInput(input);
+ operationInput.setConstraints(interfaceOperationBL.setInputConstraint(input));
+ operationInputs.add(operationInput);
+ }
+
+ return operationInputs;
+ }
+
+ private void uiMappingForOtherSources(String value, OperationInputDefinition input) {
+ try {
+ Map<String, Object> valueAsMap = (new Gson()).fromJson(value, Map.class);
+ String toscaFunction = valueAsMap.keySet().iterator().next();
+ Object consumptionValueName = valueAsMap.values().iterator().next();
+ if(consumptionValueName instanceof List) {
+ List<Object> toscaFunctionList = (List<Object>) consumptionValueName;
+ String consumptionInputValue = null;
+ if (ToscaFunctions.GET_PROPERTY.getFunctionName().equals(toscaFunction)) {
+ String propertyValue = toscaFunctionList.stream()
+ .map(Object::toString)
+ .filter(val -> !val.equals(SELF))
+ .collect(Collectors.joining("_"));
+ consumptionInputValue = String.valueOf(propertyValue);
+ } else if (ToscaFunctions.GET_OPERATION_OUTPUT.getFunctionName().equals(toscaFunction)) {
+ //Return full output name
+ consumptionInputValue =
+ toscaFunctionList.get(1) + "." + toscaFunctionList.get(2) + "." +toscaFunctionList.get(3);
+ }
+ input.setValue(consumptionInputValue);
+ } else {
+ input.setValue(String.valueOf(consumptionValueName));
+ }
+ }
+ catch(JsonParseException ex){
+ log.info("This means it is static value for which no changes are needed");
+ }
+ }
+
+ private Either<Map<String, List<ServiceConsumptionData>>, ResponseFormat> getServiceConsumptionData(String data,
+ User user) {
+ JSONParser parser = new JSONParser();
+ Map<String, List<ServiceConsumptionData>> serviceConsumptionDataMap = new HashMap<>();
+
+ try {
+ JSONArray operationsArray = (JSONArray) parser.parse(data);
+ Iterator iterator = operationsArray.iterator();
+ while (iterator.hasNext()) {
+ Map next = (Map) iterator.next();
+ Entry consumptionEntry = (Entry) next.entrySet().iterator().next();
+ String operationId = (String) consumptionEntry.getKey();
+ Object value = consumptionEntry.getValue();
+
+ JSONArray inputsArray = (JSONArray) parser.parse(value.toString());
+ serviceConsumptionDataMap.putIfAbsent(operationId, new ArrayList<>());
+ for(Object consumptionObject : inputsArray) {
+ Either<ServiceConsumptionData, ResponseFormat> serviceDataEither =
+ getComponentsUtils()
+ .convertJsonToObjectUsingObjectMapper(consumptionObject.toString(), user, ServiceConsumptionData
+ .class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ if(serviceDataEither.isRight()) {
+ return Either.right(serviceDataEither.right().value());
+ }
+
+ serviceConsumptionDataMap.get(operationId).add(serviceDataEither.left().value());
+ }
+ }
+ }
+ catch (ParseException e) {
+ log.info("Conetnt is invalid - {}", data);
+ return Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ return Either.left(serviceConsumptionDataMap);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java
index 7c22d62742..41082a3ea8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java
@@ -1,298 +1,304 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
-import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter;
-import org.openecomp.sdc.be.ui.model.UIConstraint;
-import org.openecomp.sdc.be.ui.model.UINodeFilter;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Path("/v1/catalog/services/{serviceId}/resourceInstances/{resourceInstanceId}/nodeFilter")
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-@OpenAPIDefinition(info = @Info(title = "Service Filter", description = "Service Filter Servlet"))
-@Singleton
-public class ServiceFilterServlet extends AbstractValidationsServlet {
-
- private static final Logger log = LoggerFactory.getLogger(ServiceFilterServlet.class);
- private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
- private static final String MODIFIER_ID_IS = "modifier id is {}";
- private static final String FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER = "failed to update or create node filter";
- private static final String FAILED_TO_PARSE_SERVICE = "failed to parse service";
- private static final String NODE_FILTER_CREATION_OR_UPDATE = "Node Filter Creation or update";
- private static final String CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR =
- "create or update node filter with an error";
- private final ServiceBusinessLogic serviceBusinessLogic;
-
- @Inject
- public ServiceFilterServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- ServiceBusinessLogic serviceBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.serviceBusinessLogic = serviceBusinessLogic;
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/")
- @Operation(description = "Add Service Filter Constraint", method = "POST", summary = "Add Service Filter Constraint",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Service Filter"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response addServiceFilterConstraint(@Parameter(description = "Service data", required = true) String data,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Resource Instance Id") @PathParam("resourceInstanceId") String ciId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
- final HttpSession session = request.getSession();
- ServletContext context = session.getServletContext();
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug(MODIFIER_ID_IS, userId);
-
- Response response;
-
- try {
- String serviceIdLower = serviceId.toLowerCase();
-
- Either<UIConstraint, ResponseFormat> convertResponse = parseToConstraint(data, modifier);
- if (convertResponse.isRight()) {
- log.debug(FAILED_TO_PARSE_SERVICE);
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
- UIConstraint uiConstraint = convertResponse.left().value();
- if (uiConstraint == null) {
- log.debug(FAILED_TO_PARSE_SERVICE);
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
- Either<CINodeFilterDataDefinition, ResponseFormat> actionResponse;
- String constraint = new ConstraintConvertor().convert(uiConstraint);
- actionResponse = serviceBusinessLogic
- .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.ADD, uiConstraint.getServicePropertyName(),
- constraint, -1, modifier, true);
-
- if (actionResponse.isRight()) {
- log.debug(FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER);
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- CINodeFilterDataDefinition value = actionResponse.left().value();
- UINodeFilter nodeFilter = new NodeFilterConverter().convertToUi(value);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), nodeFilter);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_CREATION_OR_UPDATE);
- log.debug(CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR, e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/")
- @Operation(description = "Update Service Filter Constraint", method = "PUT",
- summary = "Update Service Filter Constraint", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Service Filter"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateServiceFilterConstraint(@Parameter(description = "Service data", required = true) String data,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Resource Instance Id") @PathParam("resourceInstanceId") String ciId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug(MODIFIER_ID_IS, userId);
-
- Response response;
-
- try {
- String serviceIdLower = serviceId.toLowerCase();
-
- Either<List, ResponseFormat> convertResponse = parseToConstraints(data, modifier);
- if (convertResponse.isRight()) {
- log.debug(FAILED_TO_PARSE_SERVICE);
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
- List<Map<String,String>> uiConstraintsMaps = (List<Map<String,String>>) convertResponse.left().value();
- if (uiConstraintsMaps == null) {
- log.debug("failed to parse data");
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
- final ObjectMapper objectMapper = new ObjectMapper();
- List<UIConstraint> uiConstraints = uiConstraintsMaps.stream().map(dataMap -> objectMapper.convertValue(dataMap, UIConstraint.class)).collect(
- Collectors.toList());
- if (uiConstraints == null) {
- log.debug("failed to parse data");
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
- Either<CINodeFilterDataDefinition, ResponseFormat> actionResponse;
- List<String> constraints = new ConstraintConvertor().convertToList(uiConstraints);
- actionResponse = serviceBusinessLogic.updateServiceFilter(serviceIdLower, ciId, constraints, modifier, true);
-
- if (actionResponse.isRight()) {
- log.debug(FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER);
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- CINodeFilterDataDefinition value = actionResponse.left().value();
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- new NodeFilterConverter().convertToUi(value));
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_CREATION_OR_UPDATE);
- log.debug(CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR, e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/{constraintIndex}")
- @Operation(description = "Delete Service Filter Constraint", method = "Delete",
- summary = "Delete Service Filter Constraint", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Service Filter Constraint"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response deleteServiceFilterConstraint(
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Resource Instance Id") @PathParam("resourceInstanceId") String ciId,
- @Parameter(description = "Constraint Index") @PathParam("constraintIndex") int index,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug(MODIFIER_ID_IS, userId);
-
- Response response;
-
- try {
- String serviceIdLower = serviceId.toLowerCase();
-
- Either<CINodeFilterDataDefinition, ResponseFormat> actionResponse;
- actionResponse = serviceBusinessLogic
- .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.DELETE,
- null, null, index, modifier, true);
-
- if (actionResponse.isRight()) {
-
- log.debug(FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER);
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- final CINodeFilterDataDefinition value = actionResponse.left().value();
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- new NodeFilterConverter().convertToUi(value));
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_CREATION_OR_UPDATE);
- log.debug(CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR, e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- private Either<UIConstraint, ResponseFormat> parseToConstraint(String serviceJson, User user) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, UIConstraint.class,
- AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
- }
-
- private Either<List, ResponseFormat> parseToConstraints(String serviceJson, User user) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, List.class,
- AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.tosca.utils.NodeFilterConverter;
+import org.openecomp.sdc.be.ui.model.UIConstraint;
+import org.openecomp.sdc.be.ui.model.UINodeFilter;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Path("/v1/catalog/services/{serviceId}/resourceInstances/{resourceInstanceId}/nodeFilter")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@OpenAPIDefinition(info = @Info(title = "Service Filter", description = "Service Filter Servlet"))
+@Singleton
+public class ServiceFilterServlet extends AbstractValidationsServlet {
+
+ private static final Logger log = LoggerFactory.getLogger(ServiceFilterServlet.class);
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final String MODIFIER_ID_IS = "modifier id is {}";
+ private static final String FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER = "failed to update or create node filter";
+ private static final String FAILED_TO_PARSE_SERVICE = "failed to parse service";
+ private static final String NODE_FILTER_CREATION_OR_UPDATE = "Node Filter Creation or update";
+ private static final String CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR =
+ "create or update node filter with an error";
+ private final ServiceBusinessLogic serviceBusinessLogic;
+
+ @Inject
+ public ServiceFilterServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ ServiceBusinessLogic serviceBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/")
+ @Operation(description = "Add Service Filter Constraint", method = "POST", summary = "Add Service Filter Constraint",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Service Filter"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response addServiceFilterConstraint(@Parameter(description = "Service data", required = true) String data,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Resource Instance Id") @PathParam("resourceInstanceId") String ciId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ final HttpSession session = request.getSession();
+ ServletContext context = session.getServletContext();
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response;
+
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+
+ Either<UIConstraint, ResponseFormat> convertResponse = parseToConstraint(data, modifier);
+ if (convertResponse.isRight()) {
+ log.debug(FAILED_TO_PARSE_SERVICE);
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ UIConstraint uiConstraint = convertResponse.left().value();
+ if (uiConstraint == null) {
+ log.debug(FAILED_TO_PARSE_SERVICE);
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ Either<CINodeFilterDataDefinition, ResponseFormat> actionResponse;
+ String constraint = new ConstraintConvertor().convert(uiConstraint);
+ actionResponse = serviceBusinessLogic
+ .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.ADD, uiConstraint.getServicePropertyName(),
+ constraint, -1, modifier, true);
+
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER);
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ CINodeFilterDataDefinition value = actionResponse.left().value();
+ UINodeFilter nodeFilter = new NodeFilterConverter().convertToUi(value);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), nodeFilter);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_CREATION_OR_UPDATE);
+ log.debug(CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR, e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/")
+ @Operation(description = "Update Service Filter Constraint", method = "PUT",
+ summary = "Update Service Filter Constraint", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Create Service Filter"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateServiceFilterConstraint(@Parameter(description = "Service data", required = true) String data,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Resource Instance Id") @PathParam("resourceInstanceId") String ciId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response;
+
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+
+ Either<List, ResponseFormat> convertResponse = parseToConstraints(data, modifier);
+ if (convertResponse.isRight()) {
+ log.debug(FAILED_TO_PARSE_SERVICE);
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ List<Map<String,String>> uiConstraintsMaps = (List<Map<String,String>>) convertResponse.left().value();
+ if (uiConstraintsMaps == null) {
+ log.debug("failed to parse data");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ final ObjectMapper objectMapper = new ObjectMapper();
+ List<UIConstraint> uiConstraints = uiConstraintsMaps.stream().map(dataMap -> objectMapper.convertValue(dataMap, UIConstraint.class)).collect(
+ Collectors.toList());
+ if (uiConstraints == null) {
+ log.debug("failed to parse data");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ Either<CINodeFilterDataDefinition, ResponseFormat> actionResponse;
+ List<String> constraints = new ConstraintConvertor().convertToList(uiConstraints);
+ actionResponse = serviceBusinessLogic.updateServiceFilter(serviceIdLower, ciId, constraints, modifier, true);
+
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER);
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ CINodeFilterDataDefinition value = actionResponse.left().value();
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ new NodeFilterConverter().convertToUi(value));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_CREATION_OR_UPDATE);
+ log.debug(CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR, e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/{constraintIndex}")
+ @Operation(description = "Delete Service Filter Constraint", method = "Delete",
+ summary = "Delete Service Filter Constraint", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Delete Service Filter Constraint"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteServiceFilterConstraint(
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Resource Instance Id") @PathParam("resourceInstanceId") String ciId,
+ @Parameter(description = "Constraint Index") @PathParam("constraintIndex") int index,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response;
+
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+
+ Either<CINodeFilterDataDefinition, ResponseFormat> actionResponse;
+ actionResponse = serviceBusinessLogic
+ .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.DELETE,
+ null, null, index, modifier, true);
+
+ if (actionResponse.isRight()) {
+
+ log.debug(FAILED_TO_UPDATE_OR_CREATE_NODE_FILTER);
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ final CINodeFilterDataDefinition value = actionResponse.left().value();
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ new NodeFilterConverter().convertToUi(value));
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(NODE_FILTER_CREATION_OR_UPDATE);
+ log.debug(CREATE_OR_UPDATE_NODE_FILTER_WITH_AN_ERROR, e);
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ return response;
+
+ }
+ }
+
+ private Either<UIConstraint, ResponseFormat> parseToConstraint(String serviceJson, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, UIConstraint.class,
+ AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ }
+
+ private Either<List, ResponseFormat> parseToConstraints(String serviceJson, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, List.class,
+ AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java
index 22054f6791..36fd756191 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceForwardingPathServlet.java
@@ -1,280 +1,273 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.servlets;
-
-
-import java.util.Collections;
-import java.util.Set;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.collections.MapUtils;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
-import org.openecomp.sdc.be.ui.model.UiServiceDataTransfer;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.google.common.collect.Sets;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog/services/{serviceId}/paths")
-@Consumes(MediaType.APPLICATION_JSON)
-@Produces(MediaType.APPLICATION_JSON)
-@OpenAPIDefinition(info = @Info(title = "Service Forwarding Path", description = "Service Forwarding Path Servlet"))
-@Singleton
-public class ServiceForwardingPathServlet extends AbstractValidationsServlet {
-
- private static final Logger log = Logger.getLogger(ServiceForwardingPathServlet.class);
- private final ServiceBusinessLogic serviceBusinessLogic;
-
- @Inject
- public ServiceForwardingPathServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- ServiceBusinessLogic serviceBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.serviceBusinessLogic = serviceBusinessLogic;
- }
-
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/")
- @Operation(description = "Create Forwarding Path", method = "POST", summary = "Create Forwarding Path",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value =
- {@ApiResponse(responseCode = "201", description = "Create Forwarding Path"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Forwarding Path already exist")})
- public Response createForwardingPath(
- @Parameter(description = "Forwarding Path to create", required = true) String data,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, serviceId, request, userId, false);
- }
-
-
-
- @PUT
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/")
- @Operation(description = "Update Forwarding Path", method = "PUT", summary = "Update Forwarding Path",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value =
- {@ApiResponse(responseCode = "201", description = "Update Forwarding Path"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Forwarding Path already exist")})
- public Response updateForwardingPath(
- @Parameter(description = "Update Path to create", required = true) String data,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, serviceId, request, userId, true);
- }
-
- private Response createOrUpdate( String data, String serviceId, HttpServletRequest request, String userId, boolean isUpdate) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response;
-
- try {
- String serviceIdLower = serviceId.toLowerCase();
-
- Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
- if (convertResponse.isRight()) {
- log.debug("failed to parse service");
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
- Service updatedService = convertResponse.left().value();
- Either<Service, ResponseFormat> actionResponse ;
- if (isUpdate) {
- actionResponse = serviceBusinessLogic.updateForwardingPath(serviceIdLower, updatedService, modifier, true);
- } else {
- actionResponse = serviceBusinessLogic.createForwardingPath(serviceIdLower, updatedService, modifier, true);
- }
-
- if (actionResponse.isRight()) {
- log.debug("failed to update or create paths");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Service service = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(service);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Forward Path Creation or update");
- log.debug("create or update forwarding path with an error", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @GET
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/{forwardingPathId}")
- @Operation(description = "Get Forwarding Path", method = "GET", summary = "GET Forwarding Path",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = ForwardingPathDataDefinition.class)))))
- @ApiResponses(value =
- {@ApiResponse(responseCode = "201", description = "Get Forwarding Path"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Forwarding Path already exist")})
- public Response getForwardingPath(
- @Parameter(description = "Forwarding Path to create", required = true) String datax,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Parameter(description = "Forwarding Path Id") @PathParam("forwardingPathId") String forwardingPathId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
-
- try {
- Either<UiComponentDataTransfer, ResponseFormat> serviceResponse = serviceBusinessLogic.getComponentDataFilteredByParams(serviceId, modifier, Collections.singletonList(ComponentFieldsEnum.FORWARDING_PATHS.getValue()));
- if (serviceResponse.isRight()) {
- return buildErrorResponse(serviceResponse.right().value());
- }
-
- UiServiceDataTransfer uiServiceDataTransfer = (UiServiceDataTransfer) serviceResponse.left().value();
-
- ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
- if (!MapUtils.isEmpty(uiServiceDataTransfer.getForwardingPaths())) {
- forwardingPathDataDefinition = uiServiceDataTransfer.getForwardingPaths().get(forwardingPathId);
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toRepresentation(forwardingPathDataDefinition));
-
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Metadata");
- log.debug("update service metadata failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @DELETE
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/{forwardingPathId}")
- @Operation(description = "Delete Forwarding Path", method = "DELETE", summary = "Delete Forwarding Path",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value =
- {@ApiResponse(responseCode = "201", description = "Delete Forwarding Path"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Forwarding Path already exist")})
- public Response deleteForwardingPath(
- @Parameter(description = "Forwarding Path Id") @PathParam("forwardingPathId") String forwardingPathId,
- @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response;
-
- try {
- String serviceIdLower = serviceId.toLowerCase();
-
- Either<Set<String>, ResponseFormat> actionResponse = serviceBusinessLogic.deleteForwardingPaths(serviceIdLower, Sets.newHashSet(forwardingPathId), modifier, true);
-
- if (actionResponse.isRight()) {
- log.debug("failed to delete paths");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Set<String> deletedPaths = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(deletedPaths);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete forward paths");
- log.debug("Delete service paths with an error", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
-
- private Either<Service, ResponseFormat> parseToService(String serviceJson, User user) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, Service.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);//TODO: change sSERVICE constant
- }
-}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets;
+
+
+import com.google.common.collect.Sets;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
+import org.openecomp.sdc.be.ui.model.UiServiceDataTransfer;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Set;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog/services/{serviceId}/paths")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@OpenAPIDefinition(info = @Info(title = "Service Forwarding Path", description = "Service Forwarding Path Servlet"))
+@Controller
+public class ServiceForwardingPathServlet extends AbstractValidationsServlet {
+
+ private static final Logger log = Logger.getLogger(ServiceForwardingPathServlet.class);
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final String MODIFIER_ID_IS = "modifier id is {}";
+ private final ServiceBusinessLogic serviceBusinessLogic;
+
+ @Inject
+ public ServiceForwardingPathServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ ServiceBusinessLogic serviceBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/")
+ @Operation(description = "Create Forwarding Path", method = "POST", summary = "Create Forwarding Path",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value =
+ {@ApiResponse(responseCode = "201", description = "Create Forwarding Path"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Forwarding Path already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createForwardingPath(
+ @Parameter(description = "Forwarding Path to create", required = true) String data,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+ return createOrUpdate(data, serviceId, request, userId, false);
+ }
+
+
+
+ @PUT
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/")
+ @Operation(description = "Update Forwarding Path", method = "PUT", summary = "Update Forwarding Path",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value =
+ {@ApiResponse(responseCode = "201", description = "Update Forwarding Path"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Forwarding Path already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateForwardingPath(
+ @Parameter(description = "Update Path to create", required = true) String data,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+ return createOrUpdate(data, serviceId, request, userId, true);
+ }
+
+ private Response createOrUpdate( String data, String serviceId, HttpServletRequest request, String userId, boolean isUpdate) throws IOException {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response;
+
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+
+ Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
+ if (convertResponse.isRight()) {
+ log.debug("failed to parse service");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ Service updatedService = convertResponse.left().value();
+ Service actionResponse ;
+ if (isUpdate) {
+ actionResponse = serviceBusinessLogic.updateForwardingPath(serviceIdLower, updatedService, modifier, true);
+ } else {
+ actionResponse = serviceBusinessLogic.createForwardingPath(serviceIdLower, updatedService, modifier, true);
+ }
+
+ Service service = actionResponse;
+ Object result = RepresentationUtils.toRepresentation(service);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (IOException e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Forward Path Creation or update");
+ log.debug("create or update forwarding path with an error", e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/{forwardingPathId}")
+ @Operation(description = "Get Forwarding Path", method = "GET", summary = "GET Forwarding Path",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = ForwardingPathDataDefinition.class)))))
+ @ApiResponses(value =
+ {@ApiResponse(responseCode = "201", description = "Get Forwarding Path"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Forwarding Path already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getForwardingPath(
+ @Parameter(description = "Forwarding Path to create", required = true) String datax,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Parameter(description = "Forwarding Path Id") @PathParam("forwardingPathId") String forwardingPathId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+
+ try {
+ Either<UiComponentDataTransfer, ResponseFormat> serviceResponse = serviceBusinessLogic.getComponentDataFilteredByParams(serviceId, modifier, Collections.singletonList(ComponentFieldsEnum.FORWARDING_PATHS.getValue()));
+ if (serviceResponse.isRight()) {
+ return buildErrorResponse(serviceResponse.right().value());
+ }
+
+ UiServiceDataTransfer uiServiceDataTransfer = (UiServiceDataTransfer) serviceResponse.left().value();
+
+ ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
+ if (!MapUtils.isEmpty(uiServiceDataTransfer.getForwardingPaths())) {
+ forwardingPathDataDefinition = uiServiceDataTransfer.getForwardingPaths().get(forwardingPathId);
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), RepresentationUtils.toRepresentation(forwardingPathDataDefinition));
+
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Metadata");
+ log.debug("update service metadata failed with exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("/{forwardingPathId}")
+ @Operation(description = "Delete Forwarding Path", method = "DELETE", summary = "Delete Forwarding Path",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value =
+ {@ApiResponse(responseCode = "201", description = "Delete Forwarding Path"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Forwarding Path already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteForwardingPath(
+ @Parameter(description = "Forwarding Path Id") @PathParam("forwardingPathId") String forwardingPathId,
+ @Parameter(description = "Service Id") @PathParam("serviceId") String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response;
+
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+
+ Set<String> deletedPaths = serviceBusinessLogic.deleteForwardingPaths(serviceIdLower, Sets.newHashSet(forwardingPathId), modifier, true);
+ Object result = RepresentationUtils.toRepresentation(deletedPaths);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (IOException e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete forward paths");
+ log.debug("Delete service paths with an error", e);
+ throw e;
+ }
+ }
+
+
+ private Either<Service, ResponseFormat> parseToService(String serviceJson, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, Service.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);//TODO: change sSERVICE constant
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
index 8e71775e14..eb015791ac 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java
@@ -1,770 +1,724 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.reflect.TypeToken;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-import javax.inject.Inject;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import org.apache.http.HttpStatus;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.ServiceRelations;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.DistributionStatusEnum;
-import org.openecomp.sdc.be.model.GroupInstanceProperty;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Service Catalog", description = "Service Servlet"))
-@Singleton
-public class ServiceServlet extends AbstractValidationsServlet {
-
- private static final Logger log = Logger.getLogger(ServiceServlet.class);
- private final ServiceBusinessLogic serviceBusinessLogic;
- private final ResourceBusinessLogic resourceBusinessLogic;
-
- @Inject
- public ServiceServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- ServiceBusinessLogic serviceBusinessLogic,
- ResourceBusinessLogic resourceBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.serviceBusinessLogic = serviceBusinessLogic;
- this.resourceBusinessLogic = resourceBusinessLogic;
- }
-
- @POST
- @Path("/services")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Create Service", method = "POST", summary = "Returns created service",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Service already exist")})
- public Response createService(@Parameter(description = "Service object to be created", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
- if (convertResponse.isRight()) {
- log.debug("failed to parse service");
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
-
- Service service = convertResponse.left().value();
- Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.createService(service, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("Failed to create service");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Object result = RepresentationUtils.toRepresentation(actionResponse.left().value());
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), result);
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Service");
- log.debug("create service failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- public Either<Service, ResponseFormat> parseToService(String serviceJson, User user) {
- return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, Service.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
- }
-
- @GET
- @Path("/services/validate-name/{serviceName}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "validate service name", method = "GET",
- summary = "checks if the chosen service name is available ", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation")})
- public Response validateServiceName(@PathParam("serviceName") final String serviceName,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
- Response response = null;
- try {
- Either<Map<String, Boolean>, ResponseFormat> actionResponse =
- serviceBusinessLogic.validateServiceNameExists(serviceName, userId);
-
- if (actionResponse.isRight()) {
- log.debug("failed to get validate service name");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- actionResponse.left().value());
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name");
- log.debug("validate service name failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Path("/audit-records/{componentType}/{componentUniqueId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "get component audit records", method = "GET",
- summary = "get audit records for a service or a resource", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation")})
- public Response getComponentAuditRecords(@PathParam("componentType") final String componentType,
- @PathParam("componentUniqueId") final String componentUniqueId, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- init();
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<String> uuidWrapper = new Wrapper<>();
- Wrapper<String> versionWrapper = new Wrapper<>();
- Wrapper<User> userWrapper = new Wrapper<>();
- Wrapper<ComponentTypeEnum> componentWrapper = new Wrapper<>();
- try {
- validateUserExist(responseWrapper, userWrapper, userId);
-
- if (responseWrapper.isEmpty()) {
- validateComponentType(responseWrapper, componentWrapper, componentType);
- }
-
- if (responseWrapper.isEmpty()) {
- fillUUIDAndVersion(responseWrapper, uuidWrapper, versionWrapper, userWrapper.getInnerElement(),
- componentWrapper.getInnerElement(), componentUniqueId, context);
- }
-
- if (responseWrapper.isEmpty()) {
- Either<List<Map<String, Object>>, ResponseFormat> eitherServiceAudit =
- serviceBusinessLogic.getComponentAuditRecords(versionWrapper.getInnerElement(),
- uuidWrapper.getInnerElement(), userId);
-
- if (eitherServiceAudit.isRight()) {
- Response errorResponse = buildErrorResponse(eitherServiceAudit.right().value());
- responseWrapper.setInnerElement(errorResponse);
- } else {
- List<Map<String, Object>> auditRecords = eitherServiceAudit.left().value();
- Response okResponse =
- buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), auditRecords);
- responseWrapper.setInnerElement(okResponse);
-
- }
- }
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name");
- log.debug("get Service Audit Records failed with exception", e);
- Response errorResponse =
- buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- responseWrapper.setInnerElement(errorResponse);
- }
- return responseWrapper.getInnerElement();
- }
-
- private void fillUUIDAndVersion(Wrapper<Response> responseWrapper, Wrapper<String> uuidWrapper, Wrapper<String> versionWrapper, User user, final ComponentTypeEnum componentTypeEnum, final String componentUniqueId, ServletContext context) {
-
- if (componentTypeEnum == ComponentTypeEnum.RESOURCE) {
- Either<Resource, ResponseFormat> eitherResource = resourceBusinessLogic.getResource(componentUniqueId, user);
- if (eitherResource.isLeft()) {
- uuidWrapper.setInnerElement(eitherResource.left().value().getUUID());
- versionWrapper.setInnerElement(eitherResource.left().value().getVersion());
- } else {
- responseWrapper.setInnerElement(buildErrorResponse(eitherResource.right().value()));
- }
-
- } else {
- Either<Service, ResponseFormat> eitherService = serviceBusinessLogic.getService(componentUniqueId, user);
- if (eitherService.isLeft()) {
- uuidWrapper.setInnerElement(eitherService.left().value().getUUID());
- versionWrapper.setInnerElement(eitherService.left().value().getVersion());
- } else {
- responseWrapper.setInnerElement(buildErrorResponse(eitherService.right().value()));
-
- }
- }
- }
-
- @DELETE
- @Path("/services/{serviceId}")
- public Response deleteService(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
-
- try {
- String serviceIdLower = serviceId.toLowerCase();
- ResponseFormat actionResponse = serviceBusinessLogic.deleteService(serviceIdLower, modifier);
-
- if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
- log.debug("failed to delete service");
- response = buildErrorResponse(actionResponse);
- return response;
- }
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service");
- log.debug("delete service failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @DELETE
- @Path("/services/{serviceName}/{version}")
- public Response deleteServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, @PathParam("version") final String version, @Context final HttpServletRequest request) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- String userId = request.getHeader(Constants.USER_ID_HEADER);
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
-
- try {
- ResponseFormat actionResponse = serviceBusinessLogic.deleteServiceByNameAndVersion(serviceName, version, modifier);
-
- if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
- log.debug("failed to delete service");
- response = buildErrorResponse(actionResponse);
- return response;
- }
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service");
- log.debug("delete service failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- @PUT
- @Path("/services/{serviceId}/metadata")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Service Metadata", method = "PUT", summary = "Returns updated service",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service Updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateServiceMetadata(@PathParam("serviceId") final String serviceId,
- @Parameter(description = "Service object to be Updated", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
-
- try {
- String serviceIdLower = serviceId.toLowerCase();
-
- Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
- if (convertResponse.isRight()) {
- log.debug("failed to parse service");
- response = buildErrorResponse(convertResponse.right().value());
- return response;
- }
- Service updatedService = convertResponse.left().value();
- Either<Service, ResponseFormat> actionResponse =
- serviceBusinessLogic.updateServiceMetadata(serviceIdLower, updatedService, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("failed to update service");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Service service = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(service);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Metadata");
- log.debug("update service metadata failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
- /**
- * updates group instance property values
- * Note, than in case of group instance updated successfully, related resourceInstance and containing component modification time will be updated
- * @param serviceId
- * @param componentInstanceId
- * @param groupInstanceId
- * @param data
- * @param request
- * @param userId
- * @return
- */
- @PUT
- @Path("/{containerComponentType}/{serviceId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Group Instance Property Values", method = "PUT",
- summary = "Returns updated group instance", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Instance Property Values Updated"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
- public Response updateGroupInstancePropertyValues(@PathParam("serviceId") final String serviceId,
- @PathParam("componentInstanceId") final String componentInstanceId,
- @PathParam("groupInstanceId") final String groupInstanceId,
- @Parameter(description = "Group instance object to be Updated", required = true) String data,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- Response response = null;
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}",userId);
-
- Either<List<GroupInstanceProperty>, ResponseFormat> actionResponse = null;
- try {
- List<GroupInstanceProperty> updatedProperties;
- Type listType = new TypeToken<ArrayList<GroupInstanceProperty>>(){}.getType();
- ArrayList<GroupInstanceProperty> newProperties = gson.fromJson(data, listType);
- if (newProperties == null) {
- actionResponse = Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
- if(actionResponse == null){
- log.debug("Start handle update group instance property values request. Received group instance is {}", groupInstanceId);
- actionResponse = serviceBusinessLogic.updateGroupInstancePropertyValues(modifier, serviceId, componentInstanceId, groupInstanceId, newProperties);
- if(actionResponse.isRight()){
- actionResponse = Either.right(actionResponse.right().value());
- }
- }
- if(actionResponse.isLeft()){
- updatedProperties = actionResponse.left().value();
- ObjectMapper mapper = new ObjectMapper();
- String result = mapper.writeValueAsString(updatedProperties);
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
- }
- else{
- response = buildErrorResponse(actionResponse.right().value());
- }
- } catch (Exception e) {
- log.error("Exception occured during update Group Instance property values: {}", e.getMessage(), e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- return response;
- }
-
- @GET
- @Path("/services/{serviceId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve Service", method = "GET", summary = "Returns service according to serviceId",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found")})
- public Response getServiceById(@PathParam("serviceId") final String serviceId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- String serviceIdLower = serviceId.toLowerCase();
- log.debug("get service with id {}", serviceId);
- Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getService(serviceIdLower, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("failed to get service");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Service service = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(service);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service");
- log.debug("get service failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- @GET
- @Path("/services/serviceName/{serviceName}/serviceVersion/{serviceVersion}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve Service", method = "GET",
- summary = "Returns service according to name and version", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found")})
- public Response getServiceByNameAndVersion(@PathParam("serviceName") final String serviceName,
- @PathParam("serviceVersion") final String serviceVersion, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId);
-
- if (actionResponse.isRight()) {
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- Service service = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(service);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service by name and version");
- log.debug("get service failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
- @POST
- @Path("/services/{serviceId}/distribution-state/{state}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Update Service Distribution State", method = "POST",
- summary = "service with the changed distribution status")
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service distribution state changed"),
- @ApiResponse(responseCode = "409", description = "Restricted operation"),
- @ApiResponse(responseCode = "403", description = "Service is not available for distribution"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Requested service was not found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")})
- public Response updateServiceDistributionState(
- @Parameter(description = "DistributionChangeInfo - get comment out of body",
- required = true) LifecycleChangeInfoWithAction jsonChangeInfo,
- @PathParam("serviceId") final String serviceId,
- @Parameter(schema = @Schema(allowableValues = {"approve", "reject"}),
- required = true) @PathParam("state") final String state,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.changeServiceDistributionState(serviceId, state, jsonChangeInfo, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("failed to Update Service Distribution State");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
- Service service = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(service);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Distribution State");
- log.debug("updateServiceDistributionState failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- @POST
- @Path("/services/{serviceId}/distribution/{env}/activate")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Activate distribution", method = "POST", summary = "activate distribution")
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
- @ApiResponse(responseCode = "409",
- description = "Service cannot be distributed due to missing deployment artifacts"),
- @ApiResponse(responseCode = "404", description = "Requested service was not found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")})
- public Response activateDistribution(@PathParam("serviceId") final String serviceId,
- @PathParam("env") final String env, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.activateDistribution(serviceId, env, modifier, request);
-
- if (distResponse.isRight()) {
- log.debug("failed to activate service distribution");
- response = buildErrorResponse(distResponse.right().value());
- return response;
- }
- Service service = distResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(service);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Activate Distribution");
- log.debug("activate distribution failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- @POST
- @Path("/services/{serviceId}/distribution/{did}/markDeployed")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Mark distribution as deployed", method = "POST",
- summary = "relevant audit record will be created")
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service was marked as deployed"),
- @ApiResponse(responseCode = "409", description = "Restricted operation"),
- @ApiResponse(responseCode = "403", description = "Service is not available"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Requested service was not found"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")})
- public Response markDistributionAsDeployed(@PathParam("serviceId") final String serviceId,
- @PathParam("did") final String did, @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.markDistributionAsDeployed(serviceId, did, modifier);
-
- if (distResponse.isRight()) {
- log.debug("failed to mark distribution as deployed");
- response = buildErrorResponse(distResponse.right().value());
- return response;
- }
- Service service = distResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(service);
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Mark Distribution As Deployed");
- log.debug("mark distribution as deployed failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
- @POST
- @Path("/services/{serviceId}/tempUrlToBeDeleted")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.") })
- public Response tempUrlToBeDeleted(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- ServletContext context = request.getSession().getServletContext();
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response;
- try {
- Service service = (serviceBusinessLogic.getService(serviceId, modifier)).left().value();
- Either<Service, ResponseFormat> res = serviceBusinessLogic.updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED);
-
- if (res.isRight()) {
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("tempUrlToBeDeleted");
- log.debug("failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
- }
- }
-
-
- @GET
- @Path("/services/{serviceId}/linksMap")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve Service component relations map", method = "GET",
- summary = "Returns service components relations",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServiceRelations.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "404", description = "Service not found")})
- public Response getServiceComponentRelationMap(@PathParam("serviceId") final String serviceId,
- @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(userId);
- log.debug("modifier id is {}", userId);
-
- Response response = null;
- try {
- String serviceIdLower = serviceId.toLowerCase();
- log.debug("get service components relations with id {}", serviceId);
- Either<ServiceRelations, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceComponentsRelations(serviceIdLower, modifier);
-
- if (actionResponse.isRight()) {
- log.debug("failed to get service relations data");
- response = buildErrorResponse(actionResponse.right().value());
- return response;
- }
-
- ServiceRelations serviceRelations = actionResponse.left().value();
- Object result = RepresentationUtils.toRepresentation(serviceRelations);
-
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service");
- log.debug("get service relations data failed with exception", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
-
- }
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.reflect.TypeToken;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.annotations.Api;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.http.HttpStatus;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.ServiceRelations;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.DistributionStatusEnum;
+import org.openecomp.sdc.be.model.GroupInstanceProperty;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@Api(value = "Service Catalog", description = "Service Servlet")
+@Controller
+public class ServiceServlet extends AbstractValidationsServlet {
+
+ private static final Logger log = Logger.getLogger(ServiceServlet.class);
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(ServiceServlet.class.getName());
+
+ private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
+ private static final String MODIFIER_ID_IS = "modifier id is {}";
+
+ private final ServiceBusinessLogic serviceBusinessLogic;
+
+ @Inject
+ public ServiceServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ ServiceBusinessLogic serviceBusinessLogic,
+ ResourceBusinessLogic resourceBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.serviceBusinessLogic = serviceBusinessLogic;
+ }
+
+ @POST
+ @Path("/services")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Create Service", method = "POST", summary = "Returns created service",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Service created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Service already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response createService(@Parameter(description = "Service object to be created", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE,StatusCode.STARTED,"Starting to create a service by user {} ",userId);
+
+ validateNotEmptyBody(data);
+ Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
+ if (convertResponse.isRight()) {
+ throw new ByResponseFormatComponentException(convertResponse.right().value());
+ }
+
+ Service service = convertResponse.left().value();
+ Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.createService(service, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("Failed to create service");
+ throw new ByResponseFormatComponentException(actionResponse.right().value());
+ }
+
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_SERVICE,service.getComponentMetadataForSupportLog(),StatusCode.COMPLETE,"Service {} has been created by user {} ",service.getName(), userId );
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), actionResponse.left().value());
+ }
+
+ public Either<Service, ResponseFormat> parseToService(String serviceJson, User user) {
+ return getComponentsUtils().convertJsonToObjectUsingObjectMapper(serviceJson, user, Service.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.SERVICE);
+ }
+
+ @GET
+ @Path("/services/validate-name/{serviceName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "validate service name", method = "GET",
+ summary = "checks if the chosen service name is available ", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response validateServiceName(@PathParam("serviceName") final String serviceName,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+ Response response = null;
+ try {
+ Either<Map<String, Boolean>, ResponseFormat> actionResponse =
+ serviceBusinessLogic.validateServiceNameExists(serviceName, userId);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get validate service name");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value());
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name");
+ log.debug("validate service name failed with exception", e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/audit-records/{componentType}/{componentUniqueId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "get component audit records", method = "GET",
+ summary = "get audit records for a service or a resource", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getComponentAuditRecords(@PathParam("componentType") final String componentType,
+ @PathParam("componentUniqueId") final String componentUniqueId, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+ init();
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<String> uuidWrapper = new Wrapper<>();
+ Wrapper<String> versionWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+ try {
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ fillUUIDAndVersion(responseWrapper, uuidWrapper, versionWrapper, userWrapper.getInnerElement(), validateComponentType(componentType), componentUniqueId, context);
+ }
+
+ if (responseWrapper.isEmpty()) {
+ Either<List<Map<String, Object>>, ResponseFormat> eitherServiceAudit = serviceBusinessLogic.getComponentAuditRecords(versionWrapper.getInnerElement(), uuidWrapper.getInnerElement(), userId);
+
+ if (eitherServiceAudit.isRight()) {
+ Response errorResponse = buildErrorResponse(eitherServiceAudit.right().value());
+ responseWrapper.setInnerElement(errorResponse);
+ } else {
+ List<Map<String, Object>> auditRecords = eitherServiceAudit.left().value();
+ Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), auditRecords);
+ responseWrapper.setInnerElement(okResponse);
+
+ }
+ }
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Validate Service Name");
+ log.debug("get Service Audit Records failed with exception", e);
+ throw e;
+ }
+ return responseWrapper.getInnerElement();
+ }
+
+ private void fillUUIDAndVersion(Wrapper<Response> responseWrapper, Wrapper<String> uuidWrapper, Wrapper<String> versionWrapper, User user, final ComponentTypeEnum componentTypeEnum, final String componentUniqueId, ServletContext context) {
+
+ if (componentTypeEnum == ComponentTypeEnum.RESOURCE) {
+ Either<Resource, ResponseFormat> eitherResource = getResourceBL(context).getResource(componentUniqueId, user);
+ if (eitherResource.isLeft()) {
+ uuidWrapper.setInnerElement(eitherResource.left().value().getUUID());
+ versionWrapper.setInnerElement(eitherResource.left().value().getVersion());
+ } else {
+ responseWrapper.setInnerElement(buildErrorResponse(eitherResource.right().value()));
+ }
+
+ } else {
+ Either<Service, ResponseFormat> eitherService = getServiceBL(context).getService(componentUniqueId, user);
+ if (eitherService.isLeft()) {
+ uuidWrapper.setInnerElement(eitherService.left().value().getUUID());
+ versionWrapper.setInnerElement(eitherService.left().value().getVersion());
+ } else {
+ responseWrapper.setInnerElement(buildErrorResponse(eitherService.right().value()));
+
+ }
+ }
+ }
+
+ @DELETE
+ @Path("/services/{serviceId}")
+ @Operation(description = "Delete Service", method = "DELETE", summary = "Return no content", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value = { @ApiResponse(responseCode = "204", description = "Service deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Service not found") })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteService(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request) {
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+ Response response = null;
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_SERVICE, StatusCode.STARTED,"Starting to delete service {} by user {} ",serviceIdLower, userId);
+ ServiceBusinessLogic businessLogic = getServiceBL(context);
+ ResponseFormat actionResponse = businessLogic.deleteService(serviceIdLower, modifier);
+ if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
+ log.debug("failed to delete service");
+ response = buildErrorResponse(actionResponse);
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ loggerSupportability.log(LoggerSupportabilityActions.DELETE_SERVICE,StatusCode.COMPLETE,"Ended deleting service {} by user {}",serviceIdLower, userId);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service");
+ log.debug("delete service failed with exception", e);
+ throw e;
+ }
+ }
+
+ @DELETE
+ @Path("/services/{serviceName}/{version}")
+ @Operation(description = "Delete Service By Name And Version", method = "DELETE", summary = "Returns no content", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Resource.class)))))
+ @ApiResponses(value = { @ApiResponse(responseCode = "204", description = "Service deleted"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Service not found") })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response deleteServiceByNameAndVersion(@PathParam("serviceName") final String serviceName,
+ @PathParam("version") final String version,
+ @Context final HttpServletRequest request) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ // get modifier id
+ String userId = request.getHeader(Constants.USER_ID_HEADER);
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+
+ try {
+ ResponseFormat actionResponse = serviceBusinessLogic.deleteServiceByNameAndVersion(serviceName, version, modifier);
+
+ if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) {
+ log.debug("failed to delete service");
+ response = buildErrorResponse(actionResponse);
+ return response;
+ }
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null);
+ return response;
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service");
+ log.debug("delete service failed with exception", e);
+ throw e;
+ }
+ }
+
+ @PUT
+ @Path("/services/{serviceId}/metadata")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Service Metadata", method = "PUT", summary = "Returns updated service",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service Updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateServiceMetadata(@PathParam("serviceId") final String serviceId,
+ @Parameter(description = "Service object to be Updated", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+
+ Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier);
+ if (convertResponse.isRight()) {
+ log.debug("failed to parse service");
+ response = buildErrorResponse(convertResponse.right().value());
+ return response;
+ }
+ Service updatedService = convertResponse.left().value();
+ Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.updateServiceMetadata(serviceIdLower, updatedService, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to update service");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Service service = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update Service Metadata");
+ log.debug("update service metadata failed with exception", e);
+ throw e;
+ }
+ }
+ /**
+ * updates group instance property values
+ * Note, than in case of group instance updated successfully, related resourceInstance and containing component modification time will be updated
+ * @param serviceId
+ * @param componentInstanceId
+ * @param groupInstanceId
+ * @param data
+ * @param request
+ * @param userId
+ * @return
+ */
+ @PUT
+ @Path("/{containerComponentType}/{serviceId}/resourceInstance/{componentInstanceId}/groupInstance/{groupInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Update Group Instance Property Values", method = "PUT",
+ summary = "Returns updated group instance", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Group Instance Property Values Updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response updateGroupInstancePropertyValues(@PathParam("serviceId") final String serviceId,
+ @PathParam("componentInstanceId") final String componentInstanceId,
+ @PathParam("groupInstanceId") final String groupInstanceId,
+ @Parameter(description = "Group instance object to be Updated", required = true) String data,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws JsonProcessingException {
+
+ Response response = null;
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS,userId);
+
+ Either<List<GroupInstanceProperty>, ResponseFormat> actionResponse = null;
+ try {
+ List<GroupInstanceProperty> updatedProperties;
+ Type listType = new TypeToken<ArrayList<GroupInstanceProperty>>(){}.getType();
+ ArrayList<GroupInstanceProperty> newProperties = gson.fromJson(data, listType);
+ if (newProperties == null) {
+ actionResponse = Either.right(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ if(actionResponse == null){
+ log.debug("Start handle update group instance property values request. Received group instance is {}", groupInstanceId);
+ actionResponse = serviceBusinessLogic.updateGroupInstancePropertyValues(modifier, serviceId, componentInstanceId, groupInstanceId, newProperties);
+ if(actionResponse.isRight()){
+ actionResponse = Either.right(actionResponse.right().value());
+ }
+ }
+ if(actionResponse.isLeft()){
+ updatedProperties = actionResponse.left().value();
+ ObjectMapper mapper = new ObjectMapper();
+ String result = mapper.writeValueAsString(updatedProperties);
+ response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ }
+ else{
+ response = buildErrorResponse(actionResponse.right().value());
+ }
+ } catch (Exception e) {
+ log.error("Exception occured during update Group Instance property values: {}", e.getMessage(), e);
+ throw e;
+ }
+ return response;
+ }
+
+ @GET
+ @Path("/services/{serviceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve Service", method = "GET", summary = "Returns service according to serviceId",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getServiceById(@PathParam("serviceId") final String serviceId,
+ @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+ log.debug("get service with id {}", serviceId);
+ Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getService(serviceIdLower, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get service");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Service service = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service");
+ log.debug("get service failed with exception", e);
+ throw e;
+ }
+ }
+
+ @GET
+ @Path("/services/serviceName/{serviceName}/serviceVersion/{serviceVersion}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve Service", method = "GET",
+ summary = "Returns service according to name and version", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Service.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getServiceByNameAndVersion(@PathParam("serviceName") final String serviceName,
+ @PathParam("serviceVersion") final String serviceVersion, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+ try {
+ Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId);
+
+ if (actionResponse.isRight()) {
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ Service service = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service by name and version");
+ log.debug("get service failed with exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/services/{serviceId}/distribution/{env}/activate")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Activate distribution", method = "POST", summary = "activate distribution")
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"),
+ @ApiResponse(responseCode = "409",
+ description = "Service cannot be distributed due to missing deployment artifacts"),
+ @ApiResponse(responseCode = "404", description = "Requested service was not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response activateDistribution(@PathParam("serviceId") final String serviceId,
+ @PathParam("env") final String env, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+ Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.activateDistribution(serviceId, env, modifier, request);
+
+ if (distResponse.isRight()) {
+ log.debug("failed to activate service distribution");
+ response = buildErrorResponse(distResponse.right().value());
+ return response;
+ }
+ Service service = distResponse.left().value();
+ Object result = null;
+ try {
+ result = RepresentationUtils.toRepresentation(service);
+ } catch (IOException e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Activate Distribution");
+ log.debug("activate distribution failed with exception", e);
+ throw e;
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ }
+
+ @POST
+ @Path("/services/{serviceId}/distribution/{did}/markDeployed")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Mark distribution as deployed", method = "POST",
+ summary = "relevant audit record will be created")
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service was marked as deployed"),
+ @ApiResponse(responseCode = "409", description = "Restricted operation"),
+ @ApiResponse(responseCode = "403", description = "Service is not available"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Requested service was not found"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response markDistributionAsDeployed(@PathParam("serviceId") final String serviceId,
+ @PathParam("did") final String did, @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+ try {
+ Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.markDistributionAsDeployed(serviceId, did, modifier);
+
+ if (distResponse.isRight()) {
+ log.debug("failed to mark distribution as deployed");
+ response = buildErrorResponse(distResponse.right().value());
+ return response;
+ }
+ Service service = distResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(service);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Mark Distribution As Deployed");
+ log.debug("mark distribution as deployed failed with exception", e);
+ throw e;
+ }
+ }
+
+ @POST
+ @Path("/services/{serviceId}/tempUrlToBeDeleted")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "500", description = "Internal Server Error. Please try again later.") })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response tempUrlToBeDeleted(@PathParam("serviceId") final String serviceId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ ServletContext context = request.getSession().getServletContext();
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response;
+ try {
+ Service service = (serviceBusinessLogic.getService(serviceId, modifier)).left().value();
+ Either<Service, ResponseFormat> res = serviceBusinessLogic.updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED);
+
+ if (res.isRight()) {
+ response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("tempUrlToBeDeleted");
+ log.debug("failed with exception", e);
+ throw e;
+ }
+ }
+
+
+ @GET
+ @Path("/services/{serviceId}/linksMap")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve Service component relations map", method = "GET",
+ summary = "Returns service components relations",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = ServiceRelations.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Service found"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Service not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getServiceComponentRelationMap(@PathParam("serviceId") final String serviceId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+
+ // get modifier id
+ User modifier = new User();
+ modifier.setUserId(userId);
+ log.debug(MODIFIER_ID_IS, userId);
+
+ Response response = null;
+ try {
+ String serviceIdLower = serviceId.toLowerCase();
+ log.debug("get service components relations with id {}", serviceId);
+ Either<ServiceRelations, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceComponentsRelations(serviceIdLower, modifier);
+
+ if (actionResponse.isRight()) {
+ log.debug("failed to get service relations data");
+ response = buildErrorResponse(actionResponse.right().value());
+ return response;
+ }
+
+ ServiceRelations serviceRelations = actionResponse.left().value();
+ Object result = RepresentationUtils.toRepresentation(serviceRelations);
+
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
+
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Service");
+ log.debug("get service relations data failed with exception", e);
+ throw e;
+ }
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java
deleted file mode 100644
index 1964202297..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ToscaDaoServlet.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import javax.inject.Inject;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.DownloadArtifactLogic;
-import org.openecomp.sdc.be.info.ServletJsonResponse;
-import org.openecomp.sdc.be.resources.api.IResourceUploader;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.ws.rs.core.Response;
-
-public abstract class ToscaDaoServlet extends BeGenericServlet {
- public abstract Logger getLogger();
- protected final IResourceUploader resourceUploader;
- protected final DownloadArtifactLogic logic;
-
- @Inject
- public ToscaDaoServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils,
- IResourceUploader resourceUploader,
- DownloadArtifactLogic logic) {
- super(userBusinessLogic, componentsUtils);
- this.resourceUploader = resourceUploader;
- this.logic = logic;
- }
-
- protected Response buildResponse(int status, String errorMessage) {
-
- ServletJsonResponse jsonResponse = new ServletJsonResponse();
- jsonResponse.setDescription(errorMessage);
- jsonResponse.setSource(Constants.CATALOG_BE);
-
- return Response.status(status).entity(jsonResponse).build();
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
index a3e47a0b23..3af822836d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
@@ -1,387 +1,377 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-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.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.collections4.ListUtils;
-import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
-import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
-import org.openecomp.sdc.be.components.impl.RelationshipTypeBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
-import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
-import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog")
-@OpenAPIDefinition(info = @Info(title = "Types Fetch Servlet",description = "Types Fetch Servlet"))
-@Singleton
-public class TypesFetchServlet extends AbstractValidationsServlet {
-
- private static final Logger log = Logger.getLogger(TypesFetchServlet.class);
- private static final String FAILED_TO_GET_ALL_NON_ABSTRACT = "failed to get all non abstract {}";
- private final PropertyBusinessLogic propertyBusinessLogic;
- private final RelationshipTypeBusinessLogic relationshipTypeBusinessLogic;
- private final CapabilitiesBusinessLogic capabilitiesBusinessLogic;
- private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
- private final ResourceBusinessLogic resourceBusinessLogic;
-
- @Inject
- public TypesFetchServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- PropertyBusinessLogic propertyBusinessLogic,
- RelationshipTypeBusinessLogic relationshipTypeBusinessLogic,
- CapabilitiesBusinessLogic capabilitiesBusinessLogic,
- InterfaceOperationBusinessLogic interfaceOperationBusinessLogic,
- ResourceBusinessLogic resourceBusinessLogic) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.propertyBusinessLogic = propertyBusinessLogic;
- this.relationshipTypeBusinessLogic = relationshipTypeBusinessLogic;
- this.capabilitiesBusinessLogic = capabilitiesBusinessLogic;
- this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
- this.resourceBusinessLogic = resourceBusinessLogic;
- }
-
- @GET
- @Path("dataTypes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get data types", method = "GET", summary = "Returns data types", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "datatypes"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Data types not found")})
- public Response getAllDataTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<User> userWrapper = new Wrapper<>();
- try {
- init();
- validateUserExist(responseWrapper, userWrapper, userId);
-
- if (responseWrapper.isEmpty()) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} | modifier id is {}", url, userId);
-
- Either<Map<String, DataTypeDefinition>, ResponseFormat> allDataTypes =
- propertyBusinessLogic.getAllDataTypes();
-
- if (allDataTypes.isRight()) {
- log.info("Failed to get all dara types. Reason - {}", allDataTypes.right().value());
- Response errorResponse = buildErrorResponse(allDataTypes.right().value());
- responseWrapper.setInnerElement(errorResponse);
-
- } else {
-
- Map<String, DataTypeDefinition> dataTypes = allDataTypes.left().value();
- String dataTypeJson = gson.toJson(dataTypes);
- Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
- responseWrapper.setInnerElement(okResponse);
-
- }
- }
-
- return responseWrapper.getInnerElement();
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Property");
- log.debug("get all data types failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
-
- @GET
- @Path("interfaceLifecycleTypes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get interface lifecycle types", method = "GET", summary = "Returns interface lifecycle types", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {
- @ApiResponse(responseCode = "200", description = "Interface lifecycle types"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Interface lifecycle types not found")
- })
- public Response getInterfaceLifecycleTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<User> userWrapper = new Wrapper<>();
-
- try {
- validateUserExist(responseWrapper, userWrapper, userId);
-
- if (responseWrapper.isEmpty()) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.info("Start handle request of {} | modifier id is {}", url, userId);
-
- Either<Map<String, InterfaceDefinition>, ResponseFormat> allInterfaceLifecycleTypes =
- interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
-
- if (allInterfaceLifecycleTypes.isRight()) {
- log.info("Failed to get all interface lifecycle types. Reason - {}",
- allInterfaceLifecycleTypes.right().value());
- Response errorResponse = buildErrorResponse(allInterfaceLifecycleTypes.right().value());
- responseWrapper.setInnerElement(errorResponse);
-
- } else {
- String interfaceLifecycleTypeJson = gson.toJson(allInterfaceLifecycleTypes.left().value());
- Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), interfaceLifecycleTypeJson);
- responseWrapper.setInnerElement(okResponse);
-
- }
- }
-
- return responseWrapper.getInnerElement();
- } catch (Exception e) {
- log.debug("get all interface lifecycle types failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
- @GET
- @Path("capabilityTypes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get capability types", method = "GET", summary = "Returns capability types", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "capabilityTypes"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Capability types not found")})
- public Response getAllCapabilityTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value =
- Constants.USER_ID_HEADER) String userId) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<User> userWrapper = new Wrapper<>();
-
- try {
- init();
- validateUserExist(responseWrapper, userWrapper, userId);
-
- if (responseWrapper.isEmpty()) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} | modifier id is {}", url, userId);
-
- Either<Map<String, CapabilityTypeDefinition>, ResponseFormat> allDataTypes =
- capabilitiesBusinessLogic.getAllCapabilityTypes();
-
- if (allDataTypes.isRight()) {
- log.info("Failed to get all capability types. Reason - {}", allDataTypes.right().value());
- Response errorResponse = buildErrorResponse(allDataTypes.right().value());
- responseWrapper.setInnerElement(errorResponse);
-
- } else {
-
- Map<String, CapabilityTypeDefinition> dataTypes = allDataTypes.left().value();
- String dataTypeJson = gson.toJson(dataTypes);
- Response okResponse =
- buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
- responseWrapper.setInnerElement(okResponse);
-
- }
- }
-
- return responseWrapper.getInnerElement();
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Capability Types");
- log.debug("get all capability types failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
-
- @GET
- @Path("relationshipTypes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get relationship types", method = "GET", summary = "Returns relationship types", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "relationshipTypes"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Relationship types not found")})
- public Response getAllRelationshipTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value =
- Constants.USER_ID_HEADER) String userId) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<User> userWrapper = new Wrapper<>();
-
- try {
- init();
- validateUserExist(responseWrapper, userWrapper, userId);
-
- if (responseWrapper.isEmpty()) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} | modifier id is {}", url, userId);
-
- Either<Map<String, RelationshipTypeDefinition>, ResponseFormat> allDataTypes =
- relationshipTypeBusinessLogic.getAllRelationshipTypes();
-
- if (allDataTypes.isRight()) {
- log.info("Failed to get all relationship types. Reason - {}", allDataTypes.right().value());
- Response errorResponse = buildErrorResponse(allDataTypes.right().value());
- responseWrapper.setInnerElement(errorResponse);
-
- } else {
-
- Map<String, RelationshipTypeDefinition> dataTypes = allDataTypes.left().value();
- String dataTypeJson = gson.toJson(dataTypes);
- Response okResponse =
- buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
- responseWrapper.setInnerElement(okResponse);
-
- }
- }
-
- return responseWrapper.getInnerElement();
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Relationship Types");
- log.debug("get all relationship types failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
-
- @GET
- @Path("nodeTypes")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Get node types", method = "GET", summary = "Returns node types", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "nodeTypes"), @ApiResponse(responseCode = "403", description =
- "Restricted operation"), @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "404", description = "Node types not found")})
- public Response getAllNodeTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value =
- Constants.USER_ID_HEADER) String userId) {
-
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<User> userWrapper = new Wrapper<>();
- ServletContext context = request.getSession().getServletContext();
- Either<Map<String, Component>, Response> response;
- Map<String, Component> componentMap;
-
- try {
- init();
- validateUserExist(responseWrapper, userWrapper, userId);
-
- if (responseWrapper.isEmpty()) {
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} | modifier id is {}", url, userId);
-
- response = getComponent(resourceBusinessLogic, true, userId);
- if (response.isRight()) {
- return response.right().value();
- }
- componentMap = new HashMap<>(response.left().value());
-
- response = getComponent(resourceBusinessLogic, false, userId);
- if (response.isRight()) {
- return response.right().value();
- }
- componentMap.putAll(response.left().value());
-
- String nodeTypesJson = gson.toJson(componentMap);
- Response okResponse =
- buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), nodeTypesJson);
- responseWrapper.setInnerElement(okResponse);
- }
-
- return responseWrapper.getInnerElement();
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Node Types");
- log.debug("get all node types failed with exception", e);
- ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- return buildErrorResponse(responseFormat);
- }
- }
-
- private Either<Map<String, Component>, Response> getComponent(ComponentBusinessLogic resourceBL, boolean isAbstract,
- String userId) {
- Either<List<Component>, ResponseFormat> actionResponse;
- List<Component> componentList;
-
- actionResponse =
- resourceBL.getLatestVersionNotAbstractComponentsMetadata(isAbstract, HighestFilterEnum.HIGHEST_ONLY
- , ComponentTypeEnum.RESOURCE, null, userId);
- if (actionResponse.isRight()) {
- log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, ComponentTypeEnum.RESOURCE.getValue());
- return Either.right(buildErrorResponse(actionResponse.right().value()));
- }
-
- componentList = actionResponse.left().value();
-
- return Either.left(ListUtils.emptyIfNull(componentList).stream()
- .filter(component -> ((ResourceMetadataDataDefinition) component
- .getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName() != null)
- .collect(Collectors.toMap(
- component -> ((ResourceMetadataDataDefinition) component
- .getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName(),
- component -> component, (component1, component2) -> component1)));
- }
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.collections4.ListUtils;
+import org.openecomp.sdc.be.components.impl.CapabilitiesBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.components.impl.RelationshipTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+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.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog")
+@OpenAPIDefinition(info = @Info(title = "Types Fetch Servlet",description = "Types Fetch Servlet"))
+@Controller
+public class TypesFetchServlet extends AbstractValidationsServlet {
+
+ private static final Logger log = Logger.getLogger(TypesFetchServlet.class);
+ private static final String FAILED_TO_GET_ALL_NON_ABSTRACT = "failed to get all non abstract {}";
+ private final PropertyBusinessLogic propertyBusinessLogic;
+ private final RelationshipTypeBusinessLogic relationshipTypeBusinessLogic;
+ private final CapabilitiesBusinessLogic capabilitiesBusinessLogic;
+ private final InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+ private final ResourceBusinessLogic resourceBusinessLogic;
+
+ @Inject
+ public TypesFetchServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ PropertyBusinessLogic propertyBusinessLogic,
+ RelationshipTypeBusinessLogic relationshipTypeBusinessLogic,
+ CapabilitiesBusinessLogic capabilitiesBusinessLogic,
+ InterfaceOperationBusinessLogic interfaceOperationBusinessLogic,
+ ResourceBusinessLogic resourceBusinessLogic) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.propertyBusinessLogic = propertyBusinessLogic;
+ this.relationshipTypeBusinessLogic = relationshipTypeBusinessLogic;
+ this.capabilitiesBusinessLogic = capabilitiesBusinessLogic;
+ this.interfaceOperationBusinessLogic = interfaceOperationBusinessLogic;
+ this.resourceBusinessLogic = resourceBusinessLogic;
+ }
+
+ @GET
+ @Path("dataTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get data types", method = "GET", summary = "Returns data types", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "datatypes"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Data types not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getAllDataTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+
+ init();
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} - modifier id is {}", url, userId);
+
+ Map<String, DataTypeDefinition> dataTypes = propertyBusinessLogic.getAllDataTypes();
+ String dataTypeJson = gson.toJson(dataTypes);
+ Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
+ responseWrapper.setInnerElement(okResponse);
+ }
+
+ return responseWrapper.getInnerElement();
+ }
+
+ @GET
+ @Path("interfaceLifecycleTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get interface lifecycle types", method = "GET", summary = "Returns interface lifecycle types", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {
+ @ApiResponse(responseCode = "200", description = "Interface lifecycle types"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Interface lifecycle types not found")
+ })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getInterfaceLifecycleTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+
+ try {
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.info("Start handle request of {} | modifier id is {}", url, userId);
+
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> allInterfaceLifecycleTypes =
+ interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
+
+ if (allInterfaceLifecycleTypes.isRight()) {
+ log.info("Failed to get all interface lifecycle types. Reason - {}",
+ allInterfaceLifecycleTypes.right().value());
+ Response errorResponse = buildErrorResponse(allInterfaceLifecycleTypes.right().value());
+ responseWrapper.setInnerElement(errorResponse);
+
+ } else {
+ String interfaceLifecycleTypeJson = gson.toJson(allInterfaceLifecycleTypes.left().value());
+ Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), interfaceLifecycleTypeJson);
+ responseWrapper.setInnerElement(okResponse);
+
+ }
+ }
+
+ return responseWrapper.getInnerElement();
+ } catch (Exception e) {
+ log.debug("get all interface lifecycle types failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+ @GET
+ @Path("capabilityTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get capability types", method = "GET", summary = "Returns capability types", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "capabilityTypes"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Capability types not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getAllCapabilityTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value =
+ Constants.USER_ID_HEADER) String userId) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+
+ try {
+ init();
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} | modifier id is {}", url, userId);
+
+ Either<Map<String, CapabilityTypeDefinition>, ResponseFormat> allDataTypes =
+ capabilitiesBusinessLogic.getAllCapabilityTypes();
+
+ if (allDataTypes.isRight()) {
+ log.info("Failed to get all capability types. Reason - {}", allDataTypes.right().value());
+ Response errorResponse = buildErrorResponse(allDataTypes.right().value());
+ responseWrapper.setInnerElement(errorResponse);
+
+ } else {
+
+ Map<String, CapabilityTypeDefinition> dataTypes = allDataTypes.left().value();
+ String dataTypeJson = gson.toJson(dataTypes);
+ Response okResponse =
+ buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
+ responseWrapper.setInnerElement(okResponse);
+
+ }
+ }
+
+ return responseWrapper.getInnerElement();
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Capability Types");
+ log.debug("get all capability types failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+
+ @GET
+ @Path("relationshipTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get relationship types", method = "GET", summary = "Returns relationship types", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "relationshipTypes"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Relationship types not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getAllRelationshipTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value =
+ Constants.USER_ID_HEADER) String userId) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+
+ try {
+ init();
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} | modifier id is {}", url, userId);
+
+ Either<Map<String, RelationshipTypeDefinition>, ResponseFormat> allDataTypes =
+ relationshipTypeBusinessLogic.getAllRelationshipTypes();
+
+ if (allDataTypes.isRight()) {
+ log.info("Failed to get all relationship types. Reason - {}", allDataTypes.right().value());
+ Response errorResponse = buildErrorResponse(allDataTypes.right().value());
+ responseWrapper.setInnerElement(errorResponse);
+
+ } else {
+
+ Map<String, RelationshipTypeDefinition> dataTypes = allDataTypes.left().value();
+ String dataTypeJson = gson.toJson(dataTypes);
+ Response okResponse =
+ buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson);
+ responseWrapper.setInnerElement(okResponse);
+
+ }
+ }
+
+ return responseWrapper.getInnerElement();
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Relationship Types");
+ log.debug("get all relationship types failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+
+ @GET
+ @Path("nodeTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get node types", method = "GET", summary = "Returns node types", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "nodeTypes"), @ApiResponse(responseCode = "403", description =
+ "Restricted operation"), @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "404", description = "Node types not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getAllNodeTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value =
+ Constants.USER_ID_HEADER) String userId) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+ ServletContext context = request.getSession().getServletContext();
+ Either<Map<String, Component>, Response> response;
+ Map<String, Component> componentMap;
+
+ try {
+ init();
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} | modifier id is {}", url, userId);
+
+ response = getComponent(resourceBusinessLogic, true, userId);
+ if (response.isRight()) {
+ return response.right().value();
+ }
+ componentMap = new HashMap<>(response.left().value());
+
+ response = getComponent(resourceBusinessLogic, false, userId);
+ if (response.isRight()) {
+ return response.right().value();
+ }
+ componentMap.putAll(response.left().value());
+
+ String nodeTypesJson = gson.toJson(componentMap);
+ Response okResponse =
+ buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), nodeTypesJson);
+ responseWrapper.setInnerElement(okResponse);
+ }
+
+ return responseWrapper.getInnerElement();
+ } catch (Exception e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Node Types");
+ log.debug("get all node types failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
+
+ private Either<Map<String, Component>, Response> getComponent(ComponentBusinessLogic resourceBL, boolean isAbstract,
+ String userId) {
+ Either<List<Component>, ResponseFormat> actionResponse;
+ List<Component> componentList;
+
+ actionResponse =
+ resourceBL.getLatestVersionNotAbstractComponentsMetadata(isAbstract, HighestFilterEnum.HIGHEST_ONLY
+ , ComponentTypeEnum.RESOURCE, null, userId);
+ if (actionResponse.isRight()) {
+ log.debug(FAILED_TO_GET_ALL_NON_ABSTRACT, ComponentTypeEnum.RESOURCE.getValue());
+ return Either.right(buildErrorResponse(actionResponse.right().value()));
+ }
+
+ componentList = actionResponse.left().value();
+
+ return Either.left(ListUtils.emptyIfNull(componentList).stream()
+ .filter(component -> ((ResourceMetadataDataDefinition) component
+ .getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName() != null)
+ .collect(Collectors.toMap(
+ component -> ((ResourceMetadataDataDefinition) component
+ .getComponentMetadataDefinition().getMetadataDataDefinition()).getToscaResourceName(),
+ component -> component, (component1, component2) -> component1)));
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadEndpoint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadEndpoint.java
index 5a148ef39e..98d64dfc47 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadEndpoint.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadEndpoint.java
@@ -20,23 +20,28 @@
package org.openecomp.sdc.be.servlets;
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import com.google.common.annotations.VisibleForTesting;
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.openecomp.sdc.be.components.impl.CommonImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
import org.openecomp.sdc.be.components.validation.AccessValidations;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.zip.exception.ZipException;
@@ -44,19 +49,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
-import com.google.common.annotations.VisibleForTesting;
-import com.jcabi.aspects.Loggable;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.util.List;
+import java.util.Map;
/**
- * Here new APIs for types upload written in an attempt to gradually servlet responseCode
+ * Here new APIs for types upload written in an attempt to gradually servlet code
*/
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
@Path("/v1/catalog/uploadType")
@@ -64,14 +69,16 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
@Produces(MediaType.APPLICATION_JSON)
@OpenAPIDefinition(info = @Info(title = "Catalog Types Upload"))
@Controller
-public class TypesUploadEndpoint {
+public class TypesUploadEndpoint extends BeGenericServlet{
private static final Logger LOGGER = LoggerFactory.getLogger(TypesUploadEndpoint.class);
private final CommonImportManager commonImportManager;
private final AnnotationTypeOperations annotationTypeOperations;
private final AccessValidations accessValidations;
- public TypesUploadEndpoint(CommonImportManager commonImportManager, AnnotationTypeOperations annotationTypeOperations, AccessValidations accessValidations) {
+ public TypesUploadEndpoint(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils, CommonImportManager commonImportManager, AnnotationTypeOperations annotationTypeOperations, AccessValidations accessValidations) {
+ super(userBusinessLogic, componentsUtils);
this.commonImportManager = commonImportManager;
this.annotationTypeOperations = annotationTypeOperations;
this.accessValidations = accessValidations;
@@ -86,7 +93,7 @@ public class TypesUploadEndpoint {
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
@ApiResponse(responseCode = "409", description = "annotation types already exist")})
-
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadAnnotationTypes(@Parameter(description = "FileInputStream") @FormDataParam("annotationTypesZip") File file,
@HeaderParam("USER_ID") String userId) {
accessValidations.validateUserExists(userId, "Annotation Types Creation");
@@ -96,11 +103,11 @@ public class TypesUploadEndpoint {
} catch (final ZipException e) {
LOGGER.error("Could not extract zip contents", e);
}
- List<ImmutablePair<AnnotationTypeDefinition, Boolean>> typesResults =
- commonImportManager.createElementTypes(yamlStringWrapper.getInnerElement(),
- TypesUploadEndpoint::buildAnnotationFromFieldMap, annotationTypeOperations);
+ List<ImmutablePair<AnnotationTypeDefinition, Boolean>> typesResults = commonImportManager.createElementTypes(yamlStringWrapper.getInnerElement(), TypesUploadEndpoint::buildAnnotationFromFieldMap, annotationTypeOperations);
HttpStatus status = getHttpStatus(typesResults);
- return Response.status(status.value()).entity(typesResults).build();
+ return Response.status(status.value())
+ .entity(typesResults)
+ .build();
}
@VisibleForTesting
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
index d1eef493bb..ed0e27b87c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
@@ -1,407 +1,417 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.glassfish.jersey.media.multipart.FormDataParam;
-import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
-import org.openecomp.sdc.be.components.impl.CategoriesImportManager;
-import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.DataTypeImportManager;
-import org.openecomp.sdc.be.components.impl.GroupTypeImportManager;
-import org.openecomp.sdc.be.components.impl.InterfaceLifecycleTypeImportManager;
-import org.openecomp.sdc.be.components.impl.PolicyTypeImportManager;
-import org.openecomp.sdc.be.components.impl.RelationshipTypeImportManager;
-import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.GroupTypeDefinition;
-import org.openecomp.sdc.be.model.PolicyTypeDefinition;
-import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerTwoParam;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.stereotype.Controller;
-import com.google.gson.reflect.TypeToken;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog/uploadType")
-@Consumes(MediaType.MULTIPART_FORM_DATA)
-@Produces(MediaType.APPLICATION_JSON)
-@OpenAPIDefinition(info = @Info(title = "Catalog Types Upload"))
-@Controller
-public class TypesUploadServlet extends AbstractValidationsServlet {
- private static final Logger log = Logger.getLogger(TypesUploadServlet.class);
- public static final String CREATE = "Create ";
-
- private final CapabilityTypeImportManager capabilityTypeImportManager;
- private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
- private final CategoriesImportManager categoriesImportManager;
- private final DataTypeImportManager dataTypeImportManager;
- private final GroupTypeImportManager groupTypeImportManager;
- private final PolicyTypeImportManager policyTypeImportManager;
- private final RelationshipTypeImportManager relationshipTypeImportManager;
-
- @Inject
- public TypesUploadServlet(UserBusinessLogic userBusinessLogic,
- ComponentInstanceBusinessLogic componentInstanceBL,
- ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager,
- CapabilityTypeImportManager capabilityTypeImportManager,
- InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager,
- CategoriesImportManager categoriesImportManager,
- DataTypeImportManager dataTypeImportManager,
- GroupTypeImportManager groupTypeImportManager,
- PolicyTypeImportManager policyTypeImportManager,
- RelationshipTypeImportManager relationshipTypeImportManager) {
- super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.capabilityTypeImportManager = capabilityTypeImportManager;
- this.interfaceLifecycleTypeImportManager = interfaceLifecycleTypeImportManager;
- this.categoriesImportManager = categoriesImportManager;
- this.dataTypeImportManager = dataTypeImportManager;
- this.groupTypeImportManager = groupTypeImportManager;
- this.policyTypeImportManager = policyTypeImportManager;
- this.relationshipTypeImportManager = relationshipTypeImportManager;
- }
-
- @POST
- @Path("/capability")
- @Operation(description = "Create Capability Type from yaml", method = "POST",
- summary = "Returns created Capability Type", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Capability Type created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Capability Type already exist")})
- public Response uploadCapabilityType(@Parameter(description = "FileInputStream") @FormDataParam("capabilityTypeZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod =
- (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
- () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload));
- return uploadElementTypeServletLogic(createElementsMethod, file, request, creator,
- NodeTypeEnum.CapabilityType.name());
- }
-
- @POST
- @Path("/relationship")
- @Operation(description = "Create Relationship Type from yaml", method = "POST",
- summary = "Returns created Relationship Type", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship Type created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Relationship Type already exist")})
- public Response uploadRelationshipType(@Parameter(description = "FileInputStream") @FormDataParam("relationshipTypeZip") File file,
- @Context final HttpServletRequest request,
- @HeaderParam("USER_ID") String creator) {
- return uploadElementTypeServletLogic(this::createRelationshipTypes, file, request, creator,
- NodeTypeEnum.RelationshipType.getName());
- }
-
- @POST
- @Path("/interfaceLifecycle")
- @Operation(description = "Create Interface Lyfecycle Type from yaml", method = "POST",
- summary = "Returns created Interface Lifecycle Type", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Interface Lifecycle Type created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Interface Lifecycle Type already exist")})
- public Response uploadInterfaceLifecycleType(
- @Parameter(description = "FileInputStream") @FormDataParam("interfaceLifecycleTypeZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod =
- (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
- () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload));
- return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "Interface Types");
- }
-
- @POST
- @Path("/categories")
- @Operation(description = "Create Categories from yaml", method = "POST", summary = "Returns created categories",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Categories created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Category already exist")})
- public Response uploadCategories(@Parameter(description = "FileInputStream") @FormDataParam("categoriesZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod =
- (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
- () -> categoriesImportManager.createCategories(ymlPayload));
- return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "categories");
- }
-
- @POST
- @Path("/datatypes")
- @Operation(description = "Create Categories from yaml", method = "POST", summary = "Returns created data types",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Data types created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "Data types already exist")})
- public Response uploadDataTypes(@Parameter(description = "FileInputStream") @FormDataParam("dataTypesZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = this::createDataTypes;
- return uploadElementTypeServletLogic(createElementsMethod, file, request, creator,
- NodeTypeEnum.DataType.getName());
- }
-
- @POST
- @Path("/grouptypes")
- @Operation(description = "Create GroupTypes from yaml", method = "POST", summary = "Returns created group types",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "group types created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "group types already exist")})
- public Response uploadGroupTypes(
- @Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData,
- @Parameter(description = "FileInputStream") @FormDataParam("groupTypesZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData);
- return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator,
- NodeTypeEnum.GroupType.getName());
- }
-
- @POST
- @Path("/policytypes")
- @Operation(description = "Create PolicyTypes from yaml", method = "POST", summary = "Returns created policy types",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "policy types created"),
- @ApiResponse(responseCode = "403", description = "Restricted operation"),
- @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
- @ApiResponse(responseCode = "409", description = "policy types already exist")})
- public Response uploadPolicyTypes(
- @Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData,
- @Parameter(description = "FileInputStream") @FormDataParam("policyTypesZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData);
- return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator,
- NodeTypeEnum.PolicyType.getName());
- }
-
- private Map<String, ToscaTypeMetadata> getTypesMetadata(String toscaTypesMetaData) {
- return gson.fromJson(toscaTypesMetaData, new TypeToken<Map<String, ToscaTypeMetadata>>(){}.getType());
- }
-
- private Response uploadElementTypeServletLogic(ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod, File file, final HttpServletRequest request, String creator, String elementTypeName) {
- init();
- String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
- try {
- Wrapper<String> yamlStringWrapper = new Wrapper<>();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
- Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
- if (responseWrapper.isEmpty()) {
- fillZipContents(yamlStringWrapper, file);
- }
- if (responseWrapper.isEmpty()) {
- createElementsMethod.accept(responseWrapper, yamlStringWrapper.getInnerElement());
- }
- return responseWrapper.getInnerElement();
- } catch (Exception e) {
- log.debug("create {} failed with exception:", elementTypeName, e);
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private Wrapper<Response> doUploadTypeValidations(final HttpServletRequest request, String userId, File file) {
- Wrapper<Response> responseWrapper = new Wrapper<>();
- Wrapper<User> userWrapper = new Wrapper<>();
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {}", url);
-
- validateUserExist(responseWrapper, userWrapper, userId);
-
- if (responseWrapper.isEmpty()) {
- validateUserRole(responseWrapper, userWrapper.getInnerElement());
- }
-
- if (responseWrapper.isEmpty()) {
- validateDataNotNull(responseWrapper, file);
- }
- return responseWrapper;
- }
-
- private Response uploadTypesWithMetaData(ConsumerTwoParam<Wrapper<Response>, ToscaTypeImportData> createElementsMethod, Map<String, ToscaTypeMetadata> typesMetaData, File file, final HttpServletRequest request, String creator, String elementTypeName) {
- init();
- String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
- Wrapper<String> yamlStringWrapper = new Wrapper<>();
- try {
- Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
- if (responseWrapper.isEmpty()) {
- fillZipContents(yamlStringWrapper, file);
- }
- if (responseWrapper.isEmpty()) {
- ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(yamlStringWrapper.getInnerElement(), typesMetaData);
- createElementsMethod.accept(responseWrapper, toscaTypeImportData);
- }
- return responseWrapper.getInnerElement();
- } catch (Exception e) {
- log.debug("create {} failed with exception:", elementTypeName, e);
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- private <T> void createElementsType(Wrapper<Response> responseWrapper, Supplier<Either<T, ResponseFormat>> elementsCreater) {
- Either<T, ResponseFormat> eitherResult = elementsCreater.get();
- if (eitherResult.isRight()) {
- Response response = buildErrorResponse(eitherResult.right().value());
- responseWrapper.setInnerElement(response);
- } else {
- try {
- Response response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), RepresentationUtils.toRepresentation(eitherResult.left().value()));
- responseWrapper.setInnerElement(response);
- } catch (Exception e) {
- Response response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- responseWrapper.setInnerElement(response);
- log.error("#createElementsType - json serialization failed with error: ", e);
- }
- }
- }
-
- // data types
- private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml) {
- final Supplier<Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml =
- () -> dataTypeImportManager.createDataTypes(dataTypesYml);
- buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml,
- ActionStatus.DATA_TYPE_ALREADY_EXIST, NodeTypeEnum.DataType.name());
- }
-
- // group types
- private void createGroupTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData) {
- final Supplier<Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml =
- () -> groupTypeImportManager.createGroupTypes(toscaTypeImportData);
- buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml,
- ActionStatus.GROUP_TYPE_ALREADY_EXIST, NodeTypeEnum.GroupType.name());
- }
-
- // policy types
- private void createPolicyTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData) {
- final Supplier<Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml =
- () -> policyTypeImportManager.createPolicyTypes(toscaTypeImportData);
- buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml,
- ActionStatus.POLICY_TYPE_ALREADY_EXIST, NodeTypeEnum.PolicyType.name());
- }
-
- // data types
- private <ElementTypeDefinition> void buildStatusForElementTypeCreate(Wrapper<Response> responseWrapper, Supplier<Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml, ActionStatus alreadyExistStatus, String elementTypeName) {
- Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat> eitherResult = generateElementTypeFromYml.get();
-
- if (eitherResult.isRight()) {
- Response response = buildErrorResponse(eitherResult.right().value());
- responseWrapper.setInnerElement(response);
- } else {
- Object representation;
- try {
- List<ImmutablePair<ElementTypeDefinition, Boolean>> list = eitherResult.left().value();
- ActionStatus status = ActionStatus.OK;
- if (list != null) {
-
- // Group result by the right value - true or false.
- // I.e., get the number of data types which are new and
- // which are old.
- Map<Boolean, List<ImmutablePair<ElementTypeDefinition, Boolean>>> collect = list.stream().collect(Collectors.groupingBy(ImmutablePair<ElementTypeDefinition, Boolean>::getRight));
- if (collect != null) {
- Set<Boolean> keySet = collect.keySet();
- if (keySet.size() == 1) {
- Boolean isNew = keySet.iterator().next();
- if (isNew.booleanValue()) {
- // all data types created at the first time
- status = ActionStatus.CREATED;
- } else {
- // All data types already exists
-
- status = alreadyExistStatus;
- }
- }
- }
- }
- representation = RepresentationUtils.toRepresentation(eitherResult.left().value());
-
- Response response = buildOkResponse(getComponentsUtils().getResponseFormat(status), representation);
- responseWrapper.setInnerElement(response);
-
- } catch (IOException e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
- log.debug("failed to convert {} to json", elementTypeName, e);
- Response response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- responseWrapper.setInnerElement(response);
- }
- }
- }
- // relationship types
- private void createRelationshipTypes(Wrapper<Response> responseWrapper, String relationshipTypesYml) {
- final Supplier<Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat>>
- generateElementTypeFromYml =
- () -> relationshipTypeImportManager.createRelationshipTypes(relationshipTypesYml);
- buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml,
- ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST, NodeTypeEnum.RelationshipType.name());
- }
-
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.google.gson.reflect.TypeToken;
+import com.jcabi.aspects.Loggable;
+import fj.data.Either;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.glassfish.jersey.media.multipart.FormDataParam;
+import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
+import org.openecomp.sdc.be.components.impl.CategoriesImportManager;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.DataTypeImportManager;
+import org.openecomp.sdc.be.components.impl.GroupTypeImportManager;
+import org.openecomp.sdc.be.components.impl.InterfaceLifecycleTypeImportManager;
+import org.openecomp.sdc.be.components.impl.PolicyTypeImportManager;
+import org.openecomp.sdc.be.components.impl.RelationshipTypeImportManager;
+import org.openecomp.sdc.be.components.impl.ResourceImportManager;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.ServletUtils;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.FunctionalInterfaces.ConsumerTwoParam;
+import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/catalog/uploadType")
+@Consumes(MediaType.MULTIPART_FORM_DATA)
+@Produces(MediaType.APPLICATION_JSON)
+@OpenAPIDefinition(info = @Info(title = "Catalog Types Upload"))
+@Controller
+public class TypesUploadServlet extends AbstractValidationsServlet {
+ private static final Logger log = Logger.getLogger(TypesUploadServlet.class);
+ public static final String CREATE = "Create ";
+
+ private final CapabilityTypeImportManager capabilityTypeImportManager;
+ private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager;
+ private final CategoriesImportManager categoriesImportManager;
+ private final DataTypeImportManager dataTypeImportManager;
+ private final GroupTypeImportManager groupTypeImportManager;
+ private final PolicyTypeImportManager policyTypeImportManager;
+ private final RelationshipTypeImportManager relationshipTypeImportManager;
+
+ @Inject
+ public TypesUploadServlet(UserBusinessLogic userBusinessLogic,
+ ComponentInstanceBusinessLogic componentInstanceBL,
+ ComponentsUtils componentsUtils, ServletUtils servletUtils,
+ ResourceImportManager resourceImportManager,
+ CapabilityTypeImportManager capabilityTypeImportManager,
+ InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager,
+ CategoriesImportManager categoriesImportManager,
+ DataTypeImportManager dataTypeImportManager,
+ GroupTypeImportManager groupTypeImportManager,
+ PolicyTypeImportManager policyTypeImportManager,
+ RelationshipTypeImportManager relationshipTypeImportManager) {
+ super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+ this.capabilityTypeImportManager = capabilityTypeImportManager;
+ this.interfaceLifecycleTypeImportManager = interfaceLifecycleTypeImportManager;
+ this.categoriesImportManager = categoriesImportManager;
+ this.dataTypeImportManager = dataTypeImportManager;
+ this.groupTypeImportManager = groupTypeImportManager;
+ this.policyTypeImportManager = policyTypeImportManager;
+ this.relationshipTypeImportManager = relationshipTypeImportManager;
+ }
+
+ @POST
+ @Path("/capability")
+ @Operation(description = "Create Capability Type from yaml", method = "POST",
+ summary = "Returns created Capability Type", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Capability Type created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Capability Type already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response uploadCapabilityType(@Parameter(description = "FileInputStream") @FormDataParam("capabilityTypeZip") File file,
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod =
+ (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
+ () -> capabilityTypeImportManager.createCapabilityTypes(ymlPayload));
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator,
+ NodeTypeEnum.CapabilityType.name());
+ }
+
+ @POST
+ @Path("/relationship")
+ @Operation(description = "Create Relationship Type from yaml", method = "POST",
+ summary = "Returns created Relationship Type", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Relationship Type created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Relationship Type already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response uploadRelationshipType(@Parameter(description = "FileInputStream") @FormDataParam("relationshipTypeZip") File file,
+ @Context final HttpServletRequest request,
+ @HeaderParam("USER_ID") String creator) {
+ return uploadElementTypeServletLogic(this::createRelationshipTypes, file, request, creator,
+ NodeTypeEnum.RelationshipType.getName());
+ }
+
+ @POST
+ @Path("/interfaceLifecycle")
+ @Operation(description = "Create Interface Lyfecycle Type from yaml", method = "POST",
+ summary = "Returns created Interface Lifecycle Type", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Interface Lifecycle Type created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Interface Lifecycle Type already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response uploadInterfaceLifecycleType(
+ @Parameter(description = "FileInputStream") @FormDataParam("interfaceLifecycleTypeZip") File file,
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod =
+ (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
+ () -> interfaceLifecycleTypeImportManager.createLifecycleTypes(ymlPayload));
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "Interface Types");
+ }
+
+ @POST
+ @Path("/categories")
+ @Operation(description = "Create Categories from yaml", method = "POST", summary = "Returns created categories",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Categories created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Category already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response uploadCategories(@Parameter(description = "FileInputStream") @FormDataParam("categoriesZip") File file,
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod =
+ (responseWrapper, ymlPayload) -> createElementsType(responseWrapper,
+ () -> categoriesImportManager.createCategories(ymlPayload));
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, "categories");
+ }
+
+ @POST
+ @Path("/datatypes")
+ @Operation(description = "Create Categories from yaml", method = "POST", summary = "Returns created data types",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "Data types created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Data types already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response uploadDataTypes(@Parameter(description = "FileInputStream") @FormDataParam("dataTypesZip") File file,
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+ ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = this::createDataTypes;
+ return uploadElementTypeServletLogic(createElementsMethod, file, request, creator,
+ NodeTypeEnum.DataType.getName());
+ }
+
+ @POST
+ @Path("/grouptypes")
+ @Operation(description = "Create GroupTypes from yaml", method = "POST", summary = "Returns created group types",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "group types created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "group types already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response uploadGroupTypes(
+ @Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData,
+ @Parameter(description = "FileInputStream") @FormDataParam("groupTypesZip") File file,
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+ Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData);
+ return uploadTypesWithMetaData(this::createGroupTypes, typesMetadata, file, request, creator,
+ NodeTypeEnum.GroupType.getName());
+ }
+
+ @POST
+ @Path("/policytypes")
+ @Operation(description = "Create PolicyTypes from yaml", method = "POST", summary = "Returns created policy types",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "policy types created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "policy types already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response uploadPolicyTypes(
+ @Parameter(description = "toscaTypeMetadata") @FormDataParam("toscaTypeMetadata") String toscaTypesMetaData,
+ @Parameter(description = "FileInputStream") @FormDataParam("policyTypesZip") File file,
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
+ Map<String, ToscaTypeMetadata> typesMetadata = getTypesMetadata(toscaTypesMetaData);
+ return uploadTypesWithMetaData(this::createPolicyTypes, typesMetadata, file, request, creator,
+ NodeTypeEnum.PolicyType.getName());
+ }
+
+ private Map<String, ToscaTypeMetadata> getTypesMetadata(String toscaTypesMetaData) {
+ return gson.fromJson(toscaTypesMetaData, new TypeToken<Map<String, ToscaTypeMetadata>>(){}.getType());
+ }
+
+ private Response uploadElementTypeServletLogic(ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod, File file, final HttpServletRequest request, String creator, String elementTypeName) {
+ init();
+ String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
+ try {
+ Wrapper<String> yamlStringWrapper = new Wrapper<>();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+ Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
+ if (responseWrapper.isEmpty()) {
+ fillZipContents(yamlStringWrapper, file);
+ }
+ if (responseWrapper.isEmpty()) {
+ createElementsMethod.accept(responseWrapper, yamlStringWrapper.getInnerElement());
+ }
+ return responseWrapper.getInnerElement();
+ } catch (Exception e) {
+ log.debug("create {} failed with exception:", elementTypeName, e);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private Wrapper<Response> doUploadTypeValidations(final HttpServletRequest request, String userId, File file) {
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {}", url);
+
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ validateUserRole(responseWrapper, userWrapper.getInnerElement());
+ }
+
+ if (responseWrapper.isEmpty()) {
+ validateDataNotNull(responseWrapper, file);
+ }
+ return responseWrapper;
+ }
+
+ private Response uploadTypesWithMetaData(ConsumerTwoParam<Wrapper<Response>, ToscaTypeImportData> createElementsMethod, Map<String, ToscaTypeMetadata> typesMetaData, File file, final HttpServletRequest request, String creator, String elementTypeName) {
+ init();
+ String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
+ Wrapper<String> yamlStringWrapper = new Wrapper<>();
+ try {
+ Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
+ if (responseWrapper.isEmpty()) {
+ fillZipContents(yamlStringWrapper, file);
+ }
+ if (responseWrapper.isEmpty()) {
+ ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(yamlStringWrapper.getInnerElement(), typesMetaData);
+ createElementsMethod.accept(responseWrapper, toscaTypeImportData);
+ }
+ return responseWrapper.getInnerElement();
+ } catch (Exception e) {
+ log.debug("create {} failed with exception:", elementTypeName, e);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ private <T> void createElementsType(Wrapper<Response> responseWrapper, Supplier<Either<T, ResponseFormat>> elementsCreater) {
+ Either<T, ResponseFormat> eitherResult = elementsCreater.get();
+ if (eitherResult.isRight()) {
+ Response response = buildErrorResponse(eitherResult.right().value());
+ responseWrapper.setInnerElement(response);
+ } else {
+ try {
+ Response response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), RepresentationUtils.toRepresentation(eitherResult.left().value()));
+ responseWrapper.setInnerElement(response);
+ } catch (Exception e) {
+ Response response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(response);
+ log.error("#createElementsType - json serialization failed with error: ", e);
+ }
+ }
+ }
+
+ // data types
+ private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml) {
+ final Supplier<Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml =
+ () -> dataTypeImportManager.createDataTypes(dataTypesYml);
+ buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml,
+ ActionStatus.DATA_TYPE_ALREADY_EXIST, NodeTypeEnum.DataType.name());
+ }
+
+ // group types
+ private void createGroupTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData) {
+ final Supplier<Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml =
+ () -> groupTypeImportManager.createGroupTypes(toscaTypeImportData);
+ buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml,
+ ActionStatus.GROUP_TYPE_ALREADY_EXIST, NodeTypeEnum.GroupType.name());
+ }
+
+ // policy types
+ private void createPolicyTypes(Wrapper<Response> responseWrapper, ToscaTypeImportData toscaTypeImportData) {
+ final Supplier<Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml =
+ () -> policyTypeImportManager.createPolicyTypes(toscaTypeImportData);
+ buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml,
+ ActionStatus.POLICY_TYPE_ALREADY_EXIST, NodeTypeEnum.PolicyType.name());
+ }
+
+ // data types
+ private <ElementTypeDefinition> void buildStatusForElementTypeCreate(Wrapper<Response> responseWrapper, Supplier<Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml, ActionStatus alreadyExistStatus, String elementTypeName) {
+ Either<List<ImmutablePair<ElementTypeDefinition, Boolean>>, ResponseFormat> eitherResult = generateElementTypeFromYml.get();
+
+ if (eitherResult.isRight()) {
+ Response response = buildErrorResponse(eitherResult.right().value());
+ responseWrapper.setInnerElement(response);
+ } else {
+ Object representation;
+ try {
+ List<ImmutablePair<ElementTypeDefinition, Boolean>> list = eitherResult.left().value();
+ ActionStatus status = ActionStatus.OK;
+ if (list != null) {
+
+ // Group result by the right value - true or false.
+ // I.e., get the number of data types which are new and
+ // which are old.
+ Map<Boolean, List<ImmutablePair<ElementTypeDefinition, Boolean>>> collect = list.stream().collect(Collectors.groupingBy(ImmutablePair<ElementTypeDefinition, Boolean>::getRight));
+ if (collect != null) {
+ Set<Boolean> keySet = collect.keySet();
+ if (keySet.size() == 1) {
+ Boolean isNew = keySet.iterator().next();
+ if (isNew) {
+ // all data types created at the first time
+ status = ActionStatus.CREATED;
+ } else {
+ // All data types already exists
+
+ status = alreadyExistStatus;
+ }
+ }
+ }
+ }
+ representation = RepresentationUtils.toRepresentation(eitherResult.left().value());
+
+ Response response = buildOkResponse(getComponentsUtils().getResponseFormat(status), representation);
+ responseWrapper.setInnerElement(response);
+
+ } catch (IOException e) {
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
+ log.debug("failed to convert {} to json", elementTypeName, e);
+ Response response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ responseWrapper.setInnerElement(response);
+ }
+ }
+ }
+ // relationship types
+ private void createRelationshipTypes(Wrapper<Response> responseWrapper, String relationshipTypesYml) {
+ final Supplier<Either<List<ImmutablePair<RelationshipTypeDefinition, Boolean>>, ResponseFormat>>
+ generateElementTypeFromYml =
+ () -> relationshipTypeImportManager.createRelationshipTypes(relationshipTypesYml);
+ buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml,
+ ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST, NodeTypeEnum.RelationshipType.name());
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java
index 15646c26c0..a95c75c87e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/UserAdminServlet.java
@@ -1,455 +1,275 @@
-/*-
- * ============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.sdc.be.servlets;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.List;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-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;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.ResponseFormat;
-import com.jcabi.aspects.Loggable;
-import fj.data.Either;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.responses.ApiResponses;
-
-@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/user")
-@OpenAPIDefinition(info = @Info(title = "User Administration", description = "User admininstarator operations"))
-@Singleton
-public class UserAdminServlet extends BeGenericServlet {
-
- private static final String UTF_8 = "UTF-8";
- private static final String START_HANDLE_REQUEST_OF = "Start handle request of {}";
- private static final String ROLE_DELIMITER = ",";
- private static final Logger log = Logger.getLogger(UserAdminServlet.class);
- private final UserBusinessLogic userBusinessLogic;
-
- @Inject
- public UserAdminServlet(UserBusinessLogic userBusinessLogic,
- ComponentsUtils componentsUtils) {
- super(userBusinessLogic, componentsUtils);
- this.userBusinessLogic = userBusinessLogic;
- }
-
- /***************************************
- * API start
- *************************************************************/
-
- /* User by userId CRUD start */
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // retrieve all user details
- @GET
- @Path("/{userId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "retrieve user details", method = "GET",
- summary = "Returns user details according to userId",responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns user Ok"),
- @ApiResponse(responseCode = "404", description = "User not found"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response get(
- @Parameter(description = "userId of user to get", required = true) @PathParam("userId") final String userId,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
-
- try {
- Either<User, ActionStatus> either = userBusinessLogic.getUser(userId, false);
-
- if (either.isRight()) {
- return buildErrorResponse(
- getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
- } else {
- if (either.left().value() != null) {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- either.left().value());
- } else {
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get User");
- log.debug("get user failed with unexpected error: {}", e.getMessage(), e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Path("/{userId}/role")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "retrieve user role", summary = "Returns user role according to userId",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns user role Ok"),
- @ApiResponse(responseCode = "404", description = "User not found"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getRole(
- @Parameter(description = "userId of user to get", required = true) @PathParam("userId") final String userId,
- @Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(getRole) Start handle request of {}", url);
-
- try {
- Either<User, ActionStatus> either = userBusinessLogic.getUser(userId, false);
- if (either.isRight()) {
- return buildErrorResponse(
- getComponentsUtils().getResponseFormatByUserId(either.right().value(), userId));
- } else {
- if (either.left().value() != null) {
- String roleJson = "{ \"role\" : \"" + either.left().value().getRole() + "\" }";
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), roleJson);
- } else {
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get User Role");
- log.debug("Get user role failed with unexpected error: {}", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // update user role
- @POST
- @Path("/{userId}/role")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "update user role", summary = "Update user role", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Update user OK"),
- @ApiResponse(responseCode = "400", description = "Invalid Content."),
- @ApiResponse(responseCode = "403", description = "Missing information/Restricted operation"),
- @ApiResponse(responseCode = "404", description = "User not found"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
- @ApiResponse(responseCode = "409", description = "User already exists"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response updateUserRole(
- @Parameter(description = "userId of user to get",
- required = true) @PathParam("userId") final String userIdUpdateUser,
- @Context final HttpServletRequest request,
- @Parameter(description = "json describe the update role", required = true) String data,
- @HeaderParam(value = Constants.USER_ID_HEADER) String modifierUserId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(modifierUserId);
- log.debug("modifier id is {}", modifierUserId);
-
- Response response = null;
-
- try {
- User updateInfoUser = getComponentsUtils().convertJsonToObject(data, modifier, User.class, AuditingActionEnum.UPDATE_USER).left().value();
- Either<User, ResponseFormat> updateUserResponse = userBusinessLogic.updateUserRole(modifier, userIdUpdateUser, updateInfoUser.getRole());
-
- if (updateUserResponse.isRight()) {
- log.debug("failed to update user role");
- response = buildErrorResponse(updateUserResponse.right().value());
- return response;
- }
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), updateUserResponse.left().value());
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update User Metadata");
- log.debug("Update User Role failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- /* User role CRUD end */
-
- /* New user CRUD start */
- @POST
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "add user", method = "POST", summary = "Provision new user", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "New user created"),
- @ApiResponse(responseCode = "400", description = "Invalid Content."),
- @ApiResponse(responseCode = "403", description = "Missing information"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
- @ApiResponse(responseCode = "409", description = "User already exists"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response createUser(@Context final HttpServletRequest request,
- @Parameter(description = "json describe the user", required = true) String newUserData,
- @HeaderParam(value = Constants.USER_ID_HEADER) String modifierAttId) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- // get modifier id
- User modifier = new User();
- modifier.setUserId(modifierAttId);
- log.debug("modifier id is {}", modifierAttId);
-
- Response response = null;
-
- try {
- User newUserInfo = getComponentsUtils().convertJsonToObject(newUserData, modifier, User.class, AuditingActionEnum.ADD_USER).left().value();
- Either<User, ResponseFormat> createUserResponse = userBusinessLogic.createUser(modifier, newUserInfo);
-
- if (createUserResponse.isRight()) {
- log.debug("failed to create user");
- response = buildErrorResponse(createUserResponse.right().value());
- return response;
- }
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), createUserResponse.left().value());
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Update User Metadata");
- log.debug("Create User failed with exception", e);
- response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- return response;
-
- }
- }
-
- /* New user CRUD end */
-
- /* User authorization start */
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // User Authorization
- @GET
- @Path("/authorize")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
-
- @Operation(description = "authorize", summary = "authorize user", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Returns user Ok"), @ApiResponse(responseCode = "403", description = "Restricted Access"), @ApiResponse(responseCode = "500", description = "Internal Server Error") })
- public Response authorize(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @HeaderParam("HTTP_CSP_FIRSTNAME") String firstName, @HeaderParam("HTTP_CSP_LASTNAME") String lastName,
- @HeaderParam("HTTP_CSP_EMAIL") String email) {
-
- try {
- userId = userId != null ? URLDecoder.decode(userId, UTF_8) : null;
- firstName = firstName != null ? URLDecoder.decode(firstName, UTF_8) : null;
- lastName = lastName != null ? URLDecoder.decode(lastName, UTF_8) : null;
- email = email != null ? URLDecoder.decode(email, UTF_8) : null;
- } catch (UnsupportedEncodingException e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Authorize User - decode headers");
- ResponseFormat errorResponseWrapper = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
- log.error("#authorize - authorization decoding failed with error: ", e);
- return buildErrorResponse(errorResponseWrapper);
- }
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug(START_HANDLE_REQUEST_OF, url);
-
- User authUser = new User();
- authUser.setUserId(userId);
- authUser.setFirstName(firstName);
- authUser.setLastName(lastName);
- authUser.setEmail(email);
- log.debug("auth user id is {}", userId);
-
- Response response = null;
- try {
- Either<User, ResponseFormat> authorize = userBusinessLogic.authorize(authUser);
-
- if (authorize.isRight()) {
- log.debug("authorize user failed");
- response = buildErrorResponse(authorize.right().value());
- return response;
- }
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), authorize.left().value());
- return response;
-
- } catch (Exception e) {
- log.debug("authorize user failed with unexpected error: {}", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- /* User authorization end */
-
- @GET
- @Path("/admins")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "retrieve all administrators", method = "GET", summary = "Returns all administrators",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns user Ok"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getAdminsUser(@Context final HttpServletRequest request) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("(get) Start handle request of {}", url);
-
- try {
- Either<List<User>, ResponseFormat> either = userBusinessLogic.getAllAdminUsers();
-
- if (either.isRight()) {
- log.debug("Failed to get all admin users");
- return buildErrorResponse(either.right().value());
- } else {
- if (either.left().value() != null) {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
- either.left().value());
- } else {
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get All Administrators");
- log.debug("get all admins failed with unexpected error: {}", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-
- @GET
- @Path("/users")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Retrieve the list of all active ASDC users or only group of users having specific roles.",
- method = "GET",
- summary = "Returns list of users with the specified roles, or all of users in the case of empty 'roles' header",
- responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns users Ok"),
- @ApiResponse(responseCode = "204", description = "No provisioned ASDC users of requested role"),
- @ApiResponse(responseCode = "403", description = "Restricted Access"),
- @ApiResponse(responseCode = "400", description = "Missing content"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response getUsersList(@Context final HttpServletRequest request, @Parameter(
- description = "Any active user's USER_ID ") @HeaderParam(Constants.USER_ID_HEADER) final String userId,
- @Parameter(
- description = "TESTER,DESIGNER,PRODUCT_STRATEGIST,OPS,PRODUCT_MANAGER,GOVERNOR, ADMIN OR all users by not typing anything") @QueryParam("roles") final String roles) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} modifier id is {}", url, userId);
-
- List<String> rolesList = new ArrayList<>();
- if (roles != null && !roles.trim().isEmpty()) {
- String[] rolesArr = roles.split(ROLE_DELIMITER);
- for (String role : rolesArr) {
- rolesList.add(role.trim());
- }
- }
-
- try {
- Either<List<User>, ResponseFormat> either = userBusinessLogic.getUsersList(userId, rolesList, roles);
-
- if (either.isRight()) {
- log.debug("Failed to get ASDC users");
- return buildErrorResponse(either.right().value());
- } else {
- return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), either.left().value());
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get ASDC users");
- log.debug("get users failed with unexpected error: {}", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
-
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // delete user
- @DELETE
- @Path("/{userId}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "delete user", summary = "Delete user", responses = @ApiResponse(
- content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
- @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Update deleted OK"),
- @ApiResponse(responseCode = "400", description = "Invalid Content."),
- @ApiResponse(responseCode = "403", description = "Missing information"),
- @ApiResponse(responseCode = "404", description = "User not found"),
- @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
- @ApiResponse(responseCode = "409", description = "Restricted operation"),
- @ApiResponse(responseCode = "500", description = "Internal Server Error")})
- public Response deActivateUser(
- @Parameter(description = "userId of user to get", required = true) @PathParam("userId") final String userId,
- @Context final HttpServletRequest request,
- @HeaderParam(value = Constants.USER_ID_HEADER) String userIdHeader) {
-
- String url = request.getMethod() + " " + request.getRequestURI();
- log.debug("Start handle request of {} modifier id is {}", url, userIdHeader);
-
- User modifier = new User();
- modifier.setUserId(userIdHeader);
-
- Response response = null;
- try {
- Either<User, ResponseFormat> deactiveUserResponse = userBusinessLogic.deActivateUser(modifier, userId);
-
- if (deactiveUserResponse.isRight()) {
- log.debug("Failed to deactivate user");
- response = buildErrorResponse(deactiveUserResponse.right().value());
- return response;
- }
- response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), deactiveUserResponse.left().value());
- return response;
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get ASDC users");
- log.debug("deactivate user failed with unexpected error: {}", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
- }
-}
+/*-
+ * ============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.sdc.be.servlets;
+
+import com.jcabi.aspects.Loggable;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import org.eclipse.jetty.http.HttpStatus;
+import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
+import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.user.Role;
+import org.openecomp.sdc.be.user.UserBusinessLogic;
+import org.openecomp.sdc.be.user.UserBusinessLogicExt;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Controller;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+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;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.List;
+@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
+@Path("/v1/user")
+@OpenAPIDefinition(info = @Info(title = "User Administration", description = "User admininstarator operations"))
+@Controller
+public class UserAdminServlet extends BeGenericServlet {
+
+ private static final String UTF_8 = "UTF-8";
+ private static final String ROLE_DELIMITER = ",";
+ private static final Logger log = Logger.getLogger(UserAdminServlet.class);
+ private final UserBusinessLogic userBusinessLogic;
+ private final UserBusinessLogicExt userBusinessLogicExt;
+
+ static class UserRole {
+ Role role;
+
+ public Role getRole() {
+ return role;
+ }
+
+ public void setRole(Role role) {
+ this.role = role;
+ }
+
+ }
+
+ UserAdminServlet(UserBusinessLogic userBusinessLogic,
+ ComponentsUtils componentsUtils, UserBusinessLogicExt userBusinessLogicExt) {
+ super(userBusinessLogic, componentsUtils);
+ this.userBusinessLogic = userBusinessLogic;
+ this.userBusinessLogicExt = userBusinessLogicExt;
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // retrieve all user details
+ @GET
+ @Path("/{userId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "retrieve user details", method = "GET",
+ summary = "Returns user details according to userId",responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns user Ok"),
+ @ApiResponse(responseCode = "404", description = "User not found"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public User get(
+ @Parameter(description = "userId of user to get", required = true) @PathParam("userId") final String userId,
+ @Context final HttpServletRequest request) {
+ return userBusinessLogic.getUser(userId, false);
+ }
+
+ @GET
+ @Path("/{userId}/role")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "retrieve user role", summary = "Returns user role according to userId",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns user role Ok"),
+ @ApiResponse(responseCode = "404", description = "User not found"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public String getRole(
+ @Parameter(description = "userId of user to get", required = true) @PathParam("userId") final String userId,
+ @Context final HttpServletRequest request) {
+ User user = userBusinessLogic.getUser(userId, false);
+ return "{ \"role\" : \"" + user.getRole() + "\" }";
+ }
+
+ /////////////////////////////////////////////////////////////////////////////////////////////////////
+ // update user role
+ @POST
+ @Path("/{userId}/role")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "update user role", summary = "Update user role", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Update user OK"),
+ @ApiResponse(responseCode = "400", description = "Invalid Content."),
+ @ApiResponse(responseCode = "403", description = "Missing information/Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "User not found"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
+ @ApiResponse(responseCode = "409", description = "User already exists"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public User updateUserRole(
+ @Parameter(description = "userId of user to get",
+ required = true) @PathParam("userId") final String userIdUpdateUser,
+ @Context final HttpServletRequest request,
+ @Parameter(description = "json describe the update role", required = true) UserRole newRole,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String modifierUserId) {
+
+ return userBusinessLogic.updateUserRole(modifierUserId, userIdUpdateUser, newRole.getRole().name());
+ }
+
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "add user", method = "POST", summary = "Provision new user", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "201", description = "New user created"),
+ @ApiResponse(responseCode = "400", description = "Invalid Content."),
+ @ApiResponse(responseCode = "403", description = "Missing information"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
+ @ApiResponse(responseCode = "409", description = "User already exists"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ public Response createUser(@Context final HttpServletRequest request,
+ @Parameter(description = "json describe the user", required = true) User newUser,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String modifierAttId) {
+
+ log.debug("modifier id is {}", modifierAttId);
+ User user = userBusinessLogic.createUser(modifierAttId, newUser);
+ return Response.status(HttpStatus.CREATED_201)
+ .entity(user)
+ .build();
+ }
+
+ @GET
+ @Path("/authorize")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+
+ @Operation(description = "authorize", summary = "authorize user", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Returns user Ok"), @ApiResponse(responseCode = "403", description = "Restricted Access"), @ApiResponse(responseCode = "500", description = "Internal Server Error") })
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public User authorize(@HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @HeaderParam("HTTP_CSP_FIRSTNAME") String firstName,
+ @HeaderParam("HTTP_CSP_LASTNAME") String lastName,
+ @HeaderParam("HTTP_CSP_EMAIL") String email) throws UnsupportedEncodingException {
+
+ userId = userId != null ? URLDecoder.decode(userId, UTF_8) : null;
+ firstName = firstName != null ? URLDecoder.decode(firstName, UTF_8) : null;
+ lastName = lastName != null ? URLDecoder.decode(lastName, UTF_8) : null;
+ email = email != null ? URLDecoder.decode(email, UTF_8) : null;
+
+ User authUser = new User();
+ authUser.setUserId(userId);
+ authUser.setFirstName(firstName);
+ authUser.setLastName(lastName);
+ authUser.setEmail(email);
+ return userBusinessLogic.authorize(authUser);
+ }
+
+ @GET
+ @Path("/admins")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "retrieve all administrators", method = "GET", summary = "Returns all administrators",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns user Ok"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public List<User> getAdminsUser(@Context final HttpServletRequest request) {
+ return userBusinessLogic.getAllAdminUsers();
+ }
+
+ @GET
+ @Path("/users")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Retrieve the list of all active ASDC users or only group of users having specific roles.",
+ method = "GET",
+ summary = "Returns list of users with the specified roles, or all of users in the case of empty 'roles' header",
+ responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Returns users Ok"),
+ @ApiResponse(responseCode = "204", description = "No provisioned ASDC users of requested role"),
+ @ApiResponse(responseCode = "403", description = "Restricted Access"),
+ @ApiResponse(responseCode = "400", description = "Missing content"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ public List<User> getUsersList(@Context final HttpServletRequest request, @Parameter(
+ description = "Any active user's USER_ID ") @HeaderParam(Constants.USER_ID_HEADER) final String userId,
+ @Parameter(
+ description = "TESTER,DESIGNER,PRODUCT_STRATEGIST,OPS,PRODUCT_MANAGER,GOVERNOR, ADMIN OR all users by not typing anything") @QueryParam("roles") final String roles) {
+
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug("Start handle request of {} modifier id is {}", url, userId);
+
+ List<String> rolesList = new ArrayList<>();
+ if (roles != null && !roles.trim().isEmpty()) {
+ String[] rolesArr = roles.split(ROLE_DELIMITER);
+ for (String role : rolesArr) {
+ rolesList.add(role.trim());
+ }
+ }
+ return userBusinessLogic.getUsersList(userId, rolesList, roles);
+ }
+
+ @DELETE
+ @Path("/{userId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "delete user", summary = "Delete user", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = User.class)))))
+ @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Update deleted OK"),
+ @ApiResponse(responseCode = "400", description = "Invalid Content."),
+ @ApiResponse(responseCode = "403", description = "Missing information"),
+ @ApiResponse(responseCode = "404", description = "User not found"),
+ @ApiResponse(responseCode = "405", description = "Method Not Allowed"),
+ @ApiResponse(responseCode = "409", description = "Restricted operation"),
+ @ApiResponse(responseCode = "500", description = "Internal Server Error")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public User deActivateUser(
+ @Parameter(description = "userId of user to get", required = true) @PathParam("userId") final String userId,
+ @Context final HttpServletRequest request,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String modifierId) {
+ return userBusinessLogicExt.deActivateUser(modifierId, userId);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java
index 19ef727b57..72b2362945 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java
@@ -23,17 +23,19 @@ package org.openecomp.sdc.be.servlets.exception;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
-import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
+import org.onap.sdc.security.RepresentationUtils;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Component;
+import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
+import java.io.IOException;
@Component
@Provider
@@ -52,9 +54,28 @@ public class ComponentExceptionMapper implements ExceptionMapper<ComponentExcept
// TODO log this? BeEcompErrorManager.getInstance().logBeRestApiGeneralError(requestURI);
log.debug("#toResponse - An error occurred: ", exception);
ResponseFormat responseFormat = exception.getResponseFormat();
+ if (exception.getResponseFormat()==null) {
+ if (exception.getResource() == null) {
+ responseFormat = componentsUtils.getResponseFormat(exception.getActionStatus(), exception.getParams());
+ }
+ else {
+ responseFormat = componentsUtils.getResponseFormatByResource(exception.getActionStatus(), exception.getResource());
+ }
+ }
+
return Response.status(responseFormat.getStatus())
.entity(gson.toJson(responseFormat.getRequestError()))
.build();
}
+ public void writeToResponse(ComponentException ce, HttpServletResponse httpResponse) throws IOException {
+ log.info("Error during request filter= {}", ce.getActionStatus());
+ ResponseFormat responseFormat = ResponseFormatManager.getInstance()
+ .getResponseFormat(ce.getActionStatus(), ce.getParams());
+ httpResponse.setStatus(responseFormat.getStatus());
+ httpResponse.setContentType("application/json");
+ httpResponse.setCharacterEncoding("UTF-8");
+ httpResponse.getWriter().write(RepresentationUtils.toRepresentation(responseFormat.getRequestError()));
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ConstraintViolationExceptionMapper.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ConstraintViolationExceptionMapper.java
new file mode 100644
index 0000000000..516ab5d85c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ConstraintViolationExceptionMapper.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets.exception;
+
+import org.openecomp.sdc.be.config.ErrorInfo;
+import org.springframework.stereotype.Component;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import java.util.Set;
+
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+
+@Component
+@Provider
+public class ConstraintViolationExceptionMapper implements ExceptionMapper<ConstraintViolationException> {
+
+ @Override
+ public Response toResponse(ConstraintViolationException exception) {
+ Set<ConstraintViolation<?>> constraintViolations = exception.getConstraintViolations();
+ ErrorInfo error = new ErrorInfo();
+ error.setCode(500);
+ error.setMessage(constraintViolations.toString());
+ return Response.status(BAD_REQUEST)
+ .entity(error)
+ .build();
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/PropertyConstraintExceptionMapper.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/PropertyConstraintExceptionMapper.java
new file mode 100644
index 0000000000..cc90ecf00a
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/PropertyConstraintExceptionMapper.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.servlets.exception;
+
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.tosca.constraints.exception.PropertyConstraintException;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+@Component
+@Provider
+public class PropertyConstraintExceptionMapper implements ExceptionMapper<PropertyConstraintException> {
+
+ private static final Logger log = Logger.getLogger(PropertyConstraintExceptionMapper.class);
+ private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ private final ComponentsUtils componentsUtils;
+
+ public PropertyConstraintExceptionMapper(ComponentsUtils componentsUtils) {
+ this.componentsUtils = componentsUtils;
+ }
+
+ @Override
+ public Response toResponse(PropertyConstraintException exception) {
+ log.debug("#toResponse - An error occurred: ", exception);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(exception.getActionStatus(), exception.getParams());
+ return Response.status(responseFormat.getStatus())
+ .entity(gson.toJson(responseFormat.getRequestError()))
+ .build();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java b/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
index 9e0c130b21..f2f1668fb6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/switchover/detector/SwitchoverDetector.java
@@ -21,7 +21,6 @@
package org.openecomp.sdc.be.switchover.detector;
import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.codec.binary.Base64;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -35,7 +34,12 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.net.InetAddress;
import java.util.Properties;
-import java.util.concurrent.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
@Component("switchover-detector")
public class SwitchoverDetector {
@@ -117,13 +121,6 @@ public class SwitchoverDetector {
return queryGss(switchoverDetectorConfig.getgFeFqdn(), switchoverDetectorConfig.getFeVip(), maxFeQueryAttempts);
}
- private void setAuthorizationProperties() {
- String userInfo = switchoverDetectorConfig.getChangePriorityUser() + ":" + switchoverDetectorConfig.getChangePriorityPassword();
- String auth = "Basic " + new String(new Base64().encode(userInfo.getBytes()));
- authHeader = new Properties();
- authHeader.put("Authorization", auth);
- }
-
private void initializeSiteMode() {
while (siteMode.equals(SwitchoverDetectorState.UNKNOWN.getState())) {
@@ -183,9 +180,10 @@ public class SwitchoverDetector {
return;
}
- Boolean updateRequired = siteMode == SwitchoverDetectorState.STANDBY.getState() && (beRes || feRes) && (beMatch != beRes || feMatch != feRes);
+ Boolean updateRequired = siteMode.equals(SwitchoverDetectorState.STANDBY.getState()) && (beRes || feRes) && (beMatch != beRes || feMatch != feRes);
+ Boolean prevModeStandby = siteMode.equals(SwitchoverDetectorState.STANDBY.getState());
- updateSiteModeAndPriority(beRes && feRes, siteMode == SwitchoverDetectorState.STANDBY.getState(), updateRequired);
+ updateSiteModeAndPriority(beRes && feRes, prevModeStandby, updateRequired);
beMatch = beRes;
feMatch = feRes;
@@ -279,7 +277,6 @@ public class SwitchoverDetector {
maxFeQueryAttempts = maxAttempts.intValue();
}
- setAuthorizationProperties();
logger.info("switchover detector service is enabled, interval is {} seconds", detectorInterval);
this.switchoverDetectorScheduledTask = new SwitchoverDetectorScheduledTask();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/togglz/CassandraCustomStateRepository.java b/catalog-be/src/main/java/org/openecomp/sdc/be/togglz/CassandraCustomStateRepository.java
new file mode 100644
index 0000000000..a67bf4b9f4
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/togglz/CassandraCustomStateRepository.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.togglz;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.dao.cassandra.FeatureToggleDao;
+import org.openecomp.sdc.be.resources.data.togglz.FeatureToggleEvent;
+import org.openecomp.sdc.be.resources.data.togglz.ToggleableFeature;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Component;
+import org.togglz.core.Feature;
+import org.togglz.core.repository.FeatureState;
+import org.togglz.core.repository.StateRepository;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Component
+public class CassandraCustomStateRepository implements StateRepository {
+
+ private final static Logger logger = Logger.getLogger(CassandraCustomStateRepository.class);
+ private final FeatureToggleDao featureToggleDao;
+
+ public CassandraCustomStateRepository(FeatureToggleDao featureToggleDao) {
+ this.featureToggleDao = featureToggleDao;
+ }
+
+ @PostConstruct
+ private void init() {
+ removeUnusedItems();
+ }
+
+ @VisibleForTesting
+ void removeUnusedItems() {
+ List<FeatureToggleEvent> allEvents = featureToggleDao.getAllFeatures();
+
+ List<FeatureToggleEvent> eventsToDelete = allEvents.stream()
+ .filter(e-> ToggleableFeature.getFeatureByName(e.getFeatureName()) == null)
+ .collect(Collectors.toList());
+ if (!eventsToDelete.isEmpty()) {
+ logger.debug("Found Feature toggles not in use [{}], they will be deleted",
+ eventsToDelete.stream().map(FeatureToggleEvent::getFeatureName).collect(Collectors.toList()));
+ }
+ eventsToDelete.forEach(e->featureToggleDao.delete(e.getFeatureName()));
+ }
+
+ @Override
+ public FeatureState getFeatureState(Feature feature) {
+ logger.debug("getFeatureState=> Request is received for a Feature {}", feature);
+ if (feature == null) {
+ throw new IllegalArgumentException("Feature object is null");
+ }
+ FeatureState state = null;
+ FeatureToggleEvent event = featureToggleDao.get(feature.name());
+
+ if (event != null) {
+ state = event.getFeatureState();
+ logger.debug("State of feature {} is {}", feature, state.getFeature());
+ }
+ return state;
+ }
+
+ @Override
+ public void setFeatureState(FeatureState featureState) {
+ if (featureState == null) {
+ throw new IllegalArgumentException("FeatureState object is null");
+ }
+ CassandraOperationStatus status = featureToggleDao.save(new FeatureToggleEvent(featureState));
+ logger.debug("setFeatureState=> FeatureState {} is set with status {}", featureState.getFeature(), status);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/togglz/ToggleConfiguration.java b/catalog-be/src/main/java/org/openecomp/sdc/be/togglz/ToggleConfiguration.java
new file mode 100644
index 0000000000..52bbf86c6e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/togglz/ToggleConfiguration.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.togglz;
+
+import org.openecomp.sdc.be.resources.data.togglz.ToggleableFeature;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.togglz.core.Feature;
+import org.togglz.core.manager.TogglzConfig;
+import org.togglz.core.repository.StateRepository;
+import org.togglz.core.repository.cache.CachingStateRepository;
+import org.togglz.core.user.SimpleFeatureUser;
+import org.togglz.core.user.UserProvider;
+
+@Component
+public class ToggleConfiguration implements TogglzConfig {
+ @Autowired
+ private CassandraCustomStateRepository cassandraCustomStateRepository;
+
+ @Override
+ public Class<? extends Feature> getFeatureClass() {
+ return ToggleableFeature.class;
+ }
+
+ @Override
+ public StateRepository getStateRepository() {
+ return new CachingStateRepository(cassandraCustomStateRepository, 10000);
+ }
+
+ @Override
+ public UserProvider getUserProvider() {
+ return () -> new SimpleFeatureUser("admin", true);
+ }
+} \ No newline at end of file
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java
index 8e06c02767..81380301f8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java
@@ -30,18 +30,38 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.utils.ComponentUtilities;
import org.openecomp.sdc.be.tosca.ToscaUtils.SubstitutionEntry;
-import org.openecomp.sdc.be.tosca.model.*;
+import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
+import org.openecomp.sdc.be.tosca.model.ToscaCapability;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaRequirement;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateCapability;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -62,6 +82,7 @@ public class CapabilityRequirementConverter {
private static CapabilityRequirementConverter instance;
private static final Logger logger = Logger.getLogger(CapabilityRequirementConverter.class);
private static final String PATH_DELIMITER = ".";
+ private static final String FAILED_TO_FIND_CI_IN_PATH ="Failed to find ci in the path is {} component {}";
@Autowired
private ToscaOperationFacade toscaOperationFacade;
@@ -366,7 +387,7 @@ public class CapabilityRequirementConverter {
Optional<ComponentInstance> ci =
component.safeGetComponentInstances().stream().filter(c->c.getUniqueId().equals(Iterables.getLast(path))).findFirst();
if(!ci.isPresent()){
- logger.debug("Failed to find ci in the path is {} component {}", path, component.getUniqueId());
+ logger.debug(FAILED_TO_FIND_CI_IN_PATH, path, component.getUniqueId());
Collections.reverse(path);
@@ -390,7 +411,7 @@ public class CapabilityRequirementConverter {
entry.setFullName(fullName);
entry.setSourceName(sourceName);
} else {
- logger.debug("Failed to find ci in the path is {} component {}", path, component.getUniqueId());
+ logger.debug(FAILED_TO_FIND_CI_IN_PATH, path, component.getUniqueId());
return false;
}
return true;
@@ -578,7 +599,7 @@ public class CapabilityRequirementConverter {
}
Optional<ComponentInstance> ci = component.safeGetComponentInstances().stream().filter(c->c.getUniqueId().equals(Iterables.getLast(path))).findFirst();
if(!ci.isPresent()){
- logger.debug("Failed to find ci in the path is {} component {}", path, component.getUniqueId());
+ logger.debug(FAILED_TO_FIND_CI_IN_PATH, path, component.getUniqueId());
Collections.reverse(path);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index 836565c1fe..80bee80d06 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -36,15 +36,22 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
import org.openecomp.sdc.be.dao.cassandra.SdcSchemaFilesCassandraDao;
+import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.*;
+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.InterfaceDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.resources.data.DAOArtifactData;
import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
@@ -52,6 +59,9 @@ import org.openecomp.sdc.be.utils.CommonBeUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.log.elements.LoggerSupportability;
+import org.openecomp.sdc.common.log.enums.LoggerSupportabilityActions;
+import org.openecomp.sdc.common.log.enums.StatusCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.common.util.ValidationUtils;
@@ -63,13 +73,22 @@ import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
+
/**
* @author tg851x
*
@@ -77,357 +96,359 @@ import java.util.zip.ZipOutputStream;
@org.springframework.stereotype.Component("csar-utils")
public class CsarUtils {
private static final Logger log = Logger.getLogger(CsarUtils.class);
-
- @Autowired
- private SdcSchemaFilesCassandraDao sdcSchemaFilesCassandraDao;
- @Autowired
- private ArtifactCassandraDao artifactCassandraDao;
- @Autowired
- private ComponentsUtils componentsUtils;
- @Autowired
- private ToscaExportHandler toscaExportUtils;
- @Autowired
- protected ToscaOperationFacade toscaOperationFacade;
-
- private String CONFORMANCE_LEVEL;
- private String SDC_VERSION;
- public static final Pattern UUID_NORMATIVE_NEW_VERSION = Pattern.compile("^\\d{1,}.0");
- public static final String ARTIFACTS_PATH = "Artifacts/";
- public static final String RESOURCES_PATH = "Resources/";
- public static final String INFORMATIONAL_ARTIFACTS = "Informational/";
- public static final String DEPLOYMENT_ARTIFACTS = "Deployment/";
-
- public static final String DEFINITIONS_PATH = "Definitions/";
- private static final String CSAR_META_VERSION = "1.0";
- private static final String CSAR_META_PATH_FILE_NAME = "csar.meta";
- private static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta";
- private static final String TOSCA_META_VERSION = "1.0";
- private static final String CSAR_VERSION = "1.1";
- public static final String ARTIFACTS = "Artifacts";
+ private static final LoggerSupportability loggerSupportability = LoggerSupportability.getLogger(CsarUtils.class.getName());
+ private static final String PATH_DELIMITER = "/";
+ @Autowired
+ private SdcSchemaFilesCassandraDao sdcSchemaFilesCassandraDao;
+ @Autowired
+ private ArtifactCassandraDao artifactCassandraDao;
+ @Autowired
+ private ComponentsUtils componentsUtils;
+ @Autowired
+ private ToscaExportHandler toscaExportUtils;
+ @Autowired
+ protected ToscaOperationFacade toscaOperationFacade;
+
+ private static final String CONFORMANCE_LEVEL = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel();
+ private static final String SDC_VERSION = ExternalConfiguration.getAppVersion();
+ public static final String ARTIFACTS_PATH = "Artifacts/";
+ private static final String RESOURCES_PATH = "Resources/";
+ private static final String DEFINITIONS_PATH = "Definitions/";
+ public static final String WORKFLOW_ARTIFACT_DIR = "Workflows"+File.separator+"BPMN"+File.separator;
+ public static final String DEPLOYMENT_ARTIFACTS_DIR = "Deployment"+File.separator;
+ private static final String CSAR_META_VERSION = "1.0";
+ private static final String CSAR_META_PATH_FILE_NAME = "csar.meta";
+ private static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta";
+ private static final String TOSCA_META_VERSION = "1.0";
+ private static final String CSAR_VERSION = "1.1";
+ public static final String ARTIFACTS = "Artifacts";
private static final String DEFINITION = "Definitions";
private static final String DEL_PATTERN = "([/\\\\]+)";
- private static String versionFirstThreeOctates;
-
- public static final String VFC_NODE_TYPE_ARTIFACTS_PATH_PATTERN = ARTIFACTS + DEL_PATTERN
- + ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN
- + "([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN + "([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN
- + "([\\d\\w\\_\\-\\.\\s]+)";
-
- public static final String VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN = ARTIFACTS + DEL_PATTERN +
- // Artifact Group (i.e Deployment/Informational)
- "([\\w\\_\\-\\.\\s]+)" + DEL_PATTERN +
- // Artifact Type
- "([\\w\\_\\-\\.\\s]+)" + DEL_PATTERN +
- // Artifact Any File Name
- ".+";
- public static final String VALID_ENGLISH_ARTIFACT_NAME = "([\\w\\_\\-\\.\\s]+)";
- public static final String SERVICE_TEMPLATE_PATH_PATTERN = DEFINITION + DEL_PATTERN +
- // Service Template File Name
- "([\\w\\_\\-\\.\\s]+)";
-
- public static final String ARTIFACT_CREATED_FROM_CSAR = "Artifact created from csar";
+ private static final String WORD_PATTERN = "\\w\\_\\-\\.\\s]+)";
+ public static final String VALID_ENGLISH_ARTIFACT_NAME = "([" + WORD_PATTERN;
+ private static final String VALID_ENGLISH_ARTIFACT_NAME_WITH_DIGITS = "([\\d" + WORD_PATTERN;
+ private static final String ARTIFACT_NAME_UNIQUE_ID = "ArtifactName {}, unique ID {}";
+
+ private static final String VFC_NODE_TYPE_ARTIFACTS_PATH_PATTERN = ARTIFACTS + DEL_PATTERN +
+ ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX +
+ VALID_ENGLISH_ARTIFACT_NAME_WITH_DIGITS + DEL_PATTERN +
+ VALID_ENGLISH_ARTIFACT_NAME_WITH_DIGITS + DEL_PATTERN +
+ VALID_ENGLISH_ARTIFACT_NAME_WITH_DIGITS + DEL_PATTERN +
+ VALID_ENGLISH_ARTIFACT_NAME_WITH_DIGITS;
+
+ public static final String VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN = ARTIFACTS + DEL_PATTERN+
+ // Artifact Group (i.e Deployment/Informational)
+ VALID_ENGLISH_ARTIFACT_NAME + DEL_PATTERN +
+ // Artifact Type
+ VALID_ENGLISH_ARTIFACT_NAME + DEL_PATTERN +
+ // Artifact Any File Name
+ ".+";
+
+ public static final String SERVICE_TEMPLATE_PATH_PATTERN = DEFINITION + DEL_PATTERN+
+ // Service Template File Name
+ VALID_ENGLISH_ARTIFACT_NAME;
+
+ public static final String ARTIFACT_CREATED_FROM_CSAR = "Artifact created from csar";
private static final String BLOCK_0_TEMPLATE = "SDC-TOSCA-Meta-File-Version: %s\nSDC-TOSCA-Definitions-Version: %s\n";
- public CsarUtils() {
- this.CONFORMANCE_LEVEL = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getToscaConformanceLevel();
- this.SDC_VERSION = ExternalConfiguration.getAppVersion();
- if (SDC_VERSION != null && !SDC_VERSION.isEmpty()) {
- Matcher matcher = Pattern.compile("(?!\\.)(\\d+(\\.\\d+)+)(?![\\d\\.])").matcher(SDC_VERSION);
- matcher.find();
- versionFirstThreeOctates = matcher.group(0);
- } else {
- versionFirstThreeOctates = "";
- }
- }
-
- /**
- *
- * @param component
- * @param getFromCS
- * @param isInCertificationRequest
- * @return
- */
- public Either<byte[], ResponseFormat> createCsar(Component component, boolean getFromCS,
- boolean isInCertificationRequest) {
- return createCsar(component, getFromCS, isInCertificationRequest, false);
- }
-
- private Either<byte[], ResponseFormat> createCsar(Component component, boolean getFromCS,
- boolean isInCertificationRequest, boolean mockGenerator) {
- final String createdBy = component.getCreatorFullName();
-
- String fileName;
- Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
- ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
- fileName = artifactDefinition.getArtifactName();
-
- String toscaConformanceLevel = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getToscaConformanceLevel();
- String csarBlock0 = createCsarBlock0(CSAR_META_VERSION, toscaConformanceLevel);
- byte[] csarBlock0Byte = csarBlock0.getBytes();
-
- final String toscaBlock0 = createToscaBlock0(TOSCA_META_VERSION, CSAR_VERSION, createdBy, fileName);
- byte[] toscaBlock0Byte = toscaBlock0.getBytes();
+ private String versionFirstThreeOctets;
+
+ public CsarUtils() {
+ if(SDC_VERSION != null && !SDC_VERSION.isEmpty()){
+ Matcher matcher = Pattern.compile("(?!\\.)(\\d+(\\.\\d+)+)(?![\\d\\.])").matcher(SDC_VERSION);
+ matcher.find();
+ setVersionFirstThreeOctets(matcher.group(0));
+ } else {
+ setVersionFirstThreeOctets("");
+ }
+ }
+
+ /**
+ *
+ * @param component
+ * @param getFromCS
+ * @param isInCertificationRequest
+ * @return
+ */
+ public Either<byte[], ResponseFormat> createCsar(Component component, boolean getFromCS, boolean isInCertificationRequest) {
+ loggerSupportability.log(LoggerSupportabilityActions.GENERATE_CSAR, StatusCode.STARTED,"Starting to create Csar for component {} ",component.getName());
+ final String createdBy = component.getCreatorFullName();
+ String fileName;
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+ fileName = artifactDefinition.getArtifactName();
+
+ String toscaConformanceLevel = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaConformanceLevel();
+ String csarBlock0 = createCsarBlock0(CSAR_META_VERSION, toscaConformanceLevel);
+ byte[] csarBlock0Byte = csarBlock0.getBytes();
+
+ final String toscaBlock0 = createToscaBlock0(TOSCA_META_VERSION, CSAR_VERSION, createdBy, fileName);
+ byte[] toscaBlock0Byte = toscaBlock0.getBytes();
Either<byte[], ResponseFormat> generateCsarZipResponse = generateCsarZip(csarBlock0Byte, toscaBlock0Byte, component, getFromCS, isInCertificationRequest);
- if (generateCsarZipResponse.isRight()) {
- return Either.right(generateCsarZipResponse.right().value());
- }
-
- return Either.left(generateCsarZipResponse.left().value());
- }
+ if (generateCsarZipResponse.isRight()) {
+ return Either.right(generateCsarZipResponse.right().value());
+ }
+ loggerSupportability.log(LoggerSupportabilityActions.GENERATE_CSAR, StatusCode.COMPLETE,"Ended create Csar for component {} ",component.getName());
+ return Either.left(generateCsarZipResponse.left().value());
+ }
private Either<byte[], ResponseFormat> generateCsarZip(byte[] csarBlock0Byte, byte[] toscaBlock0Byte, Component component, boolean getFromCS, boolean isInCertificationRequest) {
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(out)) {
- zip.putNextEntry(new ZipEntry(CSAR_META_PATH_FILE_NAME));
- zip.write(csarBlock0Byte);
- zip.putNextEntry(new ZipEntry(TOSCA_META_PATH_FILE_NAME));
- zip.write(toscaBlock0Byte);
+ zip.putNextEntry(new ZipEntry(CSAR_META_PATH_FILE_NAME));
+ zip.write(csarBlock0Byte);
+ zip.putNextEntry(new ZipEntry(TOSCA_META_PATH_FILE_NAME));
+ zip.write(toscaBlock0Byte);
Either<ZipOutputStream, ResponseFormat> populateZip = populateZip(component, getFromCS, zip, isInCertificationRequest);
if (populateZip.isRight()) {
- log.debug("Failed to populate CSAR zip file {}", populateZip.right().value());
+ log.debug("Failed to populate CSAR zip file {}. Please fix DB table accordingly ", populateZip.right().value());
return Either.right(populateZip.right().value());
}
- zip.finish();
- byte[] byteArray = out.toByteArray();
+ zip.finish();
+ byte[] byteArray = out.toByteArray();
- return Either.left(byteArray);
- } catch (IOException | NullPointerException e) {
- log.debug("Failed with IOexception to create CSAR zip for component {}", component.getUniqueId(), e);
+ return Either.left(byteArray);
+ } catch (IOException e) {
+ log.debug("Failed with IOexception to create CSAR zip for component {}. Please fix DB table accordingly ", component.getUniqueId(), e);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- return Either.right(responseFormat);
- }
- }
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return Either.right(responseFormat);
+ }
+}
private Either<ZipOutputStream, ResponseFormat> populateZip(Component component, boolean getFromCS, ZipOutputStream zip, boolean isInCertificationRequest) throws IOException {
- LifecycleStateEnum lifecycleState = component.getLifecycleState();
- String componentYaml;
- Either<ToscaRepresentation, ToscaError> exportComponent;
- byte[] mainYaml;
- // <file name, cassandraId, component>
- List<Triple<String, String, Component>> dependencies = null;
-
- Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
- ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
- String fileName = artifactDefinition.getArtifactName();
-
- if (getFromCS || !(lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN
- || lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
- String cassandraId = artifactDefinition.getEsId();
- Either<byte[], ActionStatus> fromCassandra = getFromCassandra(cassandraId);
- if (fromCassandra.isRight()) {
- log.debug("ArtifactName {}, unique ID {}", artifactDefinition.getArtifactName(),
- artifactDefinition.getUniqueId());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(fromCassandra.right().value());
- return Either.right(responseFormat);
- }
- mainYaml = fromCassandra.left().value();
-
- } else {
- exportComponent = toscaExportUtils.exportComponent(component);
- if (exportComponent.isRight()) {
- log.debug("exportComponent failed", exportComponent.right().value());
- ActionStatus convertedFromToscaError = componentsUtils
- .convertFromToscaError(exportComponent.right().value());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(convertedFromToscaError);
- return Either.right(responseFormat);
- }
- ToscaRepresentation exportResult = exportComponent.left().value();
- componentYaml = exportResult.getMainYaml();
- mainYaml = componentYaml.getBytes();
- dependencies = exportResult.getDependencies();
- }
-
- zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + fileName));
- zip.write(mainYaml);
- // US798487 - Abstraction of complex types
- if (!ModelConverter.isAtomicComponent(component)) {
- log.debug("Component {} is complex - generating abstract type for it..", component.getName());
+ LifecycleStateEnum lifecycleState = component.getLifecycleState();
+ String componentYaml;
+ Either<ToscaRepresentation, ToscaError> exportComponent;
+ byte[] mainYaml;
+ // <file name, cassandraId, component>
+ List<Triple<String, String, Component>> dependencies = null;
+
+ Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+ ArtifactDefinition artifactDefinition = toscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+ String fileName = artifactDefinition.getArtifactName();
+
+ if (getFromCS || !(lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN || lifecycleState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT)) {
+ String cassandraId = artifactDefinition.getEsId();
+ Either<byte[], ActionStatus> fromCassandra = getFromCassandra(cassandraId);
+ if (fromCassandra.isRight()) {
+ log.debug(ARTIFACT_NAME_UNIQUE_ID, artifactDefinition.getArtifactName(), artifactDefinition.getUniqueId());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(fromCassandra.right().value());
+ return Either.right(responseFormat);
+ }
+ mainYaml = fromCassandra.left().value();
+
+ } else {
+ exportComponent = toscaExportUtils.exportComponent(component);
+ if (exportComponent.isRight()) {
+ log.debug("exportComponent failed", exportComponent.right().value());
+ ActionStatus convertedFromToscaError = componentsUtils.convertFromToscaError(exportComponent.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(convertedFromToscaError);
+ return Either.right(responseFormat);
+ }
+ ToscaRepresentation exportResult = exportComponent.left().value();
+ componentYaml = exportResult.getMainYaml();
+ mainYaml = componentYaml.getBytes();
+ dependencies = exportResult.getDependencies();
+ }
+
+ zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + fileName));
+ zip.write(mainYaml);
+ //US798487 - Abstraction of complex types
+ if (!ModelConverter.isAtomicComponent(component)){
+ log.debug("Component {} is complex - generating abstract type for it..", component.getName());
writeComponentInterface(component, zip, fileName, false);
- }
-
- if (dependencies == null) {
- Either<ToscaTemplate, ToscaError> dependenciesRes = toscaExportUtils.getDependencies(component);
- if (dependenciesRes.isRight()) {
- log.debug("Failed to retrieve dependencies for component {}, error {}", component.getUniqueId(),
- dependenciesRes.right().value());
- ActionStatus convertFromToscaError = componentsUtils
- .convertFromToscaError(dependenciesRes.right().value());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(convertFromToscaError);
- return Either.right(responseFormat);
- }
- dependencies = dependenciesRes.left().value().getDependencies();
- }
-
- // UID <cassandraId,filename,component>
- Map<String, ImmutableTriple<String, String, Component>> innerComponentsCache = new HashMap<>();
-
- if (dependencies != null && !dependencies.isEmpty()) {
- for (Triple<String, String, Component> d : dependencies) {
- String cassandraId = d.getMiddle();
- Component childComponent = d.getRight();
- Either<byte[], ActionStatus> entryData = getEntryData(cassandraId, childComponent);
-
- if (entryData.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(entryData.right().value());
- return Either.right(responseFormat);
- }
+ }
+
+ if (dependencies == null) {
+ Either<ToscaTemplate, ToscaError> dependenciesRes = toscaExportUtils.getDependencies(component);
+ if (dependenciesRes.isRight()) {
+ log.debug("Failed to retrieve dependencies for component {}, error {}", component.getUniqueId(),
+ dependenciesRes.right().value());
+ ActionStatus convertFromToscaError = componentsUtils.convertFromToscaError(dependenciesRes.right().value());
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(convertFromToscaError);
+ return Either.right(responseFormat);
+ }
+ dependencies = dependenciesRes.left().value().getDependencies();
+ }
- // fill innerComponentsCache
- fileName = d.getLeft();
- addComponentToCache(innerComponentsCache, cassandraId, fileName, childComponent);
- addInnerComponentsToCache(innerComponentsCache, childComponent);
- }
+ //UID <cassandraId,filename,component>
+ Map<String, ImmutableTriple<String,String, Component>> innerComponentsCache = new HashMap<>();
- // add inner components to CSAR
- for (Entry<String, ImmutableTriple<String, String, Component>> innerComponentTripleEntry : innerComponentsCache
- .entrySet()) {
+ Either<ZipOutputStream, ResponseFormat> responseFormat = getZipOutputStreamResponseFormatEither(zip, dependencies, innerComponentsCache);
+ if (responseFormat != null) return responseFormat;
- ImmutableTriple<String, String, Component> innerComponentTriple = innerComponentTripleEntry.getValue();
+ //retrieve SDC.zip from Cassandra
+ Either<byte[], ResponseFormat> latestSchemaFilesFromCassandra = getLatestSchemaFilesFromCassandra();
- Component innerComponent = innerComponentTriple.getRight();
- String icFileName = innerComponentTriple.getMiddle();
+ if(latestSchemaFilesFromCassandra.isRight()){
+ log.error("Error retrieving SDC Schema files from cassandra" );
+ return Either.right(latestSchemaFilesFromCassandra.right().value());
+ }
- // add component to zip
- Either<byte[], ActionStatus> entryData = getEntryData(innerComponentTriple.getLeft(), innerComponent);
- if (entryData.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(entryData.right().value());
- log.debug("Failed adding to zip component {}, error {}", innerComponentTriple.getLeft(),
- entryData.right().value());
- return Either.right(responseFormat);
- }
- byte[] content = entryData.left().value();
- zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + icFileName));
- zip.write(content);
+ //add files from retrieved SDC.zip to Definitions folder in CSAR
+ Either<ZipOutputStream, ResponseFormat> addSchemaFilesFromCassandra = addSchemaFilesFromCassandra(zip, latestSchemaFilesFromCassandra.left().value());
- // add component interface to zip
- if (!ModelConverter.isAtomicComponent(innerComponent)) {
- writeComponentInterface(innerComponent, zip, icFileName, true);
- }
- }
- }
+ if(addSchemaFilesFromCassandra.isRight()){
+ return addSchemaFilesFromCassandra;
+ }
- // retrieve SDC.zip from Cassandra
- Either<byte[], ResponseFormat> latestSchemaFilesFromCassandra = getLatestSchemaFilesFromCassandra();
+ Either<CsarDefinition, ResponseFormat> collectedComponentCsarDefinition = collectComponentCsarDefinition(component);
- if (latestSchemaFilesFromCassandra.isRight()) {
- log.error("Error retrieving SDC Schema files from cassandra");
- return Either.right(latestSchemaFilesFromCassandra.right().value());
- }
+ if (collectedComponentCsarDefinition.isRight()) {
+ return Either.right(collectedComponentCsarDefinition.right().value());
+ }
- // add files from retireved SDC.zip to Definitions folder in CSAR
- Either<ZipOutputStream, ResponseFormat> addSchemaFilesFromCassandra = addSchemaFilesFromCassandra(zip,
- latestSchemaFilesFromCassandra.left().value());
+ return writeAllFilesToCsar(component, collectedComponentCsarDefinition.left().value(), zip, isInCertificationRequest);
+ }
- if (addSchemaFilesFromCassandra.isRight()) {
- return addSchemaFilesFromCassandra;
- }
+ private Either<ZipOutputStream, ResponseFormat> getZipOutputStreamResponseFormatEither(ZipOutputStream zip, List<Triple<String, String, Component>> dependencies, Map<String, ImmutableTriple<String, String, Component>> innerComponentsCache) throws IOException {
+ String fileName;
+ if (dependencies != null && !dependencies.isEmpty()) {
+ for (Triple<String, String, Component> d : dependencies) {
+ String cassandraId = d.getMiddle();
+ Component childComponent = d.getRight();
+ Either<byte[], ActionStatus> entryData = getEntryData(cassandraId, childComponent);
- Either<CsarDefinition, ResponseFormat> collectedComponentCsarDefinition = collectComponentCsarDefinition(
- component);
+ if (entryData.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(entryData.right().value());
+ return Either.right(responseFormat);
+ }
- if (collectedComponentCsarDefinition.isRight()) {
- return Either.right(collectedComponentCsarDefinition.right().value());
- }
+ //fill innerComponentsCache
+ fileName = d.getLeft();
+ addComponentToCache(innerComponentsCache, cassandraId, fileName, childComponent);
+ addInnerComponentsToCache(innerComponentsCache, childComponent);
+ }
- return writeAllFilesToCsar(component, collectedComponentCsarDefinition.left().value(), zip,
- isInCertificationRequest);
- }
+ //add inner components to CSAR
+ Either<ZipOutputStream, ResponseFormat> responseFormat = addInnerComponentsToCSAR(zip, innerComponentsCache);
+ if (responseFormat != null) return responseFormat;
+ }
+ return null;
+ }
- private Either<ZipOutputStream, ResponseFormat> addSchemaFilesFromCassandra(final ZipOutputStream zip,
- final byte[] schemaFileZip) {
- final int initSize = 2048;
- log.debug("Starting copy from Schema file zip to CSAR zip");
- try (final ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(schemaFileZip));
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final BufferedOutputStream bos = new BufferedOutputStream(out, initSize)) {
-
- ZipEntry entry;
- while ((entry = zipStream.getNextEntry()) != null) {
- ZipUtils.checkForZipSlipInRead(entry);
- final String entryName = entry.getName();
- int readSize = initSize;
- final byte[] entryData = new byte[initSize];
-
- while ((readSize = zipStream.read(entryData, 0, readSize)) != -1) {
- bos.write(entryData, 0, readSize);
- }
+ private Either<ZipOutputStream, ResponseFormat> addInnerComponentsToCSAR(ZipOutputStream zip, Map<String, ImmutableTriple<String, String, Component>> innerComponentsCache) throws IOException {
+ for (Entry<String, ImmutableTriple<String, String, Component>> innerComponentTripleEntry : innerComponentsCache.entrySet()) {
- bos.flush();
- out.flush();
- zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + entryName));
- zip.write(out.toByteArray());
- zip.flush();
- out.reset();
- }
- } catch (final Exception e) {
- log.error("Error while writing the SDC schema file to the CSAR", e);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
+ ImmutableTriple<String, String, Component> innerComponentTriple = innerComponentTripleEntry.getValue();
- log.debug("Finished coppy from Schema file zip to CSAR zip");
- return Either.left(zip);
- }
+ Component innerComponent = innerComponentTriple.getRight();
+ String icFileName = innerComponentTriple.getMiddle();
- private void addInnerComponentsToCache(Map<String, ImmutableTriple<String, String, Component>> componentCache,
- Component childComponent) {
-
- List<ComponentInstance> instances = childComponent.getComponentInstances();
-
- if (instances != null) {
- instances.forEach(ci -> {
- ImmutableTriple<String, String, Component> componentRecord = componentCache.get(ci.getComponentUid());
- if (componentRecord == null) {
- // all resource must be only once!
- Either<Resource, StorageOperationStatus> resource = toscaOperationFacade
- .getToscaElement(ci.getComponentUid());
- if (resource == null || resource.isRight()) {
- log.debug("Failed to fetch resource with id {} for instance {}", ci.getComponentUid(), ci.getName());
- } else {
- Component componentRI = resource.left().value();
-
- Map<String, ArtifactDefinition> childToscaArtifacts = componentRI.getToscaArtifacts();
- ArtifactDefinition childArtifactDefinition = childToscaArtifacts
- .get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
- if (childArtifactDefinition != null) {
- // add to cache
- addComponentToCache(componentCache, childArtifactDefinition.getEsId(),
- childArtifactDefinition.getArtifactName(), componentRI);
- }
-
- // if not atomic - insert inner components as well
- if (!ModelConverter.isAtomicComponent(componentRI)) {
- addInnerComponentsToCache(componentCache, componentRI);
- }
- }
- }
- });
- }
- }
+ // add component to zip
+ Either<byte[], ActionStatus> entryData = getEntryData(innerComponentTriple.getLeft(), innerComponent);
+ if (entryData.isRight()) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(entryData.right().value());
+ log.debug("Failed adding to zip component {}, error {}", innerComponentTriple.getLeft(),
+ entryData.right().value());
+ return Either.right(responseFormat);
+ }
+ byte[] content = entryData.left().value();
+ zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + icFileName));
+ zip.write(content);
- private void addComponentToCache(Map<String, ImmutableTriple<String, String, Component>> componentCache, String id,
- String fileName, Component component) {
+ // add component interface to zip
+ if (!ModelConverter.isAtomicComponent(innerComponent)) {
+ writeComponentInterface(innerComponent, zip, icFileName, true);
+ }
+ }
+ return null;
+ }
+
+ private Either<ZipOutputStream, ResponseFormat> addSchemaFilesFromCassandra(ZipOutputStream zip, byte[] schemaFileZip) {
+
+ final int initSize = 2048;
+
+ log.debug("Starting copy from Schema file zip to CSAR zip");
+ try (final ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(schemaFileZip));
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
+ final BufferedOutputStream bos = new BufferedOutputStream(out, initSize)) {
+
+ ZipEntry entry;
+ while ((entry = zipStream.getNextEntry()) != null) {
+ ZipUtils.checkForZipSlipInRead(entry);
+ final String entryName = entry.getName();
+ int readSize = initSize;
+ final byte[] entryData = new byte[initSize];
+
+ while ((readSize = zipStream.read(entryData, 0, readSize)) != -1) {
+ bos.write(entryData, 0, readSize);
+ }
+
+ bos.flush();
+ out.flush();
+ zip.putNextEntry(new ZipEntry(DEFINITIONS_PATH + entryName));
+ zip.write(out.toByteArray());
+ zip.flush();
+ out.reset();
+ }
+ } catch (final Exception e) {
+ log.error("Error while writing the SDC schema file to the CSAR", e);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
- ImmutableTriple<String, String, Component> cachedComponent = componentCache.get(component.getInvariantUUID());
- if (cachedComponent == null || CommonBeUtils.compareAsdcComponentVersions(component.getVersion(),
- cachedComponent.getRight().getVersion())) {
- componentCache.put(component.getInvariantUUID(),
+ log.debug("Finished coppy from Schema file zip to CSAR zip");
+ return Either.left(zip);
+ }
+
+
+
+ private void addInnerComponentsToCache(Map<String, ImmutableTriple<String, String, Component>> componentCache,
+ Component childComponent) {
+
+ List<ComponentInstance> instances = childComponent.getComponentInstances();
+
+ if(instances != null) {
+ instances.forEach(ci -> {
+ ImmutableTriple<String, String, Component> componentRecord = componentCache.get(ci.getComponentUid());
+ if (componentRecord == null) {
+ // all resource must be only once!
+ Either<Resource, StorageOperationStatus> resource = toscaOperationFacade.getToscaElement(ci.getComponentUid());
+ Component componentRI = checkAndAddComponent(componentCache, ci, resource);
+
+ //if not atomic - insert inner components as well
+ if(!ModelConverter.isAtomicComponent(componentRI)) {
+ addInnerComponentsToCache(componentCache, componentRI);
+ }
+ }
+ });
+ }
+ }
+
+ private Component checkAndAddComponent(Map<String, ImmutableTriple<String, String, Component>> componentCache, ComponentInstance ci, Either<Resource, StorageOperationStatus> resource) {
+ if (resource.isRight()) {
+ log.debug("Failed to fetch resource with id {} for instance {}", ci.getComponentUid(), ci.getName());
+ }
+ Component componentRI = resource.left().value();
+
+ Map<String, ArtifactDefinition> childToscaArtifacts = componentRI.getToscaArtifacts();
+ ArtifactDefinition childArtifactDefinition = childToscaArtifacts.get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE);
+ if (childArtifactDefinition != null) {
+ //add to cache
+ addComponentToCache(componentCache, childArtifactDefinition.getEsId(), childArtifactDefinition.getArtifactName(), componentRI);
+ }
+ return componentRI;
+ }
+
+ private void addComponentToCache(Map<String, ImmutableTriple<String, String, Component>> componentCache,
+ String id, String fileName, Component component) {
+
+ ImmutableTriple<String, String, Component> cachedComponent = componentCache.get(component.getInvariantUUID());
+ if (cachedComponent == null || CommonBeUtils.compareAsdcComponentVersions(component.getVersion(), cachedComponent.getRight().getVersion())) {
+ componentCache.put(component.getInvariantUUID(),
new ImmutableTriple<>(id, fileName, component));
- if (cachedComponent != null) {
- // overwriting component with newer version
- log.warn("Overwriting component invariantID {} of version {} with a newer version {}", id,
- cachedComponent.getRight().getVersion(), component.getVersion());
- }
- }
- }
-
+ if(cachedComponent != null) {
+ //overwriting component with newer version
+ log.warn("Overwriting component invariantID {} of version {} with a newer version {}", id, cachedComponent.getRight().getVersion(), component.getVersion());
+ }
+ }
+ }
private Either<ZipOutputStream, ResponseFormat> writeComponentInterface(Component component, ZipOutputStream zip,
String fileName, boolean isAssociatedComponent) {
try {
@@ -469,434 +490,458 @@ public class CsarUtils {
return Either.left(content);
}
- private Either<byte[], ResponseFormat> getLatestSchemaFilesFromCassandra() {
- Either<List<SdcSchemaFilesData>, CassandraOperationStatus> specificSchemaFiles = sdcSchemaFilesCassandraDao
- .getSpecificSchemaFiles(versionFirstThreeOctates, CONFORMANCE_LEVEL);
-
- if (specificSchemaFiles.isRight()) {
- log.debug("Failed to get the schema files SDC-Version: {} Conformance-Level {}", versionFirstThreeOctates,
- CONFORMANCE_LEVEL);
- StorageOperationStatus storageStatus = DaoStatusConverter
- .convertCassandraStatusToStorageStatus(specificSchemaFiles.right().value());
- ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
- return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
- }
-
- List<SdcSchemaFilesData> listOfSchemas = specificSchemaFiles.left().value();
-
- if (listOfSchemas.isEmpty()) {
- log.debug("Failed to get the schema files SDC-Version: {} Conformance-Level {}", versionFirstThreeOctates,
- CONFORMANCE_LEVEL);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.TOSCA_SCHEMA_FILES_NOT_FOUND,
- versionFirstThreeOctates, CONFORMANCE_LEVEL));
- }
-
- SdcSchemaFilesData schemaFile = listOfSchemas.iterator().next();
-
- return Either.left(schemaFile.getPayloadAsArray());
- }
-
- private Either<byte[], ActionStatus> getFromCassandra(String cassandraId) {
- Either<ESArtifactData, CassandraOperationStatus> artifactResponse = artifactCassandraDao
- .getArtifact(cassandraId);
-
- if (artifactResponse.isRight()) {
- log.debug("Failed to fetch artifact from Cassandra by id {} error {} ", cassandraId,
- artifactResponse.right().value());
-
- StorageOperationStatus storageStatus = DaoStatusConverter
- .convertCassandraStatusToStorageStatus(artifactResponse.right().value());
- ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
- return Either.right(convertedFromStorageResponse);
- }
- ESArtifactData artifactData = artifactResponse.left().value();
- return Either.left(artifactData.getDataAsArray());
- }
-
- private String createCsarBlock0(String metaFileVersion, String toscaConformanceLevel) {
- return String.format(BLOCK_0_TEMPLATE, metaFileVersion, toscaConformanceLevel);
- }
-
- private String createToscaBlock0(String metaFileVersion, String csarVersion, String createdBy, String entryDef) {
- final String block0template = "TOSCA-Meta-File-Version: %s\nCSAR-Version: %s\nCreated-By: %s\nEntry-Definitions: Definitions/%s\n\nName: csar.meta\nContent-Type: text/plain\n";
- return String.format(block0template, metaFileVersion, csarVersion, createdBy, entryDef);
- }
-
- /**
- * Extracts artifacts of VFCs from CSAR
- *
- * @param csar
- * @return Map of <String, List<ArtifactDefinition>> the contains Lists of
- * artifacts according vfcToscaNamespace
- */
- public static Map<String, List<ArtifactDefinition>> extractVfcsArtifactsFromCsar(Map<String, byte[]> csar) {
-
- Map<String, List<ArtifactDefinition>> artifacts = new HashMap<>();
- if (csar != null) {
- log.debug("************* Going to extract VFCs artifacts from Csar. ");
- Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
- csar.entrySet().stream()
- // filter CSAR entry by node type artifact path
- .filter(e -> Pattern.compile(VFC_NODE_TYPE_ARTIFACTS_PATH_PATTERN).matcher(e.getKey()).matches())
- // extract ArtifactDefinition from CSAR entry for each entry with matching
- // artifact path
- .forEach(e -> addExtractedVfcArtifact(extractVfcArtifact(e, collectedWarningMessages), artifacts));
- // add counter suffix to artifact labels
- handleWarningMessages(collectedWarningMessages);
-
- }
- return artifacts;
- }
-
- /**
- * Print warnings to log
- *
- * @param collectedWarningMessages
- */
- public static void handleWarningMessages(Map<String, Set<List<String>>> collectedWarningMessages) {
- collectedWarningMessages.entrySet().stream()
- // for each vfc
- .forEach(e -> e.getValue().stream()
- // add each warning message to log
- .forEach(args -> log.warn(e.getKey(), args.toArray())));
-
- }
-
- private static void addExtractedVfcArtifact(ImmutablePair<String, ArtifactDefinition> extractedVfcArtifact,
- Map<String, List<ArtifactDefinition>> artifacts) {
- if (extractedVfcArtifact != null) {
- List<ArtifactDefinition> currArtifactsList;
- String vfcToscaNamespace = extractedVfcArtifact.getKey();
- if (artifacts.containsKey(vfcToscaNamespace)) {
- currArtifactsList = artifacts.get(vfcToscaNamespace);
- } else {
- currArtifactsList = new ArrayList<>();
- artifacts.put(vfcToscaNamespace, currArtifactsList);
- }
- currArtifactsList.add(extractedVfcArtifact.getValue());
- }
- }
-
- private static ImmutablePair<String, ArtifactDefinition> extractVfcArtifact(Entry<String, byte[]> entry,
- Map<String, Set<List<String>>> collectedWarningMessages) {
- ArtifactDefinition artifact;
- String[] parsedCsarArtifactPath = entry.getKey().split("/");
- Either<ArtifactGroupTypeEnum, Boolean> eitherArtifactGroupType = detectArtifactGroupType(
- parsedCsarArtifactPath[2].toUpperCase(), collectedWarningMessages);
- if (eitherArtifactGroupType.isLeft()) {
- artifact = buildArtifactDefinitionFromCsarArtifactPath(entry, collectedWarningMessages,
- parsedCsarArtifactPath, eitherArtifactGroupType.left().value());
- } else {
- return null;
- }
- return new ImmutablePair<>(parsedCsarArtifactPath[1], artifact);
- }
-
- private static Either<ArtifactGroupTypeEnum, Boolean> detectArtifactGroupType(String groupType,
- Map<String, Set<List<String>>> collectedWarningMessages) {
- Either<ArtifactGroupTypeEnum, Boolean> result;
- try {
- ArtifactGroupTypeEnum artifactGroupType = ArtifactGroupTypeEnum.findType(groupType.toUpperCase());
- if (artifactGroupType == null || (artifactGroupType != ArtifactGroupTypeEnum.INFORMATIONAL
- && artifactGroupType != ArtifactGroupTypeEnum.DEPLOYMENT)) {
- String warningMessage = "Warning - unrecognized artifact group type {} was received.";
- List<String> messageArguments = new ArrayList<>();
- messageArguments.add(groupType);
- if (!collectedWarningMessages.containsKey(warningMessage)) {
- Set<List<String>> messageArgumentLists = new HashSet<>();
- messageArgumentLists.add(messageArguments);
- collectedWarningMessages.put(warningMessage, messageArgumentLists);
- } else {
- collectedWarningMessages.get(warningMessage).add(messageArguments);
- }
-
- result = Either.right(false);
- } else {
-
- result = Either.left(artifactGroupType);
- }
- } catch (Exception e) {
- log.debug("detectArtifactGroupType failed with exception", e);
- result = Either.right(false);
- }
- return result;
- }
-
- private static ArtifactDefinition buildArtifactDefinitionFromCsarArtifactPath(Entry<String, byte[]> entry,
- Map<String, Set<List<String>>> collectedWarningMessages, String[] parsedCsarArtifactPath,
- ArtifactGroupTypeEnum artifactGroupType) {
- ArtifactDefinition artifact;
- artifact = new ArtifactDefinition();
- artifact.setArtifactGroupType(artifactGroupType);
- artifact.setArtifactType(detectArtifactTypeVFC(artifactGroupType, parsedCsarArtifactPath[3],
- parsedCsarArtifactPath[1], collectedWarningMessages));
- artifact.setArtifactName(
- ValidationUtils.normalizeFileName(parsedCsarArtifactPath[parsedCsarArtifactPath.length - 1]));
- artifact.setPayloadData(Base64.encodeBase64String(entry.getValue()));
- artifact.setArtifactDisplayName(artifact.getArtifactName().lastIndexOf('.') > 0
- ? artifact.getArtifactName().substring(0, artifact.getArtifactName().lastIndexOf('.'))
- : artifact.getArtifactName());
- artifact.setArtifactLabel(ValidationUtils.normalizeArtifactLabel(artifact.getArtifactName()));
- artifact.setDescription(ARTIFACT_CREATED_FROM_CSAR);
- artifact.setIsFromCsar(true);
- artifact.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(entry.getValue()));
- return artifact;
- }
-
- public static final class NonMetaArtifactInfo {
- private final String path;
- private final String artifactName;
- private final String displayName;
- private final String artifactLabel;
- private final ArtifactTypeEnum artifactType;
- private final ArtifactGroupTypeEnum artifactGroupType;
- private String payloadData;
- private String artifactChecksum;
- private String artifactUniqueId;
- private final boolean isFromCsar;
-
- public NonMetaArtifactInfo(String artifactName, String path, ArtifactTypeEnum artifactType,
- ArtifactGroupTypeEnum artifactGroupType, byte[] payloadData, String artifactUniqueId,
- boolean isFromCsar) {
- super();
- this.path = path;
- this.isFromCsar = isFromCsar;
- this.artifactName = ValidationUtils.normalizeFileName(artifactName);
- this.artifactType = artifactType;
- this.artifactGroupType = artifactGroupType;
- final int pointIndex = artifactName.lastIndexOf('.');
- if (pointIndex > 0) {
- displayName = artifactName.substring(0, pointIndex);
- } else {
- displayName = artifactName;
- }
- this.artifactLabel = ValidationUtils.normalizeArtifactLabel(artifactName);
- if (payloadData != null) {
- this.payloadData = Base64.encodeBase64String(payloadData);
- this.artifactChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(payloadData);
- }
- this.artifactUniqueId = artifactUniqueId;
- }
-
- public String getPath() {
- return path;
- }
-
- public String getArtifactName() {
- return artifactName;
- }
-
- public ArtifactTypeEnum getArtifactType() {
- return artifactType;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public ArtifactGroupTypeEnum getArtifactGroupType() {
- return artifactGroupType;
- }
-
- public String getArtifactLabel() {
- return artifactLabel;
- }
-
- public boolean isFromCsar() {
- return isFromCsar;
- }
-
- public String getPayloadData() {
- return payloadData;
- }
-
- public String getArtifactChecksum() {
- return artifactChecksum;
- }
-
- public String getArtifactUniqueId() {
- return artifactUniqueId;
- }
-
- public void setArtifactUniqueId(String artifactUniqueId) {
- this.artifactUniqueId = artifactUniqueId;
- }
-
- }
-
- /**
- * This method checks the artifact GroupType & Artifact Type. <br>
- * if there is any problem warning messages are added to
- * collectedWarningMessages
- *
- * @param artifactPath
- * @param collectedWarningMessages
- * @return
- */
- public static Either<NonMetaArtifactInfo, Boolean> validateNonMetaArtifact(String artifactPath, byte[] payloadData,
- Map<String, Set<List<String>>> collectedWarningMessages) {
- Either<NonMetaArtifactInfo, Boolean> ret;
- try {
- String[] parsedArtifactPath = artifactPath.split("/");
- // Validate Artifact Group Type
- Either<ArtifactGroupTypeEnum, Boolean> eitherGroupType = detectArtifactGroupType(parsedArtifactPath[1],
- collectedWarningMessages);
- if (eitherGroupType.isLeft()) {
- final ArtifactGroupTypeEnum groupTypeEnum = eitherGroupType.left().value();
+ private Either<byte[], ResponseFormat> getLatestSchemaFilesFromCassandra() {
+ Either<List<SdcSchemaFilesData>, CassandraOperationStatus> specificSchemaFiles = sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(getVersionFirstThreeOctets(), CONFORMANCE_LEVEL);
- // Validate Artifact Type
- String artifactType = parsedArtifactPath[2];
- artifactType = detectArtifactTypeVF(groupTypeEnum, artifactType, collectedWarningMessages);
+ if(specificSchemaFiles.isRight()){
+ log.debug("Failed to get the schema files SDC-Version: {} Conformance-Level {}. Please fix DB table accordingly.", getVersionFirstThreeOctets(), CONFORMANCE_LEVEL);
+ StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(specificSchemaFiles.right().value());
+ ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
+ return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
+ }
- String artifactFileNameType = parsedArtifactPath[3];
- ret = Either.left(new NonMetaArtifactInfo(artifactFileNameType, artifactPath,
- ArtifactTypeEnum.findType(artifactType), groupTypeEnum, payloadData, null, true));
+ List<SdcSchemaFilesData> listOfSchemas = specificSchemaFiles.left().value();
- } else {
- ret = Either.right(eitherGroupType.right().value());
- }
- } catch (Exception e) {
- log.debug("detectArtifactGroupType failed with exception", e);
- ret = Either.right(false);
- }
- return ret;
+ if(listOfSchemas.isEmpty()){
+ log.debug("Failed to get the schema files SDC-Version: {} Conformance-Level {}", getVersionFirstThreeOctets(), CONFORMANCE_LEVEL);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.TOSCA_SCHEMA_FILES_NOT_FOUND, getVersionFirstThreeOctets(), CONFORMANCE_LEVEL));
+ }
- }
+ SdcSchemaFilesData schemaFile = listOfSchemas.iterator().next();
- private static String detectArtifactTypeVFC(ArtifactGroupTypeEnum artifactGroupType, String receivedTypeName,
- String parentVfName, Map<String, Set<List<String>>> collectedWarningMessages) {
- String warningMessage = "Warning - artifact type {} that was provided for VFC {} is not recognized.";
- return detectArtifactType(artifactGroupType, receivedTypeName, warningMessage, collectedWarningMessages,
- parentVfName);
- }
-
- private static String detectArtifactTypeVF(ArtifactGroupTypeEnum artifactGroupType, String receivedTypeName,
- Map<String, Set<List<String>>> collectedWarningMessages) {
- String warningMessage = "Warning - artifact type {} that was provided for VF is not recognized.";
- return detectArtifactType(artifactGroupType, receivedTypeName, warningMessage, collectedWarningMessages);
- }
+ return Either.left(schemaFile.getPayloadAsArray());
+ }
- private static String detectArtifactType(ArtifactGroupTypeEnum artifactGroupType, String receivedTypeName,
- String warningMessage, Map<String, Set<List<String>>> collectedWarningMessages, String... arguments) {
-
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(receivedTypeName);
- Map<String, ArtifactTypeConfig> resourceValidTypeArtifacts = null;
-
- if (artifactGroupType != null) {
- switch (artifactGroupType) {
- case INFORMATIONAL:
- resourceValidTypeArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getResourceInformationalArtifacts();
- break;
- case DEPLOYMENT:
- resourceValidTypeArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getResourceDeploymentArtifacts();
- break;
- default:
- break;
- }
- }
+ private Either<byte[], ActionStatus> getFromCassandra(String cassandraId) {
+ Either<DAOArtifactData, CassandraOperationStatus> artifactResponse = artifactCassandraDao.getArtifact(cassandraId);
- Set<String> validArtifactTypes = null;
- if (resourceValidTypeArtifacts != null) {
- validArtifactTypes = resourceValidTypeArtifacts.keySet();
- }
+ if (artifactResponse.isRight()) {
+ log.debug("Failed to fetch artifact from Cassandra by id {} error {} ", cassandraId, artifactResponse.right().value());
- if (validArtifactTypes == null || artifactType == null
- || !validArtifactTypes.contains(artifactType.getType())) {
- List<String> messageArguments = new ArrayList<>();
- messageArguments.add(receivedTypeName);
- messageArguments.addAll(Arrays.asList(arguments));
- if (!collectedWarningMessages.containsKey(warningMessage)) {
- Set<List<String>> messageArgumentLists = new HashSet<>();
- messageArgumentLists.add(messageArguments);
- collectedWarningMessages.put(warningMessage, messageArgumentLists);
- } else {
- collectedWarningMessages.get(warningMessage).add(messageArguments);
- }
- }
+ StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(artifactResponse.right().value());
+ ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
+ return Either.right(convertedFromStorageResponse);
+ }
+ DAOArtifactData artifactData = artifactResponse.left().value();
+ return Either.left(artifactData.getDataAsArray());
+ }
- return artifactType == null ? ArtifactTypeEnum.OTHER.getType() : artifactType.getType();
- }
+ private String createCsarBlock0(String metaFileVersion, String toscaConformanceLevel) {
+ return String.format(BLOCK_0_TEMPLATE, metaFileVersion, toscaConformanceLevel);
+ }
+
+ private String createToscaBlock0(String metaFileVersion, String csarVersion, String createdBy, String entryDef) {
+ final String block0template = "TOSCA-Meta-File-Version: %s\nCSAR-Version: %s\nCreated-By: %s\nEntry-Definitions: Definitions/%s\n\nName: csar.meta\nContent-Type: text/plain\n";
+ return String.format(block0template, metaFileVersion, csarVersion, createdBy, entryDef);
+ }
+
+ /**
+ * Extracts artifacts of VFCs from CSAR
+ *
+ * @param csar
+ * @return Map of <String, List<ArtifactDefinition>> the contains Lists of artifacts according vfcToscaNamespace
+ */
+ public static Map<String, List<ArtifactDefinition>> extractVfcsArtifactsFromCsar(Map<String, byte[]> csar) {
+
+ Map<String, List<ArtifactDefinition>> artifacts = new HashMap<>();
+ if (csar != null) {
+ log.debug("************* Going to extract VFCs artifacts from Csar. ");
+ Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>();
+ csar.entrySet().stream()
+ // filter CSAR entry by node type artifact path
+ .filter(e -> Pattern.compile(VFC_NODE_TYPE_ARTIFACTS_PATH_PATTERN).matcher(e.getKey()).matches())
+ // extract ArtifactDefinition from CSAR entry for each entry with matching artifact path
+ .forEach(e -> addExtractedVfcArtifact(extractVfcArtifact(e, collectedWarningMessages), artifacts));
+ // add counter suffix to artifact labels
+ handleWarningMessages(collectedWarningMessages);
+
+ }
+ return artifacts;
+ }
+
+ /**
+ * Print warnings to log
+ *
+ * @param collectedWarningMessages
+ */
+ public static void handleWarningMessages(Map<String, Set<List<String>>> collectedWarningMessages) {
+ collectedWarningMessages.entrySet().stream()
+ // for each vfc
+ .forEach(e -> e.getValue().stream()
+ // add each warning message to log
+ .forEach(args -> log.warn(e.getKey(), args.toArray())));
+
+ }
+
+ private static void addExtractedVfcArtifact(ImmutablePair<String, ArtifactDefinition> extractedVfcArtifact, Map<String, List<ArtifactDefinition>> artifacts) {
+ if (extractedVfcArtifact != null) {
+ List<ArtifactDefinition> currArtifactsList;
+ String vfcToscaNamespace = extractedVfcArtifact.getKey();
+ if (artifacts.containsKey(vfcToscaNamespace)) {
+ currArtifactsList = artifacts.get(vfcToscaNamespace);
+ } else {
+ currArtifactsList = new ArrayList<>();
+ artifacts.put(vfcToscaNamespace, currArtifactsList);
+ }
+ currArtifactsList.add(extractedVfcArtifact.getValue());
+ }
+ }
+
+ private static ImmutablePair<String, ArtifactDefinition> extractVfcArtifact(Entry<String, byte[]> entry, Map<String, Set<List<String>>> collectedWarningMessages) {
+ ArtifactDefinition artifact;
+ String[] parsedCsarArtifactPath = entry.getKey().split(PATH_DELIMITER);
+ Either<ArtifactGroupTypeEnum, Boolean> eitherArtifactGroupType = detectArtifactGroupType(parsedCsarArtifactPath[2].toUpperCase(), collectedWarningMessages);
+ if (eitherArtifactGroupType.isLeft()) {
+ artifact = buildArtifactDefinitionFromCsarArtifactPath(entry, collectedWarningMessages, parsedCsarArtifactPath, eitherArtifactGroupType.left().value());
+ } else {
+ return null;
+ }
+ return new ImmutablePair<>(parsedCsarArtifactPath[1], artifact);
+ }
+
+ private static Either<ArtifactGroupTypeEnum, Boolean> detectArtifactGroupType(String groupType, Map<String, Set<List<String>>> collectedWarningMessages) {
+ Either<ArtifactGroupTypeEnum, Boolean> result;
+ try {
+ ArtifactGroupTypeEnum artifactGroupType = ArtifactGroupTypeEnum.findType(groupType.toUpperCase());
+ if (artifactGroupType == null || (artifactGroupType != ArtifactGroupTypeEnum.INFORMATIONAL && artifactGroupType != ArtifactGroupTypeEnum.DEPLOYMENT)) {
+ String warningMessage = "Warning - unrecognized artifact group type {} was received.";
+ List<String> messageArguments = new ArrayList<>();
+ messageArguments.add(groupType);
+ if (!collectedWarningMessages.containsKey(warningMessage)) {
+ Set<List<String>> messageArgumentLists = new HashSet<>();
+ messageArgumentLists.add(messageArguments);
+ collectedWarningMessages.put(warningMessage, messageArgumentLists);
+ } else {
+ collectedWarningMessages.get(warningMessage).add(messageArguments);
+ }
+
+ result = Either.right(false);
+ } else {
+
+ result = Either.left(artifactGroupType);
+ }
+ } catch (Exception e) {
+ log.debug("detectArtifactGroupType failed with exception", e);
+ result = Either.right(false);
+ }
+ return result;
+ }
+
+ private static ArtifactDefinition buildArtifactDefinitionFromCsarArtifactPath(Entry<String, byte[]> entry, Map<String, Set<List<String>>> collectedWarningMessages, String[] parsedCsarArtifactPath, ArtifactGroupTypeEnum artifactGroupType) {
+ ArtifactDefinition artifact;
+ artifact = new ArtifactDefinition();
+ artifact.setArtifactGroupType(artifactGroupType);
+ artifact.setArtifactType(detectArtifactTypeVFC(artifactGroupType, parsedCsarArtifactPath[3], parsedCsarArtifactPath[1], collectedWarningMessages));
+ artifact.setArtifactName(ValidationUtils.normalizeFileName(parsedCsarArtifactPath[parsedCsarArtifactPath.length - 1]));
+ artifact.setPayloadData(Base64.encodeBase64String(entry.getValue()));
+ artifact.setArtifactDisplayName(artifact.getArtifactName().lastIndexOf('.') > 0 ? artifact.getArtifactName().substring(0, artifact.getArtifactName().lastIndexOf('.')) : artifact.getArtifactName());
+ artifact.setArtifactLabel(ValidationUtils.normalizeArtifactLabel(artifact.getArtifactName()));
+ artifact.setDescription(ARTIFACT_CREATED_FROM_CSAR);
+ artifact.setIsFromCsar(true);
+ artifact.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(entry.getValue()));
+ return artifact;
+ }
+
+ public static final class NonMetaArtifactInfo {
+ private final String path;
+ private final String artifactName;
+ private final String displayName;
+ private final String artifactLabel;
+ private final ArtifactTypeEnum artifactType;
+ private final ArtifactGroupTypeEnum artifactGroupType;
+ private String payloadData;
+ private String artifactChecksum;
+ private String artifactUniqueId;
+ private final boolean isFromCsar;
+
+ public NonMetaArtifactInfo(String artifactName, String path, ArtifactTypeEnum artifactType, ArtifactGroupTypeEnum artifactGroupType, byte[] payloadData, String artifactUniqueId, boolean isFromCsar) {
+ super();
+ this.path = path;
+ this.isFromCsar = isFromCsar;
+ this.artifactName = ValidationUtils.normalizeFileName(artifactName);
+ this.artifactType = artifactType;
+ this.artifactGroupType = artifactGroupType;
+ final int pointIndex = artifactName.lastIndexOf('.');
+ if (pointIndex > 0) {
+ displayName = artifactName.substring(0, pointIndex);
+ } else {
+ displayName = artifactName;
+ }
+ this.artifactLabel = ValidationUtils.normalizeArtifactLabel(artifactName);
+ if (payloadData != null) {
+ this.payloadData = Base64.encodeBase64String(payloadData);
+ this.artifactChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(payloadData);
+ }
+ this.artifactUniqueId = artifactUniqueId;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public String getArtifactName() {
+ return artifactName;
+ }
+
+ public ArtifactTypeEnum getArtifactType() {
+ return artifactType;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public ArtifactGroupTypeEnum getArtifactGroupType() {
+ return artifactGroupType;
+ }
+
+ public String getArtifactLabel() {
+ return artifactLabel;
+ }
+
+ public boolean isFromCsar(){
+ return isFromCsar;
+ }
+
+ public String getPayloadData() {
+ return payloadData;
+ }
+
+ public String getArtifactChecksum() {
+ return artifactChecksum;
+ }
+
+ public String getArtifactUniqueId() {
+ return artifactUniqueId;
+ }
+
+ public void setArtifactUniqueId(String artifactUniqueId) {
+ this.artifactUniqueId = artifactUniqueId;
+ }
+
+ }
+
+ /**
+ * This method checks the artifact GroupType & Artifact Type. <br>
+ * if there is any problem warning messages are added to collectedWarningMessages
+ *
+ * @param artifactPath
+ * @param collectedWarningMessages
+ * @return
+ */
+ public static Either<NonMetaArtifactInfo, Boolean> validateNonMetaArtifact(String artifactPath, byte[] payloadData, Map<String, Set<List<String>>> collectedWarningMessages) {
+ Either<NonMetaArtifactInfo, Boolean> ret;
+ try {
+ String[] parsedArtifactPath = artifactPath.split(PATH_DELIMITER);
+ // Validate Artifact Group Type
+ Either<ArtifactGroupTypeEnum, Boolean> eitherGroupType = detectArtifactGroupType(parsedArtifactPath[1], collectedWarningMessages);
+ if (eitherGroupType.isLeft()) {
+ final ArtifactGroupTypeEnum groupTypeEnum = eitherGroupType.left().value();
+
+ // Validate Artifact Type
+ String artifactType = parsedArtifactPath[2];
+ artifactType = detectArtifactTypeVF(groupTypeEnum, artifactType, collectedWarningMessages);
+
+ String artifactFileNameType = parsedArtifactPath[3];
+ ret = Either.left(new NonMetaArtifactInfo(artifactFileNameType, artifactPath, ArtifactTypeEnum.findType(artifactType), groupTypeEnum, payloadData, null, true));
+
+ } else {
+ ret = Either.right(eitherGroupType.right().value());
+ }
+ } catch (Exception e) {
+ log.debug("detectArtifactGroupType failed with exception", e);
+ ret = Either.right(false);
+ }
+ return ret;
+
+ }
+
+ private static String detectArtifactTypeVFC(ArtifactGroupTypeEnum artifactGroupType, String receivedTypeName, String parentVfName, Map<String, Set<List<String>>> collectedWarningMessages) {
+ String warningMessage = "Warning - artifact type {} that was provided for VFC {} is not recognized.";
+ return detectArtifactType(artifactGroupType, receivedTypeName, warningMessage, collectedWarningMessages, parentVfName);
+ }
+
+ private static String detectArtifactTypeVF(ArtifactGroupTypeEnum artifactGroupType, String receivedTypeName, Map<String, Set<List<String>>> collectedWarningMessages) {
+ String warningMessage = "Warning - artifact type {} that was provided for VF is not recognized.";
+ return detectArtifactType(artifactGroupType, receivedTypeName, warningMessage, collectedWarningMessages);
+ }
+
+ private static String detectArtifactType(ArtifactGroupTypeEnum artifactGroupType, String receivedTypeName, String warningMessage, Map<String, Set<List<String>>> collectedWarningMessages, String... arguments) {
+
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(receivedTypeName);
+ Map<String, ArtifactTypeConfig> resourceValidTypeArtifacts = null;
+
+ if(artifactGroupType != null){
+ switch (artifactGroupType) {
+ case INFORMATIONAL:
+ resourceValidTypeArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration()
+ .getResourceInformationalArtifacts();
+ break;
+ case DEPLOYMENT:
+ resourceValidTypeArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration()
+ .getResourceDeploymentArtifacts();
+ break;
+ default:
+ break;
+ }
+ }
+
+ Set<String> validArtifactTypes = null;
+ if(resourceValidTypeArtifacts != null){
+ validArtifactTypes = resourceValidTypeArtifacts.keySet();
+ }
+
+ if (validArtifactTypes == null || artifactType == null || !validArtifactTypes.contains(artifactType.getType())) {
+ List<String> messageArguments = new ArrayList<>();
+ messageArguments.add(receivedTypeName);
+ messageArguments.addAll(Arrays.asList(arguments));
+ if (!collectedWarningMessages.containsKey(warningMessage)) {
+ Set<List<String>> messageArgumentLists = new HashSet<>();
+ messageArgumentLists.add(messageArguments);
+ collectedWarningMessages.put(warningMessage, messageArgumentLists);
+ } else {
+ collectedWarningMessages.get(warningMessage).add(messageArguments);
+ }
+ }
- private Either<ZipOutputStream, ResponseFormat> writeAllFilesToCsar(Component mainComponent,
- CsarDefinition csarDefinition, ZipOutputStream zipstream, boolean isInCertificationRequest)
- throws IOException {
- ComponentArtifacts componentArtifacts = csarDefinition.getComponentArtifacts();
+ return artifactType == null ? ArtifactTypeEnum.OTHER.getType() : artifactType.getType();
+ }
- Either<ZipOutputStream, ResponseFormat> writeComponentArtifactsToSpecifiedPath = writeComponentArtifactsToSpecifiedPath(
- mainComponent, componentArtifacts, zipstream, ARTIFACTS_PATH, isInCertificationRequest);
+ private Either<ZipOutputStream, ResponseFormat> writeAllFilesToCsar(Component mainComponent, CsarDefinition csarDefinition, ZipOutputStream zipstream, boolean isInCertificationRequest) throws IOException{
+ ComponentArtifacts componentArtifacts = csarDefinition.getComponentArtifacts();
- if (writeComponentArtifactsToSpecifiedPath.isRight()) {
- return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
- }
+ Either<ZipOutputStream, ResponseFormat> writeComponentArtifactsToSpecifiedPath = writeComponentArtifactsToSpecifiedPath(mainComponent, componentArtifacts, zipstream, ARTIFACTS_PATH, isInCertificationRequest);
- ComponentTypeArtifacts mainTypeAndCIArtifacts = componentArtifacts.getMainTypeAndCIArtifacts();
- writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedPath(mainComponent,
- mainTypeAndCIArtifacts.getComponentArtifacts(), zipstream, ARTIFACTS_PATH, isInCertificationRequest);
+ if(writeComponentArtifactsToSpecifiedPath.isRight()){
+ return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
+ }
- if (writeComponentArtifactsToSpecifiedPath.isRight()) {
- return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
- }
+ ComponentTypeArtifacts mainTypeAndCIArtifacts = componentArtifacts.getMainTypeAndCIArtifacts();
+ writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedtPath(mainComponent, mainTypeAndCIArtifacts.getComponentArtifacts(), zipstream, ARTIFACTS_PATH, isInCertificationRequest);
- Map<String, ArtifactsInfo> componentInstancesArtifacts = mainTypeAndCIArtifacts
- .getComponentInstancesArtifacts();
- Set<String> keySet = componentInstancesArtifacts.keySet();
+ if(writeComponentArtifactsToSpecifiedPath.isRight()){
+ return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
+ }
- String currentPath = ARTIFACTS_PATH + RESOURCES_PATH;
- for (String keyAssetName : keySet) {
- ArtifactsInfo artifactsInfo = componentInstancesArtifacts.get(keyAssetName);
- String pathWithAssetName = currentPath + keyAssetName + "/";
- writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedPath(mainComponent, artifactsInfo,
- zipstream, pathWithAssetName, isInCertificationRequest);
+ Map<String, ArtifactsInfo> componentInstancesArtifacts = mainTypeAndCIArtifacts.getComponentInstancesArtifacts();
+ Set<String> keySet = componentInstancesArtifacts.keySet();
- if (writeComponentArtifactsToSpecifiedPath.isRight()) {
- return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
- }
- }
- return Either.left(zipstream);
- }
+ String currentPath = ARTIFACTS_PATH + RESOURCES_PATH;
+ for (String keyAssetName : keySet) {
+ ArtifactsInfo artifactsInfo = componentInstancesArtifacts.get(keyAssetName);
+ String pathWithAssetName = currentPath + keyAssetName + PATH_DELIMITER;
+ writeComponentArtifactsToSpecifiedPath = writeArtifactsInfoToSpecifiedtPath(mainComponent, artifactsInfo, zipstream, pathWithAssetName, isInCertificationRequest);
- private Either<ZipOutputStream, ResponseFormat> writeComponentArtifactsToSpecifiedPath(Component mainComponent,
- ComponentArtifacts componentArtifacts, ZipOutputStream zipstream, String currentPath,
- boolean isInCertificationRequest) throws IOException {
- Map<String, ComponentTypeArtifacts> componentTypeArtifacts = componentArtifacts.getComponentTypeArtifacts();
- // Keys are defined:
- // <Inner Asset TOSCA name (e.g. VFC name)> folder name: <Inner Asset TOSCA name
- // (e.g. VFC name)>_v<version>.
- // E.g. "org.openecomp.resource.vf.vipr_atm_v1.0"
- Set<String> componentTypeArtifactsKeys = componentTypeArtifacts.keySet();
- for (String keyAssetName : componentTypeArtifactsKeys) {
- ComponentTypeArtifacts componentInstanceArtifacts = componentTypeArtifacts.get(keyAssetName);
- ArtifactsInfo componentArtifacts2 = componentInstanceArtifacts.getComponentArtifacts();
- String pathWithAssetName = currentPath + keyAssetName + "/";
- Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedPath = writeArtifactsInfoToSpecifiedPath(
- mainComponent, componentArtifacts2, zipstream, pathWithAssetName, isInCertificationRequest);
-
- if (writeArtifactsInfoToSpecifiedPath.isRight()) {
- return writeArtifactsInfoToSpecifiedPath;
- }
- }
+ if(writeComponentArtifactsToSpecifiedPath.isRight()){
+ return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
+ }
+ }
+ writeComponentArtifactsToSpecifiedPath = writeOperationsArtifactsToCsar(mainComponent, zipstream);
+
+ if (writeComponentArtifactsToSpecifiedPath.isRight()) {
+ return Either.right(writeComponentArtifactsToSpecifiedPath.right().value());
+ }
+ return Either.left(zipstream);
+ }
+
+ private Either<ZipOutputStream, ResponseFormat> writeOperationsArtifactsToCsar(Component component,
+ ZipOutputStream zipstream) {
+ if (checkComponentBeforeOperation(component)) return Either.left(zipstream);
+ final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces();
+ for (Map.Entry<String, InterfaceDefinition> interfaceEntry : interfaces.entrySet()) {
+ for (OperationDataDefinition operation : interfaceEntry.getValue().getOperations().values()) {
+ try {
+ if (checkComponentBeforeWrite(component, interfaceEntry, operation)) continue;
+ final String artifactUUID = operation.getImplementation().getArtifactUUID();
+ final Either<byte[], ActionStatus> artifactFromCassandra = getFromCassandra(artifactUUID);
+ final String artifactName = operation.getImplementation().getArtifactName();
+ if (artifactFromCassandra.isRight()) {
+ log.error(ARTIFACT_NAME_UNIQUE_ID, artifactName, artifactUUID);
+ log.error("Failed to get {} payload from DB reason: {}", artifactName,
+ artifactFromCassandra.right().value());
+ return Either.right(componentsUtils.getResponseFormat(
+ ActionStatus.ARTIFACT_PAYLOAD_NOT_FOUND_DURING_CSAR_CREATION, "Resource",
+ component.getUniqueId(), artifactName, artifactUUID));
+ }
+ final byte[] payloadData = artifactFromCassandra.left().value();
+ zipstream.putNextEntry(new ZipEntry(OperationArtifactUtil.createOperationArtifactPath(
+ component, null, operation,true)));
+ zipstream.write(payloadData);
+ } catch (IOException e) {
+ log.error("Component Name {}, Interface Name {}, Operation Name {}", component.getNormalizedName(),
+ interfaceEntry.getKey(), operation.getName());
+ log.error("Error while writing the operation's artifacts to the CSAR " + "{}", e);
+ return Either.right(componentsUtils
+ .getResponseFormat(ActionStatus.ERROR_DURING_CSAR_CREATION, "Resource",
+ component.getUniqueId()));
+ }
+ }
+ }
+ return Either.left(zipstream);
+ }
+
+ private boolean checkComponentBeforeWrite(Component component, Entry<String, InterfaceDefinition> interfaceEntry, OperationDataDefinition operation) {
+ if (Objects.isNull(operation.getImplementation())) {
+ log.debug("Component Name {}, Interface Id {}, Operation Name {} - no Operation Implementation found",
+ component.getNormalizedName(), interfaceEntry.getValue().getUniqueId(),
+ operation.getName());
+ return true;
+ }
+ if (Objects.isNull(operation.getImplementation().getArtifactName())) {
+ log.debug("Component Name {}, Interface Id {}, Operation Name {} - no artifact found",
+ component.getNormalizedName(), interfaceEntry.getValue().getUniqueId(),
+ operation.getName());
+ return true;
+ }
+ return false;
+ }
+
+ private boolean checkComponentBeforeOperation(Component component) {
+ if (component instanceof Service) {
+ return true;
+ }
+ if (Objects.isNull(((Resource) component).getInterfaces())) {
+ log.debug("Component Name {}- no interfaces found", component.getNormalizedName());
+ return true;
+ }
+ return false;
+ }
+
+ private Either<ZipOutputStream, ResponseFormat> writeComponentArtifactsToSpecifiedPath(Component mainComponent, ComponentArtifacts componentArtifacts, ZipOutputStream zipstream,
+ String currentPath, boolean isInCertificationRequest) throws IOException {
+ Map<String, ComponentTypeArtifacts> componentTypeArtifacts = componentArtifacts.getComponentTypeArtifacts();
+ //Keys are defined:
+ //<Inner Asset TOSCA name (e.g. VFC name)> folder name: <Inner Asset TOSCA name (e.g. VFC name)>_v<version>.
+ //E.g. "org.openecomp.resource.vf.vipr_atm_v1.0"
+ Set<String> componentTypeArtifactsKeys = componentTypeArtifacts.keySet();
+ for (String keyAssetName : componentTypeArtifactsKeys) {
+ ComponentTypeArtifacts componentInstanceArtifacts = componentTypeArtifacts.get(keyAssetName);
+ ArtifactsInfo componentArtifacts2 = componentInstanceArtifacts.getComponentArtifacts();
+ String pathWithAssetName = currentPath + keyAssetName + PATH_DELIMITER;
+ Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedPath = writeArtifactsInfoToSpecifiedtPath(mainComponent, componentArtifacts2, zipstream, pathWithAssetName, isInCertificationRequest);
+
+ if(writeArtifactsInfoToSpecifiedPath.isRight()){
+ return writeArtifactsInfoToSpecifiedPath;
+ }
+ }
- return Either.left(zipstream);
- }
+ return Either.left(zipstream);
+ }
- private Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedPath(Component mainComponent,
- ArtifactsInfo currArtifactsInfo, ZipOutputStream zip, String path, boolean isInCertificationRequest)
- throws IOException {
- Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactsInfo = currArtifactsInfo
- .getArtifactsInfo();
- Set<ArtifactGroupTypeEnum> groupTypeEnumKeySet = artifactsInfo.keySet();
+ private Either<ZipOutputStream, ResponseFormat> writeArtifactsInfoToSpecifiedtPath(Component mainComponent, ArtifactsInfo currArtifactsInfo, ZipOutputStream zip, String path, boolean isInCertificationRequest) throws IOException {
+ Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactsInfo = currArtifactsInfo
+ .getArtifactsInfo();
+ Set<ArtifactGroupTypeEnum> groupTypeEnumKeySet = artifactsInfo.keySet();
- for (ArtifactGroupTypeEnum artifactGroupTypeEnum : groupTypeEnumKeySet) {
- String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + File.separator;
+ for (ArtifactGroupTypeEnum artifactGroupTypeEnum : groupTypeEnumKeySet) {
+ String groupTypeFolder = path + WordUtils.capitalizeFully(artifactGroupTypeEnum.getType()) + PATH_DELIMITER;
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactTypesMap = artifactsInfo.get(artifactGroupTypeEnum);
- Set<ArtifactTypeEnum> artifactTypeEnumKeySet = artifactTypesMap.keySet();
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactTypesMap = artifactsInfo.get(artifactGroupTypeEnum);
+ Set<ArtifactTypeEnum> artifactTypeEnumKeySet = artifactTypesMap.keySet();
- for (ArtifactTypeEnum artifactTypeEnum : artifactTypeEnumKeySet) {
- List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactTypeEnum);
- String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + File.separator;
+ for (ArtifactTypeEnum artifactTypeEnum : artifactTypeEnumKeySet) {
+ List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactTypeEnum);
+ String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + PATH_DELIMITER;
if(artifactTypeEnum == ArtifactTypeEnum.WORKFLOW && path.contains(ARTIFACTS_PATH + RESOURCES_PATH)){
// Ignore this packaging as BPMN artifacts needs to be packaged in different manner
@@ -906,85 +951,77 @@ public class CsarUtils {
artifactTypeFolder += OperationArtifactUtil.BPMN_ARTIFACT_PATH + File.separator;
}
- Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition = writeArtifactDefinition(mainComponent,
- zip, artifactDefinitionList, artifactTypeFolder, isInCertificationRequest);
-
- if (writeArtifactDefinition.isRight()) {
- return writeArtifactDefinition;
- }
- }
- }
+ Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition = writeArtifactDefinition(mainComponent, zip, artifactDefinitionList, artifactTypeFolder, isInCertificationRequest);
- return Either.left(zip);
- }
-
- private Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition(Component mainComponent,
- ZipOutputStream zip, List<ArtifactDefinition> artifactDefinitionList, String artifactPathAndFolder,
- boolean isInCertificationRequest) throws IOException {
-
- ComponentTypeEnum componentType = mainComponent.getComponentType();
- String heatEnvType = ArtifactTypeEnum.HEAT_ENV.getType();
-
- for (ArtifactDefinition artifactDefinition : artifactDefinitionList) {
- if (!isInCertificationRequest && componentType == ComponentTypeEnum.SERVICE
- && artifactDefinition.getArtifactType().equals(heatEnvType) ||
- // this is placeholder
- (artifactDefinition.getEsId() == null && artifactDefinition.getMandatory())) {
- continue;
- }
+ if(writeArtifactDefinition.isRight()){
+ return writeArtifactDefinition;
+ }
+ }
+ }
- byte[] payloadData = artifactDefinition.getPayloadData();
- String artifactFileName = artifactDefinition.getArtifactName();
+ return Either.left(zip);
+ }
- if (payloadData == null) {
- Either<byte[], ActionStatus> fromCassandra = getFromCassandra(artifactDefinition.getEsId());
+ private Either<ZipOutputStream, ResponseFormat> writeArtifactDefinition(Component mainComponent, ZipOutputStream zip, List<ArtifactDefinition> artifactDefinitionList,
+ String artifactPathAndFolder, boolean isInCertificationRequest) throws IOException {
- if (fromCassandra.isRight()) {
- log.debug("ArtifactName {}, unique ID {}", artifactDefinition.getArtifactName(),
- artifactDefinition.getUniqueId());
- log.debug("Failed to get {} payload from DB reason: {}", artifactFileName,
- fromCassandra.right().value());
- continue;
- }
- payloadData = fromCassandra.left().value();
- }
- zip.putNextEntry(new ZipEntry(artifactPathAndFolder + artifactFileName));
- zip.write(payloadData);
- }
+ ComponentTypeEnum componentType = mainComponent.getComponentType();
+ String heatEnvType = ArtifactTypeEnum.HEAT_ENV.getType();
- return Either.left(zip);
- }
+ for (ArtifactDefinition artifactDefinition : artifactDefinitionList) {
+ if (!isInCertificationRequest && componentType == ComponentTypeEnum.SERVICE
+ && artifactDefinition.getArtifactType().equals(heatEnvType) ||
+ //this is placeholder
+ (artifactDefinition.getEsId() == null && artifactDefinition.getMandatory())){
+ continue;
+ }
- /************************************
- * Artifacts Structure
- ******************************************************************/
- /**
- * The artifacts Definition saved by their structure
- */
- private class ArtifactsInfo {
- // Key is the type of artifacts(Informational/Deployment)
- // Value is a map between an artifact type and a list of all artifacts of this
- // type
- private Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactsInfoField;
-
- public ArtifactsInfo() {
- this.artifactsInfoField = new EnumMap<>(ArtifactGroupTypeEnum.class);
- }
+ byte[] payloadData = artifactDefinition.getPayloadData();
+ String artifactFileName = artifactDefinition.getArtifactName();
- public Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> getArtifactsInfo() {
- return artifactsInfoField;
- }
+ if (payloadData == null) {
+ Either<byte[], ActionStatus> fromCassandra = getFromCassandra(artifactDefinition.getEsId());
- public List<ArtifactDefinition> getFlatArtifactsListByType(ArtifactTypeEnum artifactType) {
- List<ArtifactDefinition> artifacts = new ArrayList<>();
- for (List<ArtifactDefinition> artifactsByType : artifactsInfoField.get(artifactType).values()) {
- artifacts.addAll(artifactsByType);
- }
- return artifacts;
- }
+ if (fromCassandra.isRight()) {
+ log.debug(ARTIFACT_NAME_UNIQUE_ID, artifactDefinition.getArtifactName(), artifactDefinition.getUniqueId());
+ log.debug("Failed to get {} payload from DB reason: {}", artifactFileName, fromCassandra.right().value());
+ continue;
+ }
+ payloadData = fromCassandra.left().value();
+ }
+ zip.putNextEntry(new ZipEntry(artifactPathAndFolder + artifactFileName));
+ zip.write(payloadData);
+ }
+
+ return Either.left(zip);
+ }
+
+ /************************************ Artifacts Structure ******************************************************************/
+ /**
+ * The artifacts Definition saved by their structure
+ */
+ private class ArtifactsInfo {
+ //Key is the type of artifacts(Informational/Deployment)
+ //Value is a map between an artifact type and a list of all artifacts of this type
+ private Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactsInfoField;
+
+ public ArtifactsInfo() {
+ this.artifactsInfoField = new EnumMap<>(ArtifactGroupTypeEnum.class);
+ }
+
+ public Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> getArtifactsInfo() {
+ return artifactsInfoField;
+ }
+
+ public List<ArtifactDefinition> getFlatArtifactsListByType(ArtifactTypeEnum artifactType){
+ List<ArtifactDefinition> artifacts = new ArrayList<>();
+ for (List<ArtifactDefinition> artifactsByType:artifactsInfoField.get(artifactType).values()){
+ artifacts.addAll(artifactsByType);
+ }
+ return artifacts;
+ }
- public void addArtifactsToGroup(ArtifactGroupTypeEnum artifactGroup,
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsDefinition) {
+ public void addArtifactsToGroup(ArtifactGroupTypeEnum artifactGroup,Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsDefinition){
if (artifactsInfoField.get(artifactGroup) == null) {
artifactsInfoField.put(artifactGroup, artifactsDefinition);
} else {
@@ -994,225 +1031,198 @@ public class CsarUtils {
artifactsInfoField.put(artifactGroup, artifactTypeEnumListMap);
}
- }
-
- public boolean isEmpty() {
- return artifactsInfoField.isEmpty();
- }
-
- }
-
- /**
- * The artifacts of the component and of all its composed instances
- *
- */
- private class ComponentTypeArtifacts {
- private ArtifactsInfo componentArtifacts; // component artifacts (describes the Informational Deployment
- // folders)
- private Map<String, ArtifactsInfo> componentInstancesArtifacts; // artifacts of the composed instances mapped by
- // the resourceInstance normalized name
- // (describes the Resources folder)
-
- public ComponentTypeArtifacts() {
- componentArtifacts = new ArtifactsInfo();
- componentInstancesArtifacts = new HashMap<>();
- }
-
- public ArtifactsInfo getComponentArtifacts() {
- return componentArtifacts;
- }
-
- public void setComponentArtifacts(ArtifactsInfo artifactsInfo) {
- this.componentArtifacts = artifactsInfo;
- }
-
- public Map<String, ArtifactsInfo> getComponentInstancesArtifacts() {
- return componentInstancesArtifacts;
- }
-
- public void setComponentInstancesArtifacts(Map<String, ArtifactsInfo> componentInstancesArtifacts) {
- this.componentInstancesArtifacts = componentInstancesArtifacts;
- }
-
- public void addComponentInstancesArtifacts(String normalizedName, ArtifactsInfo artifactsInfo) {
- componentInstancesArtifacts.put(normalizedName, artifactsInfo);
- }
-
- }
-
- private class ComponentArtifacts {
- // artifacts of the component and CI's artifacts contained in it's composition
- // (represents Informational, Deployment & Resource folders of main component)
- private ComponentTypeArtifacts mainTypeAndCIArtifacts;
- // artifacts of all component types mapped by their tosca name
- private Map<String, ComponentTypeArtifacts> componentTypeArtifacts;
-
- public ComponentArtifacts() {
- mainTypeAndCIArtifacts = new ComponentTypeArtifacts();
- componentTypeArtifacts = new HashMap<>();
- }
-
- public ComponentTypeArtifacts getMainTypeAndCIArtifacts() {
- return mainTypeAndCIArtifacts;
- }
-
- public void setMainTypeAndCIArtifacts(ComponentTypeArtifacts componentInstanceArtifacts) {
- this.mainTypeAndCIArtifacts = componentInstanceArtifacts;
- }
-
- public Map<String, ComponentTypeArtifacts> getComponentTypeArtifacts() {
- return componentTypeArtifacts;
- }
-
- public void setComponentTypeArtifacts(Map<String, ComponentTypeArtifacts> componentTypeArtifacts) {
- this.componentTypeArtifacts = componentTypeArtifacts;
- }
- }
-
- private class CsarDefinition {
- private ComponentArtifacts componentArtifacts;
-
- // add list of tosca artifacts and meta describes CSAR zip root
-
- public CsarDefinition(ComponentArtifacts componentArtifacts) {
- this.componentArtifacts = componentArtifacts;
- }
-
- public ComponentArtifacts getComponentArtifacts() {
- return componentArtifacts;
- }
- }
-
- /************************************
- * Artifacts Structure END
- ******************************************************************/
-
- private Either<CsarDefinition, ResponseFormat> collectComponentCsarDefinition(Component component) {
- ComponentArtifacts componentArtifacts = new ComponentArtifacts();
- Component updatedComponent = component;
-
- // get service to receive the AII artifacts uploaded to the service
- if (updatedComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
- Either<Service, StorageOperationStatus> getServiceResponse = toscaOperationFacade
- .getToscaElement(updatedComponent.getUniqueId());
-
- if (getServiceResponse.isRight()) {
- ActionStatus actionStatus = componentsUtils
- .convertFromStorageResponse(getServiceResponse.right().value());
- return Either.right(componentsUtils.getResponseFormat(actionStatus));
- }
-
- updatedComponent = getServiceResponse.left().value();
- }
-
- // find the artifacts of the main component, it would have its composed
- // instances artifacts in a separate folder
- ComponentTypeArtifacts componentInstanceArtifacts = new ComponentTypeArtifacts();
- ArtifactsInfo artifactsInfo = collectComponentArtifacts(updatedComponent);
- componentInstanceArtifacts.setComponentArtifacts(artifactsInfo);
- componentArtifacts.setMainTypeAndCIArtifacts(componentInstanceArtifacts);
-
- Map<String, ComponentTypeArtifacts> resourceTypeArtifacts = componentArtifacts.getComponentTypeArtifacts(); // artifacts
- // mapped
- // by
- // the
- // component
- // type(tosca
- // name+version)
- // get the component instances
- List<ComponentInstance> componentInstances = updatedComponent.getComponentInstances();
- if (componentInstances != null) {
- for (ComponentInstance componentInstance : componentInstances) {
- // call recursive to find artifacts for all the path
- Either<Boolean, ResponseFormat> collectComponentInstanceArtifacts = collectComponentInstanceArtifacts(
- updatedComponent, componentInstance, resourceTypeArtifacts, componentInstanceArtifacts);
- if (collectComponentInstanceArtifacts.isRight()) {
- return Either.right(collectComponentInstanceArtifacts.right().value());
- }
- }
- }
-
- if (log.isDebugEnabled()) {
- printResult(componentArtifacts, updatedComponent.getName());
- }
-
- return Either.left(new CsarDefinition(componentArtifacts));
- }
-
- private void printResult(ComponentArtifacts componentArtifacts, String name) {
- StringBuilder result = new StringBuilder();
- result.append("Artifacts of main component " + name + "\n");
- ComponentTypeArtifacts componentInstanceArtifacts = componentArtifacts.getMainTypeAndCIArtifacts();
- printArtifacts(componentInstanceArtifacts);
- result.append("Type Artifacts\n");
- for (Map.Entry<String, ComponentTypeArtifacts> typeArtifacts : componentArtifacts.getComponentTypeArtifacts()
- .entrySet()) {
- result.append("Folder " + typeArtifacts.getKey() + "\n");
- result.append(printArtifacts(typeArtifacts.getValue()));
- }
-
- if (log.isDebugEnabled()) {
- log.debug(result.toString());
- }
- }
-
- private String printArtifacts(ComponentTypeArtifacts componentInstanceArtifacts) {
- StringBuilder result = new StringBuilder();
- ArtifactsInfo artifactsInfo = componentInstanceArtifacts.getComponentArtifacts();
- Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componetArtifacts = artifactsInfo
- .getArtifactsInfo();
- printArtifacts(componetArtifacts);
- result = result.append("Resources\n");
- for (Map.Entry<String, ArtifactsInfo> resourceInstance : componentInstanceArtifacts
- .getComponentInstancesArtifacts().entrySet()) {
- result.append("Folder" + resourceInstance.getKey() + "\n");
- result.append(printArtifacts(resourceInstance.getValue().getArtifactsInfo()));
- }
-
- return result.toString();
- }
-
- private String printArtifacts(
- Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componetArtifacts) {
- StringBuilder result = new StringBuilder();
- for (Map.Entry<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactGroup : componetArtifacts
- .entrySet()) {
- result.append(" " + artifactGroup.getKey().getType());
- for (Map.Entry<ArtifactTypeEnum, List<ArtifactDefinition>> groupArtifacts : artifactGroup.getValue()
- .entrySet()) {
- result.append(" " + groupArtifacts.getKey().getType());
- for (ArtifactDefinition artifact : groupArtifacts.getValue()) {
- result.append(" " + artifact.getArtifactDisplayName());
- }
- }
- }
-
- return result.toString();
- }
+ }
+
+ public boolean isEmpty() {
+ return artifactsInfoField.isEmpty();
+ }
+
+ }
+
+ /**
+ * The artifacts of the component and of all its composed instances
+ *
+ */
+ private class ComponentTypeArtifacts {
+ private ArtifactsInfo componentArtifacts; //component artifacts (describes the Informational Deployment folders)
+ private Map<String, ArtifactsInfo> componentInstancesArtifacts; //artifacts of the composed instances mapped by the resourceInstance normalized name (describes the Resources folder)
+
+ public ComponentTypeArtifacts() {
+ componentArtifacts = new ArtifactsInfo();
+ componentInstancesArtifacts = new HashMap<>();
+ }
+
+ public ArtifactsInfo getComponentArtifacts() {
+ return componentArtifacts;
+ }
+ public void setComponentArtifacts(ArtifactsInfo artifactsInfo) {
+ this.componentArtifacts = artifactsInfo;
+ }
+ public Map<String, ArtifactsInfo> getComponentInstancesArtifacts() {
+ return componentInstancesArtifacts;
+ }
+ public void setComponentInstancesArtifacts(Map<String, ArtifactsInfo> componentInstancesArtifacts) {
+ this.componentInstancesArtifacts = componentInstancesArtifacts;
+ }
+
+ public void addComponentInstancesArtifacts(String normalizedName, ArtifactsInfo artifactsInfo) {
+ componentInstancesArtifacts.put(normalizedName, artifactsInfo);
+ }
+
+ }
+
+ private class ComponentArtifacts {
+ //artifacts of the component and CI's artifacts contained in it's composition (represents Informational, Deployment & Resource folders of main component)
+ private ComponentTypeArtifacts mainTypeAndCIArtifacts;
+ //artifacts of all component types mapped by their tosca name
+ private Map<String, ComponentTypeArtifacts> componentTypeArtifacts;
+
+ public ComponentArtifacts(){
+ mainTypeAndCIArtifacts = new ComponentTypeArtifacts();
+ componentTypeArtifacts = new HashMap<>();
+ }
+
+ public ComponentTypeArtifacts getMainTypeAndCIArtifacts() {
+ return mainTypeAndCIArtifacts;
+ }
+
+ public void setMainTypeAndCIArtifacts(ComponentTypeArtifacts componentInstanceArtifacts) {
+ this.mainTypeAndCIArtifacts = componentInstanceArtifacts;
+ }
+
+ public Map<String, ComponentTypeArtifacts> getComponentTypeArtifacts() {
+ return componentTypeArtifacts;
+ }
+
+ public void setComponentTypeArtifacts(Map<String, ComponentTypeArtifacts> componentTypeArtifacts) {
+ this.componentTypeArtifacts = componentTypeArtifacts;
+ }
+ }
+
+ private class CsarDefinition {
+ private ComponentArtifacts componentArtifacts;
+
+ // add list of tosca artifacts and meta describes CSAR zip root
+
+ public CsarDefinition(ComponentArtifacts componentArtifacts) {
+ this.componentArtifacts = componentArtifacts;
+ }
+
+ public ComponentArtifacts getComponentArtifacts() {
+ return componentArtifacts;
+ }
+ }
+
+ /************************************ Artifacts Structure END******************************************************************/
+
+ private Either<CsarDefinition,ResponseFormat> collectComponentCsarDefinition(Component component){
+ ComponentArtifacts componentArtifacts = new ComponentArtifacts();
+ Component updatedComponent = component;
+
+ //get service to receive the AII artifacts uploaded to the service
+ if (updatedComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
+ Either<Service, StorageOperationStatus> getServiceResponse = toscaOperationFacade.getToscaElement(updatedComponent.getUniqueId());
+
+ if(getServiceResponse.isRight()){
+ ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(getServiceResponse.right().value());
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ }
- private ComponentTypeArtifacts collectComponentTypeArtifacts(Map<String, ComponentTypeArtifacts> resourcesArtifacts,
- ComponentInstance componentInstance, Component fetchedComponent) {
- String toscaComponentName = componentInstance.getToscaComponentName() + "_v"
- + componentInstance.getComponentVersion();
-
- ComponentTypeArtifacts componentArtifactsInfo = resourcesArtifacts.get(toscaComponentName);
- // if there are no artifacts for this component type we need to fetch and build
- // them
- if (componentArtifactsInfo == null) {
- ArtifactsInfo componentArtifacts = collectComponentArtifacts(fetchedComponent);
- componentArtifactsInfo = new ComponentTypeArtifacts();
- if (!componentArtifacts.isEmpty()) {
- componentArtifactsInfo.setComponentArtifacts(componentArtifacts);
- resourcesArtifacts.put(toscaComponentName, componentArtifactsInfo);
- }
- }
- return componentArtifactsInfo;
- }
+ updatedComponent = getServiceResponse.left().value();
+ }
+
+ //find the artifacts of the main component, it would have its composed instances artifacts in a separate folder
+ ComponentTypeArtifacts componentInstanceArtifacts = new ComponentTypeArtifacts();
+ ArtifactsInfo artifactsInfo = collectComponentArtifacts(updatedComponent);
+ componentInstanceArtifacts.setComponentArtifacts(artifactsInfo);
+ componentArtifacts.setMainTypeAndCIArtifacts(componentInstanceArtifacts);
+
+ Map<String,ComponentTypeArtifacts> resourceTypeArtifacts = componentArtifacts.getComponentTypeArtifacts(); //artifacts mapped by the component type(tosca name+version)
+ //get the component instances
+ List<ComponentInstance> componentInstances = updatedComponent.getComponentInstances();
+ if (componentInstances!=null){
+ for (ComponentInstance componentInstance:componentInstances){
+ //call recursive to find artifacts for all the path
+ Either<Boolean, ResponseFormat> collectComponentInstanceArtifacts = collectComponentInstanceArtifacts(
+ updatedComponent, componentInstance, resourceTypeArtifacts, componentInstanceArtifacts);
+ if (collectComponentInstanceArtifacts.isRight()){
+ return Either.right(collectComponentInstanceArtifacts.right().value());
+ }
+ }
+ }
+
+ if(log.isDebugEnabled()){
+ printResult(componentArtifacts,updatedComponent.getName());
+ }
+
+ return Either.left(new CsarDefinition(componentArtifacts));
+ }
+
+ private void printResult(ComponentArtifacts componentArtifacts, String name) {
+ StringBuilder result = new StringBuilder();
+ result.append("Artifacts of main component " + name + "\n");
+ ComponentTypeArtifacts componentInstanceArtifacts = componentArtifacts.getMainTypeAndCIArtifacts();
+ printArtifacts(componentInstanceArtifacts);
+ result.append("Type Artifacts\n");
+ for (Map.Entry<String, ComponentTypeArtifacts> typeArtifacts:componentArtifacts.getComponentTypeArtifacts().entrySet()){
+ result.append("Folder " + typeArtifacts.getKey() + "\n");
+ result.append(printArtifacts(typeArtifacts.getValue()));
+ }
+
+ if(log.isDebugEnabled()){
+ log.debug(result.toString());
+ }
+ }
+
+ private String printArtifacts(ComponentTypeArtifacts componentInstanceArtifacts) {
+ StringBuilder result = new StringBuilder();
+ ArtifactsInfo artifactsInfo = componentInstanceArtifacts.getComponentArtifacts();
+ Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componetArtifacts = artifactsInfo.getArtifactsInfo();
+ printArtifacts(componetArtifacts);
+ result = result.append("Resources\n");
+ for (Map.Entry<String, ArtifactsInfo> resourceInstance:componentInstanceArtifacts.getComponentInstancesArtifacts().entrySet()){
+ result.append("Folder" + resourceInstance.getKey() + "\n");
+ result.append(printArtifacts(resourceInstance.getValue().getArtifactsInfo()));
+ }
+
+ return result.toString();
+ }
+
+ private String printArtifacts(Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componetArtifacts) {
+ StringBuilder result = new StringBuilder();
+ for (Map.Entry<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> artifactGroup:componetArtifacts.entrySet()){
+ result.append(" " + artifactGroup.getKey().getType());
+ for (Map.Entry<ArtifactTypeEnum, List<ArtifactDefinition>> groupArtifacts:artifactGroup.getValue().entrySet()){
+ result.append(" " + groupArtifacts.getKey().getType());
+ for (ArtifactDefinition artifact:groupArtifacts.getValue()){
+ result.append(" " + artifact.getArtifactDisplayName());
+ }
+ }
+ }
+
+ return result.toString();
+ }
+
+ private ComponentTypeArtifacts collectComponentTypeArtifacts(Map<String, ComponentTypeArtifacts> resourcesArtifacts, ComponentInstance componentInstance,
+ Component fetchedComponent) {
+ String toscaComponentName = componentInstance.getToscaComponentName() + "_v" + componentInstance.getComponentVersion();
+
+ ComponentTypeArtifacts componentArtifactsInfo = resourcesArtifacts.get(toscaComponentName);
+ //if there are no artifacts for this component type we need to fetch and build them
+ if (componentArtifactsInfo==null){
+ ArtifactsInfo componentArtifacts = collectComponentArtifacts(fetchedComponent);
+ componentArtifactsInfo = new ComponentTypeArtifacts();
+ if (!componentArtifacts.isEmpty()){
+ componentArtifactsInfo.setComponentArtifacts(componentArtifacts);
+ resourcesArtifacts.put(toscaComponentName, componentArtifactsInfo);
+ }
+ }
+ return componentArtifactsInfo;
+ }
- private Either<Boolean, ResponseFormat> collectComponentInstanceArtifacts(Component parentComponent,
- ComponentInstance componentInstance, Map<String, ComponentTypeArtifacts> resourcesTypeArtifacts,
- ComponentTypeArtifacts instanceArtifactsLocation) {
- // 1. get the component instance component
+ private Either<Boolean, ResponseFormat> collectComponentInstanceArtifacts(Component parentComponent,ComponentInstance componentInstance,
+ Map<String, ComponentTypeArtifacts> resourcesTypeArtifacts,ComponentTypeArtifacts instanceArtifactsLocation) {
+ //1. get the component instance component
String componentUid;
if (componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
componentUid = componentInstance.getSourceModelUid();
@@ -1222,126 +1232,122 @@ public class CsarUtils {
}
Either<Component, StorageOperationStatus> component = toscaOperationFacade.getToscaElement(componentUid);
if (component.isRight()) {
- log.error("Failed to fetch resource with id {} for instance {}", componentUid, parentComponent.getUUID());
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.ASSET_NOT_FOUND_DURING_CSAR_CREATION,
- parentComponent.getComponentType().getValue(), parentComponent.getUUID(),
- componentInstance.getOriginType().getComponentType().getValue(), componentUid));
- }
+ log.error("Failed to fetch resource with id {} for instance {}",componentUid, parentComponent.getUUID());
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.ASSET_NOT_FOUND_DURING_CSAR_CREATION,
+ parentComponent.getComponentType().getValue(), parentComponent.getUUID(),
+ componentInstance.getOriginType().getComponentType().getValue(), componentUid));
+ }
Component fetchedComponent = component.left().value();
- // 2. fill the artifacts for the current component parent type
- ComponentTypeArtifacts componentParentArtifacts = collectComponentTypeArtifacts(resourcesTypeArtifacts,
- componentInstance, fetchedComponent);
-
- // 3. find the artifacts specific to the instance
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> componentInstanceSpecificInformationalArtifacts = getComponentInstanceSpecificArtifacts(
- componentInstance.getArtifacts(), componentParentArtifacts.getComponentArtifacts().getArtifactsInfo(),
- ArtifactGroupTypeEnum.INFORMATIONAL);
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> componentInstanceSpecificDeploymentArtifacts = getComponentInstanceSpecificArtifacts(
- componentInstance.getDeploymentArtifacts(),
- componentParentArtifacts.getComponentArtifacts().getArtifactsInfo(), ArtifactGroupTypeEnum.DEPLOYMENT);
-
- // 4. add the instances artifacts to the component type
- ArtifactsInfo artifactsInfo = new ArtifactsInfo();
- if (!componentInstanceSpecificInformationalArtifacts.isEmpty()) {
- artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.INFORMATIONAL,
- componentInstanceSpecificInformationalArtifacts);
- }
- if (!componentInstanceSpecificDeploymentArtifacts.isEmpty()) {
- artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT,
- componentInstanceSpecificDeploymentArtifacts);
- }
- if (!artifactsInfo.isEmpty()) {
- instanceArtifactsLocation.addComponentInstancesArtifacts(componentInstance.getNormalizedName(),
- artifactsInfo);
- }
-
- // 5. do the same for all the component instances
- List<ComponentInstance> componentInstances = fetchedComponent.getComponentInstances();
- if (componentInstances != null) {
- for (ComponentInstance childComponentInstance : componentInstances) {
- Either<Boolean, ResponseFormat> collectComponentInstanceArtifacts = collectComponentInstanceArtifacts(
- fetchedComponent, childComponentInstance, resourcesTypeArtifacts, componentParentArtifacts);
- if (collectComponentInstanceArtifacts.isRight()) {
- return collectComponentInstanceArtifacts;
- }
- }
- }
-
- return Either.left(true);
- }
-
- private Map<ArtifactTypeEnum, List<ArtifactDefinition>> getComponentInstanceSpecificArtifacts(
- Map<String, ArtifactDefinition> componentArtifacts,
- Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componentTypeArtifacts,
- ArtifactGroupTypeEnum artifactGroupTypeEnum) {
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> parentArtifacts = componentTypeArtifacts
- .get(artifactGroupTypeEnum); // the artfiacts of the component itself and not the instance
-
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsByTypeOfComponentInstance = new EnumMap<>(
- ArtifactTypeEnum.class);
- if (componentArtifacts != null) {
- for (ArtifactDefinition artifact : componentArtifacts.values()) {
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
- List<ArtifactDefinition> parentArtifactsByType = null;
- if (parentArtifacts != null) {
- parentArtifactsByType = parentArtifacts.get(artifactType);
- }
- // the artifact is of instance
- if (parentArtifactsByType == null || !parentArtifactsByType.contains(artifact)) {
- List<ArtifactDefinition> typeArtifacts = artifactsByTypeOfComponentInstance.get(artifactType);
- if (typeArtifacts == null) {
- typeArtifacts = new ArrayList<>();
- artifactsByTypeOfComponentInstance.put(artifactType, typeArtifacts);
- }
- typeArtifacts.add(artifact);
- }
- }
- }
+ //2. fill the artifacts for the current component parent type
+ ComponentTypeArtifacts componentParentArtifacts = collectComponentTypeArtifacts(resourcesTypeArtifacts, componentInstance, fetchedComponent);
+
+ //3. find the artifacts specific to the instance
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> componentInstanceSpecificInformationalArtifacts =
+ getComponentInstanceSpecificArtifacts(componentInstance.getArtifacts(),
+ componentParentArtifacts.getComponentArtifacts().getArtifactsInfo(), ArtifactGroupTypeEnum.INFORMATIONAL);
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> componentInstanceSpecificDeploymentArtifacts =
+ getComponentInstanceSpecificArtifacts(componentInstance.getDeploymentArtifacts(),
+ componentParentArtifacts.getComponentArtifacts().getArtifactsInfo(), ArtifactGroupTypeEnum.DEPLOYMENT);
+
+ //4. add the instances artifacts to the component type
+ ArtifactsInfo artifactsInfo = new ArtifactsInfo();
+ if (!componentInstanceSpecificInformationalArtifacts.isEmpty()){
+ artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.INFORMATIONAL, componentInstanceSpecificInformationalArtifacts);
+ }
+ if (!componentInstanceSpecificDeploymentArtifacts.isEmpty()){
+ artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT, componentInstanceSpecificDeploymentArtifacts);
+ }
+ if (!artifactsInfo.isEmpty()){
+ instanceArtifactsLocation.addComponentInstancesArtifacts(componentInstance.getNormalizedName(), artifactsInfo);
+ }
+
+ //5. do the same for all the component instances
+ List<ComponentInstance> componentInstances = fetchedComponent.getComponentInstances();
+ if (componentInstances!=null){
+ for (ComponentInstance childComponentInstance:componentInstances){
+ Either<Boolean, ResponseFormat> collectComponentInstanceArtifacts = collectComponentInstanceArtifacts(
+ fetchedComponent, childComponentInstance, resourcesTypeArtifacts, componentParentArtifacts);
+ if (collectComponentInstanceArtifacts.isRight()){
+ return collectComponentInstanceArtifacts;
+ }
+ }
+ }
+
+ return Either.left(true);
+ }
+
+ public String getVersionFirstThreeOctets() {
+ return versionFirstThreeOctets;
+ }
+
+ public void setVersionFirstThreeOctets(String versionFirstThreeOctetes) {
+ this.versionFirstThreeOctets = versionFirstThreeOctetes;
+ }
+ private Map<ArtifactTypeEnum, List<ArtifactDefinition>> getComponentInstanceSpecificArtifacts(Map<String, ArtifactDefinition> componentArtifacts,
+ Map<ArtifactGroupTypeEnum, Map<ArtifactTypeEnum, List<ArtifactDefinition>>> componentTypeArtifacts, ArtifactGroupTypeEnum artifactGroupTypeEnum) {
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> parentArtifacts = componentTypeArtifacts.get(artifactGroupTypeEnum); //the artfiacts of the component itself and not the instance
+
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsByTypeOfComponentInstance = new EnumMap<>(ArtifactTypeEnum.class);
+ if (componentArtifacts!=null){
+ for (ArtifactDefinition artifact:componentArtifacts.values()){
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
+ List<ArtifactDefinition> parentArtifactsByType = null;
+ if (parentArtifacts!=null){
+ parentArtifactsByType = parentArtifacts.get(artifactType);
+ }
+ //the artifact is of instance
+ if (parentArtifactsByType == null || !parentArtifactsByType.contains(artifact)){
+ List<ArtifactDefinition> typeArtifacts = artifactsByTypeOfComponentInstance.get(artifactType);
+ if (typeArtifacts == null){
+ typeArtifacts = new ArrayList<>();
+ artifactsByTypeOfComponentInstance.put(artifactType, typeArtifacts);
+ }
+ typeArtifacts.add(artifact);
+ }
+ }
+ }
- return artifactsByTypeOfComponentInstance;
- }
+ return artifactsByTypeOfComponentInstance;
+ }
- private ArtifactsInfo collectComponentArtifacts(Component component) {
- Map<String, ArtifactDefinition> informationalArtifacts = component.getArtifacts();
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> informationalArtifactsByType = collectGroupArtifacts(
- informationalArtifacts);
- Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> deploymentArtifactsByType = collectGroupArtifacts(
- deploymentArtifacts);
+ private ArtifactsInfo collectComponentArtifacts(Component component) {
+ Map<String, ArtifactDefinition> informationalArtifacts = component.getArtifacts();
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> informationalArtifactsByType = collectGroupArtifacts(informationalArtifacts);
+ Map<String, ArtifactDefinition> deploymentArtifacts = component.getDeploymentArtifacts();
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> deploymentArtifactsByType = collectGroupArtifacts(deploymentArtifacts);
Map<String, ArtifactDefinition> interfaceOperationArtifacts =
OperationArtifactUtil.getDistinctInterfaceOperationArtifactsByName(component);
Map<ArtifactTypeEnum, List<ArtifactDefinition>> interfaceOperationArtifactsByType = collectGroupArtifacts(
interfaceOperationArtifacts);
- ArtifactsInfo artifactsInfo = new ArtifactsInfo();
- if (!informationalArtifactsByType.isEmpty()) {
- artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.INFORMATIONAL, informationalArtifactsByType);
- }
- if (!deploymentArtifactsByType.isEmpty()) {
- artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT, deploymentArtifactsByType);
+ ArtifactsInfo artifactsInfo = new ArtifactsInfo();
+ if (!informationalArtifactsByType.isEmpty()){
+ artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.INFORMATIONAL, informationalArtifactsByType);
+ }
+ if (!deploymentArtifactsByType.isEmpty() ){
+ artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT, deploymentArtifactsByType);
}
//Add component interface operation artifacts
if(MapUtils.isNotEmpty(interfaceOperationArtifacts)) {
artifactsInfo.addArtifactsToGroup(ArtifactGroupTypeEnum.DEPLOYMENT, interfaceOperationArtifactsByType);
- }
-
- return artifactsInfo;
- }
-
- private Map<ArtifactTypeEnum, List<ArtifactDefinition>> collectGroupArtifacts(
- Map<String, ArtifactDefinition> componentArtifacts) {
- Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsByType = new EnumMap<>(ArtifactTypeEnum.class);
- for (ArtifactDefinition artifact : componentArtifacts.values()) {
- if (artifact.getArtifactUUID() != null) {
- ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
- List<ArtifactDefinition> typeArtifacts = artifactsByType.get(artifactType);
- if (typeArtifacts == null) {
- typeArtifacts = new ArrayList<>();
- artifactsByType.put(artifactType, typeArtifacts);
- }
- typeArtifacts.add(artifact);
- }
- }
- return artifactsByType;
- }
+ }
+
+ return artifactsInfo;
+ }
+
+ private Map<ArtifactTypeEnum, List<ArtifactDefinition>> collectGroupArtifacts(Map<String, ArtifactDefinition> componentArtifacts) {
+ Map<ArtifactTypeEnum, List<ArtifactDefinition>> artifactsByType = new EnumMap<>(ArtifactTypeEnum.class);
+ for (ArtifactDefinition artifact:componentArtifacts.values()){
+ if (artifact.getArtifactUUID()!=null){
+ ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(artifact.getArtifactType());
+ List<ArtifactDefinition> typeArtifacts = artifactsByType.get(artifactType);
+ if (typeArtifacts==null){
+ typeArtifacts = new ArrayList<>();
+ artifactsByType.put(artifactType, typeArtifacts);
+ }
+ typeArtifacts.add(artifact);
+ }
+ }
+ return artifactsByType;
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java
index 14b11689d3..0b6d5d87a6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java
@@ -25,17 +25,31 @@ import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundException;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.GroupInstanceProperty;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.utils.ComponentUtilities;
import org.openecomp.sdc.be.model.utils.GroupUtils;
-import org.openecomp.sdc.be.tosca.model.*;
+import org.openecomp.sdc.be.tosca.model.IToscaMetadata;
+import org.openecomp.sdc.be.tosca.model.ToscaGroupTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateCapability;
+import org.openecomp.sdc.be.tosca.model.VfModuleToscaMetadata;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.*;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.function.Predicate;
import java.util.function.Supplier;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java
index 77afdadb26..776676f7d8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java
@@ -26,7 +26,11 @@ import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundExcept
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.tosca.model.IToscaMetadata;
import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
index baf5b30267..4e4afb005d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -167,7 +167,7 @@ public class PropertyConvertor {
}
innerConverter = type.getValueConverter();
- if (ToscaPropertyType.STRING.equals(type) && valueStartsWithNonJsonChar(value)) {
+ if (ToscaPropertyType.STRING == type && valueStartsWithNonJsonChar(value)) {
return innerConverter.convertToToscaValue(value, innerType, dataTypes);
}
}
@@ -199,7 +199,7 @@ public class PropertyConvertor {
}
}
Object convertedValue;
- if (innerConverter != null && (ToscaPropertyType.MAP.equals(type) || ToscaPropertyType.LIST.equals(type))) {
+ if (innerConverter != null && (ToscaPropertyType.MAP == type || ToscaPropertyType.LIST == type)) {
convertedValue = innerConverter.convertToToscaValue(value, innerType, dataTypes);
} else if (isScalar) {
// complex json for scalar type
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 257ea3675d..995d511acb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -1,22 +1,22 @@
/*-
- * ============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
- *
+* ============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=========================================================
- */
+* 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.sdc.be.tosca;
@@ -34,11 +34,34 @@ import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundExcept
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.*;
+import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+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.ComponentInstanceInterface;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RelationshipInfo;
+import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
@@ -46,7 +69,22 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.tosca.converters.ToscaValueBaseConverter;
-import org.openecomp.sdc.be.tosca.model.*;
+import org.openecomp.sdc.be.tosca.model.CapabilityFilter;
+import org.openecomp.sdc.be.tosca.model.NodeFilter;
+import org.openecomp.sdc.be.tosca.model.SubstitutionMapping;
+import org.openecomp.sdc.be.tosca.model.ToscaCapability;
+import org.openecomp.sdc.be.tosca.model.ToscaDataType;
+import org.openecomp.sdc.be.tosca.model.ToscaGroupTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaMetadata;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
+import org.openecomp.sdc.be.tosca.model.ToscaPolicyTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaRequirement;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateArtifact;
+import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
+import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
import org.openecomp.sdc.be.tosca.utils.ForwardingPathToscaUtil;
import org.openecomp.sdc.be.tosca.utils.InputConverter;
import org.openecomp.sdc.be.tosca.utils.InterfacesOperationsToscaUtil;
@@ -67,8 +105,16 @@ import org.yaml.snakeyaml.representer.Represent;
import org.yaml.snakeyaml.representer.Representer;
import java.beans.IntrospectionException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@@ -96,17 +142,17 @@ public class ToscaExportHandler {
@Autowired
public ToscaExportHandler(ApplicationDataTypeCache dataTypeCache, ToscaOperationFacade toscaOperationFacade,
- CapabilityRequirementConverter capabilityRequirementConverter, PolicyExportParser policyExportParser,
- GroupExportParser groupExportParser, InputConverter inputConverter, InterfaceLifecycleOperation interfaceLifecycleOperation) {
- this.dataTypeCache = dataTypeCache;
- this.toscaOperationFacade = toscaOperationFacade;
- this.capabilityRequirementConverter = capabilityRequirementConverter;
- this.policyExportParser = policyExportParser;
- this.groupExportParser = groupExportParser;
- this.propertyConvertor = PropertyConvertor.getInstance();
- this.inputConverter = inputConverter;
- this.interfaceLifecycleOperation = interfaceLifecycleOperation;
- }
+ CapabilityRequirementConverter capabilityRequirementConverter, PolicyExportParser policyExportParser,
+ GroupExportParser groupExportParser, InputConverter inputConverter, InterfaceLifecycleOperation interfaceLifecycleOperation) {
+ this.dataTypeCache = dataTypeCache;
+ this.toscaOperationFacade = toscaOperationFacade;
+ this.capabilityRequirementConverter = capabilityRequirementConverter;
+ this.policyExportParser = policyExportParser;
+ this.groupExportParser = groupExportParser;
+ this.propertyConvertor = PropertyConvertor.getInstance();
+ this.inputConverter = inputConverter;
+ this.interfaceLifecycleOperation = interfaceLifecycleOperation;
+ }
private static final Logger log = Logger.getLogger(ToscaExportHandler.class);
@@ -296,17 +342,17 @@ public class ToscaExportHandler {
SubstitutionMapping substitutionMapping = new SubstitutionMapping();
String toscaResourceName;
switch (component.getComponentType()) {
- case RESOURCE:
- toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
- .getMetadataDataDefinition()).getToscaResourceName();
- break;
- case SERVICE:
- toscaResourceName = SERVICE_NODE_TYPE_PREFIX
- + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
- break;
- default:
- log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
- return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
+ case RESOURCE:
+ toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
+ .getMetadataDataDefinition()).getToscaResourceName();
+ break;
+ case SERVICE:
+ toscaResourceName = SERVICE_NODE_TYPE_PREFIX
+ + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
+ break;
+ default:
+ log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
+ return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
}
substitutionMapping.setNode_type(toscaResourceName);
@@ -317,7 +363,7 @@ public class ToscaExportHandler {
substitutionMapping = capabilities.left().value();
Either<SubstitutionMapping, ToscaError> requirements = capabilityRequirementConverter
- .convertSubstitutionMappingRequirements(componentCache, component, substitutionMapping);
+ .convertSubstitutionMappingRequirements(componentCache, component, substitutionMapping);
if (requirements.isRight()) {
return Either.right(requirements.right().value());
}
@@ -331,21 +377,19 @@ public class ToscaExportHandler {
}
private void addGroupsToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate) {
-
-
Map<String, ToscaGroupTemplate> groups = groupExportParser.getGroups(component);
if(groups!= null) {
topologyTemplate.addGroups(groups);
}
}
- private void addPoliciesToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate)
- throws SdcResourceNotFoundException {
- Map<String, ToscaPolicyTemplate> policies = policyExportParser.getPolicies(component);
- if(policies!= null) {
- topologyTemplate.addPolicies(policies);
- }
- }
+ private void addPoliciesToTopologyTemplate(Component component, ToscaTopolgyTemplate topologyTemplate)
+ throws SdcResourceNotFoundException {
+ Map<String, ToscaPolicyTemplate> policies = policyExportParser.getPolicies(component);
+ if(policies!= null) {
+ topologyTemplate.addPolicies(policies);
+ }
+ }
private ToscaMetadata convertMetadata(Component component) {
return convertMetadata(component, false, null);
@@ -367,7 +411,7 @@ public class ToscaExportHandler {
toscaMetadata.setVersion(component.getVersion());
toscaMetadata.setCustomizationUUID(componentInstance.getCustomizationUUID());
if (componentInstance.getSourceModelInvariant() != null
- && !componentInstance.getSourceModelInvariant().isEmpty()) {
+ && !componentInstance.getSourceModelInvariant().isEmpty()) {
toscaMetadata.setVersion(componentInstance.getComponentVersion());
toscaMetadata.setSourceModelInvariant(componentInstance.getSourceModelInvariant());
toscaMetadata.setSourceModelUuid(componentInstance.getSourceModelUuid());
@@ -379,35 +423,36 @@ public class ToscaExportHandler {
}
switch (component.getComponentType()) {
- case RESOURCE:
- Resource resource = (Resource) component;
+ case RESOURCE:
+ Resource resource = (Resource) component;
- if (isInstance && componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
- toscaMetadata.setType(componentInstance.getOriginType().getDisplayValue());
- } else {
- toscaMetadata.setType(resource.getResourceType().name());
- }
- toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
- toscaMetadata.setResourceVendor(resource.getVendorName());
- toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
- toscaMetadata.setResourceVendorModelNumber(resource.getResourceVendorModelNumber());
- break;
- case SERVICE:
- Service service = (Service) component;
- toscaMetadata.setType(component.getComponentType().getValue());
- toscaMetadata.setServiceType(service.getServiceType());
- toscaMetadata.setServiceRole(service.getServiceRole());
- toscaMetadata.setEnvironmentContext(service.getEnvironmentContext());
- resolveInstantiationTypeAndSetItToToscaMetaData(toscaMetadata, service);
- if (!isInstance) {
- // DE268546
- toscaMetadata.setServiceEcompNaming(((Service) component).isEcompGeneratedNaming());
- toscaMetadata.setEcompGeneratedNaming(((Service) component).isEcompGeneratedNaming());
- toscaMetadata.setNamingPolicy(((Service) component).getNamingPolicy());
- }
- break;
- default:
- log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
+ if (isInstance && componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) {
+ toscaMetadata.setType(componentInstance.getOriginType().getDisplayValue());
+ } else {
+ toscaMetadata.setType(resource.getResourceType().name());
+ }
+ toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName());
+ toscaMetadata.setResourceVendor(resource.getVendorName());
+ toscaMetadata.setResourceVendorRelease(resource.getVendorRelease());
+ toscaMetadata.setResourceVendorModelNumber(resource.getResourceVendorModelNumber());
+ break;
+ case SERVICE:
+ Service service = (Service) component;
+ toscaMetadata.setType(component.getComponentType().getValue());
+ toscaMetadata.setServiceType(service.getServiceType());
+ toscaMetadata.setServiceRole(service.getServiceRole());
+ toscaMetadata.setServiceFunction(service.getServiceFunction());
+ toscaMetadata.setEnvironmentContext(service.getEnvironmentContext());
+ resolveInstantiationTypeAndSetItToToscaMetaData(toscaMetadata, service);
+ if (!isInstance) {
+ // DE268546
+ toscaMetadata.setServiceEcompNaming(((Service) component).isEcompGeneratedNaming());
+ toscaMetadata.setEcompGeneratedNaming(((Service) component).isEcompGeneratedNaming());
+ toscaMetadata.setNamingPolicy(((Service) component).getNamingPolicy());
+ }
+ break;
+ default:
+ log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
}
return toscaMetadata;
}
@@ -472,7 +517,7 @@ public class ToscaExportHandler {
if (componentRI == null) {
// all resource must be only once!
Either<Component, StorageOperationStatus> resource = toscaOperationFacade
- .getToscaFullElement(ci.getComponentUid());
+ .getToscaFullElement(ci.getComponentUid());
if ((resource.isRight()) && (log.isDebugEnabled())) {
log.debug("Failed to fetch resource with id {} for instance {}",ci.getComponentUid() ,ci.getUniqueId());
return ;
@@ -483,7 +528,7 @@ public class ToscaExportHandler {
if (ci.getOriginType() == OriginTypeEnum.ServiceProxy){
Either<Component, StorageOperationStatus> sourceService = toscaOperationFacade
- .getToscaFullElement(ci.getSourceModelUid());
+ .getToscaFullElement(ci.getSourceModelUid());
if (sourceService.isRight() && (log.isDebugEnabled())) {
log.debug("Failed to fetch source service with id {} for proxy {}", ci.getSourceModelUid(), ci.getUniqueId());
}
@@ -529,8 +574,8 @@ public class ToscaExportHandler {
}
private Either<ToscaTemplate, ToscaError> convertInterfaceNodeType(Map<String, Component> componentsCache,
- Component component, ToscaTemplate toscaNode,
- Map<String, ToscaNodeType> nodeTypes,
+ Component component, ToscaTemplate toscaNode,
+ Map<String, ToscaNodeType> nodeTypes,
boolean isAssociatedComponent) {
log.debug("start convert node type for {}", component.getUniqueId());
ToscaNodeType toscaNodeType = createNodeType(component);
@@ -542,10 +587,10 @@ public class ToscaExportHandler {
return Either.right(ToscaError.GENERAL_ERROR);
}
List<String> allGlobalInterfaceTypes = lifecycleTypeEither.left().value()
- .values()
- .stream()
+ .values()
+ .stream()
.map(InterfaceDataDefinition::getType)
- .collect(Collectors.toList());
+ .collect(Collectors.toList());
toscaNode.setInterface_types(addInterfaceTypeElement(component, allGlobalInterfaceTypes));
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll();
@@ -622,17 +667,17 @@ public class ToscaExportHandler {
String toscaResourceName;
switch (component.getComponentType()) {
- case RESOURCE:
- toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
- .getMetadataDataDefinition()).getToscaResourceName();
- break;
- case SERVICE:
- toscaResourceName = SERVICE_NODE_TYPE_PREFIX
- + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
- break;
- default:
- log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
- return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
+ case RESOURCE:
+ toscaResourceName = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition()
+ .getMetadataDataDefinition()).getToscaResourceName();
+ break;
+ case SERVICE:
+ toscaResourceName = SERVICE_NODE_TYPE_PREFIX
+ + component.getComponentMetadataDefinition().getMetadataDataDefinition().getSystemName();
+ break;
+ default:
+ log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType());
+ return Either.right(ToscaError.NOT_SUPPORTED_TOSCA_TYPE);
}
nodeTypes.put(toscaResourceName, toscaNodeType);
@@ -666,7 +711,7 @@ public class ToscaExportHandler {
nodeTemplate.setNode_filter(convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter()));
Either<Component, Boolean> originComponentRes = capabilityRequirementConverter
- .getOriginComponent(componentCache, componentInstance);
+ .getOriginComponent(componentCache, componentInstance);
if (originComponentRes.isRight()) {
convertNodeTemplatesRes = Either.right(ToscaError.NODE_TYPE_REQUIREMENT_ERROR);
break;
@@ -693,7 +738,7 @@ public class ToscaExportHandler {
}
Either<ToscaNodeTemplate, ToscaError> capabilities = capabilityRequirementConverter
- .convertComponentInstanceCapabilities(componentInstance, dataTypes, nodeTemplate);
+ .convertComponentInstanceCapabilities(componentInstance, dataTypes, nodeTemplate);
if (capabilities.isRight()) {
convertNodeTemplatesRes = Either.right(capabilities.right().value());
break;
@@ -832,8 +877,8 @@ public class ToscaExportHandler {
}
private void addComponentInstanceInputs(Map<String, DataTypeDefinition> dataTypes,
- Map<String, List<ComponentInstanceInput>> componentInstancesInputs,
- String instanceUniqueId, Map<String, Object> props) {
+ Map<String, List<ComponentInstanceInput>> componentInstancesInputs,
+ String instanceUniqueId, Map<String, Object> props) {
List<ComponentInstanceInput> instanceInputsList = componentInstancesInputs.get(instanceUniqueId);
if (instanceInputsList != null) {
@@ -841,7 +886,7 @@ public class ToscaExportHandler {
Supplier<String> supplier = () -> input.getValue() != null && !Objects.isNull(input.getValue())
? input.getValue() : input.getDefaultValue();
- propertyConvertor.convertAndAddValue(dataTypes, props, input, supplier);
+ propertyConvertor.convertAndAddValue(dataTypes, props, input, supplier);
});
}
}
@@ -853,14 +898,14 @@ public class ToscaExportHandler {
if (isNotEmpty(componentInstancesProperties)) {
componentInstancesProperties.get(instanceUniqueId)
- // Converts and adds each value to property map
- .forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
- prop::getValue));
+ // Converts and adds each value to property map
+ .forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
+ prop::getValue));
}
}
private void addPropertiesOfParentComponent(Map<String, DataTypeDefinition> dataTypes,
- Component componentOfInstance, Map<String, Object> props) {
+ Component componentOfInstance, Map<String, Object> props) {
List<PropertyDefinition> componentProperties = componentOfInstance.getProperties();
if (isNotEmpty(componentProperties)) {
@@ -869,7 +914,7 @@ public class ToscaExportHandler {
.filter(prop -> StringUtils.isNotEmpty(prop.getDefaultValue()))
// Converts and adds each value to property map
.forEach(prop -> propertyConvertor.convertAndAddValue(dataTypes, props, prop,
- prop::getDefaultValue));
+ prop::getDefaultValue));
}
}
@@ -910,7 +955,7 @@ public class ToscaExportHandler {
toscaNodeType.setDescription(component.getDescription());
} else {
String derivedFrom = null != component.getDerivedFromGenericType() ? component.getDerivedFromGenericType()
- : "tosca.nodes.Root";
+ : "tosca.nodes.Root";
toscaNodeType.setDerived_from(derivedFrom);
}
return toscaNodeType;
@@ -980,8 +1025,8 @@ public class ToscaExportHandler {
}
Map<String, ComponentInstance> serviceProxyInstanceList = new HashMap<>();
List<ComponentInstance> proxyInst = componentInstances.stream()
- .filter(p -> p.getOriginType().name().equals(OriginTypeEnum.ServiceProxy.name()))
- .collect(Collectors.toList());
+ .filter(p -> p.getOriginType().name().equals(OriginTypeEnum.ServiceProxy.name()))
+ .collect(Collectors.toList());
if (proxyInst != null && !proxyInst.isEmpty()) {
for (ComponentInstance inst : proxyInst) {
serviceProxyInstanceList.put(inst.getToscaComponentName(), inst);
@@ -992,7 +1037,7 @@ public class ToscaExportHandler {
return res;
}
Either<Resource, StorageOperationStatus> serviceProxyOrigin = toscaOperationFacade
- .getLatestByName("serviceProxy");
+ .getLatestByName("serviceProxy");
if (serviceProxyOrigin.isRight()) {
log.debug("Failed to fetch normative service proxy resource by tosca name, error {}",
serviceProxyOrigin.right().value());
@@ -1010,7 +1055,7 @@ public class ToscaExportHandler {
componentParametersView.setIgnoreInterfaces(false);
componentParametersView.setIgnoreRequirements(false);
Either<Component, StorageOperationStatus> service = toscaOperationFacade
- .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
+ .getToscaElement(entryProxy.getValue().getSourceModelUid(), componentParametersView);
if (service.isRight()) {
log.debug("Failed to fetch resource with id {} for instance {}", entryProxy.getValue().getSourceModelUid(), entryProxy.getValue().getName());
} else {
@@ -1077,10 +1122,10 @@ public class ToscaExportHandler {
List<RequirementCapabilityRelDef> relations, Component originComponent,
List<Map<String, ToscaTemplateRequirement>> toscaRequirements, Map<String, Component> componentCache) {
List<RequirementCapabilityRelDef> filteredRelations = relations.stream()
- .filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).collect(Collectors.toList());
+ .filter(p -> componentInstance.getUniqueId().equals(p.getFromNode())).collect(Collectors.toList());
return isEmpty(filteredRelations) ||
- filteredRelations.stream()
- .allMatch(rel -> addRequirement(componentInstance, originComponent, component.getComponentInstances(), rel, toscaRequirements, componentCache));
+ filteredRelations.stream()
+ .allMatch(rel -> addRequirement(componentInstance, originComponent, component.getComponentInstances(), rel, toscaRequirements, componentCache));
}
private boolean addRequirement(ComponentInstance fromInstance, Component fromOriginComponent,
@@ -1096,7 +1141,7 @@ public class ToscaExportHandler {
Optional<CapabilityDefinition> capOpt = Optional.empty();
ComponentInstance toInstance = instancesList.stream().filter(i -> rel.getToNode().equals(i.getUniqueId()))
- .findFirst().orElse(null);
+ .findFirst().orElse(null);
if (toInstance == null) {
log.debug("Failed to find a relation from the node {} to the node {}", fromInstance.getName(),
rel.getToNode());
@@ -1125,13 +1170,13 @@ public class ToscaExportHandler {
if (result) {
toOriginComponent = getOriginRes.left().value();
capOpt = toOriginComponent.getCapabilities().get(reqOpt.get().getCapability()).stream()
- .filter(c -> isCapabilityBelongToRelation(reqAndRelationshipPair, c)).findFirst();
+ .filter(c -> isCapabilityBelongToRelation(reqAndRelationshipPair, c)).findFirst();
if (!capOpt.isPresent()) {
capOpt = findCapability(reqAndRelationshipPair, toOriginComponent, fromOriginComponent, reqOpt.get());
if(!capOpt.isPresent()){
- result = false;
- log.debug("Failed to find a capability with name {} on a component with uniqueId {}",
- reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
+ result = false;
+ log.debug("Failed to find a capability with name {} on a component with uniqueId {}",
+ reqAndRelationshipPair.getCapability(), fromOriginComponent.getUniqueId());
}
}
}
@@ -1209,7 +1254,7 @@ public class ToscaExportHandler {
return false;
}
return ModelConverter.isAtomicComponent(originComponent) ||
- isRequirementBelongToOwner(reqAndRelationshipPair, requirement, fromInstanceId, originComponent);
+ isRequirementBelongToOwner(reqAndRelationshipPair, requirement, fromInstanceId, originComponent);
}
private boolean isRequirementBelongToOwner(RelationshipInfo reqAndRelationshipPair, RequirementDefinition requirement, String fromInstanceId, Component originComponent) {
@@ -1220,7 +1265,7 @@ public class ToscaExportHandler {
private boolean isCvfc(Component component) {
return component.getComponentType() == ComponentTypeEnum.RESOURCE &&
- ((Resource) component).getResourceType() == ResourceTypeEnum.CVFC;
+ ((Resource) component).getResourceType() == ResourceTypeEnum.CVFC;
}
private Either<SubstitutionMapping, ToscaError> convertCapabilities(Component component,
@@ -1228,7 +1273,7 @@ public class ToscaExportHandler {
Either<SubstitutionMapping, ToscaError> result = Either.left(substitutionMappings);
Either<Map<String, String[]>, ToscaError> toscaCapabilitiesRes = capabilityRequirementConverter
- .convertSubstitutionMappingCapabilities(componentCache, component);
+ .convertSubstitutionMappingCapabilities(componentCache, component);
if (toscaCapabilitiesRes.isRight()) {
result = Either.right(toscaCapabilitiesRes.right().value());
log.debug("Failed convert capabilities for the component {}. ", component.getName());
@@ -1401,7 +1446,7 @@ public class ToscaExportHandler {
NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
return "_defaultp_".equals(property.getName())
- ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
+ ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
index 32cb604e76..902d789d87 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaUtils.java
@@ -26,7 +26,11 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.Component;
import java.lang.reflect.Field;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class ToscaUtils {
private ToscaUtils() {}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/CapabilityFilter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/CapabilityFilter.java
index 58a9a759bf..8afd9518ba 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/CapabilityFilter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/CapabilityFilter.java
@@ -17,10 +17,11 @@
package org.openecomp.sdc.be.tosca.model;
+import org.apache.commons.collections.CollectionUtils;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections.CollectionUtils;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
index 426522c6d4..f68f2550cf 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMetadata.java
@@ -43,6 +43,7 @@ public class ToscaMetadata implements IToscaMetadata {
private String environmentContext;
private String sourceModelName;
private String sourceModelUuid;
+ private String serviceFunction;
public String getName() {
@@ -139,7 +140,15 @@ public class ToscaMetadata implements IToscaMetadata {
public String getServiceRole() {
return serviceRole;
}
-
+
+ public String getServiceFunction() {
+ return serviceFunction;
+ }
+
+ public void setServiceFunction(String serviceFunction) {
+ this.serviceFunction = serviceFunction;
+ }
+
public void setInstantiationType(String instantiationType) {
this.instantiationType = instantiationType;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
index d757cec36c..b7fe3bc13a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java
@@ -20,15 +20,14 @@
package org.openecomp.sdc.be.tosca.model;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections.CollectionUtils;
-
-import lombok.Getter;
-import lombok.Setter;
@Getter
@Setter
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java
index f72673de39..1d40de3400 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java
@@ -33,8 +33,14 @@ import org.openecomp.sdc.be.tosca.CapabilityRequirementConverter;
import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate;
import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement;
-import java.util.*;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
/**
* @author KATYR
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
index 0360386158..4c0fb25fcd 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
@@ -19,12 +19,6 @@ package org.openecomp.sdc.be.tosca.utils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
@@ -41,6 +35,11 @@ import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
public class InterfacesOperationsToscaUtil {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
index 8470bd22a0..02da1130d6 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/NodeFilterConverter.java
@@ -16,11 +16,6 @@
package org.openecomp.sdc.be.tosca.utils;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
@@ -31,6 +26,12 @@ import org.openecomp.sdc.be.tosca.model.NodeFilter;
import org.openecomp.sdc.be.ui.model.UIConstraint;
import org.openecomp.sdc.be.ui.model.UINodeFilter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
public class NodeFilterConverter {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
index 03c161e6d3..a58d035c3d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java
@@ -16,14 +16,6 @@
package org.openecomp.sdc.be.tosca.utils;
-import java.io.File;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
-
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.WordUtils;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
@@ -40,6 +32,14 @@ import org.openecomp.sdc.be.tosca.CsarUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import java.io.File;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
public class OperationArtifactUtil {
public static final String BPMN_ARTIFACT_PATH = "BPMN";
@@ -54,7 +54,7 @@ public class OperationArtifactUtil {
* @param operation the specific operation name
* @return the full path including file name for operation's artifacts
*/
- static String createOperationArtifactPath(Component component, ComponentInstance componentInstance,
+ public static String createOperationArtifactPath(Component component, ComponentInstance componentInstance,
OperationDataDefinition operation, boolean isAssociatedComponent) {
if (!(component instanceof Resource || component instanceof Service)) {
return null;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java
index 85f1095dfb..beb9dab7e8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ToscaExportUtils.java
@@ -16,15 +16,6 @@
package org.openecomp.sdc.be.tosca.utils;
-import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
@@ -36,6 +27,15 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.tosca.PropertyConvertor;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput;
+
public class ToscaExportUtils {
private ToscaExportUtils() {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java
index 9397f6d93b..c15c063149 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/Role.java
@@ -25,5 +25,18 @@ package org.openecomp.sdc.be.user;
* which may result in ecompRole id change
*/
public enum Role {
- ADMIN, TESTER, DESIGNER, GOVERNOR, OPS, PRODUCT_MANAGER, PRODUCT_STRATEGIST
+ ADMIN, TESTER, DESIGNER, PRODUCT_MANAGER, PRODUCT_STRATEGIST;
+
+ public static Role getByNameIgnoreCase(String name) {
+ for (Role inst : Role.values()) {
+ if (inst.name().equalsIgnoreCase(name)) {
+ return inst;
+ }
+ }
+ return null;
+ }
}
+
+
+
+
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java
index a56607d4ce..e1cac1c7ed 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java
@@ -21,309 +21,280 @@
package org.openecomp.sdc.be.user;
import fj.data.Either;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
+import org.openecomp.sdc.be.facade.operations.UserOperation;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.common.api.UserRoleEnum;
-import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.datastructure.UserContext;
import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.common.util.ThreadLocalsHolder;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import javax.annotation.Resource;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
-import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum.ADD_USER;
+import static org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum.GET_USERS_LIST;
+import static org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum.UPDATE_USER;
-@Component("userBusinessLogic")
-public class UserBusinessLogic implements IUserBusinessLogic {
+@org.springframework.stereotype.Component
+public class UserBusinessLogic {
private static final Logger log = Logger.getLogger(UserBusinessLogic.class);
+ private static final String IN_CERTIFICATION_CHECKED_OUT = "in-certification/checked-out";
+ private static final String UNKNOWN = "UNKNOWN";
private static UserAdminValidator userAdminValidator = UserAdminValidator.getInstance();
- @Resource
- private IUserAdminOperation userAdminOperation;
- @Resource
- private ComponentsUtils componentsUtils;
- @Autowired
- private JanusGraphGenericDao janusGraphDao;
+ private final UserAdminOperation userAdminOperation;
+ private final ComponentsUtils componentsUtils;
+ private final UserOperation facadeUserOperation;
- @Override
- public Either<User, ActionStatus> getUser(String userId, boolean inTransaction) {
- return userAdminOperation.getUserData(userId, inTransaction);
+ public UserBusinessLogic(UserAdminOperation userAdminOperation, ComponentsUtils componentsUtils, UserOperation facadeUserOperation) {
+ this.userAdminOperation = userAdminOperation;
+ this.componentsUtils = componentsUtils;
+ this.facadeUserOperation = facadeUserOperation;
}
- @Override
- public Either<User, ResponseFormat> createUser(User modifier, User newUser) {
-
- ResponseFormat responseFormat;
- String modifierUserId = modifier.getUserId();
-
- if (modifierUserId == null) {
- modifier.setUserId("UNKNOWN");
- log.debug("createUser method - user header is missing");
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.right(responseFormat);
+ public User getUser(String userId, boolean inTransaction) {
+ Either<User, ActionStatus> result = userAdminOperation.getUserData(userId, inTransaction);
+ if (result.isRight()) {
+ handleUserAccessAuditing(userId, result.right().value());
+ throw new ByActionStatusComponentException(result.right().value(), userId);
}
-
- Either<User, ActionStatus> eitherCreator = getUser(modifierUserId, false);
- if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
- log.debug("createUser method - user is not listed. userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.right(responseFormat);
+ User user = result.left().value();
+ if (user == null) {
+ handleUserAccessAuditing(userId, ActionStatus.GENERAL_ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
+ return user;
+ }
- modifier = eitherCreator.left().value();
- if (!modifier.getRole().equals(UserRoleEnum.ADMIN.getName())) {
- log.debug("createUser method - user is not admin = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.right(responseFormat);
+ public User getUser(String userId) {
+ UserContext userContext = ThreadLocalsHolder.getUserContext();
+ if (Objects.isNull(userContext) || Objects.isNull(userContext.getUserId())) {
+ log.info("USER_NOT_FOUND, user=" + userId);
+ handleUserAccessAuditing(userId, ActionStatus.USER_NOT_FOUND);
+ throw new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND, userId);
+ }
+ if (Objects.isNull(userContext.getUserRoles())){
+ userContext.setUserRoles(new HashSet<>());
}
+ return convertUserContextToUser(userContext);
+ }
- // verify user not exist
- User userFromDb = new User();
- Either<User, ActionStatus> eitherUserInDB = getUser(newUser.getUserId(), false);
- if (eitherUserInDB.isRight()) {
- ActionStatus status = eitherUserInDB.right().value();
- if (!ActionStatus.USER_NOT_FOUND.equals(status) && !ActionStatus.USER_INACTIVE.equals(status)) {
- responseFormat = componentsUtils.getResponseFormat(eitherUserInDB.right().value(), newUser.getUserId());
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.right(responseFormat);
- }
- } else {// User exist in DB
- userFromDb = eitherUserInDB.left().value();
- if (userFromDb.getStatus() == UserStatusEnum.ACTIVE) {
- responseFormat = componentsUtils.getResponseFormatByUserId(ActionStatus.USER_ALREADY_EXIST, newUser.getUserId());
- log.debug("createUser method - user with id {} already exist with id: {}", modifier.getUserId(), userFromDb.getUserId());
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.right(responseFormat);
- }
+ protected User convertUserContextToUser(UserContext userContext) {
+ User user = new User();
+ user.setUserId(userContext.getUserId());
+ user.setFirstName(userContext.getFirstName());
+ user.setLastName(userContext.getLastName());
+ boolean userHasRoles = userContext.getUserRoles().iterator().hasNext();
+ user.setRole(!userHasRoles ? null : userContext.getUserRoles().iterator().next());
+ user.setStatus(userHasRoles ? UserStatusEnum.ACTIVE : UserStatusEnum.INACTIVE);
+ return user;
+ }
+
+ public boolean hasActiveUser(String userId) {
+ UserContext userContext = ThreadLocalsHolder.getUserContext();
+ if (Objects.isNull(userContext) || Objects.isNull(userContext.getUserId()) ) {
+ handleUserAccessAuditing(userId, ActionStatus.USER_NOT_FOUND);
+ return false;
+ }
+ if (Objects.isNull(userContext.getUserRoles()) || userContext.getUserRoles().isEmpty()){
+ handleUserAccessAuditing(userId, ActionStatus.USER_INACTIVE);
+ return false;
}
+ return true;
+ }
+ public User createUser(String modifierUserId, User newUser) {
+
+ User modifier = getValidModifier(modifierUserId, newUser.getUserId(), AuditingActionEnum.ADD_USER);
+
+ // verify user not exist
+ String newUserId = newUser.getUserId();
+ Either<User, ActionStatus> eitherUserInDB = verifyNewUser(newUserId);
newUser.setStatus(UserStatusEnum.ACTIVE);
- // validate Email
- if (newUser.getEmail() != null && !userAdminValidator.validateEmail(newUser.getEmail())) {
- log.debug("createUser method - user has invalid email = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_EMAIL_ADDRESS, newUser.getEmail());
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.right(responseFormat);
- }
+ validateEmail(newUser);
- // validate Role
- if (newUser.getRole() == null || newUser.getRole().length() == 0) {
- newUser.setRole(Role.DESIGNER.name());
- } else {
- if (!userAdminValidator.validateRole(newUser.getRole())) {
- log.debug("createUser method - user has invalid role = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_ROLE, newUser.getRole());
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.right(responseFormat);
- }
- }
+ validateRole(newUser);
// handle last login if user is import
if (newUser.getLastLoginTime() == null) {
newUser.setLastLoginTime(0L);
}
- Either<User, StorageOperationStatus> addOrUpdateUserReq;
-
- if (ActionStatus.USER_INACTIVE.equals(eitherUserInDB.right().value())) { // user
- // exist
- // with
- // inactive
- // state
- // -
- // update
- // user
- // data
+ User createdUser;
+ if (ActionStatus.USER_INACTIVE.equals(eitherUserInDB.right().value())) { // user inactive - update state // exist
newUser.setLastLoginTime(0L);
- addOrUpdateUserReq = userAdminOperation.updateUserData(newUser);
-
- } else { // user not exist - create new user
-
- if (newUser.getUserId() != null && !userAdminValidator.validateUserId(newUser.getUserId())) {
- log.debug("createUser method - user has invalid userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_USER_ID, newUser.getUserId());
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.right(responseFormat);
+ createdUser = userAdminOperation.updateUserData(newUser);
+ } else { // user does not exist - create new user
+ if (!userAdminValidator.validateUserId(newUserId)) {
+ log.debug("createUser method - user has invalid userId = {}", newUser.getUserId());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_USER_ID, newUserId);
}
- addOrUpdateUserReq = userAdminOperation.saveUserData(newUser);
- }
-
- if (addOrUpdateUserReq.isRight() || addOrUpdateUserReq.left().value() == null) {
- log.debug("createUser method - failed to create user");
- Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addOrUpdateUserReq.right().value())));
+ createdUser = userAdminOperation.saveUserData(newUser);
}
- log.debug("createUser method - user created");
- User createdUser = addOrUpdateUserReq.left().value();
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
handleAuditing(modifier, null, createdUser, responseFormat, AuditingActionEnum.ADD_USER);
- return Either.left(createdUser);
+ getFacadeUserOperation().updateUserCache(UserOperationEnum.CREATE, createdUser.getUserId(), createdUser.getRole());
+ return createdUser;
}
- @Override
- public Either<User, ResponseFormat> updateUserRole(User modifier, String userIdToUpdate, String userRole) {
-
- ResponseFormat responseFormat;
- String modifierUserId = modifier.getUserId();
-
- if (modifierUserId == null) {
- modifier.setUserId("UNKNOWN");
- log.debug("updateUserRole method - user header is missing");
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
- return Either.right(responseFormat);
+ private void validateRole(User newUser) {
+ if (newUser.getRole() == null || newUser.getRole().length() == 0) {
+ newUser.setRole(Role.DESIGNER.name());
+ } else {
+ if (!userAdminValidator.validateRole(newUser.getRole())) {
+ log.debug("createUser method - user has invalid role = {}", newUser.getUserId());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_ROLE, newUser.getRole());
+ }
}
+ }
- Either<User, ActionStatus> eitherCreator = getUser(modifierUserId, false);
- if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
- log.debug("updateUserRole method - user is not listed. userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
- return Either.right(responseFormat);
+ private void validateEmail(User newUser) {
+ if (newUser.getEmail() != null && !userAdminValidator.validateEmail(newUser.getEmail())) {
+ log.debug("createUser method - user has invalid email = {}", newUser.getUserId());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_EMAIL_ADDRESS, newUser.getEmail());
}
+ }
- modifier = eitherCreator.left().value();
- if (!modifier.getRole().equals(UserRoleEnum.ADMIN.getName())) {
- log.debug("updateUserRole method - user is not admin. userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
- return Either.right(responseFormat);
+ private Either<User, ActionStatus> verifyNewUser(String newUserId) {
+ Either<User, ActionStatus> eitherUserInDB = getUserData(newUserId);
+ if (eitherUserInDB.isRight()) {
+ ActionStatus status = eitherUserInDB.right().value();
+ if (!ActionStatus.USER_NOT_FOUND.equals(status) && !ActionStatus.USER_INACTIVE.equals(status)) {
+ componentsUtils.auditAdminUserActionAndThrowException(ADD_USER, null, null, null, status, newUserId);
+ }
+ } else {// User exist in DB
+ User userFromDb = eitherUserInDB.left().value();
+ if (userFromDb.getStatus() == UserStatusEnum.ACTIVE) {
+ log.debug("createUser method - user with id {} already exist with id: {}", newUserId, userFromDb.getUserId());
+ componentsUtils.auditAdminUserActionAndThrowException(ADD_USER, null, null, null, ActionStatus.USER_ALREADY_EXIST, newUserId);
+ }
}
+ return eitherUserInDB;
+ }
- if (modifier.getUserId().equals(userIdToUpdate)) {
- log.debug("updateUserRole method - admin role can only be updated by other admin. userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.UPDATE_USER_ADMIN_CONFLICT);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
- return Either.right(responseFormat);
+ public Either<User, ActionStatus> verifyNewUserForPortal(String newUserId) {
+ Either<User, ActionStatus> eitherUserInDB = getUserData(newUserId);
+ if (eitherUserInDB.isRight()) {
+ ActionStatus status = eitherUserInDB.right().value();
+ if (!ActionStatus.USER_NOT_FOUND.equals(status) && !ActionStatus.USER_INACTIVE.equals(status)) {
+ componentsUtils.auditAdminUserActionAndThrowException(ADD_USER, null, null, null, status, newUserId);
+ }
}
- Either<User, ActionStatus> userToUpdateReq = getUser(userIdToUpdate, false);
- if (userToUpdateReq.isRight() || userToUpdateReq.left().value() == null) {
- log.debug("updateUserRole method - user not found. userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, userIdToUpdate);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
- return Either.right(responseFormat);
+ return eitherUserInDB;
+ }
+
+ private Either<User, ActionStatus> getUserData(String newUserId) {
+ if (newUserId == null) {
+ log.error(EcompLoggerErrorCode.DATA_ERROR, "", "","Create user - new user id is missing");
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
- if (!userAdminValidator.validateRole(userRole)) {
- log.debug("updateUserRole method - user has invalid role = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_ROLE, userRole);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.UPDATE_USER);
- return Either.right(responseFormat);
+ return userAdminOperation.getUserData(newUserId, false);
+ }
+
+ public User updateUserRole(String modifierUserId, String userIdToUpdate, String userRole) {
+
+ User modifier = getValidModifier(modifierUserId, userIdToUpdate, UPDATE_USER);
+ User userToUpdate = getUser(userIdToUpdate, false);
+ validateChangeRoleToAllowedRoles(userRole);
+
+ List<Edge> userPendingTasks = userAdminOperation.getUserPendingTasksList(userToUpdate, getChangeRoleStateLimitations(userToUpdate));
+ if (!userPendingTasks.isEmpty()) {
+ log.debug("updateUserRole method - User cannot be updated, user have pending projects userId {}", userIdToUpdate);
+ String userInfo = userToUpdate.getFirstName() + " " + userToUpdate.getLastName() + '(' + userToUpdate.getUserId() + ')';
+ componentsUtils.auditAdminUserActionAndThrowException(UPDATE_USER, modifier, userToUpdate, null, ActionStatus.CANNOT_UPDATE_USER_WITH_ACTIVE_ELEMENTS, userInfo, IN_CERTIFICATION_CHECKED_OUT);
}
+ Role newRole = Role.valueOf(userRole);
User newUser = new User();
- newUser.setRole(userRole);
+ newUser.setRole(newRole.name());
newUser.setUserId(userIdToUpdate);
- User userToUpdate = userToUpdateReq.left().value();
- // if(!userRole.equals(UserRoleEnum.ADMIN.getName())){ //this is in
- // comment until admin will be able to do do check-in/check-out from the
- // UI
- Either<List<Edge>, StorageOperationStatus> userPendingTasksReq = getPendingUserPendingTasksWithCommit(userToUpdate);
- if (userPendingTasksReq.isRight()) {
- log.debug("updateUserRole method - failed to get user pending tasks list userId {}", userIdToUpdate);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(userPendingTasksReq.right().value())));
- }
+ User updatedUser = userAdminOperation.updateUserData(newUser);
+ handleAuditing(modifier, userToUpdate, updatedUser, componentsUtils.getResponseFormat(ActionStatus.OK), UPDATE_USER);
+ getFacadeUserOperation().updateUserCache(UserOperationEnum.CHANGE_ROLE, updatedUser.getUserId(), updatedUser.getRole());
+ return updatedUser;
+ }
- List<Edge> userPendingTasks = userPendingTasksReq.left().value();
- if (!userPendingTasks.isEmpty()) {
- log.debug("updateUserRole method - User canot be updated, user have pending projects userId {}", userIdToUpdate);
+ private void validateChangeRoleToAllowedRoles(String userRole) {
+ List<String> allowedRoles = Arrays.asList(UserRoleEnum.DESIGNER.getName(), UserRoleEnum.ADMIN.getName());
+ if (!allowedRoles.contains(userRole)){
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_ROLE, userRole);
+ }
+ }
- String userTasksStatusForErrorMessage = getUserPendingTaskStatusByRole(UserRoleEnum.valueOf(userToUpdate.getRole()));
- String userInfo = userToUpdate.getFirstName() + " " + userToUpdate.getLastName() + '(' + userToUpdate.getUserId() + ')';
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.CANNOT_UPDATE_USER_WITH_ACTIVE_ELEMENTS, userInfo, userTasksStatusForErrorMessage);
- handleAuditing(modifier, userToUpdate, userToUpdate, responseFormat, AuditingActionEnum.UPDATE_USER);
- return Either.right(responseFormat);
+ User getValidModifier(String modifierUserId, String userIdHandle, AuditingActionEnum actionEnum) {
+ if (modifierUserId == null) {
+ log.error(EcompLoggerErrorCode.DATA_ERROR, "", "", "user modifier is missing");
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
- // }
- Either<User, StorageOperationStatus> updateUserReq = userAdminOperation.updateUserData(newUser);
- if (updateUserReq.isRight() || updateUserReq.left().value() == null) {
- log.debug("updateUser method - failed to update user data. userId = {}", modifier.getUserId());
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(updateUserReq.right().value())));
+ User modifier = getUser(modifierUserId, false);
+ if (!modifier.getRole().equals(UserRoleEnum.ADMIN.getName())) {
+ log.debug("user is not admin. Id = {}", modifier.getUserId());
+ componentsUtils.auditAdminUserActionAndThrowException(actionEnum, modifier, null, null, ActionStatus.RESTRICTED_OPERATION);
}
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- User updatedUser = updateUserReq.left().value();
- handleAuditing(modifier, userToUpdate, updatedUser, responseFormat, AuditingActionEnum.UPDATE_USER);
- return Either.left(updatedUser);
+ if (modifier.getUserId().equals(userIdHandle)) {
+ log.debug("admin user cannot act on self. Id = {}", modifier.getUserId());
+ componentsUtils.auditAdminUserActionAndThrowException(actionEnum, modifier, null, null, ActionStatus.UPDATE_USER_ADMIN_CONFLICT);
+ }
+ return modifier;
}
- public Either<List<User>, ResponseFormat> getAllAdminUsers() {
+ public List<User> getAllAdminUsers() {
Either<List<User>, ActionStatus> response = userAdminOperation.getAllUsersWithRole(Role.ADMIN.name(), null);
-
if (response.isRight()) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(response.right().value());
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(response.right().value());
}
- return Either.left(response.left().value());
+ return response.left().value();
}
- @Override
- public Either<List<User>, ResponseFormat> getUsersList(String modifierAttId, List<String> roles, String rolesStr) {
- ResponseFormat responseFormat;
- User user = new User();
+ public List<User> getUsersList(String modifierAttId, List<String> roles, String rolesStr) {
if (modifierAttId == null) {
- user.setUserId("UNKNOWN");
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
- handleGetUsersListAuditing(user, responseFormat, rolesStr);
- return Either.right(responseFormat);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
- Either<User, ActionStatus> userResult = getUser(modifierAttId, false);
- if (userResult.isRight()) {
- user.setUserId(modifierAttId);
- if (userResult.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- } else {
- responseFormat = componentsUtils.getResponseFormat(userResult.right().value());
- }
- BeEcompErrorManager.getInstance().logBeUserMissingError("Get users per roles", modifierAttId);
-
- handleGetUsersListAuditing(user, responseFormat, rolesStr);
- return Either.right(responseFormat);
- }
- user = userResult.left().value();
- Either<List<User>, ResponseFormat> getResponse = null;
- List<User> resultList = new ArrayList<>();
- if (roles != null && !roles.isEmpty()) {
+ User user = getUser(modifierAttId, false);
+ Either<List<User>, ResponseFormat> getResponse;
+ List<User> userList = new ArrayList<>();
+ if (!CollectionUtils.isEmpty(roles)) {
for (String role : roles) {
if (!userAdminValidator.validateRole(role)) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_ROLE, role);
- handleGetUsersListAuditing(user, responseFormat, rolesStr);
- return Either.right(responseFormat);
+ componentsUtils.auditAdminUserActionAndThrowException(GET_USERS_LIST, user, null, null, ActionStatus.INVALID_ROLE, role);
}
getResponse = getUsersPerRole(role, user, rolesStr);
- resultList.addAll(getResponse.left().value());
+ userList.addAll(getResponse.left().value());
}
} else {
rolesStr = "All";
getResponse = getUsersPerRole(null, user, rolesStr);
- resultList.addAll(getResponse.left().value());
+ userList.addAll(getResponse.left().value());
}
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleGetUsersListAuditing(user, responseFormat, rolesStr);
- return Either.left(resultList);
+ handleGetUsersListAuditing(user, componentsUtils.getResponseFormat(ActionStatus.OK), rolesStr);
+ return userList;
}
- private Either<List<User>, ResponseFormat> getUsersPerRole(String role, User user, String rolesStr) {
+ Either<List<User>, ResponseFormat> getUsersPerRole(String role, User user, String rolesStr) {
ResponseFormat responseFormat;
Either<List<User>, ActionStatus> response = userAdminOperation.getAllUsersWithRole(role, UserStatusEnum.ACTIVE.name());
if (response.isRight()) {
@@ -331,135 +302,37 @@ public class UserBusinessLogic implements IUserBusinessLogic {
handleGetUsersListAuditing(user, responseFormat, rolesStr);
return Either.right(responseFormat);
}
- return Either.left(response.left().value());
+ List<User> users = response.left().value()
+ .stream()
+ .filter(u-> StringUtils.isNotEmpty(u.getUserId()))
+ .collect(Collectors.toList());
+ return Either.left(users);
}
private void handleGetUsersListAuditing(User user, ResponseFormat responseFormat, String details) {
componentsUtils.auditGetUsersList(user, details, responseFormat);
}
- private void handleAuditing(User modifier, User userBefor, User userAfter, ResponseFormat responseFormat, AuditingActionEnum actionName) {
- componentsUtils.auditAdminUserAction(actionName, modifier, userBefor, userAfter, responseFormat);
+ private void handleAuditing(User modifier, User userBefore, User userAfter, ResponseFormat responseFormat, AuditingActionEnum actionName) {
+ componentsUtils.auditAdminUserAction(actionName, modifier, userBefore, userAfter, responseFormat);
}
private void handleUserAccessAuditing(User user, ResponseFormat responseFormat) {
componentsUtils.auditUserAccess(user, responseFormat);
}
- @Override
- public Either<User, ResponseFormat> deActivateUser(User modifier, String userUniuqeIdToDeactive) {
-
- ResponseFormat responseFormat;
- String userId = modifier.getUserId();
-
- if (userId == null) {
- modifier.setUserId("UNKNOWN");
- log.debug("deActivateUser method - user header is missing");
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
- return Either.right(responseFormat);
- }
-
- Either<User, ActionStatus> eitherCreator = getUser(userId, false);
- if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
- log.debug("deActivateUser method - user is not listed. userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
- return Either.right(responseFormat);
- }
-
- modifier = eitherCreator.left().value();
-
- if (!modifier.getRole().equals(UserRoleEnum.ADMIN.getName())) {
- log.debug("deActivateUser method - user is not admin. userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
- return Either.right(responseFormat);
- }
-
- if (modifier.getUserId().equals(userUniuqeIdToDeactive)) {
- log.debug("deActivateUser deActivateUser - admin can only be deactivate by other admin. userId = {}", modifier.getUserId());
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.DELETE_USER_ADMIN_CONFLICT);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
- return Either.right(responseFormat);
- }
-
- Either<User, ActionStatus> getUserToDeleteResponse = getUser(userUniuqeIdToDeactive, false);
- if (getUserToDeleteResponse.isRight() || getUserToDeleteResponse.left().value() == null) {
- log.debug("deActivateUser method - failed to get user by id {}", userUniuqeIdToDeactive);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, userUniuqeIdToDeactive);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
- return Either.right(componentsUtils.getResponseFormat(getUserToDeleteResponse.right().value(), userUniuqeIdToDeactive));
- }
-
- User userToDeactivate = getUserToDeleteResponse.left().value();
- if (userToDeactivate.getStatus().equals(UserStatusEnum.INACTIVE)) {
- log.debug("deActivateUser method - User already inactive", userUniuqeIdToDeactive);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, userUniuqeIdToDeactive);
- handleAuditing(modifier, null, null, responseFormat, AuditingActionEnum.DELETE_USER);
- return Either.right(responseFormat);
- }
-
- Either<List<Edge>, StorageOperationStatus> userPendingTasksReq = getPendingUserPendingTasksWithCommit(userToDeactivate);
- if (userPendingTasksReq.isRight()) {
- log.debug("deActivateUser method - failed to get user pending tasks list", userUniuqeIdToDeactive);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(userPendingTasksReq.right().value())));
- }
-
- List<Edge> userPendingTasks = userPendingTasksReq.left().value();
- if (userPendingTasks.size() > 0) {
- log.debug("deActivateUser method - User canot be deleted, user have pending projects", userUniuqeIdToDeactive);
-
- String userTasksStatusForErrorMessage = getUserPendingTaskStatusByRole(UserRoleEnum.valueOf(userToDeactivate.getRole()));
- String userInfo = userToDeactivate.getFirstName() + " " + userToDeactivate.getLastName() + '(' + userToDeactivate.getUserId() + ')';
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.CANNOT_DELETE_USER_WITH_ACTIVE_ELEMENTS, userInfo, userTasksStatusForErrorMessage);
- handleAuditing(modifier, userToDeactivate, userToDeactivate, responseFormat, AuditingActionEnum.DELETE_USER);
- return Either.right(responseFormat);
- }
-
- Either<User, StorageOperationStatus> deactivateUserReq = userAdminOperation.deActivateUser(userToDeactivate);
- if (deactivateUserReq.isRight()) {
- log.debug("deActivateUser method - failed to deactivate user", userUniuqeIdToDeactive);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deactivateUserReq.right().value())));
- }
- User deactivateUser = deactivateUserReq.left().value();
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleAuditing(modifier, userToDeactivate, null, responseFormat, AuditingActionEnum.DELETE_USER);
- return Either.left(deactivateUser);
+ private void handleUserAccessAuditing(String userId, ActionStatus status, String... params) {
+ componentsUtils.auditUserAccess(new User(userId), status, params);
}
- @Override
- public Either<User, ResponseFormat> authorize(User authUser) {
-
- ResponseFormat responseFormat;
-
+ public User authorize(User authUser) {
String userId = authUser.getUserId();
-
if (userId == null) {
- authUser.setUserId("UNKNOWN");
- log.debug("deActivateUser method - user header is missing");
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
- handleUserAccessAuditing(authUser, responseFormat);
- return Either.right(responseFormat);
+ log.debug("authorize method - user id is missing");
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
- Either<User, ActionStatus> eitherCreator = getUser(userId, false);
- if (eitherCreator.isRight()) {
- if (eitherCreator.right().value() == ActionStatus.USER_NOT_FOUND || eitherCreator.right().value() == ActionStatus.USER_INACTIVE) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS);
- handleUserAccessAuditing(authUser, responseFormat);
- return Either.right(responseFormat);
- } else {
- return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), authUser));
- }
- } else {
- if (eitherCreator.left().value() == null) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- return Either.right(responseFormat);
- }
- }
-
- User user = eitherCreator.left().value();
+ User user = getUser(userId, false);
String firstName = authUser.getFirstName();
if (firstName != null && !firstName.isEmpty() && !firstName.equals(user.getFirstName())) {
@@ -479,27 +352,17 @@ public class UserBusinessLogic implements IUserBusinessLogic {
// last login time stamp handle
user.setLastLoginTime();
- Either<User, StorageOperationStatus> updateUserReq = userAdminOperation.updateUserData(user);
-
- if (updateUserReq.isRight()) {
- responseFormat = componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user);
- handleUserAccessAuditing(user, responseFormat);
- return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user));
- }
-
- User updatedUser = updateUserReq.left().value();
-
+ User updatedUser = userAdminOperation.updateUserData(user);
Long lastLoginTime = user.getLastLoginTime();
if (lastLoginTime != null) {
updatedUser.setLastLoginTime(lastLoginTime);
} else {
- updatedUser.setLastLoginTime(new Long(0));
+ updatedUser.setLastLoginTime(0L);
}
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
- handleUserAccessAuditing(updatedUser, responseFormat);
+ handleUserAccessAuditing(updatedUser.getUserId(), ActionStatus.OK);
ASDCKpiApi.countUsersAuthorizations();
- return Either.left(updatedUser);
+ return updatedUser;
}
/*
@@ -512,32 +375,14 @@ public class UserBusinessLogic implements IUserBusinessLogic {
String userId = updatedUserCred.getUserId();
if (userId == null) {
- updatedUserCred.setUserId("UNKNOWN");
+ updatedUserCred.setUserId(UNKNOWN);
log.debug("updateUserCredentials method - user header is missing");
responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
handleUserAccessAuditing(updatedUserCred, responseFormat);
return Either.right(responseFormat);
}
- Either<User, ActionStatus> eitherCreator = getUser(userId, false);
- if (eitherCreator.isRight()) {
- ActionStatus status = eitherCreator.right().value();
- if (status == ActionStatus.USER_NOT_FOUND || status == ActionStatus.USER_INACTIVE) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS);
- handleUserAccessAuditing(updatedUserCred, responseFormat);
- return Either.right(responseFormat);
- } else {
- return Either.right(componentsUtils.getResponseFormatByUser(status, updatedUserCred));
- }
- } else {
- if (eitherCreator.left().value() == null) {
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- return Either.right(responseFormat);
- }
- }
-
- User user = eitherCreator.left().value();
-
+ User user = getUser(userId, false);
String firstName = updatedUserCred.getFirstName();
if (firstName != null && !firstName.isEmpty() && !firstName.equals(user.getFirstName())) {
user.setFirstName(firstName);
@@ -561,69 +406,31 @@ public class UserBusinessLogic implements IUserBusinessLogic {
user.setLastLoginTime(updatedUserCred.getLastLoginTime());
}
- Either<User, StorageOperationStatus> updateUserReq = userAdminOperation.updateUserData(user);
-
- if (updateUserReq.isRight()) {
- responseFormat = componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user);
- handleUserAccessAuditing(user, responseFormat);
- return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user));
- }
-
- User updatedUser = updateUserReq.left().value();
-
+ User updatedUser = userAdminOperation.updateUserData(user);
responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK);
handleUserAccessAuditing(updatedUser, responseFormat);
return Either.left(updatedUser);
}
- private Either<List<Edge>, StorageOperationStatus> getPendingUserPendingTasksWithCommit(User user) {
-
- Either<List<Edge>, StorageOperationStatus> result = null;
-
- try {
- UserRoleEnum userRole = UserRoleEnum.valueOf(user.getRole());
- Map<String, Object> properties = new HashMap<>();
- switch (userRole) {
+ private List<Object> getChangeRoleStateLimitations(User user) {
+ UserRoleEnum role = UserRoleEnum.valueOf(user.getRole());
+ List<Object> properties = new ArrayList<>();
+ switch (role) {
case DESIGNER:
case PRODUCT_STRATEGIST:
case PRODUCT_MANAGER:
- properties.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
- return userAdminOperation.getUserPendingTasksList(user, properties);
- case TESTER:
- properties.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.CERTIFICATION_IN_PROGRESS.name());
- return userAdminOperation.getUserPendingTasksList(user, properties);
case ADMIN:
- properties.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.CERTIFICATION_IN_PROGRESS.name());
- properties.put(GraphPropertiesDictionary.STATE.getProperty(), LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
- return userAdminOperation.getUserPendingTasksList(user, properties);
+ properties.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ break;
+ case TESTER:
+ // For tester we allow change role even if there are pending task (per US468155 in 1810)
default:
- return Either.left(new ArrayList<>());
- }
- } finally {
- // commit will be perform outside!!!
- if (result == null || result.isRight()) {
- log.debug("getUserPendingTasksList failed to perform fetching");
- janusGraphDao.rollback();
- } else {
- janusGraphDao.commit();
- }
}
+ return properties;
}
- private String getUserPendingTaskStatusByRole(UserRoleEnum role) {
-
- switch (role) {
- case DESIGNER:
- case PRODUCT_STRATEGIST:
- case PRODUCT_MANAGER:
- return "checked-out";
-
- case TESTER:
- return "in-certification";
- case ADMIN:
- return "in-certification/checked-out";
- default:
- return "";
- }
+ public UserOperation getFacadeUserOperation() {
+ return facadeUserOperation;
}
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogicExt.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogicExt.java
new file mode 100644
index 0000000000..38b4339e7c
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogicExt.java
@@ -0,0 +1,130 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+import fj.data.Either;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@org.springframework.stereotype.Component
+public class UserBusinessLogicExt {
+
+ private static final Logger log = Logger.getLogger(UserBusinessLogicExt.class);
+
+ private final UserBusinessLogic userBusinessLogic;
+ private final UserAdminOperation userAdminOperation;
+ private final LifecycleBusinessLogic lifecycleBusinessLogic;
+ private final ComponentsUtils componentsUtils;
+
+ public UserBusinessLogicExt(UserBusinessLogic userBusinessLogic, UserAdminOperation userAdminOperation,
+ LifecycleBusinessLogic lifecycleBusinessLogic, ComponentsUtils componentsUtils) {
+ this.userBusinessLogic = userBusinessLogic;
+ this.userAdminOperation = userAdminOperation;
+ this.lifecycleBusinessLogic = lifecycleBusinessLogic;
+ this.componentsUtils = componentsUtils;
+ }
+
+
+ public User deActivateUser(String modifierUserId, String userIdToDeactivate) {
+
+ User modifier = userBusinessLogic.getValidModifier(modifierUserId, userIdToDeactivate, AuditingActionEnum.DELETE_USER);
+
+ User userToDeactivate = userBusinessLogic.getUser(userIdToDeactivate, false);
+ if (userToDeactivate.getStatus() == UserStatusEnum.INACTIVE) {
+ log.debug("deActivateUser method - User already inactive", userIdToDeactivate);
+ componentsUtils.auditAdminUserActionAndThrowException(AuditingActionEnum.DELETE_USER, modifier, userToDeactivate, null, ActionStatus.USER_NOT_FOUND, userIdToDeactivate);
+ }
+
+ handleTasksInProgress(userToDeactivate);
+
+ userAdminOperation.deActivateUser(userToDeactivate);
+ componentsUtils.auditUserAccess(userToDeactivate, ActionStatus.OK);
+ handleAuditing(modifier, userToDeactivate, null, componentsUtils.getResponseFormat(ActionStatus.OK), AuditingActionEnum.DELETE_USER);
+ userBusinessLogic.getFacadeUserOperation().updateUserCache(UserOperationEnum.DEACTIVATE, userToDeactivate.getUserId(), userToDeactivate.getRole());
+ return userToDeactivate;
+ }
+
+ private void handleTasksInProgress(User userToDeactivate) {
+ String userIdToDeactivate = userToDeactivate.getUserId();
+ List<Component> userPendingTasks = userAdminOperation
+ .getUserActiveComponents(userToDeactivate, getDeactivateUserStateLimitations());
+ if (userPendingTasks.isEmpty()) {
+ return;
+ }
+ LifecycleChangeInfoWithAction changeInfo = new LifecycleChangeInfoWithAction("User became inactive");
+ List<String> failedComponents = new ArrayList<>();
+ for (Component component : userPendingTasks) {
+ String componentId = component.getUniqueId();
+ LifecycleStateEnum currentState = component.getLifecycleState();
+ LifeCycleTransitionEnum transition = getLifeCycleTransition(currentState);
+ if (transition == null) {
+ log.debug("Erroneous component state when deactivating user for component {} state is {}", componentId, currentState);
+ continue;
+ }
+ Either<? extends Component, ResponseFormat> result = lifecycleBusinessLogic.changeComponentState(component.getComponentType(), componentId, userToDeactivate,
+ transition, changeInfo, false, true);
+ if (result.isRight()) {
+ failedComponents.add(component.getName());
+ }
+ }
+ if (CollectionUtils.isNotEmpty(failedComponents)) {
+ String componentList = failedComponents.toString();
+ log.error(EcompLoggerErrorCode.DATA_ERROR, "", "", "User cannot be deleted, {} has the following pending projects that cannot be committed: {}", userIdToDeactivate, componentList);
+ String userInfo = userToDeactivate.getFirstName() + " " + userToDeactivate.getLastName() + '(' + userToDeactivate.getUserId() + ')';
+ componentsUtils.auditAdminUserActionAndThrowException(AuditingActionEnum.DELETE_USER, null, userToDeactivate, null, ActionStatus.CANNOT_DELETE_USER_WITH_ACTIVE_ELEMENTS, userInfo, componentList);
+ }
+ }
+
+ private LifeCycleTransitionEnum getLifeCycleTransition(LifecycleStateEnum currentState) {
+ LifeCycleTransitionEnum transition = null;
+ if (LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == currentState) {
+ transition = LifeCycleTransitionEnum.CHECKIN;
+ }
+ return transition;
+ }
+
+ private List<Object> getDeactivateUserStateLimitations() {
+ List<Object> properties = new ArrayList<>();
+ properties.add(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name());
+ return properties;
+ }
+
+ private void handleAuditing(User modifier, User userBefor, User userAfter, ResponseFormat responseFormat, AuditingActionEnum actionName) {
+ componentsUtils.auditAdminUserAction(actionName, modifier, userBefor, userAfter, responseFormat);
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserMessage.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserMessage.java
new file mode 100644
index 0000000000..362bf34592
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserMessage.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+import org.openecomp.sdc.be.catalog.api.ITypeMessage;
+
+public class UserMessage implements ITypeMessage{
+ private UserOperationEnum operation;
+ private String userId;
+ private String role;
+
+ public UserMessage(UserOperationEnum operation, String userId, String role) {
+ this.setOperation(operation);
+ this.setUserId(userId);
+ this.setRole(role);
+ }
+
+ public UserOperationEnum getOperation() {
+ return operation;
+ }
+
+ public void setOperation(UserOperationEnum operation) {
+ this.operation = operation;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getRole() {
+ return role;
+ }
+
+ public void setRole(String role) {
+ this.role = role;
+ }
+
+ @Override
+ public String toString() {
+ return "UserMessage [operation=" + operation + ", userId=" + userId + ", role=" + role + "]";
+ }
+
+ @Override
+ public String getMessageType() {
+ return getClass().getSimpleName();
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserOperationEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserOperationEnum.java
new file mode 100644
index 0000000000..c4cc62d271
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserOperationEnum.java
@@ -0,0 +1,25 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.user;
+
+public enum UserOperationEnum {
+ CREATE, CHANGE_ROLE, DEACTIVATE
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/view/MixinTarget.java b/catalog-be/src/main/java/org/openecomp/sdc/be/view/MixinTarget.java
index 77aae4f1f4..823a6f74c7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/view/MixinTarget.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/view/MixinTarget.java
@@ -20,7 +20,11 @@
package org.openecomp.sdc.be.view;
-import java.lang.annotation.*;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java
deleted file mode 100644
index b964321c8a..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/ITransactionSdnc.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.api;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.TransactionCodeEnum;
-
-public interface ITransactionSdnc {
- TransactionCodeEnum finishTransaction();
-
- Either<DBActionCodeEnum, TransactionCodeEnum> invokeESAction(boolean isLastAction, ESActionTypeEnum esActiontype, ESArtifactData artifactData);
-
- <T> Either<T, TransactionCodeEnum> invokeGeneralDBAction(boolean isLastAction, DBTypeEnum dbType, IDBAction dbAction, IDBAction dbRollbackAction);
-
- <T> Either<T, TransactionCodeEnum> invokeJanusGraphAction(boolean isLastAction, IDBAction dbAction);
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java
deleted file mode 100644
index 4022655e67..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/RollbackHandler.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.api;
-
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.LogMessages;
-import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Stack;
-
-public abstract class RollbackHandler implements IDBType {
-
- // TODO test using slf4j-test and make this final
- private static Logger log = LoggerFactory.getLogger(RollbackHandler.class.getName());
- private Stack<IDBAction> dbActionRollbacks;
-
- private Integer transactionId;
- private String userId, actionType;
-
- protected RollbackHandler(Integer transactionId, String userId, String actionType) {
- if (isRollbackForPersistenceData()) {
- dbActionRollbacks = new Stack<>();
- }
- this.transactionId = transactionId;
- this.userId = userId;
- this.actionType = actionType;
- }
-
- public MethodActivationStatusEnum addRollbackAction(IDBAction rollbackAction) {
- MethodActivationStatusEnum result = MethodActivationStatusEnum.SUCCESS;
- if (isRollbackForPersistenceData()) {
- dbActionRollbacks.push(rollbackAction);
- } else {
- result = MethodActivationStatusEnum.NOT_ALLOWED;
- }
- return result;
- }
-
- public DBActionCodeEnum doRollback() {
- DBActionCodeEnum result;
-
- try {
- if (isRollbackForPersistenceData()) {
- result = doPersistenceDataRollback();
- } else {
- log.debug(LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
- log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_NON_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
- result = doNonPersistenceDataRollback();
- }
- if (result != DBActionCodeEnum.SUCCESS) {
- log.error(LogMessages.ROLLBACK_FAILED_ON_DB, transactionId, getDBType().name(), userId, actionType);
- log.error(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_ON_DB, transactionId, getDBType().name(), userId, actionType);
- }
-
- } catch (Exception e) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- log.error(LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType);
- log.debug(LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType, e);
- log.error(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION, transactionId, getDBType().name(), e.getMessage(), userId, actionType);
- }
-
- return result;
- }
-
- private <T> DBActionCodeEnum doPersistenceDataRollback() {
- DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
- while (!dbActionRollbacks.empty()) {
- log.debug(LogMessages.ROLLBACK_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
- log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_PERSISTENT_ACTION, getDBType().name(), transactionId, userId, actionType);
- IDBAction rollbackAction = dbActionRollbacks.pop();
- T rollbackResult = rollbackAction.doAction();
- if (!isRollbackResultValid()) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- }
- }
- return result;
- }
-
- /**
- * Override for specific logic
- *
- * @param <T>
- */
- public <T> boolean isRollbackResultValid() {
- return true;
- }
-
- /**
- * Override for specific logic
- */
- public DBActionCodeEnum doNonPersistenceDataRollback() {
- return DBActionCodeEnum.SUCCESS;
- }
-
- protected abstract boolean isRollbackForPersistenceData();
-
- /**
- * Only Used for Unit Tests !
- */
- // TODO test using slf4j-test and remove this
- public static void setLog(Logger log) {
- RollbackHandler.log = log;
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java
deleted file mode 100644
index 60f89ce012..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/api/TransactionUtils.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.api;
-
-import org.slf4j.Marker;
-import org.slf4j.MarkerFactory;
-
-public final class TransactionUtils {
-
- private TransactionUtils() {
-
- }
-
- public enum DBTypeEnum {
- ELASTIC_SEARCH, JANUSGRAPH, MYSTERY, SWIFT
- }
-
- public enum TransactionCodeEnum {
- ROLLBACK_SUCCESS, ROLLBACK_FAILED, SUCCESS, COMMIT_FAILED, MULTIPLE_LAST_ACTION, INTERNAL_ERROR, UNALLOWED_METHOD_USAGE, PREPARE_ROLLBACK_FAILED, TRANSACTION_CLOSED
- }
-
- public enum TransactionStatusEnum {
- OPEN, CLOSED, FAILED_ROLLBACK
- }
-
- public enum DBActionCodeEnum {
- SUCCESS, FAIL_GENERAL, FAIL_MULTIPLE_LAST_ACTION
- }
-
- public enum ESActionTypeEnum {
- ADD_ARTIFACT, UPDATE_ARTIFACT, REMOVE_ARTIFACT
- }
-
- public enum ActionTypeEnum {
- ADD_ARTIFACT, REMOVE_ARTIFACT, UPDATE_ARTIFACT, CREATE_RESOURCE, UPDATE_RESOURCE, DELETE_RESOURCE
- }
-
- public static final int MAX_SIZE_TRANSACTION_LIST = 1000;
-
- public static final int TRANSACTION_ID_RESET_LIMIT = MAX_SIZE_TRANSACTION_LIST * 10;
-
- public static final String TRANSACTION_MARKER_STR = "TRANSACTION_MARKER";
-
- public static final String DUMMY_USER = "udummy";
-
- public static final Marker TRANSACTION_MARKER = MarkerFactory.getMarker(TRANSACTION_MARKER_STR);
-
- public static class LogMessages {
- public static final String PRE_INVOKE_ACTION = "About to add Action to SdncTransaction ID:{} for DB:{}, user:{}, action:{}";
- public static final String INVOKE_ACTION = "invoking Action in SdncTransactionID:{}, on DB:{}, user:{}, action:{}";
- public static final String COMMIT_ACTION_ALL_DB = "Starting Commit for SdncTransactionID:{} for all DBs, user:{}, action:{}";
- public static final String COMMIT_ACTION_SPECIFIC_DB = "Starting Commit for SdncTransactionID:{} on DB:{}, user:{}, action:{}";
- public static final String COMMIT_ON_CLOSED_TRANSACTION = "Commit failed for SdncTransactionID:{} Transaction is in status:{}, user:{}, action:{}";
- public static final String ACTION_ON_CLOSED_TRANSACTION = "Action failed for SdncTransactionID:{} Transaction is already closed, user:{}, action:{}";
- public static final String DOUBLE_FINISH_FLAG_ACTION = "Transaction with SdncTransactionID:{} on DB:{} was called multiple times with last action flag, user:{}, action:{}";
- public static final String DB_ACTION_FAILED_WITH_EXCEPTION = "Action on DB:{} has failed for SdncTransactionID:{}, message:{}, user:{}, action:{}";
- public static final String ROLLBACK_SUCCEEDED_GENERAL = "Transaction rollback succeeded for SdncTransactionID:{}, user:{}, action:{}";
- public static final String ROLLBACK_FAILED_GENERAL = "Transaction rollback failed for SdncTransactionID:{}, user:{}, action:{}";
- public static final String ROLLBACK_FAILED_ON_DB = "Transaction rollback failed for SdncTransactionID:{} on DB:{}, user:{}, action:{}";
- public static final String ROLLBACK_FAILED_ON_DB_WITH_EXCEPTION = "Transaction rollback failed for SdncTransactionID:{} on DB:{}, exception message:{}, user:{}, action:{}";
- public static final String ROLLBACK_PERSISTENT_ACTION = "About To Rollback Action on DB{} for TransactionID:{} ... user:{}, action:{}";
- public static final String ROLLBACK_NON_PERSISTENT_ACTION = "About To Rollback Actions on DB{} for TransactionID:{} ... user:{}, action:{}";
- public static final String CREATE_ROLLBACK_HANDLER = "creating new Rollback Handler For DB:{} in SdncTransaction ID:{}, user:{}, action:{}";
- public static final String FAILED_CREATE_ROLLBACK = "failed to create new Rollback action For DB:{} with SdncTransactionID:{}, user:{}, action:{}";
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java
deleted file mode 100644
index bd638249b2..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESAction.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.impl;
-
-import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.resources.exception.ResourceDAOException;
-import org.openecomp.sdc.be.tosca.CsarUtils;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.transaction.api.IDBAction;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
-
-public class ESAction implements IDBAction {
-
- private static final Logger log = Logger.getLogger(CsarUtils.class.getName());
-
- private ESCatalogDAO esCatalogDao;
- private ESArtifactData artifactData;
- private ESActionTypeEnum esActionType;
-
- public ESAction(ESCatalogDAO esCatalogDao, ESArtifactData artifactData, ESActionTypeEnum esActiontype) {
- this.esCatalogDao = esCatalogDao;
- this.artifactData = artifactData;
- this.esActionType = esActiontype;
- }
-
- @Override
- public DBActionCodeEnum doAction() {
- DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
- try {
- if (esActionType == ESActionTypeEnum.ADD_ARTIFACT || esActionType == ESActionTypeEnum.UPDATE_ARTIFACT) {
- esCatalogDao.writeArtifact(artifactData);
- } else if (esActionType == ESActionTypeEnum.REMOVE_ARTIFACT) {
- esCatalogDao.deleteArtifact(artifactData.getId());
- }
-
- } catch (ResourceDAOException daoException) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- log.error("#doAction - {}, es action failed with error : ", result, daoException);
- }
- return result;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java
deleted file mode 100644
index da1db80d2c..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/ESRollbackHandler.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.impl;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
-import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.tosca.CsarUtils;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.transaction.api.RollbackHandler;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.ESActionTypeEnum;
-import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
-
-public class ESRollbackHandler extends RollbackHandler {
-
- private static final Logger log = Logger.getLogger(CsarUtils.class.getName());
-
- public ESRollbackHandler(Integer transactionId, String userId, String actionType) {
- super(transactionId, userId, actionType);
- }
-
- public DBTypeEnum getDBType() {
- return DBTypeEnum.ELASTIC_SEARCH;
- }
-
- protected boolean isRollbackForPersistenceData() {
- return true;
- }
-
- public boolean isRollbackResultValid(DBActionCodeEnum rollbackResult) {
- return rollbackResult == DBActionCodeEnum.SUCCESS;
- }
-
- public Either<ESAction, MethodActivationStatusEnum> buildEsRollbackAction(ESCatalogDAO esCatalogDao, ESArtifactData artifactData, ESActionTypeEnum esActiontype) {
- Either<ESAction, MethodActivationStatusEnum> result;
-
- try {
- ESAction esRollbackAction = null;
- Either<ESArtifactData, ResourceUploadStatus> either = esCatalogDao.getArtifact(artifactData.getId());
-
- switch (esActiontype) {
- case ADD_ARTIFACT:
-
- if (either.isRight() && either.right().value() == ResourceUploadStatus.NOT_EXIST) {
- esRollbackAction = new ESAction(esCatalogDao, artifactData, ESActionTypeEnum.REMOVE_ARTIFACT);
- }
- break;
- case REMOVE_ARTIFACT:
- if (either.isLeft()) {
- esRollbackAction = new ESAction(esCatalogDao, artifactData, ESActionTypeEnum.ADD_ARTIFACT);
- }
- break;
- case UPDATE_ARTIFACT:
-
- if (either.isLeft()) {
- ESArtifactData originalArtifactData = either.left().value();
- esRollbackAction = new ESAction(esCatalogDao, originalArtifactData, ESActionTypeEnum.UPDATE_ARTIFACT);
- }
- break;
-
- }
- if (esRollbackAction != null) {
- result = Either.left(esRollbackAction);
- } else {
- result = Either.right(MethodActivationStatusEnum.FAILED);
- }
- } catch (Exception e) {
- result = Either.right(MethodActivationStatusEnum.FAILED);
- log.error("#buildEsRollbackAction - {}, es rollback failed with error: ", result, e);
- }
-
- return result;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphCommitHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphCommitHandler.java
deleted file mode 100644
index dad79b5f76..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphCommitHandler.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.impl;
-
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.common.transaction.api.ICommitHandler;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
-
-public class JanusGraphCommitHandler implements ICommitHandler {
-
- private JanusGraphGenericDao janusGraphGenericDao;
-
- public JanusGraphCommitHandler(JanusGraphGenericDao janusGraphGenericDao) {
- this.janusGraphGenericDao = janusGraphGenericDao;
- }
-
- @Override
- public DBActionCodeEnum doCommit() {
- DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
- JanusGraphOperationStatus janusGraphStatus = janusGraphGenericDao.commit();
- if (janusGraphStatus != JanusGraphOperationStatus.OK) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- }
- return result;
- }
-
- @Override
- public DBTypeEnum getDBType() {
- return DBTypeEnum.JANUSGRAPH;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphRollbackHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphRollbackHandler.java
deleted file mode 100644
index ed2633fa11..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/impl/JanusGraphRollbackHandler.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.impl;
-
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.common.transaction.api.RollbackHandler;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
-
-public class JanusGraphRollbackHandler extends RollbackHandler {
-
- private JanusGraphGenericDao janusGraphGenericDao;
-
- public JanusGraphRollbackHandler(Integer transactionId, String userId, String actionType, JanusGraphGenericDao janusGraphGenericDao) {
- super(transactionId, userId, actionType);
- this.janusGraphGenericDao = janusGraphGenericDao;
- }
-
- public DBTypeEnum getDBType() {
- return DBTypeEnum.JANUSGRAPH;
- }
-
- protected boolean isRollbackForPersistenceData() {
- return false;
- }
-
- public DBActionCodeEnum doNonPersistenceDataRollback() {
- DBActionCodeEnum result = DBActionCodeEnum.SUCCESS;
- JanusGraphOperationStatus janusGraphStatus = janusGraphGenericDao.rollback();
- if (janusGraphStatus != JanusGraphOperationStatus.OK) {
- result = DBActionCodeEnum.FAIL_GENERAL;
- }
- return result;
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java
deleted file mode 100644
index abe4c3743f..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/CommitManager.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.mngr;
-
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.transaction.api.ICommitHandler;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.LogMessages;
-
-import java.util.List;
-
-public class CommitManager {
-
- // TODO test using slf4j-test and make this final
- private static Logger log = Logger.getLogger(CommitManager.class);
- private List<ICommitHandler> commitHandlers;
- private Integer transactionId;
- private String userId, actionType;
-
- CommitManager(Integer transactionId, String userId, String actionType, List<ICommitHandler> commitHandlers) {
- this.commitHandlers = commitHandlers;
- this.transactionId = transactionId;
- this.userId = userId;
- this.actionType = actionType;
-
- }
-
- public DBActionCodeEnum transactionCommit() {
- log.debug(LogMessages.COMMIT_ACTION_ALL_DB, transactionId, userId, actionType);
- DBActionCodeEnum commitResult = DBActionCodeEnum.SUCCESS;
- ICommitHandler lastHandler = null;
- try {
- for (ICommitHandler handler : commitHandlers) {
- lastHandler = handler;
- log.debug(LogMessages.COMMIT_ACTION_SPECIFIC_DB, transactionId, handler.getDBType().name(), userId, actionType);
- DBActionCodeEnum commitCode = handler.doCommit();
- if (commitCode == DBActionCodeEnum.FAIL_GENERAL) {
- BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit on DB " + handler.getDBType().name());
- log.debug("Commit failed for SdncTransactionID:{} on DB:{}", transactionId, handler.getDBType().name());
- commitResult = DBActionCodeEnum.FAIL_GENERAL;
- break;
- }
- log.debug("Commit succeeded for SdncTransactionID:{} on DB:{}", transactionId, handler.getDBType().name());
- }
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit - on DB " + getDBName(lastHandler));
- log.debug("Commit failed for SdncTransactionID:{} on DB:{}, Exception message:{}", transactionId, getDBName(lastHandler), e.getMessage(), e);
- log.info(TransactionUtils.TRANSACTION_MARKER, "Commit failed for SdncTransactionID:{} on DB:{}", transactionId, getDBName(lastHandler));
- commitResult = DBActionCodeEnum.FAIL_GENERAL;
- }
- return commitResult;
- }
-
- private String getDBName(ICommitHandler lastHandler) {
- String dbName = "Unknown";
- if (lastHandler != null) {
- dbName = lastHandler.getDBType().name();
- }
- return dbName;
- }
-
- // TODO test using slf4j-test and remove this
- static void setLog(Logger log) {
- CommitManager.log = log;
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
deleted file mode 100644
index 5e51615164..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/RollbackManager.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.mngr;
-
-import fj.P;
-import fj.data.Either;
-import fj.data.HashMap;
-import fj.data.List;
-import org.openecomp.sdc.common.transaction.api.RollbackHandler;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBActionCodeEnum;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.DBTypeEnum;
-import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
-
-public class RollbackManager {
- private final HashMap<DBTypeEnum, RollbackHandler> rollbackHandlersMap;
- private final Integer transactionId;
- private final String userId;
- private final String actionType;
-
- RollbackManager(Integer transactionId, String userId, String actionType, Iterable<RollbackHandler> rollbackHandlers) {
- this.transactionId = transactionId;
- this.userId = userId;
- this.actionType = actionType;
- this.rollbackHandlersMap = HashMap.from(List.iterableList(rollbackHandlers).map(i -> P.p(i.getDBType(), i)));
- }
-
- public DBActionCodeEnum transactionRollback() {
- List<DBActionCodeEnum> results = rollbackHandlersMap.values().map(RollbackHandler::doRollback);
- boolean failure = results.exists(r -> r == DBActionCodeEnum.FAIL_GENERAL);
- return failure ? DBActionCodeEnum.FAIL_GENERAL : DBActionCodeEnum.SUCCESS;
- }
-
- protected Either<RollbackHandler, MethodActivationStatusEnum> addRollbackHandler(RollbackHandler rollbackHandler) {
- Either<RollbackHandler, MethodActivationStatusEnum> result;
- if (rollbackHandlersMap.contains(rollbackHandler.getDBType())) {
- result = Either.right(MethodActivationStatusEnum.NOT_ALLOWED);
- } else {
- rollbackHandlersMap.set(rollbackHandler.getDBType(), rollbackHandler);
- result = Either.left(rollbackHandler);
- }
- return result;
-
- }
-
- protected Either<RollbackHandler, MethodActivationStatusEnum> createRollbackHandler(final DBTypeEnum dbType) {
-
- RollbackHandler rollbackHandler = new RollbackHandler(transactionId, userId, actionType) {
-
- @Override
- public DBTypeEnum getDBType() {
- return dbType;
- }
-
- @Override
- protected boolean isRollbackForPersistenceData() {
- return true;
- }
- };
- return addRollbackHandler(rollbackHandler);
- }
-
- protected Either<RollbackHandler, MethodActivationStatusEnum> getRollbackHandler(DBTypeEnum dbType) {
- // need to swap here because the uses of Either in SDC appears to be opposite of convention
- // by convention left is failure; in SDC right is failure
- return rollbackHandlersMap.get(dbType).toEither(MethodActivationStatusEnum.NOT_FOUND).swap();
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java
deleted file mode 100644
index 78264484fb..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionManager.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.mngr;
-
-import com.google.common.collect.EvictingQueue;
-import com.google.common.collect.Queues;
-import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.transaction.api.ITransactionSdnc;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.ActionTypeEnum;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import java.util.Queue;
-import java.util.concurrent.atomic.AtomicInteger;
-
-@Component("transactionManager")
-public class TransactionManager {
-
- private static final Logger log = Logger.getLogger(TransactionManager.class.getName());
-
- private AtomicInteger transactionIDCounter = new AtomicInteger(0);
-
- private Queue<ITransactionSdnc> transactions;
- @Resource
- private ESCatalogDAO esCatalogDao;
- @Resource
- private JanusGraphGenericDao janusGraphGenericDao;
-
- /**
- * userId and actionType parameters are used only for logging purposes.
- */
- public ITransactionSdnc getTransaction(String userId, ActionTypeEnum actionType) {
- if (transactions == null) {
- init();
- }
- log.debug("TransactionManager creating new SdncTransaction");
- ITransactionSdnc tx = new TransactionSdncImpl(generateTransactionID(), userId, actionType, esCatalogDao,
- janusGraphGenericDao);
- transactions.add(tx);
-
- return tx;
-
- }
-
- private Integer generateTransactionID() {
- boolean generatedSuccessfully = false;
- int nextId = 0;
-
- while (!generatedSuccessfully) {
- int prevId = transactionIDCounter.get();
- if (prevId > TransactionUtils.TRANSACTION_ID_RESET_LIMIT) {
- resetTransactionId();
- }
- nextId = prevId + 1;
- generatedSuccessfully = transactionIDCounter.compareAndSet(prevId, nextId);
- }
- return nextId;
- }
-
- private void resetTransactionId() {
-
- boolean resetSuccessfully = false;
- while (!resetSuccessfully) {
- int prevId = transactionIDCounter.get();
- resetSuccessfully = transactionIDCounter.compareAndSet(prevId, 0);
- }
-
- }
-
- private synchronized void init() {
- if (transactions == null) {
- log.info("TransactionManager Initialized");
- EvictingQueue<ITransactionSdnc> queue = EvictingQueue
- .<ITransactionSdnc>create(TransactionUtils.MAX_SIZE_TRANSACTION_LIST);
- // make thread-safe
- transactions = Queues.synchronizedQueue(queue);
- }
- }
-
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java
deleted file mode 100644
index 93a2c9db82..0000000000
--- a/catalog-be/src/main/java/org/openecomp/sdc/common/transaction/mngr/TransactionSdncImpl.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*-
- * ============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.sdc.common.transaction.mngr;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.impl.ESCatalogDAO;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.transaction.api.*;
-import org.openecomp.sdc.common.transaction.api.TransactionUtils.*;
-import org.openecomp.sdc.common.transaction.impl.ESAction;
-import org.openecomp.sdc.common.transaction.impl.ESRollbackHandler;
-import org.openecomp.sdc.common.transaction.impl.JanusGraphCommitHandler;
-import org.openecomp.sdc.common.transaction.impl.JanusGraphRollbackHandler;
-import org.openecomp.sdc.common.util.MethodActivationStatusEnum;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class TransactionSdncImpl implements ITransactionSdnc {
-
- // TODO test using slf4j-test and make this final
- private static Logger log = Logger.getLogger(TransactionSdncImpl.class);
- private boolean lastActionAlreadyCalled;
- private RollbackManager rollbackManager;
- private CommitManager commitManager;
- private ESCatalogDAO esCatalogDao;
- private JanusGraphGenericDao janusGraphGenericDao;
- private Integer transactionId;
- private TransactionStatusEnum status;
- private String userId, actionType;
-
- TransactionSdncImpl(Integer transactionId, String userId, ActionTypeEnum actionTypeEnum, ESCatalogDAO esCatalogDao, JanusGraphGenericDao janusGraphGenericDao) {
- this.esCatalogDao = esCatalogDao;
- this.janusGraphGenericDao = janusGraphGenericDao;
- this.transactionId = transactionId;
- this.userId = userId;
- actionType = actionTypeEnum.name();
- rollbackManager = new RollbackManager(transactionId, userId, actionType, initRollbackHandlers());
- commitManager = new CommitManager(transactionId, userId, actionType, initCommitHandlers());
- status = TransactionStatusEnum.OPEN;
-
- }
-
- private List<ICommitHandler> initCommitHandlers() {
- List<ICommitHandler> commitHandlers = new ArrayList<>();
- commitHandlers.add(new JanusGraphCommitHandler(janusGraphGenericDao));
- return commitHandlers;
- }
-
- private List<RollbackHandler> initRollbackHandlers() {
- List<RollbackHandler> rolebackHandlers = new ArrayList<>();
- rolebackHandlers.add(new JanusGraphRollbackHandler(transactionId, userId, actionType,
- janusGraphGenericDao));
- rolebackHandlers.add(new ESRollbackHandler(transactionId, userId, actionType));
- return rolebackHandlers;
- }
-
- private <T> Either<T, TransactionCodeEnum> invokeAction(boolean isLastAction, IDBAction dbAction, DBTypeEnum dbType) {
-
- Either<T, DBActionCodeEnum> actionResult;
- log.debug(LogMessages.INVOKE_ACTION, transactionId, dbType.name(), userId, actionType);
- if (isLastAction) {
- actionResult = getLastActionResult(dbAction, dbType);
- } else {
- actionResult = getActionResult(dbAction, dbType);
- }
-
- Either<T, TransactionCodeEnum> result;
- boolean isRollbackNedded = actionResult.isRight();
- if (isRollbackNedded) {
- TransactionCodeEnum transactionCode = transactionRollback();
- result = Either.right(transactionCode);
- } else {
- result = Either.left(actionResult.left().value());
- }
- return result;
- }
-
- private TransactionCodeEnum transactionRollback() {
-
- TransactionCodeEnum result;
- DBActionCodeEnum transactionRollback = rollbackManager.transactionRollback();
- if (transactionRollback == DBActionCodeEnum.SUCCESS) {
- result = TransactionCodeEnum.ROLLBACK_SUCCESS;
- log.info(LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, userId, actionType);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_SUCCEEDED_GENERAL, transactionId, userId, actionType);
-
- } else {
- result = TransactionCodeEnum.ROLLBACK_FAILED;
- BeEcompErrorManager.getInstance().logBeSystemError("transactionCommit for transaction " + transactionId);
-
- log.info(LogMessages.ROLLBACK_FAILED_GENERAL, transactionId, userId, actionType);
- log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.ROLLBACK_FAILED_GENERAL, transactionId, userId, actionType);
- }
- return result;
- }
-
- public <T> Either<T, TransactionCodeEnum> invokeJanusGraphAction(boolean isLastAction, IDBAction dbAction) {
- Either<T, TransactionCodeEnum> result;
- if (status == TransactionStatusEnum.OPEN) {
- result = invokeAction(isLastAction, dbAction, DBTypeEnum.JANUSGRAPH);
- } else {
- result = handleActionOnClosedTransaction();
- }
- updateTransactionStatus(result);
- return result;
- }
-
- public <T> Either<T, TransactionCodeEnum> invokeGeneralDBAction(boolean isLastAction, DBTypeEnum dbType, IDBAction dbAction, IDBAction dbRollbackAction) {
-
- Either<T, TransactionCodeEnum> result;
- MethodActivationStatusEnum addingHandlerResult;
- if (status == TransactionStatusEnum.OPEN) {
- log.debug(LogMessages.PRE_INVOKE_ACTION, transactionId, dbType.name(), userId, actionType);
- Either<RollbackHandler, MethodActivationStatusEnum> eitherRollbackHandler = rollbackManager.getRollbackHandler(dbType);
-
- if (eitherRollbackHandler.isLeft()) {
- RollbackHandler rollbackHandler = eitherRollbackHandler.left().value();
- addingHandlerResult = rollbackHandler.addRollbackAction(dbRollbackAction);
- } else {
- addingHandlerResult = addToNewRollbackHandler(dbType, dbRollbackAction);
- }
-
- if (addingHandlerResult == MethodActivationStatusEnum.SUCCESS) {
- result = invokeAction(isLastAction, dbAction, dbType);
- } else {
- result = Either.right(TransactionCodeEnum.PREPARE_ROLLBACK_FAILED);
- }
- } else {
- result = handleActionOnClosedTransaction();
- }
- updateTransactionStatus(result);
- return result;
- }
-
- private MethodActivationStatusEnum addToNewRollbackHandler(DBTypeEnum dbType, IDBAction dbRollbackAction) {
- log.debug(LogMessages.CREATE_ROLLBACK_HANDLER, dbType.name(), transactionId, userId, actionType);
- MethodActivationStatusEnum result;
-
- Either<RollbackHandler, MethodActivationStatusEnum> eitherRollbackHandler = rollbackManager.createRollbackHandler(dbType);
- if (eitherRollbackHandler.isRight()) {
- result = eitherRollbackHandler.right().value();
- BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - addToNewRollbackHandler");
- log.info(LogMessages.FAILED_CREATE_ROLLBACK, dbType.name(), transactionId, userId, actionType);
- log.debug(TransactionUtils.TRANSACTION_MARKER, LogMessages.FAILED_CREATE_ROLLBACK, dbType.name(), transactionId, userId, actionType);
- } else {
- RollbackHandler rollbackHandler = eitherRollbackHandler.left().value();
- rollbackHandler.addRollbackAction(dbRollbackAction);
- result = MethodActivationStatusEnum.SUCCESS;
- }
-
- return result;
- }
-
- public Either<DBActionCodeEnum, TransactionCodeEnum> invokeESAction(boolean isLastAction, ESActionTypeEnum esActiontype, ESArtifactData artifactData) {
-
- Either<DBActionCodeEnum, TransactionCodeEnum> result;
- if (status == TransactionStatusEnum.OPEN) {
- Either<RollbackHandler, MethodActivationStatusEnum> eitherEsHandler = rollbackManager.getRollbackHandler(DBTypeEnum.ELASTIC_SEARCH);
- if (eitherEsHandler.isRight()) {
- result = Either.right(TransactionCodeEnum.INTERNAL_ERROR);
- } else {
- ESRollbackHandler esHandler = (ESRollbackHandler) eitherEsHandler.left().value();
-
- Either<ESAction, MethodActivationStatusEnum> eitherEsRollbackAction = esHandler.buildEsRollbackAction(esCatalogDao, artifactData, esActiontype);
- if (eitherEsRollbackAction.isLeft()) {
- esHandler.addRollbackAction(eitherEsRollbackAction.left().value());
- result = invokeAction(isLastAction, new ESAction(esCatalogDao, artifactData, esActiontype), DBTypeEnum.ELASTIC_SEARCH);
- } else {
- result = Either.right(TransactionCodeEnum.PREPARE_ROLLBACK_FAILED);
- }
-
- }
- } else {
- result = handleActionOnClosedTransaction();
- }
- updateTransactionStatus(result);
- return result;
- }
-
- private <T> void updateTransactionStatus(Either<T, TransactionCodeEnum> result) {
- if (result.isRight()) {
- updateTransactionStatus(result.right().value());
- }
-
- }
-
- private <T> Either<T, TransactionCodeEnum> handleActionOnClosedTransaction() {
- Either<T, TransactionCodeEnum> result = Either.right(TransactionCodeEnum.TRANSACTION_CLOSED);
- log.debug(LogMessages.ACTION_ON_CLOSED_TRANSACTION, transactionId, userId, actionType);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.ACTION_ON_CLOSED_TRANSACTION, transactionId, userId, actionType);
- return result;
- }
-
- private <T> Either<T, DBActionCodeEnum> getLastActionResult(IDBAction dataBaseAction, DBTypeEnum dbType) {
- Either<T, DBActionCodeEnum> result;
- if (isLastActionAlreadyCalled()) {
- result = Either.right(DBActionCodeEnum.FAIL_MULTIPLE_LAST_ACTION);
- BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - getLastActionResult");
- log.debug(LogMessages.DOUBLE_FINISH_FLAG_ACTION, transactionId, dbType.name(), userId, actionType);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DOUBLE_FINISH_FLAG_ACTION, transactionId, dbType.name(), userId, actionType);
- } else {
- setLastActionAlreadyCalled(true);
- result = getActionResult(dataBaseAction, dbType);
- }
- return result;
- }
-
- private <T> Either<T, DBActionCodeEnum> getActionResult(IDBAction dataBaseAction, DBTypeEnum dbType) {
- Either<T, DBActionCodeEnum> result;
- try {
- T doAction = dataBaseAction.doAction();
- result = Either.left(doAction);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - getActionResult");
- log.debug(LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, dbType.name(), transactionId, e.getMessage(), userId, actionType, e);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.DB_ACTION_FAILED_WITH_EXCEPTION, dbType.name(), transactionId, e.getMessage(), userId, actionType);
-
- result = Either.right(DBActionCodeEnum.FAIL_GENERAL);
- }
- return result;
- }
-
- public TransactionCodeEnum finishTransaction() {
- TransactionCodeEnum result;
- if (status == TransactionStatusEnum.OPEN) {
- DBActionCodeEnum transactionCommit = commitManager.transactionCommit();
- if (transactionCommit == DBActionCodeEnum.SUCCESS) {
- result = TransactionCodeEnum.SUCCESS;
- status = TransactionStatusEnum.CLOSED;
- } else {
- result = transactionRollback();
- }
- } else {
- BeEcompErrorManager.getInstance().logBeSystemError("TransactionManager - finishTransaction");
- log.debug(LogMessages.COMMIT_ON_CLOSED_TRANSACTION, transactionId, status.name(), userId, actionType);
- log.info(TransactionUtils.TRANSACTION_MARKER, LogMessages.COMMIT_ON_CLOSED_TRANSACTION, transactionId, status.name(), userId, actionType);
- result = TransactionCodeEnum.TRANSACTION_CLOSED;
- }
- updateTransactionStatus(result);
- return result;
- }
-
- private void updateTransactionStatus(TransactionCodeEnum result) {
- switch (result) {
- case SUCCESS:
- status = TransactionStatusEnum.CLOSED;
- break;
- case ROLLBACK_SUCCESS:
- status = TransactionStatusEnum.CLOSED;
- break;
- case ROLLBACK_FAILED:
- status = TransactionStatusEnum.FAILED_ROLLBACK;
- break;
- default:
- break;
- }
-
- }
-
- private boolean isLastActionAlreadyCalled() {
- return lastActionAlreadyCalled;
- }
-
- private void setLastActionAlreadyCalled(boolean lastAction) {
- this.lastActionAlreadyCalled = lastAction;
- }
-
- // TODO test using slf4j-test and remove this
- static void setLog(Logger log) {
- TransactionSdncImpl.log = log;
- }
-
- TransactionStatusEnum getStatus() {
- return status;
- }
-}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/config/CatalogBESpringConfig.java b/catalog-be/src/main/java/org/openecomp/sdc/config/CatalogBESpringConfig.java
index 75f7154f18..7e5535d688 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/config/CatalogBESpringConfig.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/config/CatalogBESpringConfig.java
@@ -21,12 +21,19 @@
*/
package org.openecomp.sdc.config;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.sdc.security.PortalClient;
import org.openecomp.sdc.be.auditing.impl.ConfigurationProvider;
import org.openecomp.sdc.be.components.impl.ComponentLocker;
+import org.openecomp.sdc.be.components.impl.aaf.RoleAuthorizationHandler;
import org.openecomp.sdc.be.components.impl.lock.ComponentLockAspect;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
+import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.ecomp.converters.AssetMetadataConverter;
-import org.openecomp.sdc.common.transaction.mngr.TransactionManager;
+import org.openecomp.sdc.be.filters.FilterConfiguration;
+import org.openecomp.sdc.be.filters.PortalConfiguration;
+import org.openecomp.sdc.be.filters.ThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -35,19 +42,26 @@ import org.springframework.core.annotation.Order;
@Configuration
@ComponentScan({"org.openecomp.sdc.be.user",
+ "org.openecomp.sdc.be.facade.operations",
"org.openecomp.sdc.be.impl",
"org.openecomp.sdc.be.auditing.impl",
"org.openecomp.sdc.be.distribution",
"org.openecomp.sdc.be.switchover.detector",
"org.openecomp.sdc.be.tosca",
"org.openecomp.sdc.be.components.validation",
+ "org.openecomp.sdc.be.catalog.impl",
"org.openecomp.sdc.be.components.impl",
"org.openecomp.sdc.be.components.path",
"org.openecomp.sdc.be.components.merge",
"org.openecomp.sdc.be.components.csar",
"org.openecomp.sdc.be.components.property",
"org.openecomp.sdc.be.datamodel.utils",
- "org.openecomp.sdc.be.components.upgrade"})
+ "org.openecomp.sdc.be.components.upgrade",
+ "org.openecomp.sdc.be.externalapi.servlet",
+ "org.openecomp.sdc.be.servlets",
+ "org.openecomp.sdc.be.filters",
+ "org.openecomp.sdc.be.togglz"
+})
public class CatalogBESpringConfig {
private static final int BEFORE_TRANSACTION_MANAGER = 0;
@@ -68,11 +82,6 @@ public class CatalogBESpringConfig {
return new ConfigurationProvider();
}
- @Bean(name = "transactionManager")
- public TransactionManager transactionManager() {
- return new TransactionManager();
- }
-
@Bean(name = "asset-metadata-utils")
public AssetMetadataConverter assetMetadataConverter() {
return new AssetMetadataConverter();
@@ -84,5 +93,32 @@ public class CatalogBESpringConfig {
return new ComponentLockAspect(componentLocker);
}
+ @Bean
+ public RoleAuthorizationHandler roleAuthorizationHandler() {return new RoleAuthorizationHandler();}
+
+ @Bean
+ public CloseableHttpClient httpClientConnectionManager() {
+ HttpClientFactory httpClientFactory = new HttpClientFactory();
+ return httpClientFactory.createHttpClient();
+ }
+
+ @Bean
+ public PortalConfiguration portalConfiguration() throws CipherUtilException {return new PortalConfiguration();}
+
+ @Bean
+ public FilterConfiguration filterConfiguration() {return new FilterConfiguration(configuration());}
+
+ @Bean
+ public ThreadLocalUtils threadLocalUtils() {return new ThreadLocalUtils();}
+
+ @Bean
+ public PortalClient portalClient() throws CipherUtilException {
+ return new PortalClient(httpClientConnectionManager(), portalConfiguration());
+ }
+
+ @Bean
+ public org.openecomp.sdc.be.config.Configuration configuration(){
+ return ConfigurationManager.getConfigurationManager().getConfiguration();
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/config/HttpClientFactory.java b/catalog-be/src/main/java/org/openecomp/sdc/config/HttpClientFactory.java
new file mode 100644
index 0000000000..f2544aa7ef
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/config/HttpClientFactory.java
@@ -0,0 +1,110 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.config;
+
+import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.UserTokenHandler;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.config.SocketConfig;
+import org.apache.http.conn.HttpClientConnectionManager;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.ssl.SSLContexts;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.http.client.api.HttpClientConfigImmutable;
+import org.openecomp.sdc.common.http.config.HttpClientConfig;
+import org.openecomp.sdc.common.http.config.Timeouts;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+
+public class HttpClientFactory {
+
+ private static final int DEFAULT_CONNECTION_POOL_SIZE = 30;
+ private static final int DEFAULT_MAX_CONNECTION_PER_ROUTE = 5;
+ private static final int VALIDATE_CONNECTION_AFTER_INACTIVITY_MS = 10000;
+ private static final int CONNECT_TIMEOUT_MS = 15000;
+
+ private static final Logger log = Logger.getLogger(HttpClientFactory.class);
+ private static final UserTokenHandler userTokenHandler = context -> null;
+
+ private HttpClientConnectionManager createConnectionManager(){
+ SSLConnectionSocketFactory sslsf = getSslConnectionSocketFactory();
+
+ Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
+ .register(Constants.HTTP, PlainConnectionSocketFactory.getSocketFactory())
+ .register(Constants.HTTPS, sslsf).build();
+
+ PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry);
+
+ manager.setMaxTotal(DEFAULT_CONNECTION_POOL_SIZE);
+ manager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTION_PER_ROUTE);
+ manager.setValidateAfterInactivity(VALIDATE_CONNECTION_AFTER_INACTIVITY_MS);
+
+ SocketConfig socketConfig = SocketConfig.custom()
+ .setSoTimeout(CONNECT_TIMEOUT_MS)
+ .build();
+ manager.setDefaultSocketConfig(socketConfig);
+
+ return manager;
+ }
+
+ private SSLConnectionSocketFactory getSslConnectionSocketFactory() {
+ return new SSLConnectionSocketFactory(SSLContexts.createSystemDefault());
+ }
+
+
+ /*
+ The difference between this client factory and the one in common api,
+ is that this one returns an apache httpclient instance, rather than a custom created custom.
+ */
+ public CloseableHttpClient createHttpClient() {
+ int connectTimeoutMs = 5000;
+ int readTimeoutMs = 10000;
+ HttpClientConnectionManager connManager = createConnectionManager();
+ HttpClientConfig httpClientConfig = new HttpClientConfig(new Timeouts(connectTimeoutMs, readTimeoutMs));
+ HttpClientConfigImmutable immutableHttpClientConfig = new HttpClientConfigImmutable(httpClientConfig);
+ RequestConfig requestConfig = createClientTimeoutConfiguration(immutableHttpClientConfig);
+ return HttpClients.custom()
+ .setConnectionManager(connManager)
+ .setDefaultRequestConfig(requestConfig)
+ .setUserTokenHandler(userTokenHandler)
+ .setRetryHandler(resolveRetryHandler(immutableHttpClientConfig))
+ .build();
+ }
+
+ private RequestConfig createClientTimeoutConfiguration(HttpClientConfigImmutable config) {
+ return RequestConfig.custom()
+ .setConnectTimeout(config.getConnectTimeoutMs())
+ .setSocketTimeout(config.getReadTimeoutMs())
+ .setConnectionRequestTimeout(config.getConnectPoolTimeoutMs())
+ .build();
+ }
+
+ private HttpRequestRetryHandler resolveRetryHandler(HttpClientConfigImmutable config) {
+ return config.getNumOfRetries() > 0 ? config.getRetryHandler() : null;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/config/ObjectMapperProvider.java
index 8f01e2775b..8b5f7ed6f2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/config/ObjectMapperProvider.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,30 +18,34 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.be.user;
+package org.openecomp.sdc.config;
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.exception.ResponseFormat;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.List;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
/**
- *
- * @author tg851x
- *
+ * Customizes an ObjectMapper for the application
*/
-public interface IUserBusinessLogic {
- public Either<User, ActionStatus> getUser(String userId, boolean inTransaction);
-
- public Either<User, ResponseFormat> createUser(User modifier, User newUser);
+@Provider
+public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {
- public Either<User, ResponseFormat> updateUserRole(User modifier, String userIdToUpdate, String userRole);
+ private final ObjectMapper objectMapper;
- public Either<List<User>, ResponseFormat> getUsersList(String userId, List<String> roles, String rolesStr);
+ public ObjectMapperProvider() {
+ objectMapper = createObjectMapper();
+ }
- public Either<User, ResponseFormat> deActivateUser(User modifier, String userUniuqeIdToDeactive);
+ private ObjectMapper createObjectMapper() {
+ return new ObjectMapper()
+ .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
+ .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
+ }
- public Either<User, ResponseFormat> authorize(User authUser);
+ @Override
+ public ObjectMapper getContext(Class<?> type) {
+ return objectMapper;
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/externalupload/utils/ServiceUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/externalupload/utils/ServiceUtils.java
index 47e676dd25..e6d12c9b4c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/externalupload/utils/ServiceUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/externalupload/utils/ServiceUtils.java
@@ -12,19 +12,23 @@
* 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=========================================================
- * Modifications copyright (c) 2019 Nokia
- * ================================================================================
*/
package org.openecomp.sdc.externalupload.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableSet;
+import org.apache.commons.beanutils.BeanUtils;
import java.lang.reflect.Field;
-import java.util.*;
-import org.onap.sdc.tosca.services.CommonUtil;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
public class ServiceUtils {
@@ -41,11 +45,20 @@ public class ServiceUtils {
}
Map<String, Object> objectAsMap = getObjectAsMap(objectCandidate);
+ T result = classToCreate.newInstance();
List<Field> declaredFields = getAllFields(classToCreate);
-
- CommonUtil.createSubObjectsUsingSetters(objectAsMap, declaredFields.toArray(new Field[0]));
- T result = CommonUtil.populateBean(objectAsMap, classToCreate);
+ for( Field field : declaredFields){
+ if(isComplexClass(field)){
+ Optional<?> objectUsingSetters =
+ createObjectUsingSetters(objectAsMap.get(field.getName()), field.getType());
+ if( objectUsingSetters.isPresent()){
+ objectAsMap.remove(field.getName());
+ objectAsMap.put(field.getName(), objectUsingSetters.get());
+ }
+ }
+ }
+ BeanUtils.populate(result, objectAsMap);
return Optional.of(result);
}
diff --git a/catalog-be/src/main/resources/application-context.xml b/catalog-be/src/main/resources/application-context.xml
index b3dcbc1de1..ca36de1168 100644
--- a/catalog-be/src/main/resources/application-context.xml
+++ b/catalog-be/src/main/resources/application-context.xml
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:annotation-config />
<aop:aspectj-autoproxy proxy-target-class="true" />
@@ -14,8 +13,8 @@
base-package= "org.openecomp.sdc.be.components.health,
org.openecomp.sdc.be.servlets,
org.openecomp.sdc.be.externalapi.servlet,
- org.openecomp.sdc.be.components.scheduledtasks
- ">
+ org.openecomp.sdc.be.components.scheduledtasks,
+ org.openecomp.sdc.be.facade.operations">
</context:component-scan>
<bean class="org.openecomp.sdc.be.dao.config.DAOSpringConfig"/>
@@ -29,9 +28,10 @@
<aop:pointcut id="lockingTransaction" expression="@annotation(org.openecomp.sdc.be.components.impl.lock.LockingTransactional) and args(componentId, componentType,..)"/>
<aop:around method="lock" arg-names="proceedingJoinPoint,componentId,componentType" pointcut-ref="lockingTransaction"/>
</aop:aspect>
+ <aop:aspect id="roleAuthorizationAspect" ref="roleAuthorizationHandler">
+ <aop:pointcut id="roleAuthorize" expression="@annotation(permissions)"/>
+ <aop:before method="authorizeRole" arg-names="joinPoint, permissions" pointcut-ref="roleAuthorize"/>
+ </aop:aspect>
</aop:config>
-
- <util:properties id="elasticsearchConfig" location="file:${config.home}/elasticsearch.yml" />
-
</beans>
diff --git a/catalog-be/src/main/resources/cadi.properties b/catalog-be/src/main/resources/cadi.properties
new file mode 100644
index 0000000000..5b6c24ffe0
--- /dev/null
+++ b/catalog-be/src/main/resources/cadi.properties
@@ -0,0 +1,55 @@
+# Configure AAF
+aaf_locate_url=https://aafist.test.att.com:8095
+aaf_url=https://aafist.test.att.com:8095/locate/com.att.aaf.service:2.0
+
+#aaf_url=https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=TEST/routeOffer=BAU_SE
+
+#if you are running aaf service from a docker image you have to use aaf service IP and port number
+aaf_id=m00468@portal.ecomp.att.com
+#Encrypt the password using AAF Jar
+aaf_password= enc:uI_J4jBL4YUcIZZa5uZKj3QMUC63hbS8TmDn5PSp5nO
+# Sample CADI Properties, from CADI 1.4.2
+hostname=ecomp.att.com
+csp_domain=PROD
+
+# Add Absolute path to Keyfile
+cadi_keyfile=/opt/app/jetty/base/be/etc/keyfile
+
+
+# This is required to accept Certificate Authentication from Certman certificates.
+# can be TEST, IST or PROD
+aaf_env=IST
+
+# DEBUG prints off all the properties. Use to get started.
+cadi_loglevel=DEBUG
+
+
+# Become CSO Poodle Compliant by only allowing sanctioned TLS versions
+# The following is the default
+# cadi_protocols=TLSv1.1,TLSv1.2
+
+# Default TrustStore - REQUIRED for changing PROTOCOL Defaults for DME2
+# Read https://wiki.web.att.com/pages/viewpage.action?pageId=574623569#URGENT:SolvingSSL2-3/TLSv1removalissues-Up-to-dateTruststore
+# Add Absolute path to truststore2018.jks
+cadi_truststore=/opt/app/jetty/base/be/etc/cadi_truststore.jks
+# Note: This is the ONLY password that doesn't have to be encrypted. All Java's TrustStores are this passcode by default, because they are public certs
+cadi_truststore_password=changeit
+
+# how to turn on SSL Logging
+#javax.net.debug=ssl
+
+##
+# Hint
+# Use "maps.bing.com" to get Lat and Long for an Address
+AFT_LATITUDE=32.780140
+AFT_LONGITUDE=-96.800451
+AFT_ENVIRONMENT=AFTUAT
+AFT_DME2_CLIENT_IGNORE_SSL_CONFIG=true
+DME2.DEBUG=true
+AFT_DME2_HTTP_EXCHANGE_TRACE_ON=true
+
+cadi_latitude=32.780140
+cadi_longitude=-96.800451
+
+aaf_root_ns=com.att.aaf
+aaf_api_version=2.0 \ No newline at end of file
diff --git a/catalog-be/src/main/resources/config/configuration.yaml b/catalog-be/src/main/resources/config/configuration.yaml
index 2df1fc45cb..3dca45840a 100644
--- a/catalog-be/src/main/resources/config/configuration.yaml
+++ b/catalog-be/src/main/resources/config/configuration.yaml
@@ -23,12 +23,26 @@ beSslPort: 8443
version: 1.1.0
released: 2012-11-30
-toscaConformanceLevel: 9.0
+toscaConformanceLevel: 12.0
minToscaConformanceLevel: 3.0
+# access restriction
+authCookie:
+ securityKey: "AGLDdG4D04BKm2IxIWEr8o=="
+ maxSessionTimeOut: 24*60*60*1000
+ sessionIdleTimeOut: 2*60*60*1000
+ cookieName: "AuthenticationCookie"
+ path: /
+ domain: ""
+ isHttpOnly: true
+ # redirect variable name from portal.properties file
+ redirectURL: "ecomp_redirect_url"
+ excludedUrls: ['/config', '/configmgr', '/kibanaProxy', '/healthcheck', '/v1/catalog', '/v1/catalog/archive', '/v1/followed', '/v1/catalog/upload.*', '/v1/consumers', '/v1/screen', '/v1/catalogUpdateTimea', '/v1/user.*']
+
# These values are necessary for running upgrade migration 1710.0 process
enableAutoHealing: false
appVersion: 1.1.0
+artifactGeneratorConfig: Artifact-Generator.properties
resourcesForUpgrade:
8.0:
- org.openecomp.resource.cp.extCP
@@ -52,8 +66,6 @@ janusGraphReconnectIntervalInSeconds: 3
# The read timeout towards Janus Graph DB when health check is invoked:
janusGraphHealthCheckReadTimeout: 1
-# The interval to try and reconnect to Elasticsearch when it is down during ASDC startup:
-esReconnectIntervalInSeconds: 3
uebHealthCheckReconnectIntervalInSeconds: 15
uebHealthCheckReadTimeout: 4
@@ -105,33 +117,9 @@ cassandraConfig:
- { name: dox, replicationStrategy: NetworkTopologyStrategy, replicationInfo: ['DC-sdc-iltlv650', '1']}
- { name: sdcaudit, replicationStrategy: NetworkTopologyStrategy, replicationInfo: ['DC-sdc-iltlv650', '1']}
- { name: sdcartifact, replicationStrategy: NetworkTopologyStrategy, replicationInfo: ['DC-sdc-iltlv650', '1']}
- - { name: sdccomponent, replicationStrategy: NetworkTopologyStrategy, replicationInfo: ['DC-sdc-iltlv650', '1']}
+ - { name: sdccomponent, replicationStrategy: NetworkTopologyStrategy, replicationInfo: ['DC-sdc-iltlv650', '1']}
- { name: sdcrepository, replicationStrategy: NetworkTopologyStrategy, replicationInfo: ['DC-sdc-iltlv650', '1']}
-
-#Application-specific settings of ES
-elasticSearch:
- # Mapping of index prefix to time-based frame. For example, if below is configured:
- #
- # - indexPrefix: auditingevents
- # creationPeriod: minute
- #
- # then ES object of type which is mapped to "auditingevents-*" template, and created on 2015-12-23 13:24:54, will enter "auditingevents-2015-12-23-13-24" index.
- # Another object created on 2015-12-23 13:25:54, will enter "auditingevents-2015-12-23-13-25" index.
- # If creationPeriod: month, both of the above will enter "auditingevents-2015-12" index.
- #
- # PLEASE NOTE: the timestamps are created in UTC/GMT timezone! This is needed so that timestamps will be correctly presented in Kibana.
- #
- # Legal values for creationPeriod - year, month, day, hour, minute, none (meaning no time-based behaviour).
- #
- # If no creationPeriod is configured for indexPrefix, default behavour is creationPeriod: month.
-
- indicesTimeFrequency:
- - indexPrefix: auditingevents
- creationPeriod: month
- - indexPrefix: monitoring_events
- creationPeriod: month
-
artifactTypes:
- CHEF
- PUPPET
@@ -178,11 +166,6 @@ resourceTypes: &allResourceTypes
# - VF
# - VL
deploymentResourceArtifacts:
- cdsBlueprint:
- displayName: "CDS Blueprint"
- type: CONTROLLER_BLUEPRINT_ARCHIVE
- description: "CDS deployment artifact"
- fileExtension: "zip"
# heat:
# displayName: "Base HEAT Template"
# type: HEAT
@@ -321,7 +304,10 @@ systemMonitoring:
isProxy: false
probeIntervalInSeconds: 15
-defaultHeatArtifactTimeoutMinutes: 60
+heatArtifactDeploymentTimeout:
+ defaultMinutes: 30
+ minMinutes: 1
+ maxMinutes: 120
serviceDeploymentArtifacts:
CONTROLLER_BLUEPRINT_ARCHIVE:
@@ -352,7 +338,7 @@ serviceDeploymentArtifacts:
- xml
AAI_VF_INSTANCE_MODEL:
acceptedTypes:
- - xml
+ - xml
CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT:
acceptedTypes:
- zip
@@ -465,7 +451,7 @@ resourceDeploymentArtifacts:
acceptedTypes:
validForResourceTypes:
- VF
- - VFCMT
+ - VFCMT
DCAE_EVENT:
acceptedTypes:
validForResourceTypes:
@@ -521,7 +507,6 @@ resourceDeploymentArtifacts:
ONBOARDED_PACKAGE:
acceptedTypes:
- csar
- - zip
validForResourceTypes:
- VF
- PNF
@@ -600,7 +585,7 @@ resourceInformationalArtifacts:
validForResourceTypes: *allResourceTypes
OTHER:
acceptedTypes:
- validForResourceTypes:
+ validForResourceTypes:
- VFC
- CVFC
- CP
@@ -631,10 +616,6 @@ resourceInformationalArtifacts:
resourceInformationalDeployedArtifacts:
-requirementsToFulfillBeforeCert:
-
-capabilitiesToConsumeBeforeCert:
-
unLoggedUrls:
- /sdc2/rest/healthCheck
@@ -662,6 +643,12 @@ dcae:
port: 8080
healthCheckUri: "/dcae/healthCheck"
+ecompPortal:
+ protocol: https
+ host: ecomp-portal-web-tdevn2.mtn23a.ecomp.cci.att.com
+ port: 8443
+ healthCheckUri: "/ecompui/portalApi/healthCheck"
+
switchoverDetector:
gBeFqdn: AIO-BE.ecomp.idns.cip.com
gFeFqdn: AIO-FE.ecomp.idns.cip.com
@@ -703,6 +690,7 @@ toscaValidators:
stringMaxLength: 2500
disableAudit: false
+consumerBusinessLogic: false
vfModuleProperties:
min_vf_module_instances:
@@ -761,6 +749,7 @@ gabConfig:
path: "event.structure.faultFields.structure.alarmAdditionalInformation.comment"
searchable: "true"
+#Tenant isolation consumer
dmaapConsumerConfiguration:
active: true
hosts: olsd004.wnsnet.ws.com:3905
@@ -789,13 +778,50 @@ dmaapConsumerConfiguration:
credential:
username: m09875@sdc.com
password: mockhmXYcznAljMSisdy8zgcag==
+ aftDme2SslEnable: true
+ aftDme2ClientIgnoreSslConfig: false
+ aftDme2ClientKeystore: /opt/app/jetty/base/be/config/.truststore
+ aftDme2ClientKeystorePassword: hmXYcznAljMSisdy8zgcag==
+ aftDme2ClientSslCertAlias: certman
+
+#Performence microservice dmaap producer
+dmaapProducerConfiguration:
+ active: false
+ consumerGroup: asdc
+ consumerId: mama #mama - in Order To Consume Remove This String And Replace It With -> mama
+ timeoutMs: 15000
+ limit: 1
+ pollingInterval: 2
+ topic: com.sdc.23911-SDCforTestDev-v001
+ latitude: 32.109333
+ longitude: 34.855499
+ version: 1.0
+ serviceName: dmaap-v1.dev.dmaap.dt.saat.acsi.com/events
+ environment: TEST
+ partner: BOT_R
+ routeOffer: MR1
+ protocol: http
+ contenttype: application/json
+ dme2TraceOn: true
+ aftEnvironment: AFTUAT
+ aftDme2ConnectionTimeoutMs: 15000
+ aftDme2RoundtripTimeoutMs: 240000
+ aftDme2ReadTimeoutMs: 50000
+ dme2preferredRouterFilePath: DME2preferredRouter.txt
+ timeLimitForNotificationHandleMs: 120000
+ credential:
+ username: m09875@sdc.com
+ password: mockhmXYcznAljMSisdy8zgcag==
+ aftDme2SslEnable: true
+ aftDme2ClientIgnoreSslConfig: false
+ aftDme2ClientKeystore: /opt/app/jetty/base/be/config/.truststore
+ aftDme2ClientKeystorePassword: hmXYcznAljMSisdy8zgcag==
+ aftDme2ClientSslCertAlias: certman
-
-dmeConfiguration:
- dme2Search: DME2SEARCH
- dme2Resolve: DME2RESOLVE
+dmeConfiguration:
+ lookupUriFormat: "http://DME2RESOLVE/service=%s/version=1.0.0/envContext=%s/routeOffer=DEFAULT"
excludedPolicyTypesMapping:
# VF:
@@ -808,21 +834,49 @@ excludedGroupTypesMapping:
CR:
- org.openecomp.groups.VfModule
- org.openecomp.groups.heat.HeatStack
+ - org.openecomp.groups.Group
- tosca.groups.Root
PNF:
- org.openecomp.groups.VfModule
- org.openecomp.groups.heat.HeatStack
+ - org.openecomp.groups.Group
- tosca.groups.Root
VF:
- org.openecomp.groups.VfModule
- org.openecomp.groups.heat.HeatStack
+ - org.openecomp.groups.Group
- tosca.groups.Root
Service:
- org.openecomp.groups.VfModule
- org.openecomp.groups.heat.HeatStack
+ - org.openecomp.groups.Group
- tosca.groups.Root
healthStatusExclude:
- DE
- - ES
- DMAAP
+ - DMAAP_PRODUCER
+ - ECOMP_PORTAL
+
+aafNamespace: com.att.sdc
+
+aafAuthNeeded: false
+
+cadiFilterParams:
+ hostname: 192.168.33.10
+ csp_domain: PROD
+ cadi_keyfile: /opt/app/jetty/base/be/config/catalog-be/keyfile
+ cadi_loglevel: DEBUG
+ cadi_truststore: /opt/app/jetty/base/be/config/.truststore
+ cadi_truststore_password: enc:HdzGwQGAK5Rc29vzn3Kqoy9BCTbJNGgNxd72zpCUtjg
+ #aaf_url: https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=TEST/routeOffer=BAU_SE
+ aaf_id: m09875@sdc.att.com
+ aaf_password: enc:HdzGwQGAK5Rc29vzn3Kqoy9BCTbJNGgNxd72zpCUtjg
+ aaf_env: DEV
+ aafLocateUrl: https://aaf.api.simpledemo.onap.org:8095
+ aaf_url: https://AAF_LOCATE_URL/AAF_NS.service:2.0
+ AFT_LATITUDE: "32.780140"
+ AFT_LONGITUDE: "-96.800451"
+ AFT_ENVIRONMENT: AFTUAT
+ cadiX509Issuers: "CN=intermediateCA_1, OU=OSAAF, O=ONAP, C=US"
+
diff --git a/catalog-be/src/main/resources/config/distribution-engine-configuration.yaml b/catalog-be/src/main/resources/config/distribution-engine-configuration.yaml
index 4a788caaab..1817ecbb2b 100644
--- a/catalog-be/src/main/resources/config/distribution-engine-configuration.yaml
+++ b/catalog-be/src/main/resources/config/distribution-engine-configuration.yaml
@@ -82,4 +82,3 @@ msoConfig:
password: OTLEp5lfVhYdyw5EAtTUBQ==
numOfRetries: 3
-currentArtifactInstallationTimeout: 120
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index 3045e9ec97..25989dfe29 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -16,90 +16,96 @@ errors:
code: 204,
message: "No Content"
}
-#--------POL4050-----------------------------
+ #--------POL4050-----------------------------
NOT_ALLOWED: {
code: 405,
message: "Error: Method not allowed.",
messageId: "POL4050"
}
-#--------POL5000-----------------------------
+ #--------POL5000-----------------------------
GENERAL_ERROR: {
code: 500,
message: "Error: Internal Server Error. Please try again later.",
messageId: "POL5000"
}
-#---------POL5001------------------------------
+ #---------POL5001------------------------------
MISSING_X_ECOMP_INSTANCE_ID: {
code: 400 ,
message: "Error: Missing 'X-ECOMP-InstanceID' HTTP header.",
messageId: "POL5001"
}
-#---------POL5002------------------------------
+ #---------POL5002------------------------------
AUTH_REQUIRED: {
code: 401 ,
message: "Error: Authentication is required to use the API.",
messageId: "POL5002"
}
-#---------POL5003------------------------------
+ #---------POL5003------------------------------
AUTH_FAILED: {
code: 403 ,
message: "Error: Not authorized to use the API.",
messageId: "POL5003"
}
-#---------POL5004------------------------------
+ #---------POL5004------------------------------
MISSING_USER_ID: {
code: 400 ,
message: "Error: Missing 'USER_ID' HTTP header.",
messageId: "POL5004"
}
-#---------SVC4000-----------------------------
+ #---------POL5005------------------------------
+ SESSION_EXPIRED: {
+ code: 403 ,
+ message: "Your session has expired. Please close the SDC tab and re-enter the SDC application.",
+ messageId: "POL5005"
+ }
+ #---------SVC4000-----------------------------
INVALID_CONTENT: {
code: 400,
message: "Error: Invalid content.",
messageId: "SVC4000"
}
-#---------SVC4002-----------------------------
+ #---------SVC4002-----------------------------
MISSING_INFORMATION: {
code: 403,
message: "Error: Missing information.",
messageId: "SVC4002"
}
-#---------SVC4003------------------------------
-# %1 - Users's ID
+ #---------SVC4003------------------------------
+ # %1 - Users's ID
USER_NOT_FOUND: {
code: 404,
message: "Error: User '%1' was not found.",
messageId: "SVC4003"
}
-#---------SVC4004-----------------------------
-# %1 - Users's email address
+ #---------SVC4004-----------------------------
+ # %1 - Users's email address
INVALID_EMAIL_ADDRESS: {
code: 400,
message: "Error: Invalid email address '%1'.",
messageId: "SVC4004"
}
-#---------SVC4005------------------------------
-# %1 - role
+ #---------SVC4005------------------------------
+ # %1 - role
INVALID_ROLE: {
code: 400,
message: "Error: Invalid role '%1'.",
messageId: "SVC4005"
}
-#---------SVC4006------------------------------
-# %1 - Users's USER_ID
+ #---------SVC4006------------------------------
+ # %1 - Users's USER_ID
USER_ALREADY_EXIST: {
code: 409,
message: "Error: User with '%1' ID already exists.",
messageId: "SVC4006"
}
-#---------SVC4007------------------------------
+ #---------SVC4007------------------------------
DELETE_USER_ADMIN_CONFLICT: {
code: 409,
message: "Error: An administrator can only be deleted by another administrator.",
messageId: "SVC4007"
}
-#---------SVC4008-----------------------------
-# %1 - Users's userId
+ #---------SVC4008-----------------------------
+ # %1 - Users's userId
INVALID_USER_ID: {
code: 400,
message: "Error: Invalid userId '%1'.",
@@ -111,105 +117,105 @@ errors:
message: "Error: User Defined '%1'.",
messageId: "SVC4009"
}
-#---------SVC4049------------------------------
-# %1 - service/resource
+ #---------SVC4049------------------------------
+ # %1 - service/resource
COMPONENT_MISSING_CONTACT: {
code: 400,
message: "Error: Invalid Content. Missing %1 contact.",
messageId: "SVC4049"
}
-#---------SVC4050-----------------------------
-# %1 - Service/Resource/Additional parameter
-# %2 - service/resource/label name
+ #---------SVC4050-----------------------------
+ # %1 - Service/Resource/Additional parameter
+ # %2 - service/resource/label name
COMPONENT_NAME_ALREADY_EXIST: {
code: 409,
message: "Error: %1 with name '%2' already exists.",
messageId: "SVC4050"
}
-#---------SVC4051------------------------------
-# %1 - resource/service
+ #---------SVC4051------------------------------
+ # %1 - resource/service
COMPONENT_MISSING_CATEGORY: {
code: 400,
message: "Error: Invalid Content. Missing %1 category.",
messageId: "SVC4051"
}
-#---------SVC4052------------------------------
+ #---------SVC4052------------------------------
COMPONENT_MISSING_TAGS: {
code: 400,
message: "Error: Invalid Content. At least one tag has to be specified.",
messageId: "SVC4052"
}
-#---------SVC4053------------------------------
-# %1 - service/resource
+ #---------SVC4053------------------------------
+ # %1 - service/resource
COMPONENT_MISSING_DESCRIPTION: {
code: 400,
message: "Error: Invalid Content. Missing %1 description.",
messageId: "SVC4053"
}
-#---------SVC4054------------------------------
-# %1 - resource/service
+ #---------SVC4054------------------------------
+ # %1 - resource/service
COMPONENT_INVALID_CATEGORY: {
code: 400,
message: "Error: Invalid Content. Value %1 for the field Category is invalid.",
messageId: "SVC4054"
}
-#---------SVC4055------------------------------
+ #---------SVC4055------------------------------
MISSING_VENDOR_NAME: {
code: 400,
message: "Error: Invalid Content. Missing vendor name.",
messageId: "SVC4055"
}
-#---------SVC4056------------------------------
+ #---------SVC4056------------------------------
MISSING_VENDOR_RELEASE: {
code: 400,
message: "Error: Invalid Content. Missing vendor release.",
messageId: "SVC4056"
}
-#---------SVC4057------------------------------
+ #---------SVC4057------------------------------
MISSING_DERIVED_FROM_TEMPLATE: {
code: 400,
message: "Error: Invalid Content. Missing derived from template specification.",
messageId: "SVC4057"
}
-#---------SVC4058------------------------------
-# %1 - service/resource
+ #---------SVC4058------------------------------
+ # %1 - service/resource
COMPONENT_MISSING_ICON: {
code: 400,
message: "Error: Invalid Content. Missing %1 icon.",
messageId: "SVC4058"
}
-#---------SVC4059------------------------------
-# %1 - service/resource
+ #---------SVC4059------------------------------
+ # %1 - service/resource
COMPONENT_INVALID_ICON: {
code: 400,
message: "Error: Invalid Content. Invalid %1 icon.",
messageId: "SVC4059"
}
-#---------SVC4060------------------------------
+ #---------SVC4060------------------------------
PARENT_RESOURCE_NOT_FOUND: {
code: 400,
message: "Error: Invalid Content. Derived from resource template was not found.",
messageId: "SVC4060"
}
-#---------SVC4061------------------------------
+ #---------SVC4061------------------------------
MULTIPLE_PARENT_RESOURCE_FOUND: {
code: 400,
message: "Error: Invalid Content. Multiple derived from resource template is not allowed.",
messageId: "SVC4061"
}
-#---------SVC4062------------------------------
-# %1 - service/resource
+ #---------SVC4062------------------------------
+ # %1 - service/resource
MISSING_COMPONENT_NAME: {
code: 400,
message: "Error: Invalid Content. Missing %1 name.",
messageId: "SVC4062"
}
-#---------SVC4063------------------------------
+ #---------SVC4063------------------------------
#%1  -  resource/service name
RESOURCE_NOT_FOUND: {
code: 404,
@@ -217,205 +223,205 @@ errors:
messageId: "SVC4063"
}
-#---------SVC4064------------------------------
-# %1 - Service/Resource/Property
+ #---------SVC4064------------------------------
+ # %1 - Service/Resource/Property
COMPONENT_INVALID_DESCRIPTION: {
code: 400,
message: "Error: Invalid Content. %1 description contains non-english characters.",
messageId: "SVC4064"
}
-#---------SVC4065------------------------------
-# %1 - Service/Resource/Property
-# %2 - max resource/service name length
+ #---------SVC4065------------------------------
+ # %1 - Service/Resource/Property
+ # %2 - max resource/service name length
COMPONENT_DESCRIPTION_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 description exceeds limit of %2 characters.",
messageId: "SVC4065"
}
-#---------SVC4066------------------------------
-# %1 - max length
+ #---------SVC4066------------------------------
+ # %1 - max length
COMPONENT_TAGS_EXCEED_LIMIT: {
code: 400,
message: "Error: Invalid Content. Tags overall length exceeds limit of %1 characters.",
messageId: "SVC4066"
}
-#---------SVC4067------------------------------
-# %1 - max length
+ #---------SVC4067------------------------------
+ # %1 - max length
VENDOR_NAME_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. Vendor name exceeds limit of %1 characters.",
messageId: "SVC4067"
}
-#---------SVC4068------------------------------
-# %1 - max length
+ #---------SVC4068------------------------------
+ # %1 - max length
VENDOR_RELEASE_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. Vendor release exceeds limit of %1 characters.",
messageId: "SVC4068"
}
-#---------SVC4069------------------------------
-# %1 - Service/Resource/Product
+ #---------SVC4069------------------------------
+ # %1 - Service/Resource/Product
COMPONENT_INVALID_CONTACT: {
code: 400,
- message: "Error: Invalid Content. %1 Contact Id should be in format 'mnnnnnn' or 'aannna' or 'aannnn', where m=m ,a=a-zA-Z and n=0-9",
+ message: "Error: Invalid Content. %1 Contact Id should be in format 'mnnnnnn' or 'aannna' or 'aannnn', where m=m ,a=a-zA-Z and n=0-9. Max length: 50",
messageId: "SVC4069"
}
-#---------SVC4070------------------------------
-# %1 - Service/Resource
+ #---------SVC4070------------------------------
+ # %1 - Service/Resource
INVALID_COMPONENT_NAME: {
code: 400,
message: 'Error: Invalid Content. Value %1 for Component name is invalid. Only alphanumeric characters and regular spaces are allowed.',
messageId: "SVC4070"
}
-#---------SVC4071------------------------------
+ #---------SVC4071------------------------------
INVALID_VENDOR_NAME: {
code: 400,
message: 'Error: Invalid Content. Value %1 for the field Vendor name is invalid. Only alphanumeric characters and regular spaces are allowed.',
messageId: "SVC4071"
}
-#---------SVC4072------------------------------
+ #---------SVC4072------------------------------
INVALID_VENDOR_RELEASE: {
code: 400,
message: 'Error: Invalid Content. Value %1 for the field Vendor release is invalid. Only alphanumeric characters and regular spaces are allowed.',
messageId: "SVC4072"
}
-#---------SVC4073------------------------------
-# %1 - Service/Resource
-# %2 - max resource/service name
+ #---------SVC4073------------------------------
+ # %1 - Service/Resource
+ # %2 - max resource/service name
COMPONENT_NAME_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 name exceeds limit of %2 characters.",
messageId: "SVC4073"
}
-#---------SVC4080------------------------------
-# %1 - resource/service name
-# %2 - resource/service
-# %3 - First name of last modifier
-# %4 - Last name of last modifier
-# %5 - USER_ID of last modifier
+ #---------SVC4080------------------------------
+ # %1 - resource/service name
+ # %2 - resource/service
+ # %3 - First name of last modifier
+ # %4 - Last name of last modifier
+ # %5 - USER_ID of last modifier
COMPONENT_IN_CHECKOUT_STATE: {
code: 403,
message: "Error: Requested '%1' %2 is locked for modification by %3 %4(%5).",
messageId: "SVC4080"
}
-#---------SVC4081-----------------------------
-# %1 - resource/service name
-# %2 - resource/service
-# %3 - First name of last modifier
-# %4 - Last name of last modifier
-# %5 - USER_ID of last modifier
+ #---------SVC4081-----------------------------
+ # %1 - resource/service name
+ # %2 - resource/service
+ # %3 - First name of last modifier
+ # %4 - Last name of last modifier
+ # %5 - USER_ID of last modifier
COMPONENT_IN_CERT_IN_PROGRESS_STATE: {
code: 403,
message: "Error: Requested '%1' %2 is locked for certification by %3 %4(%5).",
messageId: "SVC4081"
}
-#-----------SVC4082---------------------------
-# %1 - resource/service name
-# %2 - resource/service
-# %3 - First name of last modifier
-# %4 - Last name of last modifier
-# %5 - USER_ID of last modifier
+ #-----------SVC4082---------------------------
+ # %1 - resource/service name
+ # %2 - resource/service
+ # %3 - First name of last modifier
+ # %4 - Last name of last modifier
+ # %5 - USER_ID of last modifier
COMPONENT_SENT_FOR_CERTIFICATION: {
code: 403,
message: "Error: Requested '%1' %2 is sent for certification by %3 %4(%5).",
messageId: "SVC4082"
}
-#-----------SVC4083---------------------------
+ #-----------SVC4083---------------------------
COMPONENT_VERSION_ALREADY_EXIST: {
code: 409,
message: "Error: Version of this %1 was already promoted.",
messageId: "SVC4083"
}
-#-----------SVC4084---------------------------
-# %1 - resource/service/product name
-# %2 - resource/service/product
-# %3 - First name of last modifier
-# %4 - Last name of last modifier
-# %5 - USER_ID of last modifier
+ #-----------SVC4084---------------------------
+ # %1 - resource/service/product name
+ # %2 - resource/service/product
+ # %3 - First name of last modifier
+ # %4 - Last name of last modifier
+ # %5 - USER_ID of last modifier
COMPONENT_ALREADY_CHECKED_IN: {
code: 409,
message: "Error: The current version of '%1' %2 was already checked-in by %3 %4(%5).",
messageId: "SVC4084"
}
-#-----------SVC4085---------------------------
-# %1 - resource/service/product name
-# %2 - resource/service/product
-# %3 - First name of last modifier
-# %4 - Last name of last modifier
-# %5 - USER_ID of last modifier
+ #-----------SVC4085---------------------------
+ # %1 - resource/service/product name
+ # %2 - resource/service/product
+ # %3 - First name of last modifier
+ # %4 - Last name of last modifier
+ # %5 - USER_ID of last modifier
COMPONENT_CHECKOUT_BY_ANOTHER_USER: {
code: 403,
message: "Error: %1 %2 has already been checked out by %3 %4(%5).",
messageId: "SVC4085"
}
-#-----------SVC4086---------------------------
-# %1  - resource/service name
-# %2  - resource/service
+ #-----------SVC4086---------------------------
+ # %1  - resource/service name
+ # %2  - resource/service
COMPONENT_IN_USE: {
code: 403,
message: "Error: '%1' %2 is still held by previous action. Please try again later.",
messageId: "SVC4086"
}
-#-----------SVC4087---------------------------
-# %1 - component name
-# %2 - resource/service/product
+ #-----------SVC4087---------------------------
+ # %1 - component name
+ # %2 - resource/service/product
COMPONENT_HAS_NEWER_VERSION: {
code: 409,
message: "Error: Checking out of the requested version of the '%1' %2 is not allowed as a newer version exists.",
messageId: "SVC4087"
}
-#-----------SVC4088---------------------------
-# %1 - resource/service name
-# %2 - resource/service
-# %3 - First name of last modifier
-# %4 - Last name of last modifier
-# %5 - USER_ID of last modifier
+ #-----------SVC4088---------------------------
+ # %1 - resource/service name
+ # %2 - resource/service
+ # %3 - First name of last modifier
+ # %4 - Last name of last modifier
+ # %5 - USER_ID of last modifier
COMPONENT_ALREADY_CERTIFIED: {
code: 403,
message: "Error: Requested %1 %2 has already been certified by %3 %4(%5).",
messageId: "SVC4088"
}
-#-----------SVC4089---------------------------
-# %1 - resource/service name
-# %2 - resource/service
+ #-----------SVC4089---------------------------
+ # %1 - resource/service name
+ # %2 - resource/service
COMPONENT_NOT_READY_FOR_CERTIFICATION: {
code: 403,
message: "Error: Requested '%1' %2 is not ready for certification.",
messageId: "SVC4089"
}
-#-----------SVC4100---------------------------
-#%1 - property name
+ #-----------SVC4100---------------------------
+ #%1 - property name
PROPERTY_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' property was not found.",
messageId: "SVC4100"
}
-#-----------SVC4101---------------------------
-#%1 - property name
+ #-----------SVC4101---------------------------
+ #%1 - property name
PROPERTY_ALREADY_EXIST: {
code: 409,
message: "Error: Property with '%1' name already exists.",
messageId: "SVC4101"
}
-#-----------SVC4102---------------------------
-# %1 - capability type name
+ #-----------SVC4102---------------------------
+ # %1 - capability type name
CAPABILITY_TYPE_ALREADY_EXIST: {
code: 409,
message: "Error: Capability Type with name '%1' already exists.",
messageId: "SVC4102"
}
-#-----------SVC4114---------------------------
+ #-----------SVC4114---------------------------
AUTH_FAILED_INVALIDE_HEADER: {
code: 400,
message: "Error: Invalid Authorization header.",
messageId: "SVC4114"
}
-#-----------SVC4115---------------------------
-# %1 - capability type name
+ #-----------SVC4115---------------------------
+ # %1 - capability type name
MISSING_CAPABILITY_TYPE: {
code: 400,
message: "Error: Invalid Content. Missing Capability Type '%1'.",
@@ -426,216 +432,216 @@ errors:
message: "Error: Invalid Content.",
messageId: "SVC4116"
}
-#-----------SVC4117---------------------------
-# %1 - resource instance name
-# %2 - resource instance name
-# %3 - requirement name
+ #-----------SVC4117---------------------------
+ # %1 - resource instance name
+ # %2 - resource instance name
+ # %3 - requirement name
RESOURCE_INSTANCE_MATCH_NOT_FOUND: {
code: 404,
message: "Error: Match not found between resource instance '%1' and resource instance '%2' for requirement '%3'.",
messageId: "SVC4117"
}
-#-----------SVC4118---------------------------
-# %1 - resource instance name
-# %2 - resource instance name
-# %3 - requirement name
+ #-----------SVC4118---------------------------
+ # %1 - resource instance name
+ # %2 - resource instance name
+ # %3 - requirement name
RESOURCE_INSTANCE_ALREADY_EXIST: {
code: 409,
message: "Error: Resource instances '%1' and '%2' are already associated with requirement '%3'.",
messageId: "SVC4118"
}
-#-----------SVC4119---------------------------
-# %1 - resource instance name
-# %2 - resource instance name
-# %3 - requirement name
+ #-----------SVC4119---------------------------
+ # %1 - resource instance name
+ # %2 - resource instance name
+ # %3 - requirement name
RESOURCE_INSTANCE_RELATION_NOT_FOUND: {
code: 404,
message: "Error: No relation found between resource instances '%1' and '%2' for requirement '%3'.",
messageId: "SVC4119"
}
-#-----------SVC4120---------------------------
-# %1 - User's USER_ID
+ #-----------SVC4120---------------------------
+ # %1 - User's USER_ID
USER_INACTIVE: {
code: 404,
- message: "Error: User %1 was not found.",
+ message: "Error: User %1 inactive.",
messageId: "SVC4120"
}
-#-----------SVC4121---------------------------
-# %1 - User's USER_ID
+ #-----------SVC4121---------------------------
+ # %1 - User's USER_ID
USER_HAS_ACTIVE_ELEMENTS: {
code: 403,
message: "Error: User with %1 ID can not be deleted since it has active elements(resources/services/artifacts).",
messageId: "SVC4121"
}
-#-----------SVC4122---------------------------
-# %1 - artifact type
+ #-----------SVC4122---------------------------
+ # %1 - artifact type
ARTIFACT_TYPE_NOT_SUPPORTED: {
code: 400,
message: "Error: Invalid artifact type '%1'.",
messageId: "SVC4122"
}
-#-----------SVC4123---------------------------
+ #-----------SVC4123---------------------------
ARTIFACT_LOGICAL_NAME_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Artifact logical name cannot be changed.",
messageId: "SVC4123"
}
-#-----------SVC4124---------------------------
+ #-----------SVC4124---------------------------
MISSING_ARTIFACT_TYPE: {
code: 400,
message: "Error: Missing artifact type.",
messageId: "SVC4124"
}
-#-----------SVC4125---------------------------
-# %1-artifact name
+ #-----------SVC4125---------------------------
+ # %1-artifact name
ARTIFACT_EXIST: {
code: 400,
message: "Error: Artifact '%1' already exists.",
messageId: "SVC4125"
}
-#---------SVC4126------------------------------
-# %1 - resource/service/product/...
-# %2 - field (tag, vendor name...)
+ #---------SVC4126------------------------------
+ # %1 - resource/service/product/...
+ # %2 - field (tag, vendor name...)
INVALID_FIELD_FORMAT: {
code: 400,
message: "Error: Invalid %1 %2 format.",
messageId: "SVC4126"
}
-#-----------SVC4127---------------------------
+ #-----------SVC4127---------------------------
ARTIFACT_INVALID_MD5: {
code: 400,
message: "Error: Invalid artifact checksum.",
messageId: "SVC4127"
}
-#-----------SVC4128---------------------------
+ #-----------SVC4128---------------------------
MISSING_ARTIFACT_NAME: {
code: 400,
message: "Error: Invalid content. Missing artifact name.",
messageId: "SVC4128"
}
-#-----------SVC4129---------------------------
+ #-----------SVC4129---------------------------
MISSING_PROJECT_CODE: {
code: 400,
message: "Error: Invalid Content. Missing PROJECT_CODE number.",
messageId: "SVC4129"
}
-#-----------SVC4130---------------------------
+ #-----------SVC4130---------------------------
INVALID_PROJECT_CODE: {
code: 400,
- message: "Error: Invalid Content. PROJECT_CODE must be from 3 up to 50 characters.",
+ message: "Error: Invalid Content. PROJECT_CODE must be from 5 up to 50 characters.",
messageId: "SVC4130"
}
-#-----------SVC4131---------------------------
-# %1-resource/service
-# %2-srtifact/artifacts
-# %3-semicolomn separated list of artifact
+ #-----------SVC4131---------------------------
+ # %1-resource/service
+ # %2-srtifact/artifacts
+ # %3-semicolomn separated list of artifact
COMPONENT_MISSING_MANDATORY_ARTIFACTS: {
code: 403,
message: "Error: Missing mandatory informational %1 %2: [%3].",
messageId: "SVC4131"
}
-#-----------SVC4132---------------------------
-# %1 - lifecycle type name
+ #-----------SVC4132---------------------------
+ # %1 - lifecycle type name
LIFECYCLE_TYPE_ALREADY_EXIST: {
code: 409,
message: "Error: Lifecycle Type with name '%1' already exists.",
messageId: "SVC4132"
}
-#-----------SVC4133---------------------------
-# %1 - service version
-# %2 - service name
+ #-----------SVC4133---------------------------
+ # %1 - service version
+ # %2 - service name
SERVICE_NOT_AVAILABLE_FOR_DISTRIBUTION: {
code: 403,
message: "Error: Version %1 of '%2' service is not available for distribution.",
messageId: "SVC4133"
}
-#-----------SVC4134---------------------------
+ #-----------SVC4134---------------------------
MISSING_LIFECYCLE_TYPE: {
code: 400,
message: "Error: Invalid Content. Missing interface life-cycle type.",
messageId: "SVC4134"
}
-#---------SVC4135------------------------------
+ #---------SVC4135------------------------------
SERVICE_CATEGORY_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Service category cannot be changed once the service is certified.",
messageId: "SVC4135"
}
-#---------SVC4136------------------------------
-# %1 - distribution environment name
+ #---------SVC4136------------------------------
+ # %1 - distribution environment name
DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE: {
code: 500,
message: "Error: Requested distribution environment '%1' is not available.",
messageId: "SVC4136"
}
-#---------SVC4137------------------------------
-# %1 - distribution environment name
+ #---------SVC4137------------------------------
+ # %1 - distribution environment name
DISTRIBUTION_ENVIRONMENT_NOT_FOUND: {
code: 400,
message: "Error: Requested distribution environment '%1' was not found.",
messageId: "SVC4137"
}
-#---------SVC4138------------------------------
+ #---------SVC4138------------------------------
DISTRIBUTION_ENVIRONMENT_INVALID: {
code: 400,
message: "Error: Invalid distribution environment.",
messageId: "SVC4138"
}
-#---------SVC4200------------------------------
-# %1 - Service/Resource
-# %2 - max icon name length
+ #---------SVC4200------------------------------
+ # %1 - Service/Resource
+ # %2 - max icon name length
COMPONENT_ICON_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 icon name exceeds limit of %2 characters.",
messageId: "SVC4200"
}
-#---------SVC4300------------------------------
+ #---------SVC4300------------------------------
RESTRICTED_ACCESS: {
code: 403,
message: "Error: Restricted access.",
messageId: "SVC4300"
}
-#---------SVC4301------------------------------
+ #---------SVC4301------------------------------
RESTRICTED_OPERATION: {
code: 403,
message: "Error: Restricted operation.",
messageId: "SVC4301"
}
-#---------SVC4500------------------------------
+ #---------SVC4500------------------------------
MISSING_BODY: {
code: 400 ,
message: "Error: Missing request body.",
messageId: "SVC4500"
}
-#---------SVC4501------------------------------
+ #---------SVC4501------------------------------
MISSING_PUBLIC_KEY: {
code: 400 ,
message: "Error: Invalid Content. Missing mandatory parameter 'apiPublicKey'." ,
messageId: "SVC4501"
}
-#---------SVC4502------------------------------
+ #---------SVC4502------------------------------
DISTRIBUTION_ENV_DOES_NOT_EXIST: {
code: 400 ,
message: "Error: Invalid Body : Missing mandatory parameter 'distrEnvName'." ,
messageId: "SVC4502"
}
-#-----------SVC4503---------------------------
-# %1 - service name
+ #-----------SVC4503---------------------------
+ # %1 - service name
SERVICE_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' service was not found.",
messageId: "SVC4503"
}
-#---------SVC4504------------------------------
-# %1 - Service/Resource
-# %2 - service/resource version
+ #---------SVC4504------------------------------
+ # %1 - Service/Resource
+ # %2 - service/resource version
COMPONENT_VERSION_NOT_FOUND: {
code: 404,
message: "Error: %1 version %2 was not found.",
messageId: "SVC4504"
}
-#-----------SVC4505---------------------------
+ #-----------SVC4505---------------------------
#%1-artifact name
ARTIFACT_NOT_FOUND: {
@@ -643,807 +649,788 @@ errors:
message: "Error: Artifact '%1' was not found.",
messageId: "SVC4505"
}
-#---------SVC4506------------------------------
+ #---------SVC4506------------------------------
MISSING_ENV_NAME: {
code: 400 ,
message: "Error: Invalid Content. Missing mandatory parameter 'distrEnvName'.",
messageId: "SVC4506"
}
-#---------SVC4507------------------------------
+ #---------SVC4507------------------------------
COMPONENT_INVALID_TAGS_NO_COMP_NAME: {
code: 400,
message: "Error: Invalid Content. One of the tags should be the component name.",
messageId: "SVC4507"
}
-#---------SVC4508------------------------------
+ #---------SVC4508------------------------------
SERVICE_NAME_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Service name cannot be changed once the service is certified.",
messageId: "SVC4508"
}
-#---------SVC4509------------------------------
+ #---------SVC4509------------------------------
SERVICE_ICON_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Icon cannot be changed once the service is certified.",
messageId: "SVC4509"
}
-#---------SVC4510------------------------------
-# %1 - icon name max length
+ #---------SVC4510------------------------------
+ # %1 - icon name max length
SERVICE_ICON_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. Icon name exceeds limit of %1 characters.",
messageId: "SVC4510"
}
-#---------SVC4511------------------------------
+ #---------SVC4511------------------------------
DISTRIBUTION_REQUESTED_NOT_FOUND: {
code: 404,
message: "Error: Requested distribution was not found.",
messageId: "SVC4511"
}
-#---------SVC4512------------------------------
-# %1 - Distribution ID
+ #---------SVC4512------------------------------
+ # %1 - Distribution ID
DISTRIBUTION_REQUESTED_FAILED: {
code: 403,
message: "Error: Requested distribution '%1' failed.",
messageId: "SVC4512"
}
-#---------SVC4513------------------------------
+ #---------SVC4513------------------------------
RESOURCE_CATEGORY_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Resource category cannot be changed once the resource is certified.",
messageId: "SVC4513"
}
-#---------SVC4514------------------------------
+ #---------SVC4514------------------------------
RESOURCE_NAME_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Resource name cannot be changed once the resource is certified.",
messageId: "SVC4514"
}
-#---------SVC4515------------------------------
+ #---------SVC4515------------------------------
RESOURCE_ICON_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Icon cannot be changed once the resource is certified.",
messageId: "SVC4515"
}
-#---------SVC4516------------------------------
+ #---------SVC4516------------------------------
RESOURCE_VENDOR_NAME_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Vendor name cannot be changed once the resource is certified.",
messageId: "SVC4516"
}
-#---------SVC4517------------------------------
+ #---------SVC4517------------------------------
RESOURCE_DERIVED_FROM_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: Derived from resource template cannot be changed once the resource is certified.",
messageId: "SVC4517"
}
-#---------SVC4518------------------------------
-# %1 - max length
+ #---------SVC4518------------------------------
+ # %1 - max length
COMPONENT_SINGLE_TAG_EXCEED_LIMIT: {
code: 400,
message: "Error: Invalid Content. Single tag exceeds limit of %1 characters.",
messageId: "SVC4518"
}
-#---------SVC4519------------------------------
+ #---------SVC4519------------------------------
INVALID_DEFAULT_VALUE: {
code: 400,
message: "Error: mismatch in data-type occurred for property %1. data type is %2 and default value found is %3.",
messageId: "SVC4519"
}
-#---------SVC4520------------------------------
-# %1 - service or resource
+ #---------SVC4520------------------------------
+ # %1 - service or resource
ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED: {
code: 409,
message: "Error: Maximal number of additional %1 parameters was reached.",
messageId: "SVC4520"
}
-#---------SVC4521------------------------------
+ #---------SVC4521------------------------------
ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED: {
code: 400,
message: "Error: Invalid Content. The Additional information label and value cannot be empty.",
messageId: "SVC4521"
}
-#---------SVC4522------------------------------
-# %1 - label/value
-# %2 - Maximal length of %1
+ #---------SVC4522------------------------------
+ # %1 - label/value
+ # %2 - Maximal length of %1
ADDITIONAL_INFORMATION_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. Additional information %1 exceeds limit of %2 characters.",
messageId: "SVC4522"
}
-#---------SVC4523------------------------------
+ #---------SVC4523------------------------------
ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS: {
code: 400,
message: 'Error: Invalid Content. Additional information label is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
messageId: "SVC4523"
}
-#---------SVC4524------------------------------
+ #---------SVC4524------------------------------
ADDITIONAL_INFORMATION_NOT_FOUND: {
code: 409,
message: "Error: Requested additional information was not found.",
messageId: "SVC4524"
}
-#---------SVC4525------------------------------
+ #---------SVC4525------------------------------
ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS: {
code: 400,
message: 'Error: Invalid Content. Additional information contains non-english characters.',
messageId: "SVC4525"
}
-#---------SVC4526------------------------------
+ #---------SVC4526------------------------------
RESOURCE_INSTANCE_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' resource instance was not found.",
messageId: "SVC4526"
}
-#---------SVC4527------------------------------
+ #---------SVC4527------------------------------
ASDC_VERSION_NOT_FOUND: {
code: 500,
message: 'Error: ASDC version cannot be displayed.',
messageId: "SVC4527"
}
-#---------SVC4528------------------------------
-# %1-artifact url/artifact label/artifact description/VNF Service Indicator
+ #---------SVC4528------------------------------
+ # %1-artifact url/artifact label/artifact description/VNF Service Indicator
MISSING_DATA: {
code: 400,
message: "Error: Invalid content. Missing %1.",
messageId: "SVC4528"
}
-#---------SVC4529------------------------------
-# %1-artifact url/artifact label/artifact description/artifact name
-# %2 - Maximal length of %1
+ #---------SVC4529------------------------------
+ # %1-artifact url/artifact label/artifact description/artifact name
+ # %2 - Maximal length of %1
EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. %1 exceeds limit of %2 characters.",
messageId: "SVC4529"
}
-#---------SVC4530------------------------------
+ #---------SVC4530------------------------------
ARTIFACT_INVALID_TIMEOUT: {
code: 400,
message: "Error: Invalid Content. Artifact Timeout should be set to valid positive non-zero number of minutes.",
messageId: "SVC4530"
}
-#---------SVC4531------------------------------
+ #---------SVC4531------------------------------
SERVICE_IS_VNF_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: VNF Indicator cannot be updated for certified service.",
messageId: "SVC4531"
}
- #---------SVC4532------------------------------
+ #---------SVC4532------------------------------
RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE: {
code: 404,
message: "Error: Requested '%1' resource instance was not found on the service '%2.",
messageId: "SVC4532"
}
- #---------SVC4533------------------------------
- # %1 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"/"YANG_XML"
+ #---------SVC4533------------------------------
+ # %1 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"/"YANG_XML"
WRONG_ARTIFACT_FILE_EXTENSION: {
code: 400,
message: "Error: Invalid file extension for %1 artifact type.",
messageId: "SVC4533"
}
-#---------SVC4534------------------------------
-# %1 - "HEAT"/"HEAT_ENV"
+ #---------SVC4534------------------------------
+ # %1 - "HEAT"/"HEAT_ENV"
INVALID_YAML: {
code: 400,
message: "Error: Uploaded YAML file for %1 artifact is invalid.",
messageId: "SVC4534"
}
-#---------SVC4535------------------------------
-# %1 - "HEAT"
+ #---------SVC4535------------------------------
+ # %1 - "HEAT"
INVALID_DEPLOYMENT_ARTIFACT_HEAT: {
code: 400,
message: "Error: Invalid %1 artifact.",
messageId: "SVC4535"
}
-#---------SVC4536------------------------------
-# %1 - "Resource"/"Service"
-# %2 - resource/service name
-# %3 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"
-# %4 - "HEAT"/"HEAT_ENV"/"MURANO_PKG
+ #---------SVC4536------------------------------
+ # %1 - "Resource"/"Service"
+ # %2 - resource/service name
+ # %3 - "HEAT"/"HEAT_ENV"/"MURANO_PKG"
+ # %4 - "HEAT"/"HEAT_ENV"/"MURANO_PKG
DEPLOYMENT_ARTIFACT_OF_TYPE_ALREADY_EXISTS: {
code: 400,
message: "Error: %1 '%2' already has a deployment artifact of %3 type .Please delete or update an existing %4 artifact.",
messageId: "SVC4536"
}
-#---------SVC4537------------------------------
+ #---------SVC4537------------------------------
MISSING_HEAT: {
code: 400,
message: "Error: Missing HEAT artifact. HEAT_ENV artifact cannot be uploaded without corresponding HEAT template.",
messageId: "SVC4537"
}
-#---------SVC4538------------------------------
+ #---------SVC4538------------------------------
MISMATCH_HEAT_VS_HEAT_ENV: {
code: 400,
message: "Error: Invalid artifact content. Parameter's set in HEAT_ENV '%1' artifact doesn't match the parameters in HEAT '%2' artifact.",
messageId: "SVC4538"
}
-#---------SVC4539------------------------------
+ #---------SVC4539------------------------------
INVALID_RESOURCE_PAYLOAD: {
code: 400,
message: "Error: Invalid resource payload.",
messageId: "SVC4539"
}
-#---------SVC4540------------------------------
+ #---------SVC4540------------------------------
INVALID_TOSCA_FILE_EXTENSION: {
code: 400,
message: "Error: Invalid file extension for TOSCA template.",
messageId: "SVC4540"
}
-#---------SVC4541------------------------------
+ #---------SVC4541------------------------------
INVALID_YAML_FILE: {
code: 400,
message: "Error: Invalid YAML file.",
messageId: "SVC4541"
}
-#---------SVC4542------------------------------
+ #---------SVC4542------------------------------
INVALID_TOSCA_TEMPLATE: {
code: 400,
message: "Error: Invalid TOSCA template.",
messageId: "SVC4542"
}
-#---------SVC4543------------------------------
+ #---------SVC4543------------------------------
NOT_RESOURCE_TOSCA_TEMPLATE: {
code: 400,
message: "Error: Imported Service TOSCA template.",
messageId: "SVC4543"
}
-#---------SVC4544------------------------------
+ #---------SVC4544------------------------------
NOT_SINGLE_RESOURCE: {
code: 400,
message: "Error: Imported TOSCA template should contain one resource definition.",
messageId: "SVC4544"
}
-#---------SVC4545------------------------------
+ #---------SVC4545------------------------------
INVALID_RESOURCE_NAMESPACE: {
code: 400,
message: "Error: Invalid resource namespace.",
messageId: "SVC4545"
}
-#---------SVC4546------------------------------
+ #---------SVC4546------------------------------
RESOURCE_ALREADY_EXISTS: {
code: 400,
message: "Error: Imported resource already exists in ASDC Catalog.",
messageId: "SVC4546"
}
-#---------SVC4549------------------------------
+ #---------SVC4549------------------------------
INVALID_RESOURCE_CHECKSUM: {
code: 400,
message: "Error: Invalid resource checksum.",
messageId: "SVC4549"
}
-#---------SVC4550------------------------------
- #%1  -  Consumer salt
- INVALID_LENGTH: {
- code: 400,
- message: "Error: Invalid %1 length.",
- messageId: "SVC4550"
- }
#---------SVC4551------------------------------
- #%1  -  ECOMP User name
+ # %1  -  ECOMP User name
ECOMP_USER_NOT_FOUND: {
code: 404,
message: "Error: ECOMP User '%1' was not found.",
messageId: "SVC4551"
}
-#---------SVC4552------------------------------
- CONSUMER_ALREADY_EXISTS: {
- code: 409,
- message: "Error: ECOMP User already exists.",
- messageId: "SVC4552"
- }
-#---------SVC4553-----------------------------
- #%1  -  Consumer name / Consumer password/ Consumer salt
- INVALID_CONTENT_PARAM: {
- code: 400,
- message: "Error: %1 is invalid.",
- messageId: "SVC4553"
- }
#---------SVC4554------------------------------
-# %1 - "Resource"/"Service"
+ # %1 - Artifact Id
+ # %2 - "Resource"/"Service"
COMPONENT_ARTIFACT_NOT_FOUND: {
code: 404,
- message: "Error: Requested artifact doesn't belong to specified %1.",
+ message: "Error: Requested artifact %1 doesn't belong to specified %2.",
messageId: "SVC4554"
}
-#---------SVC4554------------------------------
-# %1 - "Service name"
+ #---------SVC4554------------------------------
+ # %1 - "Service name"
SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND: {
code: 403,
message: "Error: Requested '%1' service is not ready for certification. Service has to have at least one deployment artifact.",
messageId: "SVC4554"
}
-#---------SVC4555------------------------------
-#%1 - "Resource"/"Service"/"Product"
-#%2 - "category"
+ #---------SVC4555------------------------------
+ # %1 - "Resource"/"Service"/"Product"
+ # %2 - "category"
COMPONENT_ELEMENT_INVALID_NAME_LENGTH: {
code: 400,
message: "Error: Invalid %1 %2 name length.",
messageId: "SVC4555"
}
-#---------SVC4556------------------------------
-#%1 - "Resource"/"Service"/"Product"
-#%2 - "category"
+ #---------SVC4556------------------------------
+ # %1 - "Resource"/"Service"/"Product"
+ # %2 - "category"
COMPONENT_ELEMENT_INVALID_NAME_FORMAT: {
code: 400,
message: "Error: Invalid %1 %2 name format.",
messageId: "SVC4556"
}
-#---------SVC4557------------------------------
-#%1 - "Resource"/"Service"/"Product"
-#%2 - "category name"
+ #---------SVC4557------------------------------
+ # %1 - "Resource"/"Service"/"Product"
+ # %2 - "category name"
COMPONENT_CATEGORY_ALREADY_EXISTS: {
code: 409,
message: "Error: %1 category name '%2' already exists.",
messageId: "SVC4557"
}
-#---------SVC4558------------------------------
-# %1 - "service"/"VF"
-# %2 - "Resource name"
+ #---------SVC4558------------------------------
+ # %1 - "service"/"VF"
+ # %2 - "Resource name"
VALIDATED_RESOURCE_NOT_FOUND: {
code: 403,
message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource.",
messageId: "SVC4558"
}
-#---------SVC4559------------------------------
-# %1 - "service"/"VF"
-# %2 - "Resource name"
+ #---------SVC4559------------------------------
+ # %1 - "service"/"VF"
+ # %2 - "Resource name"
FOUND_ALREADY_VALIDATED_RESOURCE: {
code: 403,
message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource. Please use already available validated resource version.",
messageId: "SVC4559"
}
-#---------SVC4560------------------------------
-# %1 - "service"/"VF"
-# %2 - "Resource name"
+ #---------SVC4560------------------------------
+ # %1 - "service"/"VF"
+ # %2 - "Resource name"
FOUND_LIST_VALIDATED_RESOURCES: {
code: 403,
message: "Error: Submit for Testing is not permitted as your '%1' includes non-validated '%2' resource. Please use one of available validated resource versions.",
messageId: "SVC4560"
}
-#---------SVC4561------------------------------
-# %1 - "resource"/"product"
-# %2 - "category"
-# %3 - "category name"
+ #---------SVC4561------------------------------
+ # %1 - "resource"/"product"
+ # %2 - "category"
+ # %3 - "category name"
COMPONENT_CATEGORY_NOT_FOUND: {
code: 404,
message: "Error: Requested %1 %2 '%3' was not found.",
messageId: "SVC4561"
}
-#---------SVC4562------------------------------
-# %1 - "Resource"/"Product"
-# %2 - "sub-category name"
-# %3 - "category name"
+ #---------SVC4562------------------------------
+ # %1 - "Resource"/"Product"
+ # %2 - "sub-category name"
+ # %3 - "category name"
COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY: {
code: 409,
message: "Error: %1 sub-category '%2' already exists under '%3' category.",
messageId: "SVC4562"
}
-#---------SVC4563------------------------------
-# %1 - "Product"
-# %2 - "grouping name"
-# %3 - "sub-category name"
+ #---------SVC4563------------------------------
+ # %1 - "Product"
+ # %2 - "grouping name"
+ # %3 - "sub-category name"
COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY: {
code: 409,
message: "Error: %1 grouping '%2' already exists under '%3' sub-category.",
messageId: "SVC4563"
}
-#---------SVC4564------------------------------
-# %1 - product name
+ #---------SVC4564------------------------------
+ # %1 - product name
PRODUCT_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' product was not found.",
messageId: "SVC4564"
}
-#---------SVC4565------------------------------
-# %1 - "HEAT"
-# %2 - parameter type ("string" , "boolean" , "number")
-# %3 - parameter name
+ #---------SVC4565------------------------------
+ # %1 - "HEAT"
+ # %2 - parameter type ("string" , "boolean" , "number")
+ # %3 - parameter name
INVALID_HEAT_PARAMETER_VALUE: {
code: 400,
message: "Error: Invalid %1 artifact. Invalid %2 value set for '%3' parameter.",
messageId: "SVC4565"
}
-#---------SVC4566------------------------------
-# %1 - "HEAT"
-# %2 - parameter type ("string" , "boolean" , "number")
+ #---------SVC4566------------------------------
+ # %1 - "HEAT"
+ # %2 - parameter type ("string" , "boolean" , "number")
INVALID_HEAT_PARAMETER_TYPE: {
code: 400,
message: "Error: Invalid %1 artifact. Unsupported '%2' parameter type.",
messageId: "SVC4566"
}
-#---------SVC4567------------------------------
-# %1 - "YANG_XML"
+ #---------SVC4567------------------------------
+ # %1 - "YANG_XML"
INVALID_XML: {
code: 400,
message: "Error: Uploaded XML file for %1 artifact is invalid.",
messageId: "SVC4567"
}
-#---------SVC4567------------------------------
-# %1 - "User Name and UserId"
-# %2 -"checked-out"/"in-certification"
+ #---------SVC4569------------------------------
+ # %1 - "User Name and UserId"
+ # %2 -"component names ot IDs"
CANNOT_DELETE_USER_WITH_ACTIVE_ELEMENTS: {
- code: 409,
- message: "Error: User cannot be deleted. User '%1' has %2 projects.",
- messageId: "SVC4567"
+ code: 412,
+ message: "Error: User cannot be deleted. User '%1' has projects that cannot be committed: %2.",
+ messageId: "SVC4569"
}
-#---------SVC4568------------------------------
-# %1 - "User Name and UserId"
-# %2 -"checked-out"/"in-certification"
+ #---------SVC4568------------------------------
+ # %1 - "User Name and UserId"
+ # %2 -"checked-out"/"in-certification"
CANNOT_UPDATE_USER_WITH_ACTIVE_ELEMENTS: {
code: 409,
message: "Error: Role cannot be changed. User '%1' has %2 projects.",
messageId: "SVC4568"
}
-#---------SVC4570------------------------------
+ #---------SVC4570------------------------------
UPDATE_USER_ADMIN_CONFLICT: {
code: 409,
message: "Error: An administrator is not allowed to change his/her role.",
messageId: "SVC4570"
}
-#---------SVC4571------------------------------
+ #---------SVC4571------------------------------
SERVICE_CANNOT_CONTAIN_SUBCATEGORY: {
code: 400,
message: "Error: Sub category cannot be defined for service",
messageId: "SVC4571"
}
-#---------SVC4572------------------------------
-# %1 - "Resource"/"Service"
+ #---------SVC4572------------------------------
+ # %1 - "Resource"/"Service"
COMPONENT_TOO_MUCH_CATEGORIES: {
code: 400,
message: "Error: %1 must have only 1 category",
messageId: "SVC4572"
}
-#---------SVC4574------------------------------
+ #---------SVC4574------------------------------
RESOURCE_TOO_MUCH_SUBCATEGORIES: {
code: 400,
message: "Error: Resource must have only 1 sub category",
messageId: "SVC4574"
}
-#---------SVC4575------------------------------
+ #---------SVC4575------------------------------
COMPONENT_MISSING_SUBCATEGORY: {
code: 400,
message: "Error: Missing sub category",
messageId: "SVC4575"
}
- #---------SVC4576------------------------------
-# %1 - "component type"
+ #---------SVC4576------------------------------
+ # %1 - "component type"
UNSUPPORTED_ERROR: {
code: 400,
message: "Error : Requested component type %1 is unsupported.",
messageId: "SVC4576"
}
#---------SVC4577------------------------------
-# %1 - "resource type"
+ # %1 - "resource type"
RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES: {
code: 409,
message: "Error : Resource of type %1 cannot contain resource instances.",
messageId: "SVC4577"
}
-#---------SVC4578------------------------------
-# %1 - "Resource"/"Service"
-# %2 - resource/service name
-# %3 - "artifact name"
+ #---------SVC4578------------------------------
+ # %1 - "Resource"/"Service"
+ # %2 - resource/service name
+ # %3 - "artifact name"
DEPLOYMENT_ARTIFACT_NAME_ALREADY_EXISTS: {
code: 400,
message: "Error: %1 '%2' already has a deployment artifact named '%3'.",
messageId: "SVC4578"
}
-#---------SVC4579------------------------------
-# %1 - "Category"/"Sub-Category"/"Group"
-# %2 - category/sub-category/grouping name.
+ #---------SVC4579------------------------------
+ # %1 - "Category"/"Sub-Category"/"Group"
+ # %2 - category/sub-category/grouping name.
INVALID_GROUP_ASSOCIATION: {
code: 400,
message: "Error: Invalid group association. %1 '%2' was not found.",
messageId: "SVC4579"
}
-#---------SVC4580------------------------------
+ #---------SVC4580------------------------------
EMPTY_PRODUCT_CONTACTS_LIST: {
code: 400,
message: "Error: Invalid content. At least one Product Contact has to be specified.",
messageId: "SVC4580"
}
-#---------SVC4581------------------------------
-# %1 - UserId
+ #---------SVC4581------------------------------
+ # %1 - UserId
INVALID_PRODUCT_CONTACT: {
code: 400,
message: "Error: Invalid content. User '%1' cannot be set as Product Contact.",
messageId: "SVC4581"
}
-#---------SVC4582------------------------------
-# %1 - Product
-# %2 - "abbreviated"/"full"
+ #---------SVC4582------------------------------
+ # %1 - Product
+ # %2 - "abbreviated"/"full"
MISSING_ONE_OF_COMPONENT_NAMES: {
code: 400,
message: "Error: Invalid content. Missing %1 %2 name.",
messageId: "SVC4582"
}
-#---------SVC4583------------------------------
-# %1 - "Icon"
-# %2 - "resource"/"service"/"product"
+ #---------SVC4583------------------------------
+ # %1 - "Icon"
+ # %2 - "resource"/"service"/"product"
COMPONENT_PARAMETER_CANNOT_BE_CHANGED: {
code: 400,
message: "Error: %1 cannot be changed once the %2 is certified.",
messageId: "SVC4583"
}
-#---------SVC4584------------------------------
-# %1 - service/VF name
-# %2 - "service" /"VF"
-# %3 - resource instance origin type
-# %4 - resource instance name
-# %5 - requirement/capability
-# %6 - requirement/capability name
-# %7 - "fulfilled" (for req)/"consumed (for cap)"
+ #---------SVC4584------------------------------
+ # %1 - service/VF name
+ # %2 - "service" /"VF"
+ # %3 - resource instance origin type
+ # %4 - resource instance name
+ # %5 - requirement/capability
+ # %6 - requirement/capability name
+ # %7 - "fulfilled" (for req)/"consumed (for cap)"
REQ_CAP_NOT_SATISFIED_BEFORE_CERTIFICATION: {
code: 403,
message: "Error: Requested '%1' %2 is not ready for certification. %3 '%4' has to have %5 '%6' %7.",
messageId: "SVC4584"
}
-#---------SVC4585------------------------------
+ #---------SVC4585------------------------------
INVALID_OCCURRENCES: {
code: 400,
message: "Error: Invalid occurrences format.",
messageId: "SVC4585"
}
-#---------SVC4586------------------------------
-#---------SVC4586------------------------------
+ #---------SVC4586------------------------------
+ #---------SVC4586------------------------------
INVALID_SERVICE_API_URL: {
code: 400,
message: 'Error: Invalid Service API URL. Please check whether your URL has a valid domain extension and does not contain the following characters - #?&@%+;,=$<>~^`\[]{}|"*!',
messageId: "SVC4586"
}
-#---------SVC4587------------------------------
-# %1 - Data type name
+ #---------SVC4587------------------------------
+ # %1 - Data type name
DATA_TYPE_ALREADY_EXIST: {
code: 409,
message: 'Error: Data type %1 already exists.',
messageId: "SVC4587"
}
-#---------SVC4588------------------------------
-# %1 - Data type name
+ #---------SVC4588------------------------------
+ # %1 - Data type name
DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM: {
code: 400,
message: 'Error: Invalid Data type %1. Data type must have either a valid derived from declaration or at least one valid property',
messageId: "SVC4588"
}
-#---------SVC4589------------------------------
-# %1 - Data type name
+ #---------SVC4589------------------------------
+ # %1 - Data type name
DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY: {
code: 400,
message: "Error: Invalid Data type %1. 'properties' parameter cannot be empty if provided.",
messageId: "SVC4589"
}
-#---------SVC4590------------------------------
-# %1 - Property type name
-# %2 - Property name
+ #---------SVC4590------------------------------
+ # %1 - Property type name
+ # %2 - Property name
INVALID_PROPERTY_TYPE: {
code: 400,
message: "Error: Invalid Property type %1 in property %2.",
messageId: "SVC4590"
}
-#---------SVC4591------------------------------
-# %1 - Property inner type
-# %2 - Property name
+ #---------SVC4591------------------------------
+ # %1 - Property inner type
+ # %2 - Property name
INVALID_PROPERTY_INNER_TYPE: {
code: 400,
message: "Error: Invalid property inner type %1, in property %2",
messageId: "SVC4591"
}
-#---------SVC4592------------------------------
-# %1 - component instance name
-# %2 - "resource instance"/"service instance"
+ #---------SVC4592------------------------------
+ # %1 - component instance name
+ # %2 - "resource instance"/"service instance"
COMPONENT_INSTANCE_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' %2 was not found.",
messageId: "SVC4592"
}
-#---------SVC4593------------------------------
-# %1 - component instance name
-# %2 - "resource instance"/"service instance"
-# %3 - "resource/"service"/"product"
-# %4 - container name
+ #---------SVC4593------------------------------
+ # %1 - component instance name
+ # %2 - "resource instance"/"service instance"
+ # %3 - "resource/"service"/"product"
+ # %4 - container name
COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER: {
code: 404,
message: "Error: Requested '%1' %2 was not found on the %3 '%4'.",
messageId: "SVC4593"
}
-#---------SVC4594------------------------------
-#%1 - requirement / capability
-#%2 - requirement name
+ #---------SVC4594------------------------------
+ #%1 - requirement / capability
+ #%2 - requirement name
IMPORT_DUPLICATE_REQ_CAP_NAME: {
code: 400,
message: "Error: Imported TOSCA template contains more than one %1 named '%2'.",
messageId: "SVC4594"
}
-#---------SVC4595------------------------------
-#%1 - requirement / capability
-#%2 - requirement name
-#%3 - parent containing the requirement
+ #---------SVC4595------------------------------
+ #%1 - requirement / capability
+ #%2 - requirement name
+ #%3 - parent containing the requirement
IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED: {
code: 400,
message: "Error: Imported TOSCA template contains %1 '%2' that is already defined by derived template %3.",
messageId: "SVC4595"
}
-#---------SVC4596------------------------------
-# %1 - Data type name
+ #---------SVC4596------------------------------
+ # %1 - Data type name
DATA_TYPE_DERIVED_IS_MISSING: {
code: 400,
message: "Error: Invalid Content. The ancestor data type %1 cannot be found in the system.",
messageId: "SVC4596"
}
-#---------SVC4597------------------------------
-# %1 - Data type name
-# %2 - Property names
+ #---------SVC4597------------------------------
+ # %1 - Data type name
+ # %2 - Property names
DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR: {
code: 400,
message: "Error: Invalid Content. The data type %1 contains properties named %2 which are already defined in one of its ancestors.",
messageId: "SVC4597"
}
-#---------SVC4598------------------------------
-# %1 - Data type name
+ #---------SVC4598------------------------------
+ # %1 - Data type name
DATA_TYPE_DUPLICATE_PROPERTY: {
code: 400,
message: "Error: Invalid Content. The data type %1 contains duplicate property.",
messageId: "SVC4598"
}
-#---------SVC4599------------------------------
-# %1 - Data type name
-# %2 - Property names
+ #---------SVC4599------------------------------
+ # %1 - Data type name
+ # %2 - Property names
DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE: {
code: 400,
message: "Error: Invalid Content. The data type %1 contains properties %2 which their type is this data type.",
messageId: "SVC4599"
}
-#---------SVC4600------------------------------
-# %1 - Data type name
+ #---------SVC4600------------------------------
+ # %1 - Data type name
DATA_TYPE_CANNOT_HAVE_PROPERTIES: {
code: 400,
message: "Error: Invalid Content. The data type %1 cannot have properties since it is of type scalar",
messageId: "SVC4600"
}
-#---------SVC4601------------------------------
+ #---------SVC4601------------------------------
NOT_TOPOLOGY_TOSCA_TEMPLATE: {
code: 400,
message: "Error: TOSCA yaml file %1 cannot be modeled to VF as it does not contain 'topology_template.",
messageId: "SVC4601"
}
-#---------SVC4602--------------------------------
-# %1 - yaml file name
-# %2 - node_template label
-# %3 - node_template type
+ #---------SVC4602--------------------------------
+ # %1 - yaml file name
+ # %2 - node_template label
+ # %3 - node_template type
INVALID_NODE_TEMPLATE: {
code: 400,
message: "Error: TOSCA yaml file '%1' contains node_template '%2' of type '%3' that does not represent existing VFC/CP/VL",
messageId: "SVC4602"
}
-#---------SVC4603------------------------------
-# %1 - component type
-# %2 - component name
-# %3 - state
+ #---------SVC4603------------------------------
+ # %1 - component type
+ # %2 - component name
+ # %3 - state
ILLEGAL_COMPONENT_STATE: {
code: 403,
- message: "Error: Component instance of %1 can not be created because the component '%2' is in an illegal state %3.",
+ message: "Error: Action is not allowed on %1 '%2' because it is in an illegal state %3.",
messageId: "SVC4603"
}
-#---------SVC4604------------------------------
-# %1 - csar file name
+ #---------SVC4604------------------------------
+ # %1 - csar file name
CSAR_INVALID: {
code: 400,
message: "Error: TOSCA CSAR '%1' is invalid. 'TOSCA-Metadata/Tosca.meta' file must be provided.",
messageId: "SVC4604"
}
-#---------SVC4605------------------------------
-# %1 - csar file name
+ #---------SVC4605------------------------------
+ # %1 - csar file name
CSAR_INVALID_FORMAT: {
code: 400,
message: "Error: TOSCA CSAR '%1' is invalid. Invalid 'TOSCA-Metadata/Tosca.meta' file format.",
messageId: "SVC4605"
}
-#---------SVC4606------------------------------
-# %1 - property name
-# %2 - property type
-# %3 - property innerType
-# %4 - default value is
+ #---------SVC4606------------------------------
+ # %1 - property name
+ # %2 - property type
+ # %3 - property innerType
+ # %4 - default value is
INVALID_COMPLEX_DEFAULT_VALUE: {
code: 400,
message: "Error: Invalid default value of property %1. Data type is %2 with inner type %3 and default value found is %4.",
messageId: "SVC4606"
}
-#---------SVC4607------------------------------
-# %1 - csar file name
+ #---------SVC4607------------------------------
+ # %1 - csar file name
CSAR_NOT_FOUND: {
code: 400,
message: "Error: TOSCA CSAR '%1' is not found.",
messageId: "SVC4607"
}
-#---------SVC4608------------------------------
-# %1 - artifact name
-# %2 - component type
-# %3 - actual component type
+ #---------SVC4608------------------------------
+ # %1 - artifact name
+ # %2 - component type
+ # %3 - actual component type
MISMATCH_BETWEEN_ARTIFACT_TYPE_AND_COMPONENT_TYPE: {
code: 400,
message: "Error: Artifact %1 is only compatible with component of type %2, but component type is %3.",
messageId: "SVC4608"
}
-#---------SVC4609------------------------------
-# %1 - "INVALID_JSON"
+ #---------SVC4609------------------------------
+ # %1 - "INVALID_JSON"
INVALID_JSON: {
code: 400,
message: "Error: Uploaded JSON file for %1 artifact is invalid.",
messageId: "SVC4609"
}
-#---------SVC4610------------------------------
-# %1 - csar file name
-# %2 - missing file name
+ #---------SVC4610------------------------------
+ # %1 - csar file name
+ # %2 - missing file name
YAML_NOT_FOUND_IN_CSAR: {
code: 400,
message: "Error - TOSCA CSAR %1 is invalid. TOSCA-Metadata/Tosca.meta refers to file %2 that is not provided.",
messageId: "SVC4610"
}
-#---------SVC4611------------------------------
-# %1 - group name
+ #---------SVC4611------------------------------
+ # %1 - group name
GROUP_MEMBER_EMPTY: {
code: 400,
message: "Error: Invalid Content. Group %1 member list was provided but does not have values",
messageId: "SVC4611"
}
-#---------SVC4612------------------------------
-# %1 - group name
+ #---------SVC4612------------------------------
+ # %1 - group name
GROUP_TYPE_ALREADY_EXIST: {
code: 409,
message: 'Error: Group type %1 already exists.',
messageId: "SVC4612"
}
-#---------SVC4613------------------------------
-# %1 - group name
-# %2 - VF name(component name)
-# %3 - actual component type [VF]
+ #---------SVC4613------------------------------
+ # %1 - group name
+ # %2 - VF name(component name)
+ # %3 - actual component type [VF]
GROUP_ALREADY_EXIST: {
code: 409,
message: "Error: Group with name '%1' already exists in %2 %3.",
messageId: "SVC4613"
}
-#---------SVC4614------------------------------
-# %1 - group type
+ #---------SVC4614------------------------------
+ # %1 - group type
GROUP_TYPE_IS_INVALID: {
code: 400,
message: "Error: Invalid content. Group type %1 does not exist",
messageId: "SVC4614"
}
-#---------SVC4615------------------------------
-# %1 - group name
+ #---------SVC4615------------------------------
+ # %1 - group name
GROUP_MISSING_GROUP_TYPE: {
code: 400,
message: "Error: Invalid Content. Missing Group Type for group '%1'",
messageId: "SVC4615"
}
-#---------SVC4616------------------------------
-# %1 - member name
-# %2 - group name
-# %3 - VF name
-# %4 - component type [VF ]
+ #---------SVC4616------------------------------
+ # %1 - member name
+ # %2 - group name
+ # %3 - VF name
+ # %4 - component type [VF ]
GROUP_INVALID_COMPONENT_INSTANCE: {
code: 400,
message: "Error: Member '%1' listed in group '%2' is not part of '%3' %4.",
messageId: "SVC4616"
}
-#---------SVC4617------------------------------
-# %1 - member name
-# %2 - group name
-# %3 - group type
+ #---------SVC4617------------------------------
+ # %1 - member name
+ # %2 - group name
+ # %3 - group type
GROUP_INVALID_TOSCA_NAME_OF_COMPONENT_INSTANCE: {
code: 400,
message: "Error: member %1 listed in group %2 is not part of allowed members of group type %3.",
messageId: "SVC4617"
}
-#---------SVC4618------------------------------
-# %1 - missing file name
-# %2 - csar file name
+ #---------SVC4618------------------------------
+ # %1 - missing file name
+ # %2 - csar file name
ARTIFACT_NOT_FOUND_IN_CSAR: {
code: 400,
message: "Error: artifact %1 is defined in CSAR %2 manifest but is not provided",
@@ -1458,424 +1445,398 @@ errors:
message: "Error: artifact %1 in type %2 already exists in type %3.",
messageId: "SVC4619"
}
-#---------SVC4620------------------------------
+ #---------SVC4620------------------------------
FAILED_RETRIVE_ARTIFACTS_TYPES: {
code: 400,
message: "Error: Failed to retrieve list of suported artifact types.",
messageId: "SVC4620"
}
-#---------SVC4621------------------------------
-# %1 - artifact name
-# %2 - master
+ #---------SVC4621------------------------------
+ # %1 - artifact name
+ # %2 - master
ARTIFACT_ALRADY_EXIST_IN_MASTER_IN_CSAR: {
code: 400,
message: "Error: artifact %1 already exists in master %2 .",
messageId: "SVC4621"
}
-#---------SVC4622------------------------------
-# %1 - artifact name
-# %2 - artifact type
-# %3 - master name
-# %4 - master type
+ #---------SVC4622------------------------------
+ # %1 - artifact name
+ # %2 - artifact type
+ # %3 - master name
+ # %4 - master type
ARTIFACT_NOT_VALID_IN_MASTER: {
code: 400,
message: "Error: artifact %1 in type %2 can not be exists under master %3 in type %4.",
messageId: "SVC4622"
}
-#---------SVC4623------------------------------
-# %1 - artifact name
-# %2 - artifact type
-# %3 - env name
-# %4 - existing env
+ #---------SVC4623------------------------------
+ # %1 - artifact name
+ # %2 - artifact type
+ # %3 - env name
+ # %4 - existing env
ARTIFACT_NOT_VALID_ENV: {
code: 400,
message: "Error: Artifact %1 in type %2 with env %3 already exists with another env %4",
messageId: "SVC4623"
}
-#---------SVC4624------------------------------
-# %1 - groups names
-# %2 - VF name
-# %3 - component type [VF ]
+ #---------SVC4624------------------------------
+ # %1 - groups names
+ # %2 - VF name
+ # %3 - component type [VF ]
GROUP_IS_MISSING: {
code: 400,
message: "Error: Invalid Content. The groups '%1' cannot be found under %2 %3.",
messageId: "SVC4624"
}
-#---------SVC4625------------------------------
-# %1 - groups name
+ #---------SVC4625------------------------------
+ # %1 - groups name
GROUP_ARTIFACT_ALREADY_ASSOCIATED: {
code: 400,
message: "Error: Invalid Content. Artifact already associated to group '%1'.",
messageId: "SVC4625"
}
-#---------SVC4626------------------------------
-# %1 - groups name
+ #---------SVC4626------------------------------
+ # %1 - groups name
GROUP_ARTIFACT_ALREADY_DISSOCIATED: {
code: 400,
message: "Error: Invalid Content. Artifact already dissociated from group '%1'.",
messageId: "SVC4626"
}
-#---------SVC4627------------------------------
-# %1 - property name
-# %2 - group name
-# %3 - group type name
+ #---------SVC4627------------------------------
+ # %1 - property name
+ # %2 - group name
+ # %3 - group type name
GROUP_PROPERTY_NOT_FOUND: {
code: 400,
message: "Error: property %1 listed in group %2 is not exist in group type %3.",
messageId: "SVC4627"
}
-#---------SVC4628------------------------------
-# %1 - csarUUID
-# %2 - VF name
+ #---------SVC4628------------------------------
+ # %1 - csarUUID
+ # %2 - VF name
VSP_ALREADY_EXISTS: {
code: 400,
message: "Error: The VSP with UUID %1 was already imported for VF %2. Please select another or update the existing VF.",
messageId: "SVC4628"
}
-#---------SVC4629------------------------------
-# %1 - VF name
+ #---------SVC4629------------------------------
+ # %1 - VF name
MISSING_CSAR_UUID: {
code: 400,
message: "Error: The Csar UUID or payload name is missing for VF %1.",
messageId: "SVC4629"
}
-#---------SVC4630------------------------------
-# %1 - VF name
-# %2 - new csarUUID
-# %3 - old csarUUID
+ #---------SVC4630------------------------------
+ # %1 - VF name
+ # %2 - new csarUUID
+ # %3 - old csarUUID
RESOURCE_LINKED_TO_DIFFERENT_VSP: {
code: 400,
message: "Error: Resource %1 cannot be updated using CsarUUID %2 since the resource is linked to a different VSP with csarUUID %3.",
messageId: "SVC4630"
}
-#---------SVC4631------------------------------
-# %1 - policy name
+ #---------SVC4631------------------------------
+ # %1 - policy name
POLICY_TYPE_ALREADY_EXIST: {
code: 409,
message: "Error: Policy type %1 already exists.",
messageId: "SVC4631"
}
-#---------SVC4632------------------------------
-# %1 - target name
-# %2 - policy type name
+ #---------SVC4632------------------------------
+ # %1 - target name
+ # %2 - policy type name
TARGETS_NON_VALID: {
code: 400,
message: "Error: target %1 listed in policy type %2 is not a group or resource.",
messageId: "SVC4632"
}
-#---------SVC4633------------------------------
-# %1 - policy name
+ #---------SVC4633------------------------------
+ # %1 - policy name
TARGETS_EMPTY: {
code: 400,
message: "Error: Invalid Content. Policy %1 target list was provided but does not have values",
messageId: "SVC4633"
}
-#---------SVC4634------------------------------
+ #---------SVC4634------------------------------
DATA_TYPE_CANNOT_BE_EMPTY: {
code: 500,
message: "Error: Data types are empty. Please import the data types.",
messageId: "SVC4634"
}
-#---------SVC4635------------------------------
-# %1 - csar uuid
+ #---------SVC4635------------------------------
+ # %1 - csar uuid
RESOURCE_FROM_CSAR_NOT_FOUND: {
code: 400,
message: "Error: resource from csar uuid %1 not found",
messageId: "SVC4635"
}
-#---------SVC4636------------------------------
-# %1 - Data type name
+ #---------SVC4636------------------------------
+ # %1 - Data type name
DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST: {
code: 400,
message: 'Error: Data type %1 cannot be upgraded. The new data type does not contain old properties or the type of one of the properties has been changed.',
messageId: "SVC4636"
}
-#-----------SVC4637---------------------------
-#%1 - attribute name
+ #-----------SVC4637---------------------------
+ #%1 - attribute name
ATTRIBUTE_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' attribute was not found.",
messageId: "SVC4637"
}
-#-----------SVC4638---------------------------
-#%1 - attribute name
+ #-----------SVC4638---------------------------
+ #%1 - attribute name
ATTRIBUTE_ALREADY_EXIST: {
code: 409,
message: "Error: Attribute with '%1' name already exists.",
messageId: "SVC4638"
}
-#-----------SVC4639---------------------------
-#%1 - property name
+ #-----------SVC4639---------------------------
+ #%1 - property name
PROPERTY_NAME_ALREADY_EXISTS: {
code: 409,
message: "Error: Property with '%1' name and different type already exists.",
messageId: "SVC4639"
}
-#-----------SVC4640---------------------------
-#%1 - property name
+ #-----------SVC4640---------------------------
+ #%1 - property name
INVALID_PROPERTY: {
code: 409,
message: "Error: Invalid property received.",
messageId: "SVC4640"
}
-#---------SVC4641-----------------------------
-#%1 - invalid filter
-#%2 - valid filters
+ #---------SVC4641-----------------------------
+ #%1 - invalid filter
+ #%2 - valid filters
INVALID_FILTER_KEY: {
code: 400,
message: "Error: The filter %1 is not applicable. Please use one of the following filters: %2",
messageId: "SVC4641"
}
-#---------SVC4642-----------------------------
-#%1 - asset type
-#%2 - filter
+ #---------SVC4642-----------------------------
+ #%1 - asset type
+ #%2 - filter
NO_ASSETS_FOUND: {
code: 404,
message: "No %1 were found to match criteria %2",
messageId: "SVC4642"
}
-#---------SVC4643------------------------------
-# %1 - "Resource"/"Product"
-# %2 - "sub-category name"
-# %3 - "category name"
+ #---------SVC4643------------------------------
+ # %1 - "Resource"/"Product"
+ # %2 - "sub-category name"
+ # %3 - "category name"
COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY: {
code: 404,
message: "Error: %1 sub-category '%2' not found under category '%3'.",
messageId: "SVC4643"
}
-#---------SVC4644------------------------------
-# %1 - Format
+ #---------SVC4644------------------------------
+ # %1 - Format
CORRUPTED_FORMAT: {
code: 400,
message: "Error: %1 format is corrupted.",
messageId: "SVC4644"
}
-#---------SVC4645------------------------------
-# %1 - "groupType"
+ #---------SVC4645------------------------------
+ # %1 - "groupType"
INVALID_VF_MODULE_TYPE: {
code: 400,
message: "Error: Invalid group type '%1' (should be VfModule).",
messageId: "SVC4645"
}
-#---------SVC4646------------------------------
-# %1 - "groupName"
+ #---------SVC4646------------------------------
+ # %1 - "groupName"
INVALID_VF_MODULE_NAME: {
code: 400,
message: "Error: Invalid Content. Group name '%1' contains invalid characters",
messageId: "SVC4646"
}
-#---------SVC4647------------------------------
-# %1 - "modifiedName"
+ #---------SVC4647------------------------------
+ # %1 - "modifiedName"
INVALID_VF_MODULE_NAME_MODIFICATION: {
code: 400,
message: "Error: Invalid VF Module name modification, can not modify '%1'",
messageId: "SVC4647"
}
-#---------SVC4648------------------------------
-# %1 - "inputId"
-# %2 - "componentId"
+ #---------SVC4648------------------------------
+ # %1 - "inputId"
+ # %2 - "componentId"
INPUT_IS_NOT_CHILD_OF_COMPONENT: {
code: 400,
message: "Error: Input id: '%1' is not child of component id: '%2'",
messageId: "SVC4648"
}
-#---------SVC4649------------------------------
-# %1 - "groupName"
+ #---------SVC4649------------------------------
+ # %1 - "groupName"
GROUP_HAS_CYCLIC_DEPENDENCY: {
code: 400,
message: "Error: The group '%1' has cyclic dependency",
messageId: "SVC4649"
}
-#---------SVC4650------------------------------
-# %1 - "Component Type"
-# %2 - <ServiceName>
-# %3 - error description
+ #---------SVC4650------------------------------
+ # %1 - "Component Type"
+ # %2 - <ServiceName>
+ # %3 - error description
AAI_ARTIFACT_GENERATION_FAILED: {
code: 500,
message: "Error: %1 %2 automatic generation of artifacts failed. Description: %3",
messageId: "SVC4650"
}
-#---------SVC4651------------------------------
+ #---------SVC4651------------------------------
PARENT_RESOURCE_DOES_NOT_EXTEND: {
code: 400,
message: "Error: Once resource is certified, derived_from can be changed only to a sibling",
messageId: "SVC4651"
}
-#---------SVC4652------------------------------
-# %1 - resource/service
+ #---------SVC4652------------------------------
+ # %1 - resource/service
COMPONENT_INVALID_SUBCATEGORY: {
code: 400,
message: "Error: Invalid Content. Invalid %1 sub category.",
messageId: "SVC4652"
}
-#---------SVC4653------------------------------
-# %1 - group instance uniqueId
-# %2 - service uniqueId
+ #---------SVC4653------------------------------
+ # %1 - group instance uniqueId
+ # %2 - service uniqueId
GROUP_INSTANCE_NOT_FOUND_ON_COMPONENT_INSTANCE: {
code: 404,
message: "Error: Requested group instance %1 was not found on component %2.",
messageId: "SVC4653"
}
-#---------SVC4654------------------------------
-# %1 - group property name
-# %2 - valid min limit value
-# %3 - valid max limit value
+ #---------SVC4654------------------------------
+ # %1 - group property name
+ # %2 - valid min limit value
+ # %3 - valid max limit value
INVALID_GROUP_MIN_MAX_INSTANCES_PROPERTY_VALUE: {
code: 400,
message: "Error: Value of %1 must be not higher than %2, and not lower than %3.",
messageId: "SVC4654"
}
-#---------SVC4655------------------------------
-# %1 - group property name
-# %2 - valid min limit value
-# %3 - valid max limit value
+ #---------SVC4655------------------------------
+ # %1 - group property name
+ # %2 - valid min limit value
+ # %3 - valid max limit value
INVALID_GROUP_INITIAL_COUNT_PROPERTY_VALUE: {
code: 400,
message: "Error: Value of %1 must be between %2 and %3.",
messageId: "SVC4655"
}
-#---------SVC4656------------------------------
-# %1 - group property name
-# %2 - lower/higher
-# %3 - valid max/min value
+ #---------SVC4656------------------------------
+ # %1 - group property name
+ # %2 - lower/higher
+ # %3 - valid max/min value
INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER: {
code: 400,
message: "Error: Value of %1 must be %2 or equals to %3.",
messageId: "SVC4656"
}
-#---------SVC4657------------------------------
-# %1 - certificationRequest / startTesting
+ #---------SVC4657------------------------------
+ # %1 - certificationRequest / startTesting
RESOURCE_VFCMT_LIFECYCLE_STATE_NOT_VALID: {
code: 400,
message: "Error - Lifecycle state %1 is not valid for resource of type VFCMT",
messageId: "SVC4657"
}
-#---------SVC4658------------------------------
-# %1 – asset type [service / resource ]
-# %2 – main asset uuid
-# %3 – not found asset type [service / resource]
-# %4 – not found asset name
+ #---------SVC4658------------------------------
+ # %1 – asset type [service / resource ]
+ # %2 – main asset uuid
+ # %3 – not found asset type [service / resource]
+ # %4 – not found asset name
ASSET_NOT_FOUND_DURING_CSAR_CREATION: {
code: 400,
message: "Error: CSAR packaging failed for %1 %2. %3 %4 was not found",
messageId: "SVC4658"
}
-#---------SVC4659------------------------------
-# %1 – asset type [service / resource ]
-# %2 – main asset uuid
-# %3 – Artifact name
-# %4 – Artifact uuid
+ #---------SVC4659------------------------------
+ # %1 – asset type [service / resource ]
+ # %2 – main asset uuid
+ # %3 – Artifact name
+ # %4 – Artifact uuid
ARTIFACT_PAYLOAD_NOT_FOUND_DURING_CSAR_CREATION: {
code: 400,
message: "Error: CSAR packaging failed for %1 %2. Artifact %3 [%4] was not found",
messageId: "SVC4659"
}
-#---------SVC4660------------------------------
-# %1 - assetType
-# %2 - matching generic node type name
+ #---------SVC4660------------------------------
+ # %1 - assetType
+ # %2 - matching generic node type name
GENERIC_TYPE_NOT_FOUND: {
code: 404,
message: "Creation of %1 failed. Generic type %2 was not found",
messageId: "SVC4660"
}
-#---------SVC4661------------------------------
-# %1 - assetType
-# %2 - matching generic node type name
+ #---------SVC4661------------------------------
+ # %1 - assetType
+ # %2 - matching generic node type name
TOSCA_SCHEMA_FILES_NOT_FOUND: {
code: 400,
message: "Error: CSAR packaging failed. TOSCA schema files for SDC-Version: %1 and Conformance-Level %2 were not found",
messageId: "SVC4661"
}
-#---------SVC4662------------------------------
-# %1 - file name
-# %2 - parser error
+ #---------SVC4662------------------------------
+ # %1 - file name
+ # %2 - parser error
TOSCA_PARSE_ERROR: {
code: 400,
message: "Error: Invalid TOSCA template in file %1. %2",
messageId: "SVC4662"
}
-#---------SVC4663------------------------------
-# %1 - max length
+ #---------SVC4663------------------------------
+ # %1 - max length
RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT: {
code: 400,
message: "Error: Invalid Content. Resource vendor model number exceeds limit of %1 characters.",
messageId: "SVC4663"
}
-#---------SVC4664------------------------------
+ #---------SVC4664------------------------------
INVALID_RESOURCE_VENDOR_MODEL_NUMBER: {
code: 400,
message: 'Error: Invalid Content. Resource vendor model number is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
messageId: "SVC4664"
}
-#---------SVC4665------------------------------
-# %1 - max length
- SERVICE_TYPE_EXCEEDS_LIMIT: {
- code: 400,
- message: "Error: Invalid Content. Service type exceeds limit of %1 characters.",
- messageId: "SVC4665"
- }
-#---------SVC4666------------------------------
- INVALID_SERVICE_TYPE: {
- code: 400,
- message: 'Error: Invalid Content. Serivce type is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
- messageId: "SVC4666"
- }
-#---------SVC4667------------------------------
-# %1 - max length
- SERVICE_ROLE_EXCEEDS_LIMIT: {
- code: 400,
- message: "Error: Invalid Content. Service role exceeds limit of %1 characters.",
- messageId: "SVC4667"
- }
-#---------SVC4668------------------------------
- INVALID_SERVICE_ROLE: {
- code: 400,
- message: 'Error: Invalid Content. Service role is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
- messageId: "SVC4668"
- }
-#---------SVC4669-----------------------------
+ #---------SVC4669-----------------------------
INVALID_RESOURCE_TYPE: {
code: 400,
message: "Error: Invalid resource type.",
messageId: "SVC4669"
}
-#---------SVC4670------------------------------
+ #---------SVC4670------------------------------
ARTIFACT_NAME_INVALID: {
code: 400,
message: "Error: Artifact name is invalid.",
messageId: "SVC4670"
}
-#---------SVC4671------------------------------
-# %1 - VSP name
-# %2 - VFC name
+ #---------SVC4671------------------------------
+ # %1 - VSP name
+ # %2 - VFC name
CFVC_LOOP_DETECTED: {
code: 400,
message: 'Error: VSP %1 cannot be imported. The VSP contains internal loop in VFC %2',
messageId: "SVC4671"
}
-#---------SVC4672------------------------------
-# %1 - capability uniqueId
-# %2 - instance uniqueId
-# %3 - container uniqueId
+ #---------SVC4672------------------------------
+ # %1 - capability uniqueId
+ # %2 - instance uniqueId
+ # %3 - container uniqueId
CAPABILITY_OF_INSTANCE_NOT_FOUND_ON_CONTAINER: {
code: 404,
message: "Error: Requested capability %1 of instance %2 was not found on the container %3.",
messageId: "SVC4672"
}
-#---------SVC4673------------------------------
-# %1 - requirement uniqueId
-# %2 - instance uniqueId
-# %3 - container uniqueId
+ #---------SVC4673------------------------------
+ # %1 - requirement uniqueId
+ # %2 - instance uniqueId
+ # %3 - container uniqueId
REQUIREMENT_OF_INSTANCE_NOT_FOUND_ON_CONTAINER: {
code: 404,
message: "Error: Requested requirement %1 of instance %2 was not found on the container %3.",
messageId: "SVC4673"
}
-#---------SVC4674-----------------------------
-# %1 - relation Id
-# %2 - container uniqueId
+ #---------SVC4674-----------------------------
+ # %1 - relation Id
+ # %2 - container uniqueId
RELATION_NOT_FOUND: {
code: 404,
message: "Error: Requested relation %1 was not found on the container %2.",
@@ -1883,168 +1844,168 @@ errors:
}
-#---------SVC4675------------------------------
+ #---------SVC4675------------------------------
INVALID_SERVICE_STATE: {
code: 409,
message: "Service state is invalid for this action",
messageId: "SVC4675"
}
-#---------SVC4676------------------------------
+ #---------SVC4676------------------------------
INVALID_RESPONSE_FROM_PROXY: {
code: 502,
message: "Error: The server was acting as a gateway or proxy and received an invalid response from the upstream server",
messageId: "SVC4676"
}
-#---------SVC4677------------------------------
+ #---------SVC4677------------------------------
API_RESOURCE_NOT_FOUND: {
code: 404,
message: "Error: Requested '%1' was not found.",
messageId: "SVC4677"
}
-#---------SVC4678------------------------------
+ #---------SVC4678------------------------------
BAD_REQUEST_MISSING_RESOURCE: {
code: 400,
message: "Error: The required resource name/id is missing in the request",
messageId: "SVC4678"
}
-#---------SVC4679------------------------------
-# %1 forwarding path name maximum length
+ #---------SVC4679------------------------------
+ # %1 forwarding path name maximum length
FORWARDING_PATH_NAME_MAXIMUM_LENGTH: {
code: 400,
message: "Forwarding path name too long, , maximum allowed 200 characters : '%1'.",
messageId: "SVC4679"
}
-#---------SVC4680------------------------------
-# %1 Forwarding path name already in use
+ #---------SVC4680------------------------------
+ # %1 Forwarding path name already in use
FORWARDING_PATH_NAME_ALREADY_IN_USE: {
code: 400,
message: "Forwarding path name already in use : '%1'.",
messageId: "SVC4680"
}
-#---------SVC4681------------------------------
-# %1 Forwarding path name empty
+ #---------SVC4681------------------------------
+ # %1 Forwarding path name empty
FORWARDING_PATH_NAME_EMPTY: {
code: 400,
message: "Forwarding Path Name can't be empty .",
messageId: "SVC4681"
}
-#---------SVC4682------------------------------
-# %1 - resource uniqueId
-# %2 - resource component type
+ #---------SVC4682------------------------------
+ # %1 - resource uniqueId
+ # %2 - resource component type
RESOURCE_CANNOT_CONTAIN_POLICIES: {
code: 400,
message: "Error: The resource %1 type of %2 cannot contain policies.",
messageId: "SVC4682"
}
-#---------SVC4683------------------------------
-# %1 - policy uniqueId
-# %2 - component uniqueId
+ #---------SVC4683------------------------------
+ # %1 - policy uniqueId
+ # %2 - component uniqueId
POLICY_NOT_FOUND_ON_CONTAINER: {
code: 404,
message: "Error: Requested policy %1 was not found on the container %2.",
messageId: "SVC4683"
-}
-#---------SVC4684------------------------------
-# %1 - policy name
+ }
+ #---------SVC4684------------------------------
+ # %1 - policy name
INVALID_POLICY_NAME: {
code: 400,
message: "Error: Invalid policy name %1 received.",
messageId: "SVC4684"
}
-#---------SVC4685------------------------------
-# %1 - policy name
+ #---------SVC4685------------------------------
+ # %1 - policy name
POLICY_NAME_ALREADY_EXIST: {
code: 409,
message: "Error: The policy with the name %1 already exists.",
messageId: "SVC4685"
}
-#---------SVC4686------------------------------
-# %1 - policy name
+ #---------SVC4686------------------------------
+ # %1 - policy name
POLICY_TARGET_DOES_NOT_EXIST: {
code: 400,
message: "Error: The targets %1 are not valid, all targets have to be on the topologyTemplate.",
messageId: "SVC4686"
}
-#---------SVC4687------------------------------
-# %1 - policy type
-# %2 - component type
+ #---------SVC4687------------------------------
+ # %1 - policy type
+ # %2 - component type
EXCLUDED_POLICY_TYPE: {
code: 400,
message: "Error: The policy of the type %1 excluded to add to a component of the type %2.",
messageId: "SVC4687"
}
#---------SVC4688------------------------------
-# %1 - group type
-# %2 - component type
+ # %1 - group type
+ # %2 - component type
GROUP_TYPE_ILLEGAL_PER_COMPONENT: {
code: 400,
message: "Error: group type %1 not permitted in component of type %2",
messageId: "SVC4688"
}
#---------SVC4689------------------------------
-# %1 - group type
-# %2 - component type
+ # %1 - group type
+ # %2 - component type
POLICY_TARGET_TYPE_DOES_NOT_EXIST: {
code: 400,
message: "Error: The target types %1 are not valid.",
messageId: "SVC4689"
}
-#---------SVC4690------------------------------
-# %1 forwarding path protocol maximum length
+ #---------SVC4690------------------------------
+ # %1 forwarding path protocol maximum length
FORWARDING_PATH_PROTOCOL_MAXIMUM_LENGTH: {
code: 400,
message: "Forwarding path protocol too long, , maximum allowed 200 characters : '%1'.",
messageId: "SVC4690"
}
-#---------SVC4691------------------------------
-# %1 forwarding path destination port maximum length
+ #---------SVC4691------------------------------
+ # %1 forwarding path destination port maximum length
FORWARDING_PATH_DESTINATION_PORT_MAXIMUM_LENGTH: {
code: 400,
message: "Forwarding path destination port too long, , maximum allowed 200 characters : '%1'.",
messageId: "SVC4691"
}
-#---------POL4692------------------------------
+ #---------POL4692------------------------------
MISSING_OLD_COMPONENT_INSTANCE: {
code: 400 ,
message: "Error: Missing 'componentInstanceId' HTTP param.",
messageId: "POL4692"
}
-#---------POL4693------------------------------
+ #---------POL4693------------------------------
MISSING_NEW_COMPONENT_INSTANCE: {
code: 400 ,
message: "Error: Missing 'newComponentInstanceId' HTTP param.",
messageId: "POL4693"
}
-#---------SVC4694------------------------------
-# %1 External Reference Value
+ #---------SVC4694------------------------------
+ # %1 External Reference Value
EXT_REF_NOT_FOUND: {
code: 404,
message: "Error: External Reference '%1' was not found.",
messageId: "SVC4694"
}
-#---------SVC4695-----------------------------
-# %1 - Interface Operation Name
+ #---------SVC4695-----------------------------
+ # %1 - Interface Operation Name
INTERFACE_OPERATION_NAME_ALREADY_IN_USE: {
code: 409,
message: "Error: Interface Operation name '%1' already in use, Your current changes will not be saved.",
messageId: "SVC4695"
}
-#---------SVC4696-----------------------------
-# %1 - Interface Operation Name
+ #---------SVC4696-----------------------------
+ # %1 - Interface Operation Name
INTERFACE_OPERATION_NAME_INVALID: {
code: 400,
message: "Error: Interface Operation name '%1' is Invalid, Operation name should not contain special character, space and should not be greater than 200 characters.",
messageId: "SVC4696"
}
-#---------SVC4697-----------------------------
+ #---------SVC4697-----------------------------
INTERFACE_OPERATION_NAME_MANDATORY: {
code: 400,
message: "Error: Interface Operation name is mandatory, Operation name can't be empty.",
@@ -2057,14 +2018,14 @@ errors:
message: "Error: Invalid input, only one operation is allowed in local interface type '%1'.",
messageId: "SVC4698"
}
-#---------SVC4699-----------------------------
-# %1 - Interface Operation input parameter name
+ #---------SVC4699-----------------------------
+ # %1 - Interface Operation input parameter name
INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE: {
- code: 400,
- message: "Error: Interface Operation input parameter name '%1' already in use, Your current changes will not be saved.",
- messageId: "SVC4699"
+ code: 400,
+ message: "Error: Interface Operation input parameter name '%1' already in use, Your current changes will not be saved.",
+ messageId: "SVC4699"
}
-#---------SVC4700-----------------------------
+ #---------SVC4700-----------------------------
INTERFACE_OPERATION_INPUT_NAME_MANDATORY: {
code: 400,
message: "Error: Interface operation input parameter name should not be empty.",
@@ -2077,61 +2038,68 @@ errors:
message: "Error: Interface operation not found in the component '%1'.",
messageId: "SVC4701"
}
-#---------SVC4702-----------------------------
+ #---------SVC4702-----------------------------
INTERFACE_OPERATION_NOT_DELETED: {
code: 400,
message: "Error: Failed to delete interface operation.",
messageId: "SVC4702"
}
-#-----------SVC4692---------------------------
+ #-----------SVC4692---------------------------
RESOURCE_LIFECYCLE_STATE_NOT_VALID: {
code: 400,
message: "Error: Lifecycle state %1 is not valid for resource",
messageId: "SVC4692"
}
-#-----------SVC4693---------------------------
-#%1 - component name
+ #-----------SVC4693---------------------------
+ #%1 - component name
COMPONENT_IS_ARCHIVED: {
code: 400,
- message: "Error: Component %1 is arhived",
+ message: "Error: Component %1 is archived",
messageId: "SVC4693"
}
-#-----------SVC4703---------------------------
-#%1 - component name
+ #-----------SVC4703---------------------------
+ #%1 - component name
COMPONENT_IS_NOT_HIHGEST_CERTIFIED: {
code: 400,
message: "Error: Component %1 is not highest certified",
messageId: "SVC4703"
}
-#---------SVC4704------------------------------
-# %1 - "service"/"VF"
-# %2 - "Resource name"
+ #---------SVC4704------------------------------
+ # %1 - "service"/"VF"
+ # %2 - "Resource name"
ARCHIVED_ORIGINS_FOUND: {
code: 403,
message: "Error: Action is not permitted as your '%1' '%2' includes archived resources",
messageId: "SVC4704"
}
-#---------SVC4705------------------------------
-# %1-artifact name
+ #---------SVC4705------------------------------
+ # %1-artifact name
ARTIFACT_PAYLOAD_EMPTY: {
code: 400,
message: "Error: Invalid content. Uploaded file %1 is empty. Please retry with the correct file.",
messageId: "SVC4705"
}
-#---------SVC4706------------------------------
-# %1-input(s) name(s) string
+ #---------SVC4800------------------------------
+ # %1 - "component id"
+ UPDATE_CATALOG_FAILED: {
+ code: 403,
+ message: "Error: update catalog for component '%1' failed.",
+ messageId: "SVC4800"
+ }
+ #---------SVC4706------------------------------
+ # %1-input(s) name(s) string
INPUTS_NOT_FOUND: {
code: 400,
message: "Error: missing input value(s) %1.",
messageId: "SVC4706"
}
#---------SVC4707-----------------------------
-# %1 – asset type [service / resource ]
-# %2 – main asset uuid
+ # %1 – asset type [service / resource ]
+ # %2 – main asset uuid
ERROR_DURING_CSAR_CREATION: {
- code: 404,
- message: "Error: CSAR packaging failed for %1 %2.",
- messageId: "SVC4706"
+ code: 404,
+ message: "Error: CSAR packaging failed for %1 %2.",
+ messageId: "SVC4706"
}
#---------SVC4708-----------------------------
# %1 - Interface Operation input property name, component type
@@ -2160,18 +2128,128 @@ errors:
message: "Error: Interface not found in the component '%1'.",
messageId: "SVC4711"
}
+ #---------SVC4709-----------------------------
+ INVALID_PROPERTY_CONSTRAINTS: {
+ # %1 – property constraints type
+ # %2 – received property constraints value
+ # %3 – property type
+ code: 400,
+ message: "Error: Invalid %1 %2 for the type %3 have been received.",
+ messageId: "SVC4709"
+ }
+ #---------SVC4710-----------------------------
+ INVALID_PROPERTY_CONSTRAINTS_FORMAT: {
+ # %1 – received property constraints json section
+ code: 400,
+ message: "Error: Invalid format of the received property constraints section: %1. The property constraints section should be a list.",
+ messageId: "SVC4710"
+ }
+ #---------SVC4711-----------------------------
+ CANNOT_DELETE_VALID_VALUES: {
+ # %1 – property constraints type
+ # %2 – missing valid values
+ code: 400,
+ message: "Error: Deletion of existing %1 is not permitted on an update. Missing values: %2",
+ messageId: "SVC4711"
+ }
+ #---------SVC4712------------------------------
+ MISSING_PROPERTY_NAME: {
+ code: 400 ,
+ message: "Error: Invalid Content. Missing mandatory parameter 'name'." ,
+ messageId: "SVC4712"
+ }
+ #---------SVC4713------------------------------
+ MISSING_PROPERTY_VALUE: {
+ code: 400 ,
+ message: "Error: Invalid Content. Missing mandatory parameter 'value'." ,
+ messageId: "SVC4713"
+ }
+
+ #---------SVC4712---------------------------
+ INVALID_INSTANTIATION_TYPE: {
+ code: 400,
+ message: "Invalid instantiationType: %1",
+ messageId: "SVC4712"
+ }
+
+ #----------SVC4713---------------------------
+ MISSING_ECOMP_GENERATED_NAMING: {
+ code: 400,
+ message: "Missing ecompGeneratedNaming property",
+ messageId: "SVC4713"
+ }
+
+ #-----------SVC4714--------------------------
+ NAMING_POLICY_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. Naming policy exceeds limit of %1 characters.",
+ messageId: "SVC4714"
+ }
+
+ #---------SVC4715------------------------------
+ INVALID_NAMING_POLICY: {
+ code: 400,
+ message: 'Error: Invalid Content. Naming policy is not allowed to contain characters like <>:"\/|?* and space characters other than regular space.',
+ messageId: "SVC4715"
+ }
+
+ #---------SVC4716------------------------------
+ INVALID_ENVIRONMENT_CONTEXT: {
+ code: 400,
+ message: 'Error: Invalid Environment context: %1',
+ messageId: "SVC4716"
+ }
+
+ #---------SVC4717------------------------------
+ UNSUPPORTED_DISTRIBUTION_STATUS: {
+ code: 400,
+ message: 'Error: Unsupported distribution action: %1',
+ messageId: "SVC4717"
+ }
+ #---------SVC4718------------------------------
+ CONTAINER_CANNOT_CONTAIN_INSTANCE: {
+ # %1 - "container type"
+ # %2- “component type”
+ code: 400 ,
+ message: "Error : %1 can’t contain component instance %2" ,
+ messageId: "SVC4718"
+ }
+ #---------SVC4719------------------------------
+ CONTAINER_CANNOT_CONTAIN_COMPONENT_IN_STATE: {
+ # %1 - "container type"
+ # %2- "lifecycle state"
+ code: 400 ,
+ message: "Error: Container %1 can’t contain component in state %2" ,
+ messageId: "SVC4719"
+ }
+
+ #---------SVC4720------------------------------
+ MISSING_MANDATORY_PROPERTY: {
+ # %1 - "property name"
+ code: 400 ,
+ message: "Error: Missing mandatory %1 property" ,
+ messageId: "SVC4720"
+ }
+
+ #---------SVC4721------------------------------
+ MANDATORY_PROPERTY_MISSING_VALUE: {
+ # %1 - "property name"
+ code: 400 ,
+ message: "Error: Missing value for the mandatory %1 property" ,
+ messageId: "SVC4721"
+ }
#---------SVC4712-----------------------------
INTERFACE_LIFECYCLE_TYPES_NOT_FOUND: {
- code: 404,
- message: "Error: Interface Lifecycle types not found.",
- messageId: "SVC4712"
+ code: 404,
+ message: "Error: Interface Lifecycle types not found.",
+ messageId: "SVC4712"
}
#---------SVC4713-----------------------------
# %1 - Interface Operation Name
INTERFACE_OPERATION_INVALID_FOR_GLOBAL_TYPE: {
- code: 400,
- message: "Error: Invalid input, only pre-defined operation names are allowed in global interface type '%1'",
- messageId: "SVC4713"
+ code: 400,
+ message: "Error: Invalid input, only pre-defined operation names are allowed in global interface type '%1'",
+ messageId: "SVC4713"
}
#---------SVC4714-----------------------------
@@ -2284,9 +2362,23 @@ errors:
}
#---------SVC4729------------------------------
- # %1 - resource Id
+ # %1 - resource Id
CAPABILITY_PROPERTIES_NOT_FOUND: {
code: 400,
message: "Error: Capability properties not found in the resource '%1'.",
messageId: "SVC4729"
- } \ No newline at end of file
+ }
+#---------SVC4730------------------------------
+ # %1 - property name
+ PROPERTY_EXCEEDS_LIMIT: {
+ code: 400,
+ message: "Error: Invalid Content. %1 exceeds limit.",
+ messageId: "SVC4722"
+ }
+#---------SVC4731------------------------------
+ INVALID_PROPERY: {
+ # %1 - property name
+ code: 400,
+ message: 'Error: Invalid Content. %1 has invalid format.',
+ messageId: "SVC4723"
+ }
diff --git a/catalog-be/src/main/resources/config/logback.xml b/catalog-be/src/main/resources/config/logback.xml
index 7044d345c5..2098836dd3 100644
--- a/catalog-be/src/main/resources/config/logback.xml
+++ b/catalog-be/src/main/resources/config/logback.xml
@@ -1,315 +1,253 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds">
- <property scope="system" name="ECOMP-component-name" value="SDC" />
- <property scope="system" name="ECOMP-subcomponent-name" value="SDC-BE" />
- <property file="${config.home}/catalog-be/configuration.yaml" />
- <property scope="context" name="enable-all-log" value="false" />
-
- <!-- value used by pattern field list (| - is inter-field separator, || - unavailable or not applicable field value) (m - mandatory, o- optional)-->
- <!--timestamp(m)| requestID(m)| serviceInstanceID(o)| threadID(m)| physicalServerName(o)| serviceName(m)| userID(m)| logLevel(m)| severity(o)| serverIpAddress(m)| serverName(m)| clientIpAddress(o)| className(m)| timer(o)| detailedMessage(o)-->
- <property name="default-log-pattern"
- value="%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{BeginTimestamp}|%X{EndTimestamp}|%X{uuid}|%X{serviceInstanceID}|%thread|%X{ServerName}|%X{ServiceName}|${ECOMP-subcomponent-name}|%X{userId}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%level|%X{alarmSeverity}|%X{localAddr}|%X{ElapsedTime}|${beFqdn}|%X{remoteAddr}|%logger{35}|%X{timer}|ActivityType=&lt;%M&gt;, Desc=&lt;%msg&gt;%n" />
-
- <property name="error-log-pattern"
- value="%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestId}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{ErrorCategory}|%X{ErrorCode}|%msg|%n" />
-
- <property name="audit-log-pattern" value="%X{AuditBeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Unused}|%X{ProcessKey}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|ActivityType=&lt;%M&gt;, Desc=&lt;%msg&gt;%n" />
-
- <property name="metric-log-pattern" value="%X{MetricBeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Unused}|%X{ProcessKey}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|ActivityType=&lt;%M&gt;, Desc=&lt;%msg&gt;%n" />
-
- <property name="debug-log-pattern" value="%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestId}|%msg|^\n%n"/>
-
- <!-- All log -->
- <if condition='property("enable-all-log").equalsIgnoreCase("true")'>
- <then>
- <appender name="ALL_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/all.log
- </file>
-
- <rollingPolicy
- class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/all.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${default-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <appender name="ASYNC_ALL" class="ch.qos.logback.classic.AsyncAppender">
- <appender-ref ref="ALL_ROLLING" />
- </appender>
- </then>
- </if>
-
- <!-- Error log -->
- <appender name="ERROR_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/error.log
- </file>
-
- <!-- Audit messages filter - deny audit messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>AUDIT_MARKER</marker>
- </evaluator>
- <onMismatch>NEUTRAL</onMismatch>
- <onMatch>DENY</onMatch>
- </filter>
-
- <!-- Transaction messages filter - deny Transaction messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>TRANSACTION_MARKER</marker>
- </evaluator>
- <onMismatch>NEUTRAL</onMismatch>
- <onMatch>DENY</onMatch>
- </filter>
-
- <!-- deny all events with a level below INFO, that is TRACE and DEBUG -->
- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
- <level>INFO</level>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/error.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${error-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <!-- Debug log -->
- <appender name="DEBUG_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug.log
- </file>
-
- <!-- No need to deny audit messages - they are INFO only, will be denied
- anyway -->
- <!-- Transaction messages filter - deny Transaction messages, there are
- some DEBUG level messages among them -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>TRANSACTION_MARKER</marker>
- </evaluator>
- <onMismatch>NEUTRAL</onMismatch>
- <onMatch>DENY</onMatch>
- </filter>
-
- <!-- accept DEBUG and TRACE level -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
- <expression>
- e.level.toInt() &lt;= DEBUG.toInt()
- </expression>
- </evaluator>
- <OnMismatch>DENY</OnMismatch>
- <!--<OnMatch>NEUTRAL</OnMatch>-->
- <OnMatch>ACCEPT</OnMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${debug-log-pattern}</pattern>
- </encoder>
- </appender>
-
-
- <!-- ASDC debug by package-->
- <appender name="PACKAGE_DEBUG_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug_by_package.log
- </file>
-
- <!-- No need to deny audit messages - they are INFO only, will be denied
- anyway -->
- <!-- Transaction messages filter - deny Transaction messages, there are
- some DEBUG level messages among them -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>TRANSACTION_MARKER</marker>
- </evaluator>
- <onMismatch>NEUTRAL</onMismatch>
- <onMatch>DENY</onMatch>
- </filter>
-
- <!-- accept DEBUG and TRACE level -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
- <expression>
- e.level.toInt() &lt;= DEBUG.toInt()
- </expression>
- </evaluator>
- <OnMismatch>DENY</OnMismatch>
- <OnMatch>NEUTRAL</OnMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug_by_package.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${debug-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <!-- Audit log -->
- <appender name="AUDIT_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
-
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/audit.log
- </file>
-
- <!-- Audit messages filter - accept audit messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>AUDIT_MARKER</marker>
- <marker>AUDIT</marker>
- </evaluator>
- <onMismatch>DENY</onMismatch>
- <onMatch>ACCEPT</onMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/audit.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${audit-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <!-- Metrics log -->
- <appender name="METRICS_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
-
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/metrics.log
- </file>
-
- <!-- Metric messages filter - accept metric messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>METRICS</marker>
- </evaluator>
- <onMismatch>DENY</onMismatch>
- <onMatch>ACCEPT</onMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/metrics.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${metric-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <!-- SdncTransaction log -->
- <appender name="TRANSACTION_ROLLING"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
-
- <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/transaction.log
- </file>
-
- <!-- Transaction messages filter - accept audit messages -->
- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
- <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
- <marker>TRANSACTION_MARKER</marker>
- </evaluator>
- <onMismatch>DENY</onMismatch>
- <onMatch>ACCEPT</onMatch>
- </filter>
-
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/transaction.log.%i
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
-
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>20MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${default-log-pattern}</pattern>
- </encoder>
- </appender>
-
- <!-- Asynchronicity Configurations -->
- <appender name="ASYNC_DEBUG" class="ch.qos.logback.classic.AsyncAppender">
- <appender-ref ref="DEBUG_ROLLING" />
- </appender>
-
- <appender name="ASYNC_TRANSACTION" class="ch.qos.logback.classic.AsyncAppender">
- <appender-ref ref="TRANSACTION_ROLLING" />
- </appender>
-
- <appender name="ASYNC_ERROR" class="ch.qos.logback.classic.AsyncAppender">
- <appender-ref ref="ERROR_ROLLING" />
- </appender>
-
- <root level="INFO">
- <appender-ref ref="ASYNC_ERROR" />
- <appender-ref ref="ASYNC_DEBUG" />
- <appender-ref ref="AUDIT_ROLLING" />
- <appender-ref ref="ASYNC_TRANSACTION" />
- <appender-ref ref="METRICS_ROLLING" />
- <if condition='property("enable-all-log").equalsIgnoreCase("true")'>
- <then>
- <appender-ref ref="ALL_ROLLING" />
- </then>
- </if>
- </root>
-
- <logger name="org.openecomp.sdc" level="INFO" />
-</configuration> \ No newline at end of file
+ <property scope="system" name="ECOMP-component-name" value="SDC"/>
+ <property scope="system" name="ECOMP-subcomponent-name" value="SDC-BE"/>
+ <property file="${config.home}/catalog-be/configuration.yaml"/>
+ <property scope="context" name="enable-all-log" value="false"/>
+ <property name="p_msg" value="%replace(%replace(%replace(%replace(%msg){'\t','\\\\t'}){'\n', '\\\\n'}){'\\\|', '-'}){'\r','\\\\r'}"/>
+ <property name="p_ex" value="%replace(%replace(%replace(%replace(%exception{full}){'\t','\\\\t'}){'\n', '\\\\n'}){'\\\|', '-'}){'\r','\\\\r'}"/>
+ <property name="p_debugInfo" value="%replace(%replace(%replace(%replace(%thread#%level#%logger{35}#%msg){'\t','\\\\t'}){'\n', '\\\\n'}){'\\\|', '-'}){'\r','\\\\r'}"/>
+
+ <property name="all-log-pattern"
+ value="%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{BeginTimestamp}|%X{EndTimestamp}|%X{uuid}|%X{serviceInstanceID}|%thread|%X{ServerName}|%X{ServiceName}|${ECOMP-subcomponent-name}|%X{userId}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceID}|%level|%X{alarmSeverity}|%X{localAddr}|%X{ElapsedTime}|${beFqdn}|%X{remoteAddr}|%logger{35}|%X{timer}|ActivityType=&lt;%M&gt;, Desc=&lt;${p_msg}&gt;%n"/>
+
+ <property name="debug-log-pattern"
+ value="%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestID}|${p_debugInfo} ${p_ex}|^\n%n%nopex"/>
+
+ <property name="error-log-pattern"
+ value="%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestID}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{ErrorCategory}|%X{ErrorCode}|${p_msg} ${p_ex}|%n%nopex"/>
+
+ <property name="audit-log-pattern"
+ value="%X{EntryTimestamp}|%X{LogTimestamp}|%X{RequestID}|%X{ServiceInstanceID}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{Severity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%logger{35}|%X{Unused}|%X{ProcessKey}|%marker|InvocationID=%X{InvocationID}|%X{CustomField3}|%X{CustomField4}|ActivityType=&lt;%M&gt;, Desc=&lt;${p_msg}&gt;%n"/>
+
+ <property name="metric-log-pattern"
+ value="%X{InvokeTimestamp}|%X{EndTimestamp}|%X{RequestID}|%X{ServiceInstanceID}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceID}|%.-5level|%X{Severity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|||%X{ClassName}|%X{Unused}|%X{ProcessKey}|%marker|InvocationID=%X{OutgoingInvocationId}|%X{CustomField3}|%X{CustomField4}|ActivityType=&lt;%M&gt;, Desc=&lt;%msg&gt;%n" />
+
+ <property name="supportability-log-pattern"
+ value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{SupportablityComponentName}|%X{SupportablityAction}|%thread|%X{SupportablityComponentUUID}|%X{SupportablityStatus}|ActivityType=&lt;%M&gt;, Desc=&lt;${p_msg}&gt;%n"/>
+
+
+ <!-- All log -->
+ <if condition='property("enable-all-log").equalsIgnoreCase("true")'>
+ <then>
+ <appender name="ALL_ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/all.log</file>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/all.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+
+ <encoder>
+ <pattern>${all-log-pattern}</pattern>
+ </encoder>
+ </appender>
+ </then>
+ </if>
+
+
+ <!-- Debug log -->
+ <appender name="DEBUG_ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug.log</file>
+
+ <!-- Audit and Metric messages filter - deny audit and metric messages -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>ENTRY</marker>
+ <marker>EXIT</marker>
+ <marker>INVOKE</marker>
+ <marker>INVOKE-RETURN</marker>
+ <marker>INVOKE-SYNCHRONOUS</marker>
+ </evaluator>
+ <onMismatch>NEUTRAL</onMismatch>
+ <onMatch>DENY</onMatch>
+ </filter>
+
+ <!-- accept INFO, DEBUG and TRACE level -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
+ <expression>
+ e.level.toInt() &lt;= INFO.toInt()
+ </expression>
+ </evaluator>
+ <OnMismatch>DENY</OnMismatch>
+ <OnMatch>ACCEPT</OnMatch>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/debug.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+
+ <encoder>
+ <pattern>${debug-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+
+ <!-- Error log -->
+ <appender name="ERROR_ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/error.log</file>
+
+ <!-- deny all events with a level below WARN, that is INFO TRACE and DEBUG -->
+ <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+ <level>WARN</level>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/error.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+
+ <encoder>
+ <pattern>${error-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+
+ <!-- Audit log -->
+ <appender name="AUDIT_ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/audit.log</file>
+
+ <!-- Audit messages filter - accept audit messages -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>ENTRY</marker>
+ <marker>EXIT</marker>
+ </evaluator>
+ <onMismatch>DENY</onMismatch>
+ <onMatch>ACCEPT</onMatch>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/audit.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+
+ <encoder>
+ <pattern>${audit-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+
+ <!-- Metrics log -->
+ <appender name="METRICS_ROLLING"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/metrics.log
+ </file>
+
+ <!-- Metric messages filter - accept metric messages -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>INVOKE</marker>
+ <marker>INVOKE-RETURN</marker>
+ <marker>INVOKE-SYNCHRONOUS</marker>
+ </evaluator>
+ <onMismatch>DENY</onMismatch>
+ <onMatch>ACCEPT</onMatch>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/metrics.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+
+ <encoder>
+ <pattern>${metric-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+
+ <!-- Supporability log -->
+ <appender name="SUPPORTABILITY_ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
+
+ <file>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/supportability.log</file>
+
+ <!-- Supporability messages filter - accept suppportability messages -->
+ <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
+ <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
+ <marker>SUPPORTABILITY_MARKER</marker>
+ </evaluator>
+ <onMismatch>DENY</onMismatch>
+ <onMatch>ACCEPT</onMatch>
+ </filter>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${log.home}/${ECOMP-component-name}/${ECOMP-subcomponent-name}/supportability.log.%i
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>10</maxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>20MB</maxFileSize>
+ </triggeringPolicy>
+
+ <encoder>
+ <pattern>${supportability-log-pattern}</pattern>
+ </encoder>
+ </appender>
+
+
+ <!-- Asynchronicity Configurations -->
+ <appender name="ASYNC_DEBUG" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="DEBUG_ROLLING"/>
+ </appender>
+
+ <appender name="ASYNC_ERROR" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="ERROR_ROLLING"/>
+ </appender>
+
+ <appender name="ASYNC_ALL" class="ch.qos.logback.classic.AsyncAppender">
+ <appender-ref ref="ALL_ROLLING"/>
+ </appender>
+
+
+ <root level="INFO">
+ <appender-ref ref="ASYNC_DEBUG"/>
+ <appender-ref ref="ASYNC_ERROR"/>
+ <appender-ref ref="AUDIT_ROLLING"/>
+ <appender-ref ref="METRICS_ROLLING"/>
+ <appender-ref ref="SUPPORTABILITY_ROLLING"/>
+ <if condition='property("enable-all-log").equalsIgnoreCase("true")'>
+ <then>
+ <appender-ref ref="ASYNC_ALL"/>
+ </then>
+ </if>
+ </root>
+
+ <logger name="org.openecomp.sdc" level="INFO"/>
+</configuration>
diff --git a/catalog-be/src/main/resources/elasticsearch.yml b/catalog-be/src/main/resources/elasticsearch.yml
deleted file mode 100644
index 71ccdbb8f5..0000000000
--- a/catalog-be/src/main/resources/elasticsearch.yml
+++ /dev/null
@@ -1,399 +0,0 @@
-
-cluster.name: elasticsearch
-
-discovery.zen.ping.multicast.enabled: false
-discovery.zen.ping.unicast.enabled: true
-discovery.zen.ping.unicast.hosts: elasticsearch_host
-
-http.cors.enabled: true
-
-path.home: "/home/vagrant/catalog-be/config"
-
-elasticSearch.transportclient: true
-
-transport.client.initial_nodes:
- - elasticsearch_host:9300
-
-#shield.user: asdc:Aa12345
-#shield.ssl.keystore.path: "/vagrant/install/resources/catalog-be/keystore/es-client.jks"
-#shield.ssl.keystore.password: Aa123456
-#shield.transport.ssl: true
-
-##################### Elasticsearch Configuration Example #####################
-
-# This file contains an overview of various configuration settings,
-# targeted at operations staff. Application developers should
-# consult the guide at <http://elasticsearch.org/guide>.
-#
-# The installation procedure is covered at
-# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>.
-#
-# Elasticsearch comes with reasonable defaults for most settings,
-# so you can try it out without bothering with configuration.
-#
-# Most of the time, these defaults are just fine for running a production
-# cluster. If you're fine-tuning your cluster, or wondering about the
-# effect of certain configuration option, please _do ask_ on the
-# mailing list or IRC channel [http://elasticsearch.org/community].
-
-# Any element in the configuration can be replaced with environment variables
-# by placing them in ${...} notation. For example:
-#
-# node.rack: ${RACK_ENV_VAR}
-
-# For information on supported formats and syntax for the config file, see
-# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html>
-
-
-################################### Cluster ###################################
-
-# Cluster name identifies your cluster for auto-discovery. If you're running
-# multiple clusters on the same network, make sure you're using unique names.
-#
-# cluster.name: elasticsearch
-
-
-#################################### Node #####################################
-
-# Node names are generated dynamically on startup, so you're relieved
-# from configuring them manually. You can tie this node to a specific name:
-#
-# node.name: "Franz Kafka"
-
-# Every node can be configured to allow or deny being eligible as the master,
-# and to allow or deny to store the data.
-#
-# Allow this node to be eligible as a master node (enabled by default):
-#
-# node.master: true
-#
-# Allow this node to store data (enabled by default):
-#
-# node.data: true
-
-# You can exploit these settings to design advanced cluster topologies.
-#
-# 1. You want this node to never become a master node, only to hold data.
-# This will be the "workhorse" of your cluster.
-#
-# node.master: false
-# node.data: true
-#
-# 2. You want this node to only serve as a master: to not store any data and
-# to have free resources. This will be the "coordinator" of your cluster.
-#
-# node.master: true
-# node.data: false
-#
-# 3. You want this node to be neither master nor data node, but
-# to act as a "search load balancer" (fetching data from nodes,
-# aggregating results, etc.)
-#
-# node.master: false
-# node.data: false
-
-# Use the Cluster Health API [http://localhost:9200/_cluster/health], the
-# Node Info API [http://localhost:9200/_nodes] or GUI tools
-# such as <http://www.elasticsearch.org/overview/marvel/>,
-# <http://github.com/karmi/elasticsearch-paramedic>,
-# <http://github.com/lukas-vlcek/bigdesk> and
-# <http://mobz.github.com/elasticsearch-head> to inspect the cluster state.
-
-# A node can have generic attributes associated with it, which can later be used
-# for customized shard allocation filtering, or allocation awareness. An attribute
-# is a simple key value pair, similar to node.key: value, here is an example:
-#
-# node.rack: rack314
-
-# By default, multiple nodes are allowed to start from the same installation location
-# to disable it, set the following:
-# node.max_local_storage_nodes: 1
-
-
-#################################### Index ####################################
-
-# You can set a number of options (such as shard/replica options, mapping
-# or analyzer definitions, translog settings, ...) for indices globally,
-# in this file.
-#
-# Note, that it makes more sense to configure index settings specifically for
-# a certain index, either when creating it or by using the index templates API.
-#
-# See <http://elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules.html> and
-# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html>
-# for more information.
-
-# Set the number of shards (splits) of an index (5 by default):
-#
-# index.number_of_shards: 5
-
-# Set the number of replicas (additional copies) of an index (1 by default):
-#
-# index.number_of_replicas: 1
-
-# Note, that for development on a local machine, with small indices, it usually
-# makes sense to "disable" the distributed features:
-#
-index.number_of_shards: 1
-index.number_of_replicas: 0
-
-# These settings directly affect the performance of index and search operations
-# in your cluster. Assuming you have enough machines to hold shards and
-# replicas, the rule of thumb is:
-#
-# 1. Having more *shards* enhances the _indexing_ performance and allows to
-# _distribute_ a big index across machines.
-# 2. Having more *replicas* enhances the _search_ performance and improves the
-# cluster _availability_.
-#
-# The "number_of_shards" is a one-time setting for an index.
-#
-# The "number_of_replicas" can be increased or decreased anytime,
-# by using the Index Update Settings API.
-#
-# Elasticsearch takes care about load balancing, relocating, gathering the
-# results from nodes, etc. Experiment with different settings to fine-tune
-# your setup.
-
-# Use the Index Status API (<http://localhost:9200/A/_status>) to inspect
-# the index status.
-
-
-#################################### Paths ####################################
-
-# Path to directory containing configuration (this file and logging.yml):
-#
-path.conf: /src/test/resources
-
-# Path to directory where to store index data allocated for this node.
-#
-path.data: target/esdata
-#
-# Can optionally include more than one location, causing data to be striped across
-# the locations (a la RAID 0) on a file level, favouring locations with most free
-# space on creation. For example:
-#
-# path.data: /path/to/data1,/path/to/data2
-
-# Path to temporary files:
-#
-path.work: /target/eswork
-
-# Path to log files:
-#
-path.logs: /target/eslogs
-
-# Path to where plugins are installed:
-#
-# path.plugins: /path/to/plugins
-
-
-#################################### Plugin ###################################
-
-# If a plugin listed here is not installed for current node, the node will not start.
-#
-# plugin.mandatory: mapper-attachments,lang-groovy
-
-
-################################### Memory ####################################
-
-# Elasticsearch performs poorly when JVM starts swapping: you should ensure that
-# it _never_ swaps.
-#
-# Set this property to true to lock the memory:
-#
-# bootstrap.mlockall: true
-
-# Make sure that the ES_MIN_MEM and ES_MAX_MEM environment variables are set
-# to the same value, and that the machine has enough memory to allocate
-# for Elasticsearch, leaving enough memory for the operating system itself.
-#
-# You should also make sure that the Elasticsearch process is allowed to lock
-# the memory, eg. by using `ulimit -l unlimited`.
-
-
-############################## Network And HTTP ###############################
-
-# Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens
-# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node
-# communication. (the range means that if the port is busy, it will automatically
-# try the next port).
-
-# Set the bind address specifically (IPv4 or IPv6):
-#
-# network.bind_host: 192.168.0.1
-
-# Set the address other nodes will use to communicate with this node. If not
-# set, it is automatically derived. It must point to an actual IP address.
-#
-# network.publish_host: 192.168.0.1
-
-# Set both 'bind_host' and 'publish_host':
-#
-# network.host: 192.168.0.1
-
-# Set a custom port for the node to node communication (9300 by default):
-#
-# transport.tcp.port: 9300
-
-# Enable compression for all communication between nodes (disabled by default):
-#
-# transport.tcp.compress: true
-
-# Set a custom port to listen for HTTP traffic:
-#
-# http.port: 9200
-
-# Set a custom allowed content length:
-#
-# http.max_content_length: 100mb
-
-# Disable HTTP completely:
-#
-# http.enabled: false
-
-
-################################### Gateway ###################################
-
-# The gateway allows for persisting the cluster state between full cluster
-# restarts. Every change to the state (such as adding an index) will be stored
-# in the gateway, and when the cluster starts up for the first time,
-# it will read its state from the gateway.
-
-# There are several types of gateway implementations. For more information, see
-# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-gateway.html>.
-
-# The default gateway type is the "local" gateway (recommended):
-#
-# gateway.type: local
-
-# Settings below control how and when to start the initial recovery process on
-# a full cluster restart (to reuse as much local data as possible when using shared
-# gateway).
-
-# Allow recovery process after N nodes in a cluster are up:
-#
-gateway.recover_after_nodes: 1
-
-# Set the timeout to initiate the recovery process, once the N nodes
-# from previous setting are up (accepts time value):
-#
-# gateway.recover_after_time: 5m
-
-# Set how many nodes are expected in this cluster. Once these N nodes
-# are up (and recover_after_nodes is met), begin recovery process immediately
-# (without waiting for recover_after_time to expire):
-#
-gateway.expected_nodes: 1
-
-
-############################# Recovery Throttling #############################
-
-# These settings allow to control the process of shards allocation between
-# nodes during initial recovery, replica allocation, rebalancing,
-# or when adding and removing nodes.
-
-# Set the number of concurrent recoveries happening on a node:
-#
-# 1. During the initial recovery
-#
-# cluster.routing.allocation.node_initial_primaries_recoveries: 4
-#
-# 2. During adding/removing nodes, rebalancing, etc
-#
-# cluster.routing.allocation.node_concurrent_recoveries: 2
-
-# Set to throttle throughput when recovering (eg. 100mb, by default 20mb):
-#
-# indices.recovery.max_bytes_per_sec: 20mb
-
-# Set to limit the number of open concurrent streams when
-# recovering a shard from a peer:
-#
-# indices.recovery.concurrent_streams: 5
-
-
-################################## Discovery ##################################
-
-# Discovery infrastructure ensures nodes can be found within a cluster
-# and master node is elected. Multicast discovery is the default.
-
-# Set to ensure a node sees N other master eligible nodes to be considered
-# operational within the cluster. Its recommended to set it to a higher value
-# than 1 when running more than 2 nodes in the cluster.
-#
-# discovery.zen.minimum_master_nodes: 1
-
-# Set the time to wait for ping responses from other nodes when discovering.
-# Set this option to a higher value on a slow or congested network
-# to minimize discovery failures:
-#
-# discovery.zen.ping.timeout: 3s
-
-# For more information, see
-# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-zen.html>
-
-# Unicast discovery allows to explicitly control which nodes will be used
-# to discover the cluster. It can be used when multicast is not present,
-# or to restrict the cluster communication-wise.
-#
-# 1. Disable multicast discovery (enabled by default):
-#
-# discovery.zen.ping.multicast.enabled: false
-#
-# 2. Configure an initial list of master nodes in the cluster
-# to perform discovery when new nodes (master or data) are started:
-#
-# discovery.zen.ping.unicast.hosts: ["host1", "host2:port"]
-
-# EC2 discovery allows to use AWS EC2 API in order to perform discovery.
-#
-# You have to install the cloud-aws plugin for enabling the EC2 discovery.
-#
-# For more information, see
-# <http://elasticsearch.org/guide/en/elasticsearch/reference/current/modules-discovery-ec2.html>
-#
-# See <http://elasticsearch.org/tutorials/elasticsearch-on-ec2/>
-# for a step-by-step tutorial.
-
-# GCE discovery allows to use Google Compute Engine API in order to perform discovery.
-#
-# You have to install the cloud-gce plugin for enabling the GCE discovery.
-#
-# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-gce>.
-
-# Azure discovery allows to use Azure API in order to perform discovery.
-#
-# You have to install the cloud-azure plugin for enabling the Azure discovery.
-#
-# For more information, see <https://github.com/elasticsearch/elasticsearch-cloud-azure>.
-
-################################## Slow Log ##################################
-
-# Shard level query and fetch threshold logging.
-
-#index.search.slowlog.threshold.query.warn: 10s
-#index.search.slowlog.threshold.query.info: 5s
-#index.search.slowlog.threshold.query.debug: 2s
-#index.search.slowlog.threshold.query.trace: 500ms
-
-#index.search.slowlog.threshold.fetch.warn: 1s
-#index.search.slowlog.threshold.fetch.info: 800ms
-#index.search.slowlog.threshold.fetch.debug: 500ms
-#index.search.slowlog.threshold.fetch.trace: 200ms
-
-#index.indexing.slowlog.threshold.index.warn: 10s
-#index.indexing.slowlog.threshold.index.info: 5s
-#index.indexing.slowlog.threshold.index.debug: 2s
-#index.indexing.slowlog.threshold.index.trace: 500ms
-
-################################## GC Logging ################################
-
-#monitor.jvm.gc.young.warn: 1000ms
-#monitor.jvm.gc.young.info: 700ms
-#monitor.jvm.gc.young.debug: 400ms
-
-#monitor.jvm.gc.old.warn: 10s
-#monitor.jvm.gc.old.info: 5s
-#monitor.jvm.gc.old.debug: 2s
-
diff --git a/catalog-be/src/main/resources/import/tosca/heat-types/extVl/extVl.yml b/catalog-be/src/main/resources/import/tosca/heat-types/extVl/extVl.yml
index 53b453c67d..581d688bcc 100644
--- a/catalog-be/src/main/resources/import/tosca/heat-types/extVl/extVl.yml
+++ b/catalog-be/src/main/resources/import/tosca/heat-types/extVl/extVl.yml
@@ -17,7 +17,7 @@ node_types:
network_scope:
type: string
constraints:
- valid_values: ["VF", "SERVICE", "GLOBAL"]
+ - valid_values: ["VF", "SERVICE", "GLOBAL"]
description: >
Uniquely identifies the network scope. Valid values for the network scope
includes:
diff --git a/catalog-be/src/main/resources/portal.properties b/catalog-be/src/main/resources/portal.properties
index 185a4fb9dc..a182e80972 100644
--- a/catalog-be/src/main/resources/portal.properties
+++ b/catalog-be/src/main/resources/portal.properties
@@ -54,6 +54,7 @@ use_rest_for_functional_menu=true
# Name of java class that implements the OnBoardingApiService interface.
portal.api.impl.class = org.openecomp.sdc.be.ecomp.PortalRestAPICentralServiceImpl
+# Use this tag if the app is centralized remote/local
role_access_centralized = remote
# URL of the Portal where this app is onboarded
@@ -75,4 +76,8 @@ portal_app_name = Ipwxi2oLvDxctMA1royaRw1W0jhucLx+grHzci3ePIA=
# then only the ueb_app_key is required.
ueb_app_key = REPLACE-ME-UEB-APP-KEY-EPSDK-APP-OS
-
+# Connection and Read timeout values
+#ext_req_connection_timeout = 15000
+#ext_req_read_timeout = 20000
+#Add AAF namespace if the app is centralized
+aaf_namespace = com.att.sdc
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
index 74ecf71784..969c2f805f 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importHeatTypes.py
@@ -60,13 +60,13 @@ def importHeatTypes(scheme, beHost, bePort, adminUser, fileDir, updateversion):
"extContrailCP",
"portMirroringByPolicy",
"forwardingPath",
+ "configuration",
"VRFObject",
"extVirtualMachineInterfaceCP",
"VLANNetworkReceptor",
"VRFEntry",
"subInterfaceV2",
"contrailV2VLANSubInterfaceV2",
- "configuration",
"fabricConfiguration"
]
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py b/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
index 24218b6a73..1418722dff 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNodeType.py
@@ -56,7 +56,8 @@ def createUserNormativeType(scheme, beHost, bePort, adminUser, fileDir, ELEMENT_
c.setopt(c.WRITEFUNCTION, buffer.write)
if scheme == 'https':
- c.setopt(c.SSL_VERIFYPEER, 0)
+ c.setopt(pycurl.SSL_VERIFYPEER, 0)
+ c.setopt(pycurl.SSL_VERIFYHOST, 0)
res = c.perform()
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
index 19ffc1762f..e4f536ff85 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeAll.py
@@ -4,6 +4,7 @@ from StringIO import StringIO
import json
import copy
import time
+# from importNormativeElements import createNormativeElement
from importNormativeElements import *
from importNormativeTypes import importNormativeTypes
from importHeatTypes import importHeatTypes
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
index 3d5e9fd13b..47ed633b06 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeElements.py
@@ -17,11 +17,9 @@ from importCommon import *
# python importUsers.py [-f <input file> | --ifile=<input file> ] #
# #
#################################################################################################################################################################################
-def import_element(scheme, be_host, be_port, admin_user, exit_on_success, file_dir, url_suffix, element_name,
- element_form_name,
+def import_element(scheme, be_host, be_port, admin_user, exit_on_success, file_dir, url_suffix, element_name, element_form_name,
with_metadata=False):
- result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_suffix, element_name,
- element_form_name, with_metadata)
+ result = createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_suffix, element_name, element_form_name, with_metadata)
print_frame_line()
print_name_and_return_code(result[0], result[1])
print_frame_line()
@@ -33,6 +31,7 @@ def import_element(scheme, be_host, be_port, admin_user, exit_on_success, file_d
error_and_exit(0, None)
+
def createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_suffix, element_name, element_form_name,
with_metadata=False):
try:
@@ -41,37 +40,35 @@ def createNormativeElement(scheme, be_host, be_port, admin_user, file_dir, url_s
c = pycurl.Curl()
url = scheme + '://' + be_host + ':' + be_port + url_suffix
- c.setopt(pycurl.URL, url)
- c.setopt(pycurl.POST, 1)
+ c.setopt(c.URL, url)
+ c.setopt(c.POST, 1)
admin_header = 'USER_ID: ' + admin_user
c.setopt(pycurl.HTTPHEADER, [admin_header])
type_file_name = file_dir + "/" + element_name
- multi_part_form_data = create_multipart_form_data(element_form_name, type_file_name, with_metadata,
- element_name)
+ multi_part_form_data = create_multipart_form_data(element_form_name, type_file_name, with_metadata, element_name)
c.setopt(pycurl.HTTPPOST, multi_part_form_data)
- c.setopt(pycurl.WRITEFUNCTION, buffer.write)
+ c.setopt(c.WRITEFUNCTION, buffer.write)
if scheme == 'https':
- # security "man in middle" vulnerability
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.perform()
- http_res = c.getinfo(pycurl.RESPONSE_CODE)
+ http_res = c.getinfo(c.RESPONSE_CODE)
if http_res is not None:
debug("http response=", http_res)
debug("response buffer", buffer.getvalue())
c.close()
- return element_name, http_res, buffer.getvalue()
+ return (element_name, http_res, buffer.getvalue())
except Exception as inst:
print("ERROR=" + str(inst))
- return element_name, None, None
+ return (element_name, None, None)
def create_multipart_form_data(element_form_name, type_file_name, with_metadata, element_name):
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py
index a86e520558..7adcf333c7 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeRelationships.py
@@ -5,7 +5,7 @@ import json
import copy
from importNormativeElements import createNormativeElement
from importCommon import *
-import importCommon
+import importCommon
#################################################################################################################################################################################################
# #
@@ -22,62 +22,62 @@ import importCommon
# #
#################################################################################################################################################################################################
-
+
def usage():
- print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
+ print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ]'
def importNormativeRelationships(scheme, beHost, bePort, adminUser, exitOnSuccess, fileDir):
- result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/relationship", "relationshipTypes", "relationshipTypeZip")
-
- print_frame_line()
- print_name_and_return_code(result[0], result[1])
- print_frame_line()
+ result = createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, "/sdc2/rest/v1/catalog/uploadType/relationship", "relationshipTypes", "relationshipTypeZip")
+
+ print_frame_line()
+ print_name_and_return_code(result[0], result[1])
+ print_frame_line()
- if ( result[1] == None or result[1] not in [200, 201, 409] ):
- importCommon.error_and_exit(1, None)
- else:
- if (exitOnSuccess == True):
- importCommon.error_and_exit(0, None)
+ if ( result[1] == None or result[1] not in [200, 201, 409] ):
+ importCommon.error_and_exit(1, None)
+ else:
+ if (exitOnSuccess == True):
+ importCommon.error_and_exit(0, None)
def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv,"i:p:u:h:s:",["ip=","port=","user=","scheme="])
- except getopt.GetoptError:
- usage()
- importCommon.error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- #print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
-
- print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
-
- if ( beHost == None ):
- usage()
- sys.exit(3)
-
- importNormativeRelationships(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/relationship-types/")
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ scheme = 'http'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:h:s:",["ip=","port=","user=","scheme="])
+ except getopt.GetoptError:
+ usage()
+ importCommon.error_and_exit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-s", "--scheme"):
+ scheme = arg
+
+ print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ importNormativeRelationships(scheme, beHost, bePort, adminUser, True, "../../../import/tosca/relationship-types/")
if __name__ == "__main__":
- main(sys.argv[1:])
+ main(sys.argv[1:])
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
index b74cead75e..6eea374716 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importNormativeTypes.py
@@ -19,158 +19,154 @@ import importCommon
#########################################################################################################################################################################################
def createNormativeType(scheme, beHost, bePort, adminUser, fileDir, ELEMENT_NAME, updateversion):
- try:
- log("in create normative type ", ELEMENT_NAME)
- debug("userId", adminUser)
- debug("fileDir", fileDir)
-
- buffer = StringIO()
- c = pycurl.Curl()
-
- url = scheme + '://' + beHost + ':' + bePort + '/sdc2/rest/v1/catalog/upload/multipart'
- if updateversion != None:
- url += '?createNewVersion=' + updateversion
- c.setopt(pycurl.URL, url)
- c.setopt(pycurl.POST, 1)
-
- adminHeader = 'USER_ID: ' + adminUser
- # c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
- c.setopt(pycurl.HTTPHEADER, [adminHeader])
-
- yml_path = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".yml"
- path = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".zip"
-
- zf = zipfile.ZipFile(path, "w")
- zf.write(yml_path, ELEMENT_NAME + '.yml')
- zf.close()
-
- debug(path)
- CURRENT_JSON_FILE = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".json"
- # sed -i 's/"userId": ".*",/"userId": "'${USER_ID}'",/' ${CURRENT_JSON_FILE}
-
- jsonFile = open(CURRENT_JSON_FILE)
-
- debug("before load json")
- json_data = json.load(jsonFile, strict=False)
- debug(json_data)
-
- jsonAsStr = json.dumps(json_data)
-
- send = [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))]
- debug(send)
- c.setopt(pycurl.HTTPPOST, send)
-
- # data = json.dumps(user)
- # c.setopt(c.POSTFIELDS, data)
-
- if scheme == 'https':
- # security "man in middle" vulnerability
- c.setopt(pycurl.SSL_VERIFYPEER, 0)
- c.setopt(pycurl.SSL_VERIFYHOST, 0)
-
- # c.setopt(c.WRITEFUNCTION, lambda x: None)
- c.setopt(pycurl.WRITEFUNCTION, buffer.write)
- # print("before perform")
- c.perform()
-
- # print("Before get response code")
- httpRes = c.getinfo(pycurl.RESPONSE_CODE)
- if (httpRes != None):
- debug("http response=", httpRes)
- # print('Status: ' + str(responseCode))
- debug(buffer.getvalue())
- c.close()
-
- return ELEMENT_NAME, httpRes, buffer.getvalue()
-
- except Exception as inst:
- print("ERROR=" + str(inst))
- return ELEMENT_NAME, None, None
+
+ try:
+ log("in create normative type ", ELEMENT_NAME)
+ debug("userId", adminUser)
+ debug("fileDir", fileDir)
+
+ buffer = StringIO()
+ c = pycurl.Curl()
+
+ url = scheme + '://' + beHost + ':' + bePort + '/sdc2/rest/v1/catalog/upload/multipart'
+ if updateversion != None:
+ url += '?createNewVersion=' + updateversion
+ c.setopt(c.URL, url)
+ c.setopt(c.POST, 1)
+
+ adminHeader = 'USER_ID: ' + adminUser
+ #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
+ c.setopt(pycurl.HTTPHEADER, [adminHeader])
+
+ yml_path = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".yml"
+ path = fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".zip"
+
+ zf = zipfile.ZipFile(path, "w")
+ zf.write(yml_path, ELEMENT_NAME + '.yml')
+ zf.close()
+
+ debug(path)
+ CURRENT_JSON_FILE=fileDir + ELEMENT_NAME + "/" + ELEMENT_NAME + ".json"
+ #sed -i 's/"userId": ".*",/"userId": "'${USER_ID}'",/' ${CURRENT_JSON_FILE}
+
+ jsonFile = open(CURRENT_JSON_FILE)
+
+ debug("before load json")
+ json_data = json.load(jsonFile, strict=False)
+ debug(json_data)
+
+ jsonAsStr = json.dumps(json_data)
+
+ send = [('resourceMetadata', jsonAsStr), ('resourceZip', (pycurl.FORM_FILE, path))]
+ debug(send)
+ c.setopt(pycurl.HTTPPOST, send)
+
+ #data = json.dumps(user)
+ #c.setopt(c.POSTFIELDS, data)
+
+ if scheme == 'https':
+ c.setopt(pycurl.SSL_VERIFYPEER, 0)
+ c.setopt(pycurl.SSL_VERIFYHOST, 0)
+
+ #c.setopt(c.WRITEFUNCTION, lambda x: None)
+ c.setopt(c.WRITEFUNCTION, buffer.write)
+ #print("before perform")
+ res = c.perform()
+
+ #print("Before get response code")
+ httpRes = c.getinfo(c.RESPONSE_CODE)
+ if (httpRes != None):
+ debug("http response=", httpRes)
+ #print('Status: ' + str(responseCode))
+ debug(buffer.getvalue())
+ c.close()
+
+ return (ELEMENT_NAME, httpRes, buffer.getvalue())
+
+ except Exception as inst:
+ print("ERROR=" + str(inst))
+ return (ELEMENT_NAME, None, None)
def usage():
- print sys.argv[0], \
- '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | ' \
- '--ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] ' \
- '[-v <true|false> | --updateversion=<true|false>]'
+ print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-v <true|false> | --updateversion=<true|false>]'
def importNormativeTypes(scheme, beHost, bePort, adminUser, fileDir, updateversion):
- normativeTypes = ["root", "compute", "softwareComponent", "webServer", "webApplication", "DBMS", "database",
- "objectStorage", "blockStorage", "containerRuntime", "containerApplication", "loadBalancer",
- "port", "network"]
- # normativeTypes = [ "root" ]
- responseCodes = [200, 201]
-
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- results = []
- for normativeType in normativeTypes:
- result = createNormativeType(scheme, beHost, bePort, adminUser, fileDir, normativeType, updateversion)
- results.append(result)
- if (result[1] == None or result[1] not in responseCodes):
- print "Failed creating normative type " + normativeType + ". " + str(result[1])
- return results
+
+ normativeTypes = [ "root", "compute", "softwareComponent", "webServer", "webApplication", "DBMS", "database", "objectStorage", "blockStorage", "containerRuntime", "containerApplication", "loadBalancer", "port", "network"]
+ #normativeTypes = [ "root" ]
+ responseCodes = [200, 201]
+
+ if(updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ results = []
+ for normativeType in normativeTypes:
+ result = createNormativeType(scheme, beHost, bePort, adminUser, fileDir, normativeType, updateversion)
+ results.append(result)
+ if ( result[1] == None or result[1] not in responseCodes ):
+ print "Failed creating normative type " + normativeType + ". " + str(result[1])
+ return results
def main(argv):
- print 'Number of arguments:', len(sys.argv), 'arguments.'
-
- beHost = 'localhost'
- bePort = '8080'
- adminUser = 'jh0003'
- updateversion = 'true'
- scheme = 'http'
-
- try:
- opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=", "scheme="])
- except getopt.GetoptError:
- usage()
- error_and_exit(2, 'Invalid input')
-
- for opt, arg in opts:
- # print opt, arg
- if opt == '-h':
- usage()
- sys.exit(3)
- elif opt in ("-i", "--ip"):
- beHost = arg
- elif opt in ("-p", "--port"):
- bePort = arg
- elif opt in ("-u", "--user"):
- adminUser = arg
- elif opt in ("-s", "--scheme"):
- scheme = arg
- elif opt in ("-v", "--updateversion"):
- if (arg.lower() == "false" or arg.lower() == "no"):
- updateversion = 'false'
-
- print 'scheme =', scheme, ', be host =', beHost, ', be port =', bePort, ', user =', adminUser, ', updateversion =', updateversion
-
- if (beHost == None):
- usage()
- sys.exit(3)
-
- results = importNormativeTypes(scheme, beHost, bePort, adminUser, "../../../import/tosca/normative-types/",
- updateversion)
-
- print "-----------------------------"
- for result in results:
- print "{0:20} | {1:6}".format(result[0], result[1])
- print "-----------------------------"
-
- responseCodes = [200, 201]
-
- if (updateversion == 'false'):
- responseCodes = [200, 201, 409]
-
- failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
- if (len(failedNormatives) > 0):
- error_and_exit(1, None)
- else:
- error_and_exit(0, None)
+ print 'Number of arguments:', len(sys.argv), 'arguments.'
+
+ beHost = 'localhost'
+ bePort = '8080'
+ adminUser = 'jh0003'
+ updateversion = 'true'
+ scheme = 'http'
+
+ try:
+ opts, args = getopt.getopt(argv,"i:p:u:v:h:s:",["ip=","port=","user=","updateversion=","scheme="])
+ except getopt.GetoptError:
+ usage()
+ error_and_exit(2, 'Invalid input')
+
+ for opt, arg in opts:
+ #print opt, arg
+ if opt == '-h':
+ usage()
+ sys.exit(3)
+ elif opt in ("-i", "--ip"):
+ beHost = arg
+ elif opt in ("-p", "--port"):
+ bePort = arg
+ elif opt in ("-u", "--user"):
+ adminUser = arg
+ elif opt in ("-s", "--scheme"):
+ scheme = arg
+ elif opt in ("-v", "--updateversion"):
+ if (arg.lower() == "false" or arg.lower() == "no"):
+ updateversion = 'false'
+
+ print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', updateversion =', updateversion
+
+ if ( beHost == None ):
+ usage()
+ sys.exit(3)
+
+ results = importNormativeTypes(scheme, beHost, bePort, adminUser, "../../../import/tosca/normative-types/", updateversion)
+
+ print "-----------------------------"
+ for result in results:
+ print "{0:20} | {1:6}".format(result[0], result[1])
+ print "-----------------------------"
+
+ responseCodes = [200, 201]
+
+ if(updateversion == 'false'):
+ responseCodes = [200, 201, 409]
+
+ failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results)
+ if (len(failedNormatives) > 0):
+ error_and_exit(1, None)
+ else:
+ error_and_exit(0, None)
if __name__ == "__main__":
- main(sys.argv[1:])
+ main(sys.argv[1:])
+
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py b/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py
index 3e9103a95f..c573a448a4 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importONAPNormativeAll.py
@@ -66,8 +66,8 @@ def main(argv):
opts = []
try:
- opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s",
- ["scheme=", "ip=", "port=", "user=", "debug=", "updateversion="])
+ opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s:",
+ ["ip=", "port=", "user=", "debug=", "updateversion=", "scheme="])
except getopt.GetoptError:
usage()
error_and_exit(2, 'Invalid input')
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py b/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
index 23e854bcb8..09fe726cec 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/importUsersFromYaml.py
@@ -60,7 +60,8 @@ def getUser(scheme, beHost, bePort, user):
c.setopt(c.URL, url)
if scheme == 'https':
- c.setopt(c.SSL_VERIFYPEER, 0)
+ c.setopt(pycurl.SSL_VERIFYPEER, 0)
+ c.setopt(pycurl.SSL_VERIFYHOST, 0)
#adminHeader = 'USER_ID: ' + adminUser
c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json'])
@@ -106,7 +107,8 @@ def createUser(scheme, beHost, bePort, user, adminUser):
c.setopt(c.POSTFIELDS, data)
if scheme == 'https':
- c.setopt(c.SSL_VERIFYPEER, 0)
+ c.setopt(pycurl.SSL_VERIFYPEER, 0)
+ c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(c.WRITEFUNCTION, lambda x: None)
#print("before perform")
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json b/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json
index 1ef72856a4..ffda46e042 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json
+++ b/catalog-be/src/main/resources/scripts/import/tosca/typesToUpgrade.json
@@ -1,7 +1,35 @@
{
"heat": [
- "Generic_PNF"
+ "AbstractSubstitute",
+ "cinderVolume",
+ "contrailAbstractSubstitute",
+ "contrailCompute",
+ "contrailNetworkRules",
+ "contrailPort",
+ "contrailV2NetworkRules",
+ "contrailV2VirtualMachineInterface",
+ "contrailVirtualNetwork",
+ "contrailV2VLANSubInterface",
+ "contrailV2VLANSubInterfaceV2",
+ "contrailVirtualNetwork",
+ "extContrailCP",
+ "extCp",
+ "extNeutronCP",
+ "extVirtualMachineInterfaceCP",
+ "extVl",
+ "forwardingPath",
+ "Generic_PNF",
+ "Generic_Service",
+ "Generic_VF",
+ "Generic_VFC",
+ "globalCompute",
+ "globalPort",
+ "neutronNet",
+ "neutronPort",
+ "novaServer",
+ "securityRules"
],
"normative": [
+ "loadBalancer"
]
-} \ No newline at end of file
+}
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py
index b4447c26d1..222d22d1f1 100644
--- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py
+++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py
@@ -59,7 +59,6 @@ def main(argv):
updateOnapVersion = 'false'
importCommon.debugFlag = False
scheme = 'http'
- opts = []
try:
opts, args = getopt.getopt(argv, "i:p:u:d:v:h:s",
diff --git a/catalog-be/src/main/resources/swagger/index.html b/catalog-be/src/main/resources/swagger/index.html
index 1e6926d136..0e9a9e8de3 100644
--- a/catalog-be/src/main/resources/swagger/index.html
+++ b/catalog-be/src/main/resources/swagger/index.html
@@ -1,20 +1,3 @@
-<!--
- ~ Copyright (C) 2018 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.
- -->
-
-
<!DOCTYPE html>
<html>
<head>
diff --git a/catalog-be/src/main/resources/swagger/o2c.html b/catalog-be/src/main/resources/swagger/o2c.html
index cec91e5bd1..88e8bf114b 100644
--- a/catalog-be/src/main/resources/swagger/o2c.html
+++ b/catalog-be/src/main/resources/swagger/o2c.html
@@ -1,20 +1,3 @@
-<!--
- ~ Copyright (C) 2018 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.
- -->
-
-
<script>
var qp = null;
if(window.location.hash) {
diff --git a/catalog-be/src/main/webapp/WEB-INF/web.xml b/catalog-be/src/main/webapp/WEB-INF/web.xml
index 027601b952..3acf64ca6f 100644
--- a/catalog-be/src/main/webapp/WEB-INF/web.xml
+++ b/catalog-be/src/main/webapp/WEB-INF/web.xml
@@ -1,164 +1,301 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
-
- <servlet>
- <servlet-name>jersey</servlet-name>
- <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
- <init-param>
- <param-name>jersey.config.server.provider.packages</param-name>
- <param-value>io.swagger.jaxrs.json, org.openecomp.sdc.be.servlets</param-value>
- </init-param>
- <init-param>
- <param-name>jersey.config.server.provider.classnames</param-name>
- <param-value>io.swagger.jersey.listing.ApiListingResourceJSON,
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+
+ <servlet>
+ <servlet-name>jersey</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>io.swagger.jaxrs.json, org.openecomp.sdc.be.servlets</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>io.swagger.jersey.listing.ApiListingResourceJSON,
org.glassfish.jersey.media.multipart.MultiPartFeature,
org.openecomp.sdc.be.filters.BeServletFilter,
org.openecomp.sdc.be.filters.ComponentsAvailabilityFilter,
+ org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature,
org.openecomp.sdc.be.servlets.exception.DefaultExceptionMapper,
org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper,
+ org.openecomp.sdc.be.servlets.exception.ConstraintViolationExceptionMapper,
org.openecomp.sdc.be.servlets.exception.StorageExceptionMapper,
- org.openecomp.sdc.be.view.MixinModelWriter
+ org.openecomp.sdc.be.view.MixinModelWriter,
+ org.openecomp.sdc.config.ObjectMapperProvider
</param-value>
- </init-param>
- <init-param>
- <param-name>swagger.scanner.id</param-name>
- <param-value>test.1</param-value>
- </init-param>
- <init-param>
- <param-name>swagger.config.id</param-name>
- <param-value>test.1</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>jersey</servlet-name>
- <url-pattern>/sdc2/rest/*</url-pattern>
- </servlet-mapping>
-
- <servlet>
- <servlet-name>EsGateway</servlet-name>
- <servlet-class>org.openecomp.sdc.be.monitoring.EsGateway</servlet-class>
- <load-on-startup>1</load-on-startup>
- <async-supported>true</async-supported>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>EsGateway</servlet-name>
- <url-pattern>/sdc2/esGateway/*</url-pattern>
- </servlet-mapping>
-
- <servlet>
- <servlet-name>jerseyDistribution</servlet-name>
- <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
- <init-param>
- <param-name>jersey.config.server.provider.packages</param-name>
- <param-value>io.swagger.jaxrs.json, org.openecomp.sdc.be.distribution.servlet, org.openecomp.sdc.be.externalapi.servlet</param-value>
- </init-param>
- <init-param>
- <param-name>jersey.config.server.provider.classnames</param-name>
- <param-value>io.swagger.jersey.listing.ApiListingResourceJSON,
- org.glassfish.jersey.media.multipart.MultiPartFeature,
- org.openecomp.sdc.be.filters.BeServletFilter,
- org.openecomp.sdc.be.servlets.exception.DefaultExceptionMapper,
- org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper,
- org.openecomp.sdc.be.servlets.exception.StorageExceptionMapper,
- org.openecomp.sdc.be.filters.BasicAuthenticationFilter</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.scanner.id</param-name>
- <param-value>test.2</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.config.id</param-name>
- <param-value>test.2</param-value>
- </init-param>
-
- <load-on-startup>1</load-on-startup>
- <async-supported>true</async-supported>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>jerseyDistribution</servlet-name>
- <url-pattern>/sdc/*</url-pattern>
- </servlet-mapping>
-
- <servlet>
- <servlet-name>Internal-APIs-Configurations</servlet-name>
- <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
-
- <init-param>
- <param-name>api.version</param-name>
- <param-value>1.2.0</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.api.title</param-name>
- <param-value>Internal API's</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.api.basepath</param-name>
- <param-value>/sdc2/rest</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.scanner.id</param-name>
- <param-value>test.1</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.config.id</param-name>
- <param-value>test.1</param-value>
- </init-param>
-
- <load-on-startup>2</load-on-startup>
- <async-supported>true</async-supported>
- </servlet>
-
- <servlet>
- <servlet-name>External and Distribution API's</servlet-name>
- <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
-
- <init-param>
- <param-name>api.version</param-name>
- <param-value>1.2.0</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.api.title</param-name>
- <param-value>DistributionAndExternalAPIs</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.api.basepath</param-name>
- <!-- Check if second param can be added -->
- <param-value>/sdc</param-value>
- </init-param>
-
- <init-param>
- <param-name>swagger.context.id</param-name>
- <param-value>test.2</param-value>
- </init-param>
- <load-on-startup>2</load-on-startup>
- </servlet>
-
- <servlet>
- <servlet-name>ViewStatusMessages</servlet-name>
- <servlet-class>ch.qos.logback.classic.ViewStatusMessagesServlet</servlet-class>
- <async-supported>true</async-supported>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>ViewStatusMessages</servlet-name>
- <url-pattern>/lbClassicStatus</url-pattern>
- </servlet-mapping>
+ </init-param>
+ <init-param>
+ <param-name>swagger.scanner.id</param-name>
+ <param-value>test.1</param-value>
+ </init-param>
+ <init-param>
+ <param-name>swagger.config.id</param-name>
+ <param-value>test.1</param-value>
+ </init-param>
+ <init-param>
+ <param-name>exclude_url_endpoints</param-name>
+ <param-value>/api/v3/analytics,/api/v3/storeAnalytics</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>jersey</servlet-name>
+ <url-pattern>/sdc2/rest/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>jerseyDistribution</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>io.swagger.jaxrs.json, org.openecomp.sdc.be.distribution.servlet, org.openecomp.sdc.be.externalapi.servlet </param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>io.swagger.jersey.listing.ApiListingResourceJSON,
+ org.glassfish.jersey.media.multipart.MultiPartFeature,
+ org.openecomp.sdc.be.filters.BeServletFilter,
+ org.openecomp.sdc.be.servlets.exception.DefaultExceptionMapper,
+ org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper,
+ org.openecomp.sdc.be.servlets.exception.StorageExceptionMapper,
+ org.openecomp.sdc.be.filters.BasicAuthenticationFilter
+ </param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.scanner.id</param-name>
+ <param-value>test.2</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.config.id</param-name>
+ <param-value>test.2</param-value>
+ </init-param>
+
+ <load-on-startup>1</load-on-startup>
+ <async-supported>true</async-supported>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>jerseyDistribution</servlet-name>
+ <url-pattern>/sdc/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>Internal-APIs-Configurations</servlet-name>
+ <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
+
+ <init-param>
+ <param-name>api.version</param-name>
+ <param-value>1.2.0</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.api.title</param-name>
+ <param-value>Internal API's</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.api.basepath</param-name>
+ <param-value>/sdc2/rest</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.scanner.id</param-name>
+ <param-value>test.1</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.config.id</param-name>
+ <param-value>test.1</param-value>
+ </init-param>
+
+ <load-on-startup>2</load-on-startup>
+ <async-supported>true</async-supported>
+ </servlet>
+
+ <servlet>
+ <servlet-name>External and Distribution API's</servlet-name>
+ <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
+
+ <init-param>
+ <param-name>api.version</param-name>
+ <param-value>1.2.0</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.api.title</param-name>
+ <param-value>DistributionAndExternalAPIs</param-value>
+ </init-param>
+ <init-param>
+ <param-name>swagger.api.basepath</param-name>
+ <!-- Check if second param can be added -->
+ <param-value>/sdc</param-value>
+ </init-param>
+
+ <init-param>
+ <param-name>swagger.context.id</param-name>
+ <param-value>test.2</param-value>
+ </init-param>
+ <load-on-startup>2</load-on-startup>
+ </servlet>
+
+ <!-- ECOMP Portal -->
+ <servlet>
+ <servlet-name>ECOMPServlet</servlet-name>
+ <servlet-class>org.onap.portalsdk.core.onboarding.crossapi.PortalRestAPIProxy</servlet-class>
+ <load-on-startup>3</load-on-startup>
+ <async-supported>true</async-supported>
+ </servlet>
+
+<!-- <filter>-->
+<!-- <filter-name>CadiAuthFilter</filter-name>-->
+<!-- <filter-class>org.onap.portalsdk.core.onboarding.crossapi.CadiAuthFilter</filter-class>-->
+<!-- <init-param>-->
+<!-- <param-name>cadi_prop_files</param-name>-->
+<!-- &lt;!&ndash; Add Absolute path of cadi.properties &ndash;&gt;-->
+<!-- <param-value>etc/cadi.properties</param-value>-->
+<!-- </init-param>-->
+<!-- &lt;!&ndash;Add param values with comma delimited values &ndash;&gt;-->
+<!-- &lt;!&ndash; for example /api/v3/*,/auxapi/*&ndash;&gt;-->
+<!-- <init-param>-->
+<!-- <param-name>include_url_endpoints</param-name>-->
+<!-- <param-value>/api/v3/roles,/api/v3/user/*,/api/v3/user/*/roles,/api/v3/users,/api/v3/sessionTimeOuts,/api/v3/updateSessionTimeOuts</param-value>-->
+<!-- </init-param>-->
+<!-- <init-param>-->
+<!-- <param-name>exclude_url_endpoints</param-name>-->
+<!-- <param-value>/api/v3/analytics,/api/v3/storeAnalytics</param-value>-->
+<!-- </init-param>-->
+<!-- </filter>-->
+<!-- <filter-mapping>-->
+<!-- <filter-name>CadiAuthFilter</filter-name>-->
+<!-- <url-pattern>/api/v3/*</url-pattern>-->
+<!-- </filter-mapping>-->
+
+ <servlet>
+ <servlet-name>ViewStatusMessages</servlet-name>
+ <servlet-class>ch.qos.logback.classic.ViewStatusMessagesServlet</servlet-class>
+ <async-supported>true</async-supported>
+ </servlet>
+
+ <servlet>
+ <servlet-name>TogglzConsoleServlet</servlet-name>
+ <servlet-class>org.togglz.console.TogglzConsoleServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>TogglzConsoleServlet</servlet-name>
+ <url-pattern>/catalog/togglz/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>ViewStatusMessages</servlet-name>
+ <url-pattern>/lbClassicStatus</url-pattern>
+ </servlet-mapping>
+
+ <!-- <filter>
+ <filter-name>GzipFilter</filter-name>
+ <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
+ <async-supported>true</async-supported>
+ <init-param>
+ <param-name>methods</param-name>
+ <param-value>GET,POST,PUT,DELETE</param-value>
+ </init-param>
+ <init-param>
+ <param-name>mimeTypes</param-name>
+ <param-value>text/html,text/plain,text/css,application/javascript,application/json</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>GzipFilter</filter-name>
+ <url-pattern>/sdc2/rest/*</url-pattern>
+ </filter-mapping>
+
+ -->
+ <!--<filter>-->
+ <!--<filter-name>RestrictionAccessFilter</filter-name>-->
+ <!--<filter-class>org.openecomp.sdc.be.filters.RestrictionAccessFilter</filter-class>-->
+ <!--<async-supported>true</async-supported>-->
+ <!--</filter>-->
+
+<!-- <filter>-->
+<!-- <filter-name>gatewayFilter</filter-name>-->
+<!-- <filter-class>org.openecomp.sdc.be.filters.GatewayFilter</filter-class>-->
+<!-- </filter>-->
+
+ <filter>
+ <filter-name>gatewayFilter</filter-name>
+ <filter-class>
+ org.springframework.web.filter.DelegatingFilterProxy
+ </filter-class>
+ <init-param>
+ <param-name>targetFilterLifecycle</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>gatewayFilter</filter-name>
+ <url-pattern>/sdc2/rest/*</url-pattern>
+ <url-pattern>/sdc/*</url-pattern>
+ </filter-mapping>
+
+<!-- <filter>-->
+<!-- <filter-name>beRestrictionAccessFilter</filter-name>-->
+<!-- <filter-class>-->
+<!-- org.springframework.web.filter.DelegatingFilterProxy-->
+<!-- </filter-class>-->
+<!-- <init-param>-->
+<!-- <param-name>targetFilterLifecycle</param-name>-->
+<!-- <param-value>true</param-value>-->
+<!-- </init-param>-->
+<!-- </filter>-->
+<!-- <filter-mapping>-->
+<!-- <filter-name>beRestrictionAccessFilter</filter-name>-->
+<!-- <url-pattern>/sdc2/rest/*</url-pattern>-->
+<!-- </filter-mapping>-->
+
+<!-- <filter>-->
+<!-- <filter-name>CADI</filter-name>-->
+<!-- <filter-class>org.openecomp.sdc.be.filters.BeCadiServletFilter</filter-class>-->
+<!-- <init-param>-->
+<!-- <param-name>cadi_prop_files</param-name>-->
+<!-- <param-value>etc/cadi.properties</param-value>-->
+<!-- </init-param>-->
+<!-- </filter>-->
+
+<!-- <filter-mapping>-->
+<!-- <filter-name>CADI</filter-name>-->
+<!-- <url-pattern>/sdc/*</url-pattern>-->
+<!-- <url-pattern>/sdc2/rest/*</url-pattern>-->
+<!-- </filter-mapping>-->
+
+ <filter>
+ <filter-name>reqValidationFilter</filter-name>
+ <filter-class>
+ org.springframework.web.filter.DelegatingFilterProxy
+ </filter-class>
+ <init-param>
+ <param-name>targetFilterLifecycle</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>reqValidationFilter</filter-name>
+ <url-pattern>/sdc2/rest/*</url-pattern>
+ <url-pattern>/sdc/*</url-pattern>
+ </filter-mapping>
+
+ <error-page>
+ <exception-type>java.lang.RuntimeException</exception-type>
+ <location>/sdc2/rest/v1/catalog/handleException/</location>
+ </error-page>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-context.xml</param-value>
@@ -168,11 +305,11 @@
<listener-class>org.openecomp.sdc.be.listen.BEAppContextListener</listener-class>
</listener>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- </welcome-file-list>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
</web-app>
diff --git a/catalog-be/src/main/webapp/index.html b/catalog-be/src/main/webapp/index.html
index b2231d6ffc..4b26987758 100644
--- a/catalog-be/src/main/webapp/index.html
+++ b/catalog-be/src/main/webapp/index.html
@@ -1,20 +1,3 @@
-<!--
- ~ Copyright (C) 2018 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.
- -->
-
-
<html>
<body>