From 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 31 Dec 2018 17:21:27 +0200 Subject: Merge from ECOMP's repository Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern --- .../src/main/java/org/onap/vid/RelatedTo.java | 39 -- .../src/main/java/org/onap/vid/aai/AaiClient.java | 425 ++++++++---- .../java/org/onap/vid/aai/AaiClientInterface.java | 27 +- .../java/org/onap/vid/aai/AaiGetVnfResponse.java | 3 +- .../java/org/onap/vid/aai/AaiOverTLSClient.java | 43 +- .../onap/vid/aai/AaiOverTLSClientInterface.java | 3 +- .../org/onap/vid/aai/AaiResponseTranslator.java | 4 +- .../onap/vid/aai/AaiResponseWithRequestInfo.java | 3 +- .../org/onap/vid/aai/ExceptionWithRequestInfo.java | 4 +- .../org/onap/vid/aai/OperationalEnvironment.java | 39 +- .../java/org/onap/vid/aai/PombaClientImpl.java | 23 +- .../java/org/onap/vid/aai/PombaRestInterface.java | 6 +- .../java/org/onap/vid/aai/ServiceInstance.java | 12 +- .../java/org/onap/vid/aai/ServiceInstances.java | 4 +- .../vid/aai/ServiceInstancesSearchResults.java | 5 +- .../java/org/onap/vid/aai/ServiceSubscription.java | 4 +- .../org/onap/vid/aai/ServiceSubscriptions.java | 4 +- .../src/main/java/org/onap/vid/aai/Services.java | 6 +- .../org/onap/vid/aai/SubscriberWithFilter.java | 2 +- .../onap/vid/aai/model/AaiGetAicZone/AicZones.java | 4 +- .../org/onap/vid/aai/model/AaiGetAicZone/Zone.java | 6 +- .../CloudRegion.java | 55 ++ .../AaiGetNetworkCollectionDetails/Network.java | 16 +- .../ServiceInstance.java | 42 +- .../model/AaiGetNetworkCollectionDetails/Vlan.java | 41 ++ .../model/AaiGetNetworkCollectionDetails/Vnf.java | 84 +++ .../OperationalEnvironmentList.java | 7 +- .../org/onap/vid/aai/model/AaiGetPnfResponse.java | 7 +- .../org/onap/vid/aai/model/AaiGetPnfs/Pnf.java | 32 +- .../aai/model/AaiGetPortMirroringSourcePorts.java | 2 +- .../GetServicesAAIRespone.java | 3 +- .../model/AaiGetServicesRequestModel/Service.java | 4 +- .../model/AaiGetTenatns/GetTenantsResponse.java | 23 +- .../onap/vid/aai/model/AaiRelationResponse.java | 16 +- .../vid/aai/model/CustomQuerySimpleResult.java | 18 + ...tServiceModelsByDistributionStatusResponse.java | 4 +- .../onap/vid/aai/model/LogicalLinkResponse.java | 14 +- .../main/java/org/onap/vid/aai/model/Model.java | 20 +- .../main/java/org/onap/vid/aai/model/ModelVer.java | 28 +- .../java/org/onap/vid/aai/model/ModelVers.java | 8 +- .../java/org/onap/vid/aai/model/OwningEntity.java | 10 +- .../onap/vid/aai/model/OwningEntityResponse.java | 6 +- .../java/org/onap/vid/aai/model/Permissions.kt | 6 + .../java/org/onap/vid/aai/model/PnfProperties.java | 47 +- .../java/org/onap/vid/aai/model/PnfResult.java | 40 +- .../onap/vid/aai/model/PortDetailsTranslator.java | 42 +- .../main/java/org/onap/vid/aai/model/Project.java | 6 +- .../org/onap/vid/aai/model/ProjectResponse.java | 5 - .../java/org/onap/vid/aai/model/Properties.java | 77 ++- .../java/org/onap/vid/aai/model/RelatedTo.java | 14 +- .../org/onap/vid/aai/model/RelatedToProperty.java | 8 +- .../java/org/onap/vid/aai/model/Relationship.java | 15 +- .../org/onap/vid/aai/model/RelationshipData.java | 42 +- .../org/onap/vid/aai/model/RelationshipList.java | 4 +- .../java/org/onap/vid/aai/model/ResourceType.java | 10 +- .../main/java/org/onap/vid/aai/model/Result.java | 4 +- .../org/onap/vid/aai/model/ServiceProperties.java | 25 +- .../onap/vid/aai/model/ServiceRelationships.java | 62 +- .../java/org/onap/vid/aai/model/SimpleResult.java | 32 +- .../java/org/onap/vid/aai/model/VnfResult.java | 34 +- .../interfaces/AaiModelWithRelationships.java | 7 + .../org/onap/vid/aai/util/AAIRestInterface.java | 108 ++- .../org/onap/vid/aai/util/AAITreeConverter.java | 89 +++ .../main/java/org/onap/vid/aai/util/CacheConfig.kt | 52 ++ .../java/org/onap/vid/aai/util/CacheProvider.java | 37 + .../aai/util/CacheProviderWithLoadingCache.java | 100 +++ .../org/onap/vid/aai/util/HttpsAuthClient.java | 28 +- .../onap/vid/aai/util/HttpsComponentsClient.java | 117 ---- .../JettyObfuscationConversionCommandLineUtil.java | 4 +- .../vid/aai/util/ServiceInstanceStandardQuery.java | 93 +++ .../onap/vid/aai/util/SystemPropertyHelper.java | 11 + .../main/java/org/onap/vid/asdc/AsdcClient.java | 1 + .../org/onap/vid/asdc/beans/SecureServices.java | 1 - .../java/org/onap/vid/asdc/beans/tosca/Input.java | 17 +- .../onap/vid/asdc/beans/tosca/InputProperties.java | 3 - .../onap/vid/asdc/beans/tosca/NodeTemplate.java | 4 +- .../org/onap/vid/asdc/beans/tosca/Property.java | 2 +- .../vid/asdc/beans/tosca/SubstitutionMappings.java | 4 +- .../vid/asdc/beans/tosca/TopologyTemplate.java | 6 +- .../org/onap/vid/asdc/beans/tosca/ToscaCsar.java | 2 +- .../org/onap/vid/asdc/beans/tosca/ToscaMeta.java | 11 +- .../org/onap/vid/asdc/local/LocalAsdcClient.java | 60 +- .../onap/vid/asdc/parser/ServiceModelInflator.kt | 43 ++ .../onap/vid/asdc/parser/ToscaNamingPolicy.java | 28 + .../org/onap/vid/asdc/parser/ToscaParserImpl.java | 5 +- .../org/onap/vid/asdc/parser/ToscaParserImpl2.java | 449 +++++++----- .../onap/vid/asdc/parser/VidNotionsBuilder.java | 130 ++++ .../changeManagement/ChangeManagementRequest.java | 21 +- .../vid/changeManagement/CloudConfiguration.java | 10 +- .../changeManagement/LeanCloudConfiguration.java | 9 +- .../org/onap/vid/changeManagement/ModelInfo.java | 13 +- .../ModelInfoOfRelatedInstance.java | 10 +- .../onap/vid/changeManagement/RequestDetails.java | 5 + .../org/onap/vid/changeManagement/RequestInfo.java | 10 +- .../vid/changeManagement/UpdateRequestInfo.java | 4 +- .../org/onap/vid/changeManagement/VnfDetails.java | 1 - .../changeManagement/VnfDetailsWithWorkflows.java | 10 +- .../onap/vid/changeManagement/WorkflowsDetail.java | 1 - .../java/org/onap/vid/client/HttpBasicClient.java | 5 - .../java/org/onap/vid/client/HttpsBasicClient.java | 111 --- .../java/org/onap/vid/client/SyncRestClient.java | 8 +- .../org/onap/vid/controller/AaiController.java | 731 ++++++++++++++++++++ .../org/onap/vid/controller/AaiController2.java | 98 +++ .../AaiServiceInstanceStandardQueryController.java | 173 +++++ .../vid/controller/AsyncControllerForTests.java | 48 ++ .../controller/AsyncInstantiationController.java | 104 +++ .../vid/controller/ChangeManagementController.java | 213 ++++++ .../org/onap/vid/controller/ControllersUtils.java | 45 ++ .../vid/controller/FeatureTogglingController.java | 29 + .../onap/vid/controller/HealthCheckController.java | 135 ++++ .../java/org/onap/vid/controller/HealthStatus.java | 31 + .../org/onap/vid/controller/LoggerController.java | 115 +++ .../onap/vid/controller/MaintenanceController.java | 152 ++++ .../java/org/onap/vid/controller/MsoConfig.java | 66 ++ .../org/onap/vid/controller/MsoController.java | 705 +++++++++++++++++++ .../OperationalEnvironmentController.java | 362 ++++++++++ .../org/onap/vid/controller/ProbeController.java | 42 ++ .../onap/vid/controller/PropertyController.java | 126 ++++ .../vid/controller/RoleGeneratorController.java | 26 + .../org/onap/vid/controller/VersionController.java | 63 ++ .../org/onap/vid/controller/VidController.java | 114 +++ .../controller/VidRestrictedBaseController.java | 42 ++ .../org/onap/vid/controller/ViewLogController.java | 65 ++ .../java/org/onap/vid/controller/WebConfig.java | 193 ++++++ .../controller/filter/ClientCredentialsFilter.java | 10 +- .../filter/PromiseEcompRequestIdFilter.java | 17 +- .../vid/controller/test/TestAaiController.java | 2 +- .../vid/controller/test/TestAsdcController.java | 2 +- .../vid/controller/test/TestMsoController.java | 2 +- .../org/onap/vid/controllers/AaiController.java | 763 -------------------- .../vid/controllers/AsyncControllerForTests.java | 56 -- .../controllers/AsyncInstantiationController.java | 78 --- .../controllers/ChangeManagementController.java | 227 ------ .../org/onap/vid/controllers/ControllersUtils.java | 47 -- .../vid/controllers/FeatureTogglingController.java | 29 - .../vid/controllers/HealthCheckController.java | 135 ---- .../org/onap/vid/controllers/HealthStatus.java | 31 - .../org/onap/vid/controllers/LoggerController.java | 115 --- .../vid/controllers/MaintenanceController.java | 156 ----- .../java/org/onap/vid/controllers/MsoConfig.java | 68 -- .../org/onap/vid/controllers/MsoController.java | 693 ------------------- .../OperationalEnvironmentController.java | 362 ---------- .../org/onap/vid/controllers/PolicyController.java | 84 --- .../org/onap/vid/controllers/ProbeController.java | 27 - .../onap/vid/controllers/PropertyController.java | 132 ---- .../vid/controllers/RoleGeneratorController.java | 26 - .../org/onap/vid/controllers/VidController.java | 114 --- .../controllers/VidRestrictedBaseController.java | 43 -- .../onap/vid/controllers/ViewLogController.java | 65 -- .../java/org/onap/vid/controllers/WebConfig.java | 226 ------ .../src/main/java/org/onap/vid/job/Job.java | 28 +- .../src/main/java/org/onap/vid/job/JobAdapter.java | 11 +- .../src/main/java/org/onap/vid/job/JobCommand.java | 9 +- .../main/java/org/onap/vid/job/JobException.java | 16 + .../src/main/java/org/onap/vid/job/JobType.java | 24 +- .../java/org/onap/vid/job/JobsBrokerService.java | 2 + .../onap/vid/job/command/ALaCarteServiceCommand.kt | 122 ++++ .../ALaCarteServiceInstantiationCommand.java | 21 + .../job/command/BaseInProgressStatusCommand.java | 95 +++ .../vid/job/command/BaseInstantiationCommand.java | 18 + .../org/onap/vid/job/command/BaseRootCommand.java | 41 ++ .../onap/vid/job/command/BaseWatchingCommand.java | 70 ++ .../java/org/onap/vid/job/command/CommandBase.java | 27 + .../onap/vid/job/command/CommandParentData.java | 80 +++ .../org/onap/vid/job/command/CommandUtils.java | 46 ++ .../org/onap/vid/job/command/ExpiryChecker.java | 8 + .../org/onap/vid/job/command/HttpCallCommand.java | 8 +- .../vid/job/command/InProgressStatusCommand.java | 137 ---- .../vid/job/command/InProgressStatusService.java | 87 +++ .../onap/vid/job/command/InstanceGroupCommand.kt | 59 ++ .../command/InstanceGroupInstantiationCommand.java | 47 ++ .../onap/vid/job/command/JobCommandFactory.java | 2 +- .../command/MacroServiceInstantiationCommand.java | 26 + .../java/org/onap/vid/job/command/MsoResult.kt | 9 + .../vid/job/command/MsoResultHandlerService.kt | 66 ++ .../job/command/NetworkInstantiationCommand.java | 41 ++ .../org/onap/vid/job/command/ResourceCommand.kt | 324 +++++++++ .../command/ResourceInProgressStatusCommand.java | 32 + .../job/command/ResourceInstantiationCommand.java | 87 +++ .../ResourceWithChildrenInProgressCommand.java | 65 ++ .../command/ServiceInProgressStatusCommand.java | 100 +++ .../job/command/ServiceInstantiationCommand.java | 146 ++-- .../job/command/VfmoduleInstantiationCommand.java | 44 ++ .../job/command/VnfInProgressStatusCommand.java | 87 +++ .../vid/job/command/VnfInstantiationCommand.java | 50 ++ .../VolumeGroupInProgressStatusCommand.java | 65 ++ .../command/VolumeGroupInstantiationCommand.java | 83 +++ .../onap/vid/job/command/WatchChildrenJobsBL.kt | 61 ++ .../org/onap/vid/job/command/WatchingCommand.java | 33 + .../vid/job/command/WatchingCommandBaseModule.java | 93 +++ .../java/org/onap/vid/job/impl/JobAdapterImpl.java | 55 +- .../java/org/onap/vid/job/impl/JobDaoImpl.java | 40 +- .../main/java/org/onap/vid/job/impl/JobData.java | 54 ++ .../onap/vid/job/impl/JobSchedulerInitializer.java | 4 +- .../java/org/onap/vid/job/impl/JobSharedData.java | 84 +++ .../main/java/org/onap/vid/job/impl/JobWorker.java | 35 +- .../job/impl/JobsBrokerServiceInDatabaseImpl.java | 75 +- .../src/main/java/org/onap/vid/model/Action.java | 15 + .../src/main/java/org/onap/vid/model/CR.java | 2 +- .../java/org/onap/vid/model/CommandProperty.java | 5 +- .../src/main/java/org/onap/vid/model/Group.java | 21 +- .../java/org/onap/vid/model/GroupProperties.java | 9 + .../java/org/onap/vid/model/JobAuditStatus.java | 75 +- .../main/java/org/onap/vid/model/MinimalNode.kt | 8 + .../java/org/onap/vid/model/ModelConstants.java | 12 +- .../main/java/org/onap/vid/model/NameCounter.java | 2 +- .../main/java/org/onap/vid/model/NewNetwork.java | 2 - .../src/main/java/org/onap/vid/model/NewNode.java | 18 +- .../java/org/onap/vid/model/NewServiceModel.java | 91 +-- .../src/main/java/org/onap/vid/model/NewVNF.java | 41 +- .../src/main/java/org/onap/vid/model/Node.java | 44 +- .../org/onap/vid/model/PortMirroringConfig.java | 10 - .../onap/vid/model/RequestReferencesContainer.java | 4 +- .../src/main/java/org/onap/vid/model/Resource.java | 28 - .../main/java/org/onap/vid/model/ResourceGroup.kt | 13 + .../src/main/java/org/onap/vid/model/Service.java | 14 +- .../main/java/org/onap/vid/model/ServiceInfo.java | 75 +- .../main/java/org/onap/vid/model/ServiceModel.java | 41 +- .../main/java/org/onap/vid/model/ServiceProxy.java | 11 - .../java/org/onap/vid/model/SoftDeleteRequest.java | 42 ++ .../main/java/org/onap/vid/model/Subscriber.java | 2 +- .../java/org/onap/vid/model/SubscriberList.java | 2 - .../src/main/java/org/onap/vid/model/VNF.java | 29 +- .../src/main/java/org/onap/vid/model/VfModule.java | 14 +- .../src/main/java/org/onap/vid/model/VidNotions.kt | 34 + .../org/onap/vid/model/aaiTree/AAITreeNode.java | 178 +++++ .../org/onap/vid/model/aaiTree/AbstractNode.java | 53 ++ .../onap/vid/model/aaiTree/FailureAAITreeNode.java | 31 + .../java/org/onap/vid/model/aaiTree/Network.java | 20 + .../main/java/org/onap/vid/model/aaiTree/Node.java | 139 ++++ .../org/onap/vid/model/aaiTree/RelatedVnf.java | 52 ++ .../onap/vid/model/aaiTree/ServiceInstance.java | 193 ++++++ .../java/org/onap/vid/model/aaiTree/VfModule.java | 41 ++ .../main/java/org/onap/vid/model/aaiTree/Vnf.java | 54 ++ .../java/org/onap/vid/model/aaiTree/VnfGroup.java | 52 ++ .../vid/model/probes/ExternalComponentStatus.java | 2 +- .../onap/vid/model/probes/HttpRequestMetadata.java | 61 +- .../model/serviceInstantiation/BaseResource.java | 115 +++ .../model/serviceInstantiation/InstanceGroup.java | 22 + .../vid/model/serviceInstantiation/Network.java | 74 ++ .../serviceInstantiation/ServiceInstantiation.java | 90 ++- .../vid/model/serviceInstantiation/VfModule.java | 60 +- .../onap/vid/model/serviceInstantiation/Vnf.java | 81 +-- .../java/org/onap/vid/mso/MsoBusinessLogic.java | 18 +- .../org/onap/vid/mso/MsoBusinessLogicImpl.java | 148 ++-- .../main/java/org/onap/vid/mso/MsoInterface.java | 41 +- .../main/java/org/onap/vid/mso/MsoProperties.java | 30 +- .../java/org/onap/vid/mso/MsoResponseWrapper.java | 4 +- .../java/org/onap/vid/mso/MsoResponseWrapper2.java | 6 +- .../onap/vid/mso/MsoResponseWrapperInterface.java | 4 +- .../src/main/java/org/onap/vid/mso/MsoUtil.java | 40 +- .../org/onap/vid/mso/RestMsoImplementation.java | 237 ++++--- .../src/main/java/org/onap/vid/mso/RestObject.java | 17 +- .../onap/vid/mso/RestObjectWithRequestInfo.java | 61 ++ .../BaseResourceInstantiationRequestDetails.java | 142 ++++ .../org/onap/vid/mso/model/CloudConfiguration.java | 173 +++++ .../InstanceGroupInstantiationRequestDetails.java | 48 ++ .../java/org/onap/vid/mso/model/ModelInfo.java | 279 ++++++++ .../model/NetworkInstantiationRequestDetails.java | 86 +++ .../model/OperationalEnvironmentActivateInfo.java | 3 +- .../java/org/onap/vid/mso/model/RequestInfo.java | 376 ++++++++++ .../org/onap/vid/mso/model/RequestParameters.java | 123 ++++ .../org/onap/vid/mso/model/RequestReferences.java | 121 ++++ .../vid/mso/model/ServiceDeletionRequestDetails.kt | 15 + .../model/ServiceInstantiationRequestDetails.java | 84 ++- .../java/org/onap/vid/mso/model/UserParam.java | 98 +++ .../org/onap/vid/mso/model/UserParamTypes.java | 4 + .../model/VfModuleInstantiationRequestDetails.java | 111 +++ .../java/org/onap/vid/mso/model/VfModuleMacro.java | 71 ++ .../mso/model/VnfInstantiationRequestDetails.java | 87 +++ .../vid/mso/model/VolumeGroupRequestDetails.java | 18 + .../org/onap/vid/mso/rest/AsyncRequestStatus.java | 27 +- .../onap/vid/mso/rest/AsyncRequestStatusList.java | 17 + .../java/org/onap/vid/mso/rest/InstanceIds.java | 202 ++++++ .../org/onap/vid/mso/rest/MsoRestClientNew.java | 186 +++-- .../org/onap/vid/mso/rest/RelatedInstance.java | 84 ++- .../java/org/onap/vid/mso/rest/RelatedModel.java | 125 ---- .../main/java/org/onap/vid/mso/rest/Request.java | 231 ++++++- .../java/org/onap/vid/mso/rest/RequestDetails.java | 41 +- .../java/org/onap/vid/mso/rest/RequestList.java | 23 +- .../java/org/onap/vid/mso/rest/RequestStatus.java | 208 ++++++ .../java/org/onap/vid/mso/rest/RestInterface.java | 25 +- .../java/org/onap/vid/mso/rest/SubscriberInfo.java | 144 ++++ .../java/org/onap/vid/policy/PolicyProperties.java | 26 - .../org/onap/vid/policy/PolicyResponseWrapper.java | 56 -- .../java/org/onap/vid/policy/PolicyRestInt.java | 66 -- .../org/onap/vid/policy/PolicyRestInterface.java | 230 ------ .../vid/policy/PolicyRestInterfaceFactory.java | 14 - .../onap/vid/policy/PolicyRestInterfaceIfc.java | 58 -- .../main/java/org/onap/vid/policy/PolicyUtil.java | 71 -- .../main/java/org/onap/vid/policy/RestObject.java | 68 -- .../org/onap/vid/policy/rest/RequestDetails.java | 107 --- .../java/org/onap/vid/properties/Features.java | 27 +- .../properties/FeaturesTogglingConfiguration.java | 6 +- .../org/onap/vid/properties/VidProperties.java | 34 +- .../main/java/org/onap/vid/roles/RoleProvider.java | 61 +- .../java/org/onap/vid/scheduler/RestObject.java | 44 -- .../onap/vid/scheduler/RestObjects/RestObject.java | 39 -- .../onap/vid/scheduler/SchedulerRestInterface.java | 62 +- .../vid/scheduler/SchedulerRestInterfaceIfc.java | 7 +- .../org/onap/vid/scheduler/SchedulerService.java | 7 + .../onap/vid/scheduler/SchedulerServiceImpl.java | 43 ++ .../java/org/onap/vid/services/AAIServiceTree.java | 247 +++++++ .../org/onap/vid/services/AAITreeNodeBuilder.java | 281 ++++++++ .../java/org/onap/vid/services/AaiService.java | 10 +- .../java/org/onap/vid/services/AaiServiceImpl.java | 138 +++- .../services/AsyncInstantiationBusinessLogic.java | 39 +- .../AsyncInstantiationBusinessLogicImpl.java | 767 ++++++++++++++------- .../java/org/onap/vid/services/AuditService.java | 11 +- .../org/onap/vid/services/AuditServiceImpl.java | 127 +++- .../vid/services/BulkInstantiationService.java | 4 - .../vid/services/BulkInstantiationServiceImpl.java | 10 - .../onap/vid/services/ChangeManagementService.java | 6 +- .../vid/services/ChangeManagementServiceImpl.java | 61 +- .../org/onap/vid/services/CloudOwnerService.java | 12 + .../onap/vid/services/CloudOwnerServiceImpl.java | 76 ++ .../java/org/onap/vid/services/CsvService.java | 1 - .../java/org/onap/vid/services/CsvServiceImpl.java | 9 +- .../vid/services/RoleGenaratorServiceImpl.java | 16 +- .../java/org/onap/vid/services/VidServiceImpl.java | 6 +- .../org/onap/vid/services/WorkflowService.java | 1 - .../main/java/org/onap/vid/utils/KotlinUtils.kt | 10 + .../src/main/java/org/onap/vid/utils/Logging.java | 4 +- .../src/main/java/org/onap/vid/utils/Multival.java | 54 ++ .../src/main/java/org/onap/vid/utils/Streams.java | 11 +- .../main/java/org/onap/vid/utils/TimeUtils.java | 21 + .../src/main/java/org/onap/vid/utils/Tree.kt | 44 ++ .../main/java/org/onap/vid/utils/Unchecked.java | 23 + 328 files changed, 14623 insertions(+), 7246 deletions(-) delete mode 100644 vid-app-common/src/main/java/org/onap/vid/RelatedTo.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/CloudRegion.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vlan.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vnf.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/model/CustomQuerySimpleResult.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/model/Permissions.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/model/interfaces/AaiModelWithRelationships.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/util/CacheConfig.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProvider.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProviderWithLoadingCache.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/aai/util/ServiceInstanceStandardQuery.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaNamingPolicy.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/client/HttpsBasicClient.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/AsyncControllerForTests.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/ChangeManagementController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/FeatureTogglingController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/HealthCheckController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/HealthStatus.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/MaintenanceController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/OperationalEnvironmentController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/ProbeController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/PropertyController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/RoleGeneratorController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/VersionController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/VidController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/VidRestrictedBaseController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/ViewLogController.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/AaiController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/AsyncControllerForTests.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/AsyncInstantiationController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/ChangeManagementController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/FeatureTogglingController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/HealthCheckController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/HealthStatus.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/LoggerController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/MaintenanceController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/MsoConfig.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/MsoController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/OperationalEnvironmentController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/PolicyController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/ProbeController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/PropertyController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/RoleGeneratorController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/VidController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/VidRestrictedBaseController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/ViewLogController.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/JobException.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/BaseInProgressStatusCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/BaseInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/BaseRootCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/BaseWatchingCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/CommandBase.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/CommandParentData.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/ExpiryChecker.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/InstanceGroupCommand.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/InstanceGroupInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/MsoResult.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/MsoResultHandlerService.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/NetworkInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/ResourceInProgressStatusCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/ResourceInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/ResourceWithChildrenInProgressCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInProgressStatusCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/VnfInProgressStatusCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/VnfInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/VolumeGroupInProgressStatusCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/VolumeGroupInstantiationCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/WatchChildrenJobsBL.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/WatchingCommand.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/command/WatchingCommandBaseModule.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/impl/JobData.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/job/impl/JobSharedData.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/Action.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/MinimalNode.kt delete mode 100644 vid-app-common/src/main/java/org/onap/vid/model/Resource.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/ResourceGroup.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/SoftDeleteRequest.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/AAITreeNode.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/AbstractNode.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/FailureAAITreeNode.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Network.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Node.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/RelatedVnf.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/VfModule.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Vnf.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/aaiTree/VnfGroup.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/BaseResource.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/InstanceGroup.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/Network.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/RestObjectWithRequestInfo.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/BaseResourceInstantiationRequestDetails.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/CloudConfiguration.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/InstanceGroupInstantiationRequestDetails.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/ModelInfo.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/NetworkInstantiationRequestDetails.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/RequestInfo.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/RequestParameters.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/RequestReferences.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceDeletionRequestDetails.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/UserParam.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/UserParamTypes.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/VfModuleInstantiationRequestDetails.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/VfModuleMacro.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/VnfInstantiationRequestDetails.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/model/VolumeGroupRequestDetails.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/rest/AsyncRequestStatusList.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/rest/InstanceIds.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/rest/RelatedModel.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestStatus.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/mso/rest/SubscriberInfo.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/PolicyProperties.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/PolicyResponseWrapper.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInt.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterface.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterfaceFactory.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterfaceIfc.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/RestObject.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/rest/RequestDetails.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/services/AAIServiceTree.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/services/CloudOwnerService.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/services/CloudOwnerServiceImpl.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/Multival.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt create mode 100644 vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java (limited to 'vid-app-common/src/main/java') diff --git a/vid-app-common/src/main/java/org/onap/vid/RelatedTo.java b/vid-app-common/src/main/java/org/onap/vid/RelatedTo.java deleted file mode 100644 index 08e028168..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/RelatedTo.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.onap.vid; - -import com.fasterxml.jackson.annotation.*; -import org.codehaus.jackson.annotate.JsonProperty; - -import java.util.HashMap; -import java.util.Map; - -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "id", - "node-type", - "relationship-label", - "url" -}) -public class RelatedTo { - - @JsonProperty("id") - public String id; - @JsonProperty("node-type") - public String nodeType; - @JsonProperty("relationship-label") - public String relationshipLabel; - @JsonProperty("url") - public String url; - @JsonIgnore - private Map additionalProperties = new HashMap<>(); - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java index baf92b880..e1a1e706f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java @@ -1,25 +1,25 @@ package org.onap.vid.aai; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpStatus; import org.apache.http.client.utils.URIBuilder; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.map.ObjectMapper; +import org.jetbrains.annotations.NotNull; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.aai.exceptions.InvalidAAIResponseException; import org.onap.vid.aai.model.AaiGetAicZone.AicZones; import org.onap.vid.aai.model.*; import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.*; import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; import org.onap.vid.aai.model.AaiGetPnfs.Pnf; import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone; -import org.onap.vid.aai.model.Relationship; -import org.onap.vid.aai.model.RelationshipData; -import org.onap.vid.aai.model.RelationshipList; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; import org.onap.vid.aai.util.AAIRestInterface; +import org.onap.vid.aai.util.CacheProvider; import org.onap.vid.aai.util.VidObjectMapperType; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.SubscriberList; @@ -27,6 +27,8 @@ import org.onap.vid.model.probes.ErrorMetadata; import org.onap.vid.model.probes.ExternalComponentStatus; import org.onap.vid.model.probes.HttpRequestMetadata; import org.onap.vid.utils.Logging; +import org.onap.vid.utils.Unchecked; +import org.springframework.http.HttpMethod; import org.springframework.web.util.UriUtils; import javax.inject.Inject; @@ -34,15 +36,16 @@ import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.URI; import java.net.URLEncoder; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.function.Function; import static java.util.Collections.emptyList; +import static java.util.stream.Collectors.toMap; import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; /** @@ -52,13 +55,13 @@ import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; public class AaiClient implements AaiClientInterface { - public static final String QUERY_FORMAT_RESOURCE = "query?format=resource"; - public static final String SERVICE_SUBSCRIPTIONS_PATH = "/service-subscriptions/service-subscription/"; - public static final String MODEL_INVARIANT_ID = "&model-invariant-id="; - public static final String QUERY_FORMAT_SIMPLE = "query?format=simple"; - public static final String BUSINESS_CUSTOMER = "/business/customers/customer/"; - public static final String SERVICE_INSTANCE = "/service-instances/service-instance/"; - public static final String BUSINESS_CUSTOMERS_CUSTOMER = "business/customers/customer/"; + private static final String QUERY_FORMAT_RESOURCE = "query?format=resource"; + private static final String SERVICE_SUBSCRIPTIONS_PATH = "/service-subscriptions/service-subscription/"; + private static final String MODEL_INVARIANT_ID = "&model-invariant-id="; + private static final String QUERY_FORMAT_SIMPLE = "query?format=simple"; + private static final String BUSINESS_CUSTOMER = "/business/customers/customer/"; + private static final String SERVICE_INSTANCE = "/service-instances/service-instance/"; + private static final String BUSINESS_CUSTOMERS_CUSTOMER = "business/customers/customer/"; protected String fromAppId = "VidAaiController"; @@ -66,22 +69,22 @@ public class AaiClient implements AaiClientInterface { private final AAIRestInterface restController; + private final CacheProvider cacheProvider; + + ObjectMapper objectMapper = new ObjectMapper(); + /** * The logger */ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiClient.class); - /** - * The Constant dateFormat. - */ - static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - static final String GET_SERVICE_MODELS_RESPONSE_BODY = "{\"start\" : \"service-design-and-creation/models/\", \"query\" : \"query/serviceModels-byDistributionStatus?distributionStatus=DISTRIBUTION_COMPLETE_OK\"}"; + private static final String GET_SERVICE_MODELS_RESPONSE_BODY = "{\"start\" : \"service-design-and-creation/models/\", \"query\" : \"query/serviceModels-byDistributionStatus?distributionStatus=DISTRIBUTION_COMPLETE_OK\"}"; @Inject - public AaiClient(AAIRestInterface restController, PortDetailsTranslator portDetailsTranslator) { + public AaiClient(AAIRestInterface restController, PortDetailsTranslator portDetailsTranslator, CacheProvider cacheProvider) { this.restController = restController; this.portDetailsTranslator = portDetailsTranslator; + this.cacheProvider = cacheProvider; } @@ -107,8 +110,14 @@ public class AaiClient implements AaiClientInterface { @Override public AaiResponse getServiceModelsByDistributionStatus() { - Response resp = doAaiPut(QUERY_FORMAT_RESOURCE, GET_SERVICE_MODELS_RESPONSE_BODY, false); - return processAaiResponse(resp, GetServiceModelsByDistributionStatusResponse.class, null); + return getFromCache("getServiceModelsByDistributionStatus", this::getServiceModelsByDistributionStatusNonCached, + true, "Failed to get service models by distribution status"); + } + + private AaiResponse getServiceModelsByDistributionStatusNonCached(boolean propagateExceptions) { + GetServiceModelsByDistributionStatusResponse response = typedAaiRest(QUERY_FORMAT_RESOURCE, GetServiceModelsByDistributionStatusResponse.class, + GET_SERVICE_MODELS_RESPONSE_BODY, HttpMethod.PUT, propagateExceptions); + return new AaiResponse(response, "", HttpStatus.SC_OK); } @Override @@ -121,14 +130,14 @@ public class AaiClient implements AaiClientInterface { @Override public AaiResponse getInstanceGroupsByCloudRegion(String cloudOwner, String cloudRegionId, String networkFunction) { Response resp = doAaiPut(QUERY_FORMAT_RESOURCE, - "{\"start\": [\"cloud-infrastructure/cloud-regions/cloud-region/" + cloudOwner + "/" + cloudRegionId + "\"]," + - "\"query\": \"query/instance-group-byCloudRegion?type=L3-NETWORK&role=SUB-INTERFACE&function=" + networkFunction + "\"}\n", false); + "{\"start\": [\"cloud-infrastructure/cloud-regions/cloud-region/" + encodePathSegment(cloudOwner) + "/" + encodePathSegment(cloudRegionId) + "\"]," + + "\"query\": \"query/instance-groups-byCloudRegion?type=L3-NETWORK&role=SUB-INTERFACE&function=" + encodePathSegment(networkFunction) + "\"}\n", false); return processAaiResponse(resp, AaiGetInstanceGroupsByCloudRegion.class, null, VidObjectMapperType.FASTERXML); } private AaiResponse getNetworkCollectionDetailsResponse(AaiResponse aaiResponse){ if(aaiResponse.getHttpCode() == 200) { - com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); + ObjectMapper om = objectMapper; AaiGetNetworkCollectionDetails aaiGetNetworkCollectionDetails = new AaiGetNetworkCollectionDetails(); try { for (int i = 0; i < aaiResponse.getT().getResults().size(); i++) { @@ -145,7 +154,8 @@ public class AaiClient implements AaiClientInterface { return new AaiResponse(aaiGetNetworkCollectionDetails, null, HttpStatus.SC_OK); } catch (com.fasterxml.jackson.databind.JsonMappingException e) { - return new AaiResponse(e.getCause(), "AAI response parsing Error" , aaiResponse.getHttpCode()); + logger.error(EELFLoggerDelegate.errorLogger, "AAI response parsing Error", e); + return new AaiResponse(e.getCause(), "AAI response parsing Error" , HttpStatus.SC_INTERNAL_SERVER_ERROR); } catch (Exception e) { return new AaiResponse(e.getCause(), "Got " + aaiResponse.getHttpCode() + " from a&ai" , aaiResponse.getHttpCode()); @@ -183,7 +193,7 @@ public class AaiClient implements AaiClientInterface { Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false); resp.bufferEntity(); // avoid later "Entity input stream has already been closed" problems String rawPayload = resp.readEntity(String.class); - AaiResponse aaiResponse = processAaiResponse(resp, AaiGetPortMirroringSourcePorts.class, rawPayload); + AaiResponse aaiResponse = processAaiResponse(resp, CustomQuerySimpleResult.class, rawPayload); return portDetailsTranslator.extractPortDetails(aaiResponse, rawPayload); } @@ -202,21 +212,80 @@ public class AaiClient implements AaiClientInterface { } @Override - public AaiResponse searchNodeTypeByName(String name, ResourceType type) { - String path = String.format( - "search/nodes-query?search-node-type=%s&filter=%s:EQUALS:%s", + public boolean isNodeTypeExistsByName(String name, ResourceType type) { + if (StringUtils.isEmpty(name)) { + throw new GenericUncheckedException("Empty resource-name provided to searchNodeTypeByName; request is rejected as this will cause full resources listing"); + } + + URI path = Unchecked.toURI(String.format( // e.g. GET /aai/v$/nodes/vf-modules?vf-module-name={vf-module-name} + "nodes/%s?%s=%s", type.getAaiFormat(), type.getNameFilter(), - name - ); - return typedAaiGet(path, AaiNodeQueryResponse.class); + encodePathSegment(name) + )); + final ResponseWithRequestInfo responseWithRequestInfo = restController.RestGet(fromAppId, UUID.randomUUID().toString(), path, false, true); + + return isResourceExistByStatusCode(responseWithRequestInfo); + } + + public Map getCloudRegionAndTenantByVnfId(String vnfId) { + String start = "/network/generic-vnfs/generic-vnf/" + vnfId; + String query = "/query/cloud-region-fromVnf"; + + String payload = "{\"start\":[\"" + start + "\"],\"query\":\"" + query + "\"}"; + CustomQuerySimpleResult result = typedAaiRest(QUERY_FORMAT_SIMPLE, CustomQuerySimpleResult.class, payload, HttpMethod.PUT, false); + + return result.getResults().stream() + .filter(res -> StringUtils.equals(res.getNodeType(), "tenant") || + StringUtils.equals(res.getNodeType(), "cloud-region")) + .collect(toMap(SimpleResult::getNodeType, SimpleResult::getProperties)); + } + + private boolean isResourceExistByStatusCode(ResponseWithRequestInfo responseWithRequestInfo) { + // 200 - is found + // 404 - resource not found + Response.Status statusInfo = responseWithRequestInfo.getResponse().getStatusInfo().toEnum(); + switch (statusInfo) { + case OK: + return true; + case NOT_FOUND: + return false; + default: + throw new GenericUncheckedException("Unexpected response-code (only OK and NOT_FOUND are expected): " + + responseWithRequestInfo.getResponse().getStatusInfo()); + } } - private AaiResponse typedAaiGet(String path, Class clz) { - Response resp = doAaiGet(path , false); - return processAaiResponse(resp, clz, null, VidObjectMapperType.FASTERXML); + @Override + public T typedAaiGet(URI uri, Class clz) { + return typedAaiRest(uri, clz, null, HttpMethod.GET, false); } + public T typedAaiRest(String path, Class clz, String payload, HttpMethod method, boolean propagateExceptions) { + return typedAaiRest(Unchecked.toURI(path), clz, payload, method, propagateExceptions); + } + + + public T typedAaiRest(URI path, Class clz, String payload, HttpMethod method, boolean propagateExceptions) { + ResponseWithRequestInfo responseWithRequestInfo; + try { + responseWithRequestInfo = restController.doRest(fromAppId, UUID.randomUUID().toString(), path, payload, method, false, propagateExceptions); + } catch (Exception e) { + responseWithRequestInfo = handleExceptionFromRestCall(propagateExceptions, "doAai"+method.name(), e); + } + + final AaiResponseWithRequestInfo aaiResponse = processAaiResponse(responseWithRequestInfo, clz, VidObjectMapperType.FASTERXML, true); + + if (aaiResponse.getAaiResponse().getHttpCode() > 399 || aaiResponse.getAaiResponse().getT() == null) { + throw new ExceptionWithRequestInfo(aaiResponse.getHttpMethod(), + aaiResponse.getRequestedUrl(), + aaiResponse.getRawData(), + responseWithRequestInfo.getResponse().getStatus(), + new InvalidAAIResponseException(aaiResponse.getAaiResponse())); + } + + return aaiResponse.getAaiResponse().getT(); + } private String getUrlFromLIst(String url, String paramKey, List params){ @@ -229,8 +298,8 @@ public class AaiClient implements AaiClientInterface { encodedParam= URLEncoder.encode(param, "UTF-8"); } catch (UnsupportedEncodingException e) { String methodName = "getUrlFromList"; - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString()); } url = url.concat(encodedParam); if(i != params.size()){ @@ -241,9 +310,34 @@ public class AaiClient implements AaiClientInterface { } + @Override public AaiResponse getAllSubscribers() { - return getAllSubscribers(false).getAaiResponse(); + return getFromCache("getAllSubscribers", this::getAllSubscribersNonCached, true, "Failed to get all subscribers"); + } + + private AaiResponse getFromCache(String cacheName, Function function, K argument, String errorMessage) { + try { + return cacheProvider + .aaiClientCacheFor(cacheName, function) + .get(argument); + } catch (ExceptionWithRequestInfo exception) { + logger.error(errorMessage, exception); + return new AaiResponse(null, exception.getRawData(), exception.getHttpCode()); + } + catch (Exception exception) { + logger.error(errorMessage, exception); + return new AaiResponse(null, exception.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + } + + private AaiResponse getAllSubscribersNonCached(boolean propagateExceptions) { + AaiResponse aaiResponse = getAllSubscribers(propagateExceptions).getAaiResponse(); + if (propagateExceptions && (aaiResponse.getT() == null || aaiResponse.getT().customer == null || aaiResponse.getT().customer.isEmpty())) { + throw new GenericUncheckedException("Failed to get Subscribers data. The data is null or empty."); + } else { + return aaiResponse; + } } AaiResponseWithRequestInfo getAllSubscribers(boolean propagateExceptions){ @@ -262,33 +356,12 @@ public class AaiClient implements AaiClientInterface { return processAaiResponse(resp, AicZones.class, null); } - - @Override - public AaiResponse getAicZoneForPnf(String globalCustomerId , String serviceType , String serviceId) { - String aicZonePath = BUSINESS_CUSTOMERS_CUSTOMER + globalCustomerId + SERVICE_SUBSCRIPTIONS_PATH + serviceType + SERVICE_INSTANCE + serviceId; - Response resp = doAaiGet(aicZonePath , false); - AaiResponse aaiResponse = processAaiResponse(resp , ServiceRelationships.class , null); - ServiceRelationships serviceRelationships = aaiResponse.getT(); - RelationshipList relationshipList = serviceRelationships.getRelationshipList(); - Relationship relationship = relationshipList.getRelationship().get(0); - RelationshipData relationshipData= relationship.getRelationDataList().get(0); - String aicZone = relationshipData.getRelationshipValue(); - return new AaiResponse(aicZone , null ,HttpStatus.SC_OK); - } - - @Override - public AaiResponse getVNFData() { - String payload = "{\"start\": [\"/business/customers/customer/e433710f-9217-458d-a79d-1c7aff376d89/service-subscriptions/service-subscription/VIRTUAL%20USP/service-instances/service-instance/3f93c7cb-2fd0-4557-9514-e189b7b04f9d\"], \"query\": \"query/vnf-topology-fromServiceInstance\"}"; - Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false); - return processAaiResponse(resp, AaiGetVnfResponse.class, null); - } - - @Override - public Response getVNFData(String globalSubscriberId, String serviceType) { + public AaiResponse getVNFData(String globalSubscriberId, String serviceType) { String payload = "{\"start\": [\"business/customers/customer/" + globalSubscriberId + SERVICE_SUBSCRIPTIONS_PATH + encodePathSegment(serviceType) +"/service-instances\"]," + "\"query\": \"query/vnf-topology-fromServiceInstance\"}"; - return doAaiPut(QUERY_FORMAT_SIMPLE, payload, false); + Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false); + return processAaiResponse(resp, AaiGetVnfResponse.class, null); } @Override @@ -343,22 +416,17 @@ public class AaiClient implements AaiClientInterface { @Override public AaiResponse getTenants(String globalCustomerId, String serviceType) { - AaiResponse aaiResponse; - if ((globalCustomerId == null || globalCustomerId.isEmpty()) || ((serviceType == null) || (serviceType.isEmpty())) ){ - aaiResponse = new AaiResponse<>(null, "{\"statusText\":\" Failed to retrieve LCP Region & Tenants from A&AI, Subscriber ID or Service Type is missing.\"}", HttpStatus.SC_INTERNAL_SERVER_ERROR); - return aaiResponse; + return buildAaiResponseForGetTenantsFailure(" Failed to retrieve LCP Region & Tenants from A&AI, Subscriber ID or Service Type is missing."); } - - String url = BUSINESS_CUSTOMERS_CUSTOMER + globalCustomerId + SERVICE_SUBSCRIPTIONS_PATH + serviceType; - - Response resp = doAaiGet(url, false); - String responseAsString = parseForTenantsByServiceSubscription(resp.readEntity(String.class)); - if (responseAsString.equals("")){ - return new AaiResponse<>(null, String.format("{\"statusText\":\" A&AI has no LCP Region & Tenants associated to subscriber '%s' and service type '%s'\"}", globalCustomerId, serviceType), HttpStatus.SC_INTERNAL_SERVER_ERROR); + try { + return cacheProvider + .aaiClientCacheFor("getTenants", this::getTenantsByKey) + .get(CacheProvider.compileKey(globalCustomerId, serviceType)); } - else { - return processAaiResponse(resp, GetTenantsResponse[].class, responseAsString); + catch (ParsingGetTenantsResponseFailure exception) { + logger.error("Failed to get tenants ", exception); + return buildAaiResponseForGetTenantsFailure(exception.getMessage()); } } @@ -389,13 +457,17 @@ public class AaiClient implements AaiClientInterface { } private AaiResponseWithRequestInfo processAaiResponse(ResponseWithRequestInfo responseWithRequestInfo, Class classType, boolean propagateExceptions) { + return processAaiResponse(responseWithRequestInfo, classType, VidObjectMapperType.CODEHAUS, propagateExceptions); + } + + private AaiResponseWithRequestInfo processAaiResponse(ResponseWithRequestInfo responseWithRequestInfo, Class classType, VidObjectMapperType omType, boolean propagateExceptions) { String responseBody = null; Integer responseHttpCode = null; try { Response response = responseWithRequestInfo.getResponse(); responseHttpCode = (response != null) ? response.getStatus() : null; responseBody = (response != null) ? response.readEntity(String.class) : null; - AaiResponse processedAaiResponse = processAaiResponse(response, classType, responseBody, VidObjectMapperType.CODEHAUS, propagateExceptions); + AaiResponse processedAaiResponse = processAaiResponse(response, classType, responseBody, omType, propagateExceptions); return new AaiResponseWithRequestInfo<>(responseWithRequestInfo.getRequestHttpMethod(), responseWithRequestInfo.getRequestUrl(), processedAaiResponse, responseBody); } catch (Exception e) { @@ -408,17 +480,17 @@ public class AaiClient implements AaiClientInterface { return processAaiResponse(resp, classType, responseBody, VidObjectMapperType.CODEHAUS); } - private AaiResponse processAaiResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType) { + private AaiResponse processAaiResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType) { return processAaiResponse(resp, classType, responseBody, omType, false); } - private AaiResponse processAaiResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) { - AaiResponse subscriberDataResponse; + private AaiResponse processAaiResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) { + AaiResponse subscriberDataResponse; if (resp == null) { subscriberDataResponse = new AaiResponse<>(null, null, HttpStatus.SC_INTERNAL_SERVER_ERROR); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "Invalid response from AAI"); + logger.debug(EELFLoggerDelegate.debugLogger, "Invalid response from AAI"); } else { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "getSubscribers() resp=" + resp.getStatusInfo().toString()); if (resp.getStatus() != HttpStatus.SC_OK) { subscriberDataResponse = processFailureResponse(resp,responseBody); } else { @@ -429,7 +501,7 @@ public class AaiClient implements AaiClientInterface { } private AaiResponse processFailureResponse(Response resp, String responseBody) { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "Invalid response from AAI"); + logger.debug(EELFLoggerDelegate.debugLogger, "Invalid response from AAI"); String rawData; if (responseBody != null) { rawData = responseBody; @@ -439,8 +511,8 @@ public class AaiClient implements AaiClientInterface { return new AaiResponse<>(null, rawData, resp.getStatus()); } - private AaiResponse processOkResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) { - AaiResponse subscriberDataResponse; + private AaiResponse processOkResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) { + AaiResponse subscriberDataResponse; String finalResponse = null; try { if (responseBody != null) { @@ -465,50 +537,59 @@ public class AaiClient implements AaiClientInterface { return subscriberDataResponse; } - private AaiResponse parseFasterXmlObject(Class classType, String finalResponse) throws IOException { - com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); + private AaiResponse parseFasterXmlObject(Class classType, String finalResponse) throws IOException { return new AaiResponse<>((objectMapper.readValue(finalResponse, classType)), null, HttpStatus.SC_OK); } - private AaiResponse parseCodeHausObject(Class classType, String finalResponse) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); + private AaiResponse parseCodeHausObject(Class classType, String finalResponse) throws IOException { return new AaiResponse<>((objectMapper.readValue(finalResponse, classType)), null, HttpStatus.SC_OK); } + @Override public Response doAaiGet(String uri, boolean xml) { return doAaiGet(uri, xml, false).getResponse(); } public ResponseWithRequestInfo doAaiGet(String uri, boolean xml, boolean propagateExceptions) { + return doAaiGet(Unchecked.toURI(uri), xml, propagateExceptions); + } + + public ResponseWithRequestInfo doAaiGet(URI uri, boolean xml, boolean propagateExceptions) { String methodName = "doAaiGet"; - String transId = UUID.randomUUID().toString(); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); ResponseWithRequestInfo resp; try { - resp = restController.RestGet(fromAppId, transId, uri, xml, propagateExceptions); + resp = restController.RestGet(fromAppId, UUID.randomUUID().toString(), uri, xml, propagateExceptions); } catch (Exception e) { - if (propagateExceptions) { - throw (e instanceof RuntimeException) ? (RuntimeException)e : new GenericUncheckedException(e); - } else { - final Exception actual = - e instanceof ExceptionWithRequestInfo ? (Exception) e.getCause() : e; + resp = handleExceptionFromRestCall(propagateExceptions, methodName, e); + } + return resp; + } - final String message = - actual instanceof WebApplicationException ? ((WebApplicationException) actual).getResponse().readEntity(String.class) : e.toString(); + @NotNull + protected ResponseWithRequestInfo handleExceptionFromRestCall(boolean propagateExceptions, String methodName, Exception e) { + ResponseWithRequestInfo resp; + if (propagateExceptions) { + throw (e instanceof RuntimeException) ? (RuntimeException)e : new GenericUncheckedException(e); + } else { + final Exception actual = + e instanceof ExceptionWithRequestInfo ? (Exception) e.getCause() : e; - //ToDo: change parameter of requestUrl to real url from RestGet function - resp = new ResponseWithRequestInfo(null, null, org.springframework.http.HttpMethod.GET); - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message); - } + final String message = + actual instanceof WebApplicationException ? ((WebApplicationException) actual).getResponse().readEntity(String.class) : e.toString(); + + //ToDo: change parameter of requestUrl to real url from doRest function + resp = new ResponseWithRequestInfo(null, null, org.springframework.http.HttpMethod.GET); + logger.info(EELFLoggerDelegate.errorLogger, methodName + message); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + message); } return resp; } - private String parseForTenantsByServiceSubscription(String resp) { + private String parseForTenantsByServiceSubscription(String relatedToKey, String resp) { String tenantList = ""; try { @@ -516,7 +597,7 @@ public class AaiClient implements AaiClientInterface { JSONObject jsonObject = (JSONObject) jsonParser.parse(resp); - return parseServiceSubscriptionObjectForTenants(jsonObject); + return parseServiceSubscriptionObjectForTenants(relatedToKey, jsonObject); } catch (Exception ex) { logger.debug(EELFLoggerDelegate.debugLogger, "parseForTenantsByServiceSubscription error while parsing tenants by service subscription", ex); } @@ -524,24 +605,26 @@ public class AaiClient implements AaiClientInterface { } protected Response doAaiPut(String uri, String payload, boolean xml) { + return doAaiPut(uri, payload, xml, false).getResponse(); + } + + protected ResponseWithRequestInfo doAaiPut(String uri, String payload, boolean xml, boolean propagateExceptions) { String methodName = "doAaiPut"; - String transId = UUID.randomUUID().toString(); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); - Response resp = null; + ResponseWithRequestInfo resp; try { - resp = restController.RestPut(fromAppId, uri, payload, xml); + resp = restController.RestPut(fromAppId, uri, payload, xml, propagateExceptions); } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + resp = handleExceptionFromRestCall(propagateExceptions, methodName, e); } return resp; } - private String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) { + private String parseServiceSubscriptionObjectForTenants(String relatedToKey, JSONObject jsonObject) { JSONArray tenantArray = new JSONArray(); boolean bconvert = false; try { @@ -550,7 +633,7 @@ public class AaiClient implements AaiClientInterface { JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship"); for (Object innerObj : defaultIfNull(rShipArray, emptyList())) { if (innerObj != null) { - bconvert = parseTenant(tenantArray, bconvert, (JSONObject) innerObj); + bconvert = parseTenant(relatedToKey, tenantArray, bconvert, (JSONObject) innerObj); } } } @@ -565,9 +648,9 @@ public class AaiClient implements AaiClientInterface { } - private static boolean parseTenant(JSONArray tenantArray, boolean bconvert, JSONObject inner1Obj) { + private static boolean parseTenant(String relatedToKey, JSONArray tenantArray, boolean bconvert, JSONObject inner1Obj) { String relatedTo = checkForNull((String) inner1Obj.get("related-to")); - if (relatedTo.equalsIgnoreCase("tenant")) { + if (relatedTo.equalsIgnoreCase(relatedToKey)) { JSONObject tenantNewObj = new JSONObject(); String relatedLink = checkForNull((String) inner1Obj.get("related-link")); @@ -609,9 +692,7 @@ public class AaiClient implements AaiClientInterface { tenantNewObj.put("cloudOwner", rShipVal); } else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id")) { tenantNewObj.put("cloudRegionID", rShipVal); - } - - if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) { + } else if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) { tenantNewObj.put("tenantID", rShipVal); } } @@ -639,7 +720,7 @@ public class AaiClient implements AaiClientInterface { responseWithRequestInfo.getHttpMethod(), (aaiResponse != null) ? aaiResponse.getHttpCode() : 0, responseWithRequestInfo.getRequestedUrl(), - StringUtils.substring(responseWithRequestInfo.getRawData(), 0, 500), + responseWithRequestInfo.getRawData(), isAvailable ? "OK" : "No subscriber received", duration ); @@ -648,16 +729,104 @@ public class AaiClient implements AaiClientInterface { } catch (ExceptionWithRequestInfo e) { long duration = System.currentTimeMillis() - startTime; return new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, false, - new HttpRequestMetadata( - e.getHttpMethod(), - defaultIfNull(e.getHttpCode(), 0), - e.getRequestedUrl(), - e.getRawData(), - Logging.exceptionToDescription(e.getCause()), duration)); + new HttpRequestMetadata(e, duration)); } catch (Exception e) { long duration = System.currentTimeMillis() - startTime; return new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, false, new ErrorMetadata(Logging.exceptionToDescription(e), duration)); } } + + @Override + public String getCloudOwnerByCloudRegionId(String cloudRegionId) { + return cacheProvider + .aaiClientCacheFor("getCloudOwnerByCloudRegionId", this::getCloudOwnerByCloudRegionIdNonCached) + .get(cloudRegionId); + } + + + @Override + public GetTenantsResponse getHomingDataByVfModule(String vnfInstanceId, String vfModuleId) { + + if (StringUtils.isEmpty(vnfInstanceId)||StringUtils.isEmpty(vfModuleId)){ + throw new GenericUncheckedException("Failed to retrieve homing data associated to vfModule from A&AI, VNF InstanceId or VF Module Id is missing."); + } + Response resp = doAaiGet("network/generic-vnfs/generic-vnf/" + vnfInstanceId +"/vf-modules/vf-module/"+ vfModuleId, false); + String responseAsString = parseForTenantsByServiceSubscription("vserver",resp.readEntity(String.class)); + if (responseAsString.equals("")){ + throw new GenericUncheckedException( String.format("A&AI has no homing data associated to vfModule '%s' of vnf '%s'", vfModuleId, vnfInstanceId)); + } + else { + AaiResponse aaiResponse = processAaiResponse(resp, GetTenantsResponse[].class, responseAsString); + return ((GetTenantsResponse[])aaiResponse.getT())[0]; + } + } + + @Override + public void resetCache(String cacheName) { + cacheProvider.resetCache(cacheName); + } + + String getCloudOwnerByCloudRegionIdNonCached(String cloudRegionId) { + String uri = "cloud-infrastructure/cloud-regions?cloud-region-id=" + encodePathSegment(cloudRegionId); + + final CloudRegion.Collection cloudRegionCollection = + typedAaiGet(Unchecked.toURI(uri), CloudRegion.Collection.class); + + return cloudRegionCollection + .getCloudRegions().stream() + .map(CloudRegion::getCloudOwner) + // from here we assure that the cloud owner is given, and not null + // and non-empty, and that if more than one cloud-owner is given - + // it is only a single value. + // exception is thrown if none or more than a single values are + // given. + .filter(StringUtils::isNotEmpty) + .distinct() + .reduce((a, b) -> { + // will be invoked only if distinct() leaves more than a single element + throw new GenericUncheckedException("Conflicting cloud-owner found for " + cloudRegionId + ": '" + a + "' / '" + b + "'"); + }) + .orElseThrow(() -> new GenericUncheckedException("No cloud-owner found for " + cloudRegionId)); + } + + private AaiResponse getTenantsByKey(String key) { + String[] args = CacheProvider.decompileKey(key); + String globalCustomerId = safeGetFromArray(args, 0); + String serviceType = safeGetFromArray(args, 1); + return getTenantsNonCached(globalCustomerId, serviceType); + } + + AaiResponse getTenantsNonCached(String globalCustomerId, String serviceType) { + String url = BUSINESS_CUSTOMERS_CUSTOMER + globalCustomerId + SERVICE_SUBSCRIPTIONS_PATH + serviceType; + + Response resp = doAaiGet(url, false); + String responseAsString = parseForTenantsByServiceSubscription("tenant",resp.readEntity(String.class)); + if (StringUtils.isEmpty(responseAsString)){ + throw new ParsingGetTenantsResponseFailure(String.format("A&AI has no LCP Region & Tenants associated to subscriber '%s' and service type '%s'", globalCustomerId, serviceType)); + } + else { + return processAaiResponse(resp, GetTenantsResponse[].class, responseAsString); + } + } + + public static class ParsingGetTenantsResponseFailure extends GenericUncheckedException { + + public ParsingGetTenantsResponseFailure(String message) { + super(message); + } + } + + @NotNull + private AaiResponse buildAaiResponseForGetTenantsFailure(String errorText) { + return new AaiResponse<>(null, String.format("{\"statusText\":\"%s\"}", errorText), HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + + private static String safeGetFromArray(String[] array, int i) { + if (i < 0 || i >= array.length) { + return null; + } else { + return array[i]; + } + } } \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java index 901591a8c..bf97e5992 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java @@ -1,24 +1,29 @@ package org.onap.vid.aai; -import org.codehaus.jackson.JsonNode; +import com.fasterxml.jackson.databind.JsonNode; import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; import org.onap.vid.aai.model.AaiGetPnfs.Pnf; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; -import org.onap.vid.aai.model.AaiNodeQueryResponse; +import org.onap.vid.aai.model.CustomQuerySimpleResult; import org.onap.vid.aai.model.PortDetailsTranslator; +import org.onap.vid.aai.model.Properties; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.model.SubscriberList; import org.onap.vid.model.probes.ExternalComponentStatus; import javax.ws.rs.core.Response; +import java.net.URI; import java.util.List; +import java.util.Map; /** * Created by Oren on 7/4/17. */ public interface AaiClientInterface { - AaiResponse searchNodeTypeByName(String name, ResourceType type); + boolean isNodeTypeExistsByName(String name, ResourceType type); + + T typedAaiGet(URI path, Class clz); AaiResponse getAllSubscribers(); @@ -34,15 +39,11 @@ public interface AaiClientInterface { AaiResponse getAllAicZones(); - AaiResponse getAicZoneForPnf(String globalCustomerId , String serviceType , String serviceId); - - AaiResponse getVNFData(); - AaiResponse getNetworkCollectionDetails(String serviceInstanceId); AaiResponse getInstanceGroupsByCloudRegion(String cloudOwner, String cloudRegionId, String networkFunction); - Response getVNFData(String globalSubscriberId, String serviceType); + AaiResponse getVNFData(String globalSubscriberId, String serviceType); AaiResponse getVNFData(String globalSubscriberId, String serviceType, String serviceInstanceId); @@ -69,4 +70,14 @@ public interface AaiClientInterface { AaiResponse getInstanceGroupsByVnfInstanceId(String vnfInstanceId); ExternalComponentStatus probeAaiGetAllSubscribers(); + + Response doAaiGet(String uri, boolean xml); + + String getCloudOwnerByCloudRegionId(String cloudRegionId); + + GetTenantsResponse getHomingDataByVfModule(String vnfInstanceId, String vfModuleId); + + void resetCache(String cacheName); + + Map getCloudRegionAndTenantByVnfId(String vnfId); } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java index 08585206d..479bd1384 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java @@ -1,8 +1,7 @@ package org.onap.vid.aai; -import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.*; import com.google.common.base.MoreObjects; -import org.codehaus.jackson.annotate.*; import org.onap.vid.aai.model.VnfResult; import java.util.HashMap; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java index 6e25e2715..fe62f029c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java @@ -20,26 +20,25 @@ package org.onap.vid.aai; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.ACCEPT; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.CONTENT_TYPE; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.FROM_APP_ID_HEADER; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.REQUEST_ID; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.TRANSACTION_ID_HEADER; - import io.joshworks.restclient.http.HttpResponse; +import io.joshworks.restclient.http.JsonNode; import io.vavr.collection.HashMap; -import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.Collections; -import java.util.Map; -import javax.ws.rs.core.MediaType; +import org.apache.commons.lang3.StringUtils; import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.aai.model.AaiNodeQueryResponse; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.aai.util.AAIProperties; import org.onap.vid.client.SyncRestClientInterface; +import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.SubscriberList; +import javax.ws.rs.core.MediaType; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Collections; +import java.util.Map; + +import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.*; + public class AaiOverTLSClient implements AaiOverTLSClientInterface { private final AaiOverTLSPropertySupplier propertySupplier; @@ -64,9 +63,23 @@ public class AaiOverTLSClient implements AaiOverTLSClientInterface { } @Override - public HttpResponse searchNodeTypeByName(String name, ResourceType type) { - String uri = urlBase + String.format(URIS.NODE_TYPE_BY_NAME, type.getAaiFormat(), type.getNameFilter(), name); - return syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap(), AaiNodeQueryResponse.class); + public boolean isNodeTypeExistsByName(String name, ResourceType type) { + + if (StringUtils.isEmpty(name)) { + throw new GenericUncheckedException("Empty resource-name provided to isNodeTypeExistsByName; request is rejected as this will cause full resources listing"); + } + + String path = String.format( // e.g. GET /aai/v$/nodes/vf-modules?vf-module-name={vf-module-name} + "nodes/%s?%s=%s", + type.getAaiFormat(), + type.getNameFilter(), + name + ); + + String uri = urlBase + path; + final HttpResponse response = syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap()); + + return response.isSuccessful(); } @Override diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java index ad43746ca..57ec519c8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java @@ -22,7 +22,6 @@ package org.onap.vid.aai; import io.joshworks.restclient.http.HttpResponse; import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.aai.model.AaiNodeQueryResponse; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.model.SubscriberList; @@ -44,7 +43,7 @@ public interface AaiOverTLSClientInterface { void setUseClientCert(boolean useClientCert); - HttpResponse searchNodeTypeByName(String name, ResourceType type); + boolean isNodeTypeExistsByName(String name, ResourceType type); HttpResponse getAllSubscribers(); diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseTranslator.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseTranslator.java index c7a98a8cc..a0a8a30d6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseTranslator.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseTranslator.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; +import com.fasterxml.jackson.databind.JsonNode; import org.apache.commons.lang3.StringUtils; -import org.codehaus.jackson.JsonNode; import org.springframework.stereotype.Component; import java.util.Optional; @@ -26,7 +26,7 @@ public class AaiResponseTranslator { for (JsonNode resultNode : results) { final JsonNode nodeType = resultNode.path("node-type"); - if (nodeType.isTextual() && "cloud-region".equals(nodeType.getTextValue())) { + if (nodeType.isTextual() && "cloud-region".equals(nodeType.textValue())) { return getPortMirroringConfigData(payload, resultNode); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseWithRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseWithRequestInfo.java index cd1f9044b..a1806f0c3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseWithRequestInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseWithRequestInfo.java @@ -3,9 +3,8 @@ package org.onap.vid.aai; import org.springframework.http.HttpMethod; -import java.io.Serializable; -public class AaiResponseWithRequestInfo implements Serializable { +public class AaiResponseWithRequestInfo { private AaiResponse aaiResponse; private String requestedUrl; private String rawData; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java index dcca3ec4b..388c38193 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java @@ -42,13 +42,13 @@ public class ExceptionWithRequestInfo extends RuntimeException { private static String toMessage(HttpMethod httpMethod, String requestedUrl, Throwable cause) { if (StringUtils.isEmpty(requestedUrl)) { - return cause.toString(); + return String.valueOf(cause); } else { return "" + "Exception while handling " + defaultIfNull(httpMethod, "request").toString() + " " + requestedUrl + - ": " + cause.toString(); + ": " + (cause == null ? "null" : cause.toString()); } } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/OperationalEnvironment.java b/vid-app-common/src/main/java/org/onap/vid/aai/OperationalEnvironment.java index 10ad4e963..4b4a496cc 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/OperationalEnvironment.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/OperationalEnvironment.java @@ -1,12 +1,9 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; -import org.onap.vid.aai.model.Relationship; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import org.onap.vid.aai.model.RelationshipList; -import java.util.List; - @JsonIgnoreProperties(ignoreUnknown = true) public class OperationalEnvironment { @@ -33,75 +30,75 @@ public class OperationalEnvironment { this.relationshipList = relationshipList; } - @JsonProperty("operational-environment-id") public String getOperationalEnvironmentId() { return operationalEnvironmentId; } - public void setOperationalEnvironmentId(String operationalEnvironmentId) { + @JsonProperty("operational-environment-id") + public void setJsonOperationalEnvironmentId(String operationalEnvironmentId) { this.operationalEnvironmentId = operationalEnvironmentId; } - @JsonProperty("operational-environment-name") public String getOperationalEnvironmentName() { return operationalEnvironmentName; } - public void setOperationalEnvironmentName(String operationalEnvironmentName) { + @JsonProperty("operational-environment-name") + public void setJsonOperationalEnvironmentName(String operationalEnvironmentName) { this.operationalEnvironmentName = operationalEnvironmentName; } - @JsonProperty("operational-environment-type") public String getOperationalEnvironmentType() { return operationalEnvironmentType; } - public void setOperationalEnvironmentType(String operationalEnvironmentType) { + @JsonProperty("operational-environment-type") + public void setJsonOperationalEnvironmentType(String operationalEnvironmentType) { this.operationalEnvironmentType = operationalEnvironmentType; } - @JsonProperty("operational-environment-status") public String getOperationalEnvironmentStatus() { return operationalEnvironmentStatus; } - public void setOperationalEnvironmentStatus(String operationalEnvironmentStatus) { + @JsonProperty("operational-environment-status") + public void setJsonOperationalEnvironmentStatus(String operationalEnvironmentStatus) { this.operationalEnvironmentStatus = operationalEnvironmentStatus; } - @JsonProperty("tenant-context") public String getTenantContext() { return tenantContext; } - public void setTenantContext(String tenantContext) { + @JsonProperty("tenant-context") + public void setJsonTenantContext(String tenantContext) { this.tenantContext = tenantContext; } - @JsonProperty("workload-context") public String getWorkloadContext() { return workloadContext; } - public void setWorkloadContext(String workloadContext) { + @JsonProperty("workload-context") + public void setJsonWorkloadContext(String workloadContext) { this.workloadContext = workloadContext; } - @JsonProperty("resource-version") public String getResourceVersion() { return resourceVersion; } - public void setResourceVersion(String resourceVersion) { + @JsonProperty("resource-version") + public void setJsonResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } - @JsonProperty("relationship-list") public RelationshipList getRelationshipList() { return relationshipList; } - public void setRelationshipList(RelationshipList relationshipList) { + @JsonProperty("relationship-list") + public void setJsonRelationshipList(RelationshipList relationshipList) { this.relationshipList = relationshipList; } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java b/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java index 28b6f542f..000628d8a 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java @@ -1,21 +1,15 @@ package org.onap.vid.aai; import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.vid.model.PombaInstance.PombaRequest; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.model.PombaInstance.PombaRequest; import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.ServletContext; -import javax.ws.rs.core.Response; -import java.io.File; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; public class PombaClientImpl implements PombaClientInterface { - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); protected String fromAppId = "VidAaiController"; EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiClient.class); @@ -29,22 +23,15 @@ public class PombaClientImpl implements PombaClientInterface { @Override public void verify(PombaRequest request) { String methodName = "doAaiPost"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); String uri = SystemProperties.getProperty("pomba.server.url"); try { - Response response = pombaRestInterface.RestPost(fromAppId, uri, new ObjectMapper().writeValueAsString(request)); + pombaRestInterface.RestPost(fromAppId, uri, new ObjectMapper().writeValueAsString(request)); } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.info(EELFLoggerDelegate.errorLogger, methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString()); } } - - - private File getCertificatesFile() { - if (servletContext != null) - return new File(servletContext.getRealPath("/WEB-INF/cert/")); - return null; - } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java index c4bc852ff..63762373a 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java @@ -42,11 +42,12 @@ public class PombaRestInterface extends AAIRestInterface { private Client client = null; - private void initRestClient() + @Override + protected void initRestClient() { if (client == null) { try { - client = httpsAuthClientFactory.getClient(HttpClientMode.UNSECURE); + client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE); } catch (Exception e) { logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString()); @@ -78,6 +79,7 @@ public class PombaRestInterface extends AAIRestInterface { } else { logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, cres)); } + return cres; } catch (Exception e) { logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e)); } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstance.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstance.java index 26f4a21e7..59f367339 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstance.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstance.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class ServiceInstance { @@ -11,16 +11,16 @@ public class ServiceInstance { @JsonProperty("service-instance-name") public String serviceInstanceName; - + @JsonProperty("persona-model-id") public String personaModelId; - + @JsonProperty("persona-model-version") public String personaModelVersion; - + @JsonProperty("resource-version") public String resourceVersion; - + @JsonProperty("orchestration-status") public String orchestrationStatus; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstances.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstances.java index c92a47a36..fb5f18b64 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstances.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstances.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstancesSearchResults.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstancesSearchResults.java index b32a83a13..79d90986b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstancesSearchResults.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstancesSearchResults.java @@ -1,10 +1,9 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import org.onap.vid.model.ServiceInstanceSearchResult; -import java.util.ArrayList; import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscription.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscription.java index 5dc9d526b..805780144 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscription.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscription.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class ServiceSubscription { diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscriptions.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscriptions.java index 686dc7d60..8938f2cdf 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscriptions.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscriptions.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/Services.java b/vid-app-common/src/main/java/org/onap/vid/aai/Services.java index fe70de5af..2a7fc407b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/Services.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/Services.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Services { @@ -16,7 +16,7 @@ public class Services { @JsonProperty("resource-version") public String resourceVersion; - + @JsonProperty("service-subscriptions") public ServiceSubscriptions serviceSubscriptions; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberWithFilter.java b/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberWithFilter.java index aaaa14455..a91e33e5c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberWithFilter.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberWithFilter.java @@ -1,6 +1,6 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import org.onap.vid.model.Subscriber; /** diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java index c30aaeb8f..f91797a79 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java @@ -1,8 +1,8 @@ package org.onap.vid.aai.model.AaiGetAicZone; -import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; -import org.codehaus.jackson.annotate.JsonProperty; +import java.util.List; public class AicZones { @JsonProperty("zone") diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java index 89400f20e..13e26844c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java @@ -1,13 +1,13 @@ package org.onap.vid.aai.model.AaiGetAicZone; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Zone { @JsonProperty("zone-id") public String zoneId; - + @JsonProperty("zone-name") public String zoneName; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/CloudRegion.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/CloudRegion.java new file mode 100644 index 000000000..38dd2b128 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/CloudRegion.java @@ -0,0 +1,55 @@ +package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.ObjectUtils; + +import java.util.List; + +import static java.util.Collections.emptyList; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CloudRegion { + + private final String cloudOwner; + private final String cloudRegionId; + + public CloudRegion( + @JsonProperty("cloud-owner") String cloudOwner, + @JsonProperty("cloud-region-id") String cloudRegionId + ) { + this.cloudOwner = cloudOwner; + this.cloudRegionId = cloudRegionId; + } + + public String getCloudOwner() { + return cloudOwner; + } + + public String getCloudRegionId() { + return cloudRegionId; + } + + /* + This will handle container like: + { + "cloud-region": [{ + "cloud-owner": "alfi", + "cloud-region-id": "foo", + . . . + }, { + "cloud-owner": "alba", + "cloud-region-id": "bar", + */ + public static class Collection { + private final List cloudRegions; + + public Collection(@JsonProperty("cloud-region") List cloudRegions) { + this.cloudRegions = ObjectUtils.defaultIfNull(cloudRegions, emptyList()); + } + + public List getCloudRegions() { + return cloudRegions; + } + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Network.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Network.java index 29450a8f8..41b720a4d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Network.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Network.java @@ -2,9 +2,10 @@ package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; @JsonIgnoreProperties(ignoreUnknown = true) -public class Network { +public class Network implements AaiModelWithRelationships { @JsonProperty("network-id") private String networkId; @JsonProperty("network-name") @@ -19,6 +20,8 @@ public class Network { private Boolean isBoundToVpn; @JsonProperty("resource-version") private String resourceVersion; + @JsonProperty("orchestration-status") + private String orchestrationStatus; @JsonProperty("is-provider-network") private Boolean isProviderNetwork; @JsonProperty("is-shared-network") @@ -99,6 +102,16 @@ public class Network { this.resourceVersion = resourceVersion; } + @JsonProperty("orchestration-status") + public String getOrchestrationStatus() { + return orchestrationStatus; + } + + @JsonProperty("orchestration-status") + public void setOrchestrationStatus(String orchestrationStatus) { + this.orchestrationStatus = orchestrationStatus; + } + @JsonProperty("is-provider-network") public Boolean getIsProviderNetwork() { return isProviderNetwork; @@ -129,6 +142,7 @@ public class Network { this.isExternalNetwork = isExternalNetwork; } + @Override @JsonProperty("relationship-list") public RelationshipList getRelationshipList() { return relationshipList; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/ServiceInstance.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/ServiceInstance.java index c366402e4..49b8536c1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/ServiceInstance.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/ServiceInstance.java @@ -1,17 +1,51 @@ package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; + +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; @JsonIgnoreProperties(ignoreUnknown = true) -public class ServiceInstance { +public class ServiceInstance implements AaiModelWithRelationships { + + private final String serviceInstanceId; + private final String serviceInstanceName; + private final String resourceVersion; + private final RelationshipList relationshipList; + + public ServiceInstance( + @JsonProperty("service-instance-id") String serviceInstanceId, + @JsonProperty("service-instance-name") String serviceInstanceName, + @JsonProperty("resource-version") String resourceVersion, + @JsonProperty("relationship-list") RelationshipList relationshipList + ) { + this.serviceInstanceId = serviceInstanceId; + this.serviceInstanceName = serviceInstanceName; + this.resourceVersion = resourceVersion; + this.relationshipList = relationshipList; + } @JsonProperty("service-instance-id") - public String serviceInstanceId; + public String getServiceInstanceId() { + return serviceInstanceId; + } + + @JsonProperty("service-instance-name") + @JsonInclude(NON_NULL) + public String getServiceInstanceName() { + return serviceInstanceName; + } @JsonProperty("resource-version") - public String resourceVersion; + public String getResourceVersion() { + return resourceVersion; + } + @Override @JsonProperty("relationship-list") - public RelationshipList relationshipList; + public RelationshipList getRelationshipList() { + return relationshipList; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vlan.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vlan.java new file mode 100644 index 000000000..a18464850 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vlan.java @@ -0,0 +1,41 @@ +package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class Vlan implements AaiModelWithRelationships { + + public Vlan( + @JsonProperty("vlan-interface") String vlanInterface, + @JsonProperty("vlan-id-inner") String vlanIdInner, + @JsonProperty("relationship-list") RelationshipList relationshipList) { + this.vlanInterface = vlanInterface; + this.vlanIdInner = vlanIdInner; + this.relationshipList = relationshipList; + } + + @JsonProperty("vlan-interface") + private final String vlanInterface; + + @JsonProperty("vlan-id-inner") + private final String vlanIdInner; + + @JsonProperty("relationship-list") + public final RelationshipList relationshipList; + + public String getVlanInterface() { + return vlanInterface; + } + + public String getVlanIdInner() { + return vlanIdInner; + } + + @Override + public RelationshipList getRelationshipList() { + return relationshipList; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vnf.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vnf.java new file mode 100644 index 000000000..5dc6e4d3b --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vnf.java @@ -0,0 +1,84 @@ +package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class Vnf implements AaiModelWithRelationships { + @JsonProperty("vnf-id") + private String vnfId; + @JsonProperty("vnf-name") + private String vnfName; + @JsonProperty("vnf-type") + private String vnfType; + @JsonProperty("resource-version") + private String resourceVersion; + @JsonProperty("orchestration-status") + private String orchestrationStatus; + @JsonProperty("relationship-list") + private RelationshipList relationshipList; + + + @JsonProperty("vnf-id") + public String getVnfId() { + return vnfId; + } + + @JsonProperty("vnf-id") + public void setVnfId(String vnfId) { + this.vnfId = vnfId; + } + + @JsonProperty("vnf-name") + public String getVnfName() { + return vnfName; + } + + @JsonProperty("vnf-name") + public void setVnfName(String vnfName) { + this.vnfName = vnfName; + } + + @JsonProperty("vnf-type") + public String getVnfType() { + return vnfType; + } + + @JsonProperty("vnf-type") + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + + @JsonProperty("resource-version") + public String getResourceVersion() { + return resourceVersion; + } + + @JsonProperty("resource-version") + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + @JsonProperty("orchestration-status") + public String getOrchestrationStatus() { + return orchestrationStatus; + } + + @JsonProperty("orchestration-status") + public void setOrchestrationStatus(String orchestrationStatus) { + this.orchestrationStatus = orchestrationStatus; + } + + @Override + @JsonProperty("relationship-list") + public RelationshipList getRelationshipList() { + return relationshipList; + } + + @JsonProperty("relationship-list") + public void setRelationshipList(RelationshipList relationshipList) { + this.relationshipList = relationshipList; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetOperationalEnvironments/OperationalEnvironmentList.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetOperationalEnvironments/OperationalEnvironmentList.java index 1f31cfaa9..254d5edc4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetOperationalEnvironments/OperationalEnvironmentList.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetOperationalEnvironments/OperationalEnvironmentList.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model.AaiGetOperationalEnvironments; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.onap.vid.aai.OperationalEnvironment; import java.util.List; @@ -9,12 +9,11 @@ import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) public class OperationalEnvironmentList { - @JsonProperty("operational-environment") public List getOperationalEnvironment() { return operationalEnvironment; } - @JsonProperty("operational-environment") + @JsonAlias("operational-environment") public void setOperationalEnvironment(List operationalEnvironment) { this.operationalEnvironment = operationalEnvironment; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfResponse.java index fa9fe9350..93c12c8e3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfResponse.java @@ -1,12 +1,7 @@ package org.onap.vid.aai.model; -import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.*; import com.google.common.base.MoreObjects; -import org.codehaus.jackson.annotate.JsonAnyGetter; -import org.codehaus.jackson.annotate.JsonAnySetter; -import org.codehaus.jackson.annotate.JsonIgnore; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.annotate.JsonPropertyOrder; import java.util.HashMap; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java index 00a731a70..d359474d9 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java @@ -1,31 +1,25 @@ package org.onap.vid.aai.model.AaiGetPnfs; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.onap.vid.aai.model.AaiRelationResponse; @JsonIgnoreProperties(ignoreUnknown = true) public class Pnf extends AaiRelationResponse { - @JsonProperty("pnf-name") - public String pnfName; - @JsonProperty("pnf-name2") - public String pnfName2; - @JsonProperty("pnf-name2-source") - public String pnfName2Source; - @JsonProperty("pnf-id") - public String pnfId; - @JsonProperty("equip-type") - public String equipType; - @JsonProperty("equip-vendor") - public String equipVendor; - @JsonProperty("equip-model") - public String equipModel; + private String pnfName; + private String pnfName2; + private String pnfName2Source; + private String pnfId; + private String equipType; + private String equipVendor; + private String equipModel; public String getPnfName() { return pnfName; } + @JsonAlias("pnf-name") public void setPnfName(String pnfName) { this.pnfName = pnfName; } @@ -34,6 +28,7 @@ public class Pnf extends AaiRelationResponse { return equipType; } + @JsonAlias("equip-type") public void setEquipType(String equipType) { this.equipType = equipType; } @@ -42,6 +37,7 @@ public class Pnf extends AaiRelationResponse { return equipVendor; } + @JsonAlias("equip-vendor") public void setEquipVendor(String equipVendor) { this.equipVendor = equipVendor; } @@ -50,6 +46,7 @@ public class Pnf extends AaiRelationResponse { return pnfName2; } + @JsonAlias("pnf-name2") public void setPnfName2(String pnfName2) { this.pnfName2 = pnfName2; } @@ -58,6 +55,7 @@ public class Pnf extends AaiRelationResponse { return pnfId; } + @JsonAlias("pnf-id") public void setPnfId(String pnfId) { this.pnfId = pnfId; } @@ -66,12 +64,14 @@ public class Pnf extends AaiRelationResponse { return equipModel; } + @JsonAlias("equip-model") public void setEquipModel(String equipModel) { this.equipModel = equipModel; } public String getPnfName2Source() { return pnfName2Source; } + @JsonAlias("pnf-name2-source") public void setPnfName2Source(String pnfName2Source) { this.pnfName2Source = pnfName2Source; } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPortMirroringSourcePorts.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPortMirroringSourcePorts.java index 47a57dafb..b629d9040 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPortMirroringSourcePorts.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPortMirroringSourcePorts.java @@ -1,6 +1,6 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/GetServicesAAIRespone.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/GetServicesAAIRespone.java index d3dd7d26c..d5858de20 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/GetServicesAAIRespone.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/GetServicesAAIRespone.java @@ -1,7 +1,6 @@ package org.onap.vid.aai.model.AaiGetServicesRequestModel; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/Service.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/Service.java index 367287e1d..36b5a5140 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/Service.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/Service.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model.AaiGetServicesRequestModel; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by Oren on 7/17/17. diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetTenatns/GetTenantsResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetTenatns/GetTenantsResponse.java index 1d0e84952..c799c8fa6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetTenatns/GetTenantsResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetTenatns/GetTenantsResponse.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model.AaiGetTenatns; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by Oren on 7/18/17. @@ -9,26 +9,29 @@ import org.codehaus.jackson.annotate.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class GetTenantsResponse { - @JsonProperty("cloudRegionID") - public String cloudRegionId; + public String cloudRegionID; - @JsonProperty("cloudOwner") public String cloudOwner; - - @JsonProperty("tenantName") + public String tenantName; - @JsonProperty("tenantID") public String tenantID; - @JsonProperty("is-permitted") public boolean isPermitted; + @JsonProperty("is-permitted") + public boolean getJsonIsPermitted() { + // this is a special case to *duplicate* the permission field + // as it might be that both -- camelCase and hyphen faces -- + // are in use + return isPermitted; + } + public GetTenantsResponse() { } public GetTenantsResponse(String cloudRegionId, String cloudOwner, String tenantName, String tenantID, boolean isPermitted) { - this.cloudRegionId = cloudRegionId; + this.cloudRegionID = cloudRegionId; this.cloudOwner = cloudOwner; this.tenantName = tenantName; this.tenantID = tenantID; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiRelationResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiRelationResponse.java index 7bc2e7a2e..981f85656 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiRelationResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiRelationResponse.java @@ -1,9 +1,8 @@ package org.onap.vid.aai.model; - -import org.codehaus.jackson.annotate.JsonIgnore; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.HashMap; import java.util.Map; @@ -13,30 +12,27 @@ import java.util.Map; */ public class AaiRelationResponse { - @JsonProperty("resource-version") private String resourceVersion; - @JsonProperty("relationship-list") private RelationshipList relationshipList; + @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); - @JsonProperty("resource-version") public String getResourceVersion() { return resourceVersion; } - @JsonProperty("resource-version") + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } - @JsonProperty("relationship-list") public RelationshipList getRelationshipList() { return relationshipList; } - @JsonProperty("relationship-list") + @JsonAlias("relationship-list") public void setRelationshipList(RelationshipList relationshipList) { this.relationshipList = relationshipList; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/CustomQuerySimpleResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/CustomQuerySimpleResult.java new file mode 100644 index 000000000..4f91b7566 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/CustomQuerySimpleResult.java @@ -0,0 +1,18 @@ +package org.onap.vid.aai.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class CustomQuerySimpleResult { + + private final List results; + + public CustomQuerySimpleResult(@JsonProperty("results") List results) { + this.results = results; + } + + public List getResults() { + return results; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/GetServiceModelsByDistributionStatusResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/GetServiceModelsByDistributionStatusResponse.java index 5a6924dcb..c17f930c0 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/GetServiceModelsByDistributionStatusResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/GetServiceModelsByDistributionStatusResponse.java @@ -1,8 +1,8 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/LogicalLinkResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/LogicalLinkResponse.java index 6625957ec..4d815bc3d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/LogicalLinkResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/LogicalLinkResponse.java @@ -1,31 +1,26 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; public class LogicalLinkResponse { - @JsonProperty("link-name") public String linkName; - @JsonProperty("in-maint") public Boolean inMaint; - @JsonProperty("link-type") public String linkType; - @JsonProperty("resource-version") public String resourceVersion; - @JsonProperty("purpose") public String purpose; - @JsonProperty("relationship-list") public RelationshipList relationshipList; public String getLinkName() { return linkName; } + @JsonAlias("link-name") public void setLinkName(String linkName) { this.linkName = linkName; } @@ -34,6 +29,7 @@ public class LogicalLinkResponse { return inMaint; } + @JsonAlias("in-maint") public void setInMaint(Boolean inMaint) { this.inMaint = inMaint; } @@ -42,6 +38,7 @@ public class LogicalLinkResponse { return linkType; } + @JsonAlias("link-type") public void setLinkType(String linkType) { this.linkType = linkType; } @@ -50,6 +47,7 @@ public class LogicalLinkResponse { return resourceVersion; } + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } @@ -58,6 +56,7 @@ public class LogicalLinkResponse { return purpose; } + @JsonAlias("purpose") public void setPurpose(String purpose) { this.purpose = purpose; } @@ -66,6 +65,7 @@ public class LogicalLinkResponse { return relationshipList; } + @JsonAlias("relationship-list") public void setRelationshipList(RelationshipList relationshipList) { this.relationshipList = relationshipList; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Model.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Model.java index 5f422f68a..7a771e4e8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Model.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Model.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** * Created by moriya1 on 15/10/2017. @@ -9,51 +9,43 @@ import org.codehaus.jackson.annotate.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Model { - @JsonProperty("model-invariant-id") private String modelInvariantId; - @JsonProperty("model-type") private String modelType; - @JsonProperty("resource-version") private String resourceVersion; - @JsonProperty("model-vers") private ModelVers modelVers; - @JsonProperty("model-invariant-id") public String getModelInvariantId() { return modelInvariantId; } - @JsonProperty("model-invariant-id") + @JsonAlias("model-invariant-id") public void setModelInvariantId(String modelInvariantId) { this.modelInvariantId = modelInvariantId; } - @JsonProperty("model-type") public String getModelType() { return modelType; } - @JsonProperty("model-type") + @JsonAlias("model-type") public void setModelType(String modelType) { this.modelType = modelType; } - @JsonProperty("resource-version") public String getResourceVersion() { return resourceVersion; } - @JsonProperty("resource-version") + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } - @JsonProperty("model-vers") public ModelVers getModelVers() { return modelVers; } - @JsonProperty("model-vers") + @JsonAlias("model-vers") public void setModelVers(ModelVers modelVers) { this.modelVers = modelVers; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java index f02bbacfe..6908feb71 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java @@ -1,82 +1,70 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class ModelVer { - @JsonProperty("model-version-id") private String modelVersionId; - @JsonProperty("model-name") private String modelName; - @JsonProperty("model-version") private String modelVersion; - @JsonProperty("distribution-status") private String distributionStatus; - @JsonProperty("resource-version") private String resourceVersion; - @JsonProperty("model-description") private String modelDescription; - @JsonProperty("model-version-id") public String getModelVersionId() { return modelVersionId; } - @JsonProperty("model-version-id") + @JsonAlias("model-version-id") public void setModelVersionId(String modelVersionId) { this.modelVersionId = modelVersionId; } - @JsonProperty("model-name") public String getModelName() { return modelName; } - @JsonProperty("model-name") + @JsonAlias("model-name") public void setModelName(String modelName) { this.modelName = modelName; } - @JsonProperty("model-version") public String getModelVersion() { return modelVersion; } - @JsonProperty("model-version") + @JsonAlias("model-version") public void setModelVersion(String modelVersion) { this.modelVersion = modelVersion; } - @JsonProperty("distribution-status") public String getDistributionStatus() { return distributionStatus; } - @JsonProperty("distribution-status") + @JsonAlias("distribution-status") public void setDistributionStatus(String distributionStatus) { this.distributionStatus = distributionStatus; } - @JsonProperty("resource-version") public String getResourceVersion() { return resourceVersion; } - @JsonProperty("resource-version") + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } - @JsonProperty("model-description") public String getModelDescription() { return modelDescription; } - @JsonProperty("model-description") + @JsonAlias("model-description") public void setModelDescription(String modelDescription) { this.modelDescription = modelDescription; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVers.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVers.java index f352158f2..eed40fc00 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVers.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVers.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.util.List; @@ -11,15 +11,13 @@ import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) public class ModelVers { - @JsonProperty("model-ver") private List modelVer; - @JsonProperty("model-ver") public List getModelVer() { return modelVer; } - @JsonProperty("model-ver") + @JsonAlias("model-ver") public void setModelVer(List modelVer) { this.modelVer = modelVer; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntity.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntity.java index edf5242d6..366a1088f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntity.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntity.java @@ -1,33 +1,29 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; /** * Created by moriya1 on 08/10/2017. */ public class OwningEntity extends AaiRelationResponse { - @JsonProperty("owning-entity-id") private String owningEntityId; - @JsonProperty("owning-entity-name") private String owningEntityName; - @JsonProperty("owning-entity-id") public String getOwningEntityId() { return owningEntityId; } - @JsonProperty("owning-entity-id") + @JsonAlias("owning-entity-id") public void setOwningEntityId(String owningEntityId) { this.owningEntityId = owningEntityId; } - @JsonProperty("owning-entity-name") public String getOwningEntityName() { return owningEntityName; } - @JsonProperty("owning-entity-name") + @JsonAlias("owning-entity-name") public void setOwningEntityName(String owningEntityName) { this.owningEntityName = owningEntityName; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntityResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntityResponse.java index 3a571ea14..1d9bd8393 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntityResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntityResponse.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; @@ -10,17 +10,15 @@ import java.util.List; */ public class OwningEntityResponse { - @JsonProperty("owning-entity") private List owningEntity; - @JsonProperty("owning-entity") public List getOwningEntity() { return owningEntity; } @JsonProperty("owning-entity") - public void setOwningEntity(List owningEntity) { + public void setJsonOwningEntity(List owningEntity) { this.owningEntity = owningEntity; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Permissions.kt b/vid-app-common/src/main/java/org/onap/vid/aai/model/Permissions.kt new file mode 100644 index 000000000..472da8db4 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Permissions.kt @@ -0,0 +1,6 @@ +package org.onap.vid.aai.model + +import com.fasterxml.jackson.annotation.JsonProperty + + +data class Permissions(@get:JsonProperty("isEditPermitted") val isEditPermitted: Boolean) \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfProperties.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfProperties.java index 3481d263e..032714b93 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfProperties.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfProperties.java @@ -1,12 +1,6 @@ package org.onap.vid.aai.model; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.*; import java.util.HashMap; import java.util.Map; @@ -23,20 +17,15 @@ import java.util.Map; }) public class PnfProperties { - @JsonProperty("pnf-name") public String pnfName; - @JsonProperty("equip-type") public String equipType; - @JsonProperty("equip-vendor") public String equipVendor; - @JsonProperty("equip-model") public String equipModel; - @JsonProperty("in-maint") public Boolean inMaint; - @JsonProperty("resource-version") public String resourceVersion; + @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); @JsonAnyGetter public Map getAdditionalProperties() { @@ -48,4 +37,34 @@ public class PnfProperties { this.additionalProperties.put(name, value); } + @JsonProperty("pnf-name") + public void setJsonPnfName(String pnfName) { + this.pnfName = pnfName; + } + + @JsonProperty("equip-type") + public void setJsonEquipType(String equipType) { + this.equipType = equipType; + } + + @JsonProperty("equip-vendor") + public void setJsonEquipVendor(String equipVendor) { + this.equipVendor = equipVendor; + } + + @JsonProperty("equip-model") + public void setJsonEquipModel(String equipModel) { + this.equipModel = equipModel; + } + + @JsonProperty("in-maint") + public void setJsonInMaint(Boolean inMaint) { + this.inMaint = inMaint; + } + + @JsonProperty("resource-version") + public void setJsonResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfResult.java index a727d8f3c..a2c3d3bed 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfResult.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfResult.java @@ -1,12 +1,6 @@ package org.onap.vid.aai.model; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.codehaus.jackson.annotate.JsonProperty; -import org.onap.vid.RelatedTo; +import com.fasterxml.jackson.annotation.*; import java.util.HashMap; import java.util.List; @@ -23,19 +17,39 @@ import java.util.Map; }) public class PnfResult { - @JsonProperty("id") public String id; - @JsonProperty("node-type") public String nodeType; - @JsonProperty("url") public String url; - @JsonProperty("properties") public PnfProperties properties; - @JsonProperty("related-to") public List relatedTo; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); + + @JsonProperty("id") + public void setJsonId(String id) { + this.id = id; + } + + @JsonProperty("node-type") + public void setJsonNodeType(String nodeType) { + this.nodeType = nodeType; + } + + @JsonProperty("url") + public void setJsonUrl(String url) { + this.url = url; + } + + @JsonProperty("properties") + public void setJsonProperties(PnfProperties properties) { + this.properties = properties; + } + + @JsonProperty("related-to") + public void setJsonRelatedTo(List relatedTo) { + this.relatedTo = relatedTo; + } @JsonAnyGetter public Map getAdditionalProperties() { diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/PortDetailsTranslator.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/PortDetailsTranslator.java index f8980457a..ae74af6fa 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/PortDetailsTranslator.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/PortDetailsTranslator.java @@ -3,10 +3,7 @@ package org.onap.vid.aai.model; import com.google.common.collect.ImmutableList; import org.onap.vid.aai.AaiResponse; -import org.onap.vid.properties.Features; -import org.togglz.core.manager.FeatureManager; -import javax.inject.Inject; import java.util.LinkedList; import java.util.List; import java.util.Optional; @@ -15,10 +12,7 @@ import java.util.stream.Collectors; public class PortDetailsTranslator { - @Inject - FeatureManager featureManager; - - public static class PortDetailsOk extends PortDetails { + public static class PortDetailsOk implements PortDetails { private final String interfaceId; private final String interfaceName; @@ -43,16 +37,16 @@ public class PortDetailsTranslator { } } - public abstract static class PortDetails { + public interface PortDetails { } - public static class PortDetailsError extends PortDetails { + public static class PortDetailsError implements PortDetails { private final String errorDescription; private final String rawAaiResponse; - public PortDetailsError(String errorDescription, String rawAaiResponse){ - this.errorDescription = errorDescription; - this.rawAaiResponse = rawAaiResponse; + public PortDetailsError(String errorDescription, String rawAaiResponse) { + this.errorDescription = errorDescription; + this.rawAaiResponse = rawAaiResponse; } public String getErrorDescription() { @@ -64,13 +58,13 @@ public class PortDetailsTranslator { } } - public static PortDetails extractPortDetailsFromProperties(Properties properties, String rawPayload){ + public static PortDetails extractPortDetailsFromProperties(Properties properties, String rawPayload) { List errorDescriptions = new LinkedList<>(); describeIfNullOrEmpty("interface-id", properties.getInterfaceId(), errorDescriptions); describeIfNullOrEmpty("interface-name", properties.getInterfaceName(), errorDescriptions); describeIfNullOrEmpty("is-port-mirrored", properties.getIsPortMirrored(), errorDescriptions); - if(errorDescriptions.isEmpty()){ + if (errorDescriptions.isEmpty()) { return new PortDetailsOk(properties.getInterfaceId(), properties.getInterfaceName(), properties.getIsPortMirrored()); } else { return new PortDetailsError(String.join(" ", errorDescriptions), rawPayload); @@ -90,14 +84,14 @@ public class PortDetailsTranslator { final String errorMessage = aaiResponse.getErrorMessage(); return Optional.of(ImmutableList.of(new PortDetailsError( "Got " + aaiResponse.getHttpCode() + " from aai", - errorMessage != null ? errorMessage.toString() : rawPayload) + errorMessage != null ? errorMessage : rawPayload) )); } else { return Optional.empty(); } } - public List extractPortDetailsInternal(AaiGetPortMirroringSourcePorts aaiGetPortsResponse, String rawPayload){ + public List extractPortDetailsInternal(CustomQuerySimpleResult aaiGetPortsResponse, String rawPayload) { List filteredResult = getFilteredPortList(aaiGetPortsResponse.getResults()); return filteredResult.stream() @@ -107,7 +101,7 @@ public class PortDetailsTranslator { } public List getFilteredPortList(List results) { - String LINTERFACE = "l-interface"; + final String LINTERFACE = "l-interface"; final Predicate ifIsPort = (SimpleResult r) -> LINTERFACE.equals(r.getNodeType()); Predicate ifIsSource = getIsSourcePredicate(); @@ -119,18 +113,12 @@ public class PortDetailsTranslator { } private Predicate getIsSourcePredicate() { - boolean FLAG_ADVANCED_PORTS_FILTER = featureManager.isActive(Features.FLAG_ADVANCED_PORTS_FILTER); - - if (FLAG_ADVANCED_PORTS_FILTER) { - String PORT_LABEL = "org.onap.relationships.inventory.Source"; - return (SimpleResult r) -> r.getRelatedTo().stream() - .anyMatch(relatedTo -> PORT_LABEL.equalsIgnoreCase(relatedTo.getRelationshipLabel())); - } else { - return (SimpleResult r) -> true; - } + final String PORT_LABEL = "org.onap.relationships.inventory.Source"; + return (SimpleResult r) -> r.getRelatedTo().stream() + .anyMatch(relatedTo -> PORT_LABEL.equalsIgnoreCase(relatedTo.getRelationshipLabel())); } - public List extractPortDetails(AaiResponse aaiGetPortsResponse, String rawPayload){ + public List extractPortDetails(AaiResponse aaiGetPortsResponse, String rawPayload) { return extractErrorResponseIfHttpError(aaiGetPortsResponse, rawPayload).orElseGet(() -> extractPortDetailsInternal(aaiGetPortsResponse.getT(), rawPayload)); } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Project.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Project.java index 5931bb97a..4e9f945c4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Project.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Project.java @@ -1,20 +1,18 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; /** * Created by moriya1 on 08/10/2017. */ public class Project extends AaiRelationResponse { - @JsonProperty("project-name") private String projectName; - @JsonProperty("project-name") public String getProjectName() { return projectName; } - @JsonProperty("project-name") + @JsonAlias("project-name") public void setProjectName(String projectName) { this.projectName = projectName; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ProjectResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ProjectResponse.java index 0ca35b0a9..125e1061d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ProjectResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ProjectResponse.java @@ -1,8 +1,6 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; - import java.util.List; /** @@ -10,16 +8,13 @@ import java.util.List; */ public class ProjectResponse { - @JsonProperty("project") private List project; - @JsonProperty("project") public List getProject() { return project; } - @JsonProperty("project") public void setProject(List project) { this.project = project; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Properties.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Properties.java index 6fecbed53..dec632ea8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Properties.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Properties.java @@ -1,23 +1,38 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.HashMap; +import java.util.Map; -@JsonIgnoreProperties(ignoreUnknown = true) public class Properties { - private final String interfaceName; - private final String interfaceId; - private final Boolean isPortMirrored; + //properties for l-interface node-type + @JsonProperty("interface-name") + private String interfaceName; - public Properties( - @JsonProperty("interface-name") String interfaceName, - @JsonProperty("interface-id") String interfaceId, - @JsonProperty("is-port-mirrored") Boolean isPortMirrored) { - this.interfaceName = interfaceName; - this.interfaceId = interfaceId; - this.isPortMirrored = isPortMirrored; - } + @JsonProperty("interface-id") + private String interfaceId; + + @JsonProperty("is-port-mirrored") + private Boolean isPortMirrored; + + //properties for tenant node-type + @JsonProperty("tenant-id") + private String tenantId; + + @JsonProperty("tenant-name") + private String tenantName; + + //properties for cloud-region node-type + @JsonProperty("cloud-region-id") + private String cloudRegionId; + + private Map additionalProperties = new HashMap<>(); + + public Properties(){} public String getInterfaceName() { return interfaceName; @@ -30,4 +45,38 @@ public class Properties { public Boolean getIsPortMirrored() { return isPortMirrored; } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public String getCloudRegionId() { + return cloudRegionId; + } + + public void setCloudRegionId(String cloudRegionId) { + this.cloudRegionId = cloudRegionId; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperties(String name, String value) { + additionalProperties.put(name, value); + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedTo.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedTo.java index f14a445fe..fa0351e85 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedTo.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedTo.java @@ -1,9 +1,11 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) public class RelatedTo { private final String id; private final String relationshipLabel; @@ -20,19 +22,19 @@ public class RelatedTo { this.nodeType = nodeType; this.url = url; } - + @JsonProperty("id") public String getId() { return id; } - + @JsonProperty("relationship-label") public String getRelationshipLabel() { return relationshipLabel; } - + @JsonProperty("node-type") public String getNodeType() { return nodeType; } - + @JsonProperty("url") public String getUrl() { return url; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java index a2a98fc27..9227e87cf 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java @@ -1,8 +1,8 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class RelatedToProperty { @@ -12,6 +12,7 @@ public class RelatedToProperty { } + @JsonAlias("property-key") public void setPropertyKey(String propertyKey) { this.propertyKey = propertyKey; } @@ -22,16 +23,15 @@ public class RelatedToProperty { } + @JsonAlias("property-value") public void setPropertyValue(String propertyValue) { this.propertyValue = propertyValue; } - @JsonProperty("property-key") public String propertyKey; - @JsonProperty("property-value") public String propertyValue; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java index 6bf63c433..d6ba8d84e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java @@ -1,7 +1,8 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + import java.util.List; @@ -9,19 +10,14 @@ import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) public class Relationship { - @JsonProperty("related-to") public String relatedTo; - @JsonProperty("related-link") public String relatedLink; - @JsonProperty("relationship-label") public String relationshipLabel; - @JsonProperty("relationship-data") public List relationshipData; - @JsonProperty("related-to-property") public List relatedToProperty; @@ -29,6 +25,7 @@ public class Relationship { return relatedTo; } + @JsonAlias("related-to") public void setRelatedTo(String relatedTo) { this.relatedTo = relatedTo; } @@ -37,6 +34,7 @@ public class Relationship { return relatedLink; } + @JsonAlias("related-link") public void setRelatedLink(String relatedLink) { this.relatedLink = relatedLink; } @@ -45,6 +43,7 @@ public class Relationship { return relationshipData; } + @JsonAlias("relationship-data") public void setRelationDataList(List relationDataList) { this.relationshipData = relationDataList; } @@ -53,6 +52,7 @@ public class Relationship { return relatedToProperty; } + @JsonAlias("related-to-property") public void setRelatedToPropertyList(List relatedToPropertyList) { this.relatedToProperty = relatedToPropertyList; } @@ -61,6 +61,7 @@ public class Relationship { return relationshipLabel; } + @JsonAlias("relationship-label") public void setRelationshipLabel(String relationshipLabel) { this.relationshipLabel = relationshipLabel; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java index 415366514..55a0b77df 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java @@ -1,29 +1,29 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class RelationshipData { - @JsonProperty("relationship-key") - public String getRelationshipKey() { - return relationshipKey; - } - @JsonProperty("relationship-key") - public void setRelationshipKey(String relationshipKey) { - this.relationshipKey = relationshipKey; - } - @JsonProperty("relationship-value") - public String getRelationshipValue() { - return relationshipValue; - } - @JsonProperty("relationship-value") - public void setRelationshipValue(String relationshipValue) { - this.relationshipValue = relationshipValue; - } + public String relationshipKey; + public String relationshipValue; - public String relationshipKey; - - public String relationshipValue; + public String getRelationshipKey() { + return relationshipKey; + } + + @JsonAlias("relationship-key") + public void setRelationshipKey(String relationshipKey) { + this.relationshipKey = relationshipKey; + } + + public String getRelationshipValue() { + return relationshipValue; + } + + @JsonAlias("relationship-value") + public void setRelationshipValue(String relationshipValue) { + this.relationshipValue = relationshipValue; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java index b16ddd01c..f51fb9dfd 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ResourceType.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ResourceType.java index 736a1aa9e..79f5272cb 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ResourceType.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ResourceType.java @@ -10,10 +10,12 @@ import java.util.stream.Stream; public enum ResourceType { - SERVICE_INSTANCE("service-instance", "service-instance-name"), - GENERIC_VNF("generic-vnf", "vnf-name"), - VF_MODULE("vf-module", "vf-module-name"), - VOLUME_GROUP("volume-group", "volume-group-name"); + SERVICE_INSTANCE("service-instances", "service-instance-name"), + GENERIC_VNF("generic-vnfs", "vnf-name"), + L3_NETWORK("l3-networks", "network-name"), + VF_MODULE("vf-modules", "vf-module-name"), + INSTANCE_GROUP("instance-groups", "instance-group-name"), + VOLUME_GROUP("volume-groups", "volume-group-name"); private static Map AAI_FORMAT_MAP = Stream .of(ResourceType.values()) diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Result.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Result.java index 1eb46be75..cb4dc869c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Result.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Result.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by moriya1 on 15/10/2017. diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceProperties.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceProperties.java index a76bcf8a1..a1962cc53 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceProperties.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceProperties.java @@ -1,8 +1,6 @@ package org.onap.vid.aai.model; import com.fasterxml.jackson.annotation.*; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; import java.util.HashMap; import java.util.Map; @@ -35,70 +33,49 @@ import java.util.Map; public class ServiceProperties { @JsonProperty("service-instance-id") - @com.fasterxml.jackson.annotation.JsonProperty("service-instance-id") public String serviceInstanceId; @JsonProperty("service-instance-name") - @com.fasterxml.jackson.annotation.JsonProperty("service-instance-name") public String serviceInstanceName; @JsonProperty("model-invariant-id") - @com.fasterxml.jackson.annotation.JsonProperty("model-invariant-id") public String modelInvariantId; @JsonProperty("model-version-id") - @com.fasterxml.jackson.annotation.JsonProperty("model-version-id") public String modelVersionId; @JsonProperty("resource-version") - @com.fasterxml.jackson.annotation.JsonProperty("resource-version") public String resourceVersion; @JsonProperty("orchestration-status") - @com.fasterxml.jackson.annotation.JsonProperty("orchestration-status") public String orchestrationStatus; @JsonProperty("global-customer-id") - @com.fasterxml.jackson.annotation.JsonProperty("global-customer-id") public String globalCustomerId; @JsonProperty("subscriber-name") - @com.fasterxml.jackson.annotation.JsonProperty("subscriber-name") public String subscriberName; @JsonProperty("subscriber-type") - @com.fasterxml.jackson.annotation.JsonProperty("subscriber-type") public String subscriberType; @JsonProperty("vnf-id") - @com.fasterxml.jackson.annotation.JsonProperty("vnf-id") public String vnfId; @JsonProperty("vnf-name") - @com.fasterxml.jackson.annotation.JsonProperty("vnf-name") public String vnfName; @JsonProperty("vnf-type") - @com.fasterxml.jackson.annotation.JsonProperty("vnf-type") public String vnfType; @JsonProperty("service-id") - @com.fasterxml.jackson.annotation.JsonProperty("service-id") public String serviceId; @JsonProperty("prov-status") - @com.fasterxml.jackson.annotation.JsonProperty("prov-status") public String provStatus; @JsonProperty("in-maint") - @com.fasterxml.jackson.annotation.JsonProperty("in-maint") public Boolean inMaint; @JsonProperty("is-closed-loop-disabled") - @com.fasterxml.jackson.annotation.JsonProperty("is-closed-loop-disabled") public Boolean isClosedLoopDisabled; @JsonProperty("model-customization-id") - @com.fasterxml.jackson.annotation.JsonProperty("model-customization-id") public String modelCustomizationId; @JsonProperty("nf-type") - @com.fasterxml.jackson.annotation.JsonProperty("nf-type") public String nfType; @JsonProperty("nf-function") - @com.fasterxml.jackson.annotation.JsonProperty("nf-function") public String nfFunction; @JsonProperty("nf-role") - @com.fasterxml.jackson.annotation.JsonProperty("nf-role") public String nfRole; @JsonProperty("nf-naming-code") - @com.fasterxml.jackson.annotation.JsonProperty("nf-naming-code") public String nfNamingCode; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); @JsonAnyGetter public Map getAdditionalProperties() { diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceRelationships.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceRelationships.java index b8abc8494..eba00356e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceRelationships.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceRelationships.java @@ -1,40 +1,31 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +@JsonIgnoreProperties(ignoreUnknown = true) public class ServiceRelationships { - @JsonProperty("service-instance-id") public String serviceInstanceId; - @JsonProperty("service-instance-name") public String serviceInstanceName; - @JsonProperty("service-type") public String serviceType; - @JsonProperty("service-role") public String serviceRole; - @JsonProperty("environment-context") public String environmentContext; - @JsonProperty("workload-context") public String workloadContext; - @JsonProperty("model-invariant-id") public String modelInvariantId; - - @JsonProperty("model-version-id") + public String modelVersionId; - @JsonProperty("resource-version") public String resourceVersion; - - @JsonProperty("orchestration-status") + public String orchestrationStatus; - @JsonProperty("relationship-list") public RelationshipList relationshipList; @@ -42,6 +33,7 @@ public class ServiceRelationships { return serviceInstanceId; } + @JsonAlias("service-instance-id") public void setServiceInstanceId(String serviceInstanceId) { this.serviceInstanceId = serviceInstanceId; } @@ -50,6 +42,7 @@ public class ServiceRelationships { return serviceInstanceName; } + @JsonAlias("service-instance-name") public void setServiceInstanceName(String serviceInstanceName) { this.serviceInstanceName = serviceInstanceName; } @@ -58,6 +51,43 @@ public class ServiceRelationships { return modelInvariantId; } + public String getServiceType() { + return serviceType; + } + + @JsonAlias("service-type") + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public String getServiceRole() { + return serviceRole; + } + + @JsonAlias("service-role") + public void setServiceRole(String serviceRole) { + this.serviceRole = serviceRole; + } + + public String getEnvironmentContext() { + return environmentContext; + } + + @JsonAlias("environment-context") + public void setEnvironmentContext(String environmentContext) { + this.environmentContext = environmentContext; + } + + public String getWorkloadContext() { + return workloadContext; + } + + @JsonAlias("workload-context") + public void setWorkloadContext(String workloadContext) { + this.workloadContext = workloadContext; + } + + @JsonAlias("model-invariant-id") public void setModelInvariantId(String modelInvariantId) { this.modelInvariantId = modelInvariantId; } @@ -66,6 +96,7 @@ public class ServiceRelationships { return modelVersionId; } + @JsonAlias("model-version-id") public void setModelVersionId(String modelVersionId) { this.modelVersionId = modelVersionId; } @@ -74,6 +105,7 @@ public class ServiceRelationships { return resourceVersion; } + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } @@ -82,6 +114,7 @@ public class ServiceRelationships { return orchestrationStatus; } + @JsonAlias("orchestration-status") public void setOrchestrationStatus(String orchestrationStatus) { this.orchestrationStatus = orchestrationStatus; } @@ -90,6 +123,7 @@ public class ServiceRelationships { return relationshipList; } + @JsonAlias("relationship-list") public void setRelationshipList(RelationshipList relationshipList) { this.relationshipList = relationshipList; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/SimpleResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/SimpleResult.java index b2edfc17e..554449b96 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/SimpleResult.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/SimpleResult.java @@ -1,85 +1,73 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonAnyGetter; -import org.codehaus.jackson.annotate.JsonAnySetter; -import org.codehaus.jackson.annotate.JsonIgnore; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.HashMap; import java.util.List; import java.util.Map; public class SimpleResult { - @JsonProperty("id") private String id; - @JsonProperty("node-type") private String nodeType; - @JsonProperty("url") private String url; - @JsonProperty("properties") private Properties properties; - @JsonProperty("related-to") private List relatedTo = null; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); - @JsonProperty("id") public String getId() { return id; } @JsonProperty("id") - public void setId(String id) { + public void setJsonId(String id) { this.id = id; } - @JsonProperty("node-type") public String getNodeType() { return nodeType; } @JsonProperty("node-type") - public void setNodeType(String nodeType) { + public void setJsonNodeType(String nodeType) { this.nodeType = nodeType; } - @JsonProperty("url") public String getUrl() { return url; } @JsonProperty("url") - public void setUrl(String url) { + public void setJsonUrl(String url) { this.url = url; } - @JsonProperty("properties") public Properties getProperties() { return properties; } @JsonProperty("properties") - public void setProperties(Properties properties) { + public void setJsonProperties(Properties properties) { this.properties = properties; } - @JsonProperty("related-to") public List getRelatedTo() { return relatedTo; } @JsonProperty("related-to") - public void setRelatedTo(List relatedTo) { + public void setJsonRelatedTo(List relatedTo) { this.relatedTo = relatedTo; } - @JsonAnyGetter public Map getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { + public void setJsonAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java index e4f22849d..b404a0251 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java @@ -1,8 +1,6 @@ package org.onap.vid.aai.model; import com.fasterxml.jackson.annotation.*; -import org.codehaus.jackson.annotate.JsonProperty; -import org.onap.vid.RelatedTo; import java.util.HashMap; import java.util.List; @@ -18,10 +16,8 @@ import java.util.Map; "related-to" }) public class VnfResult { - @JsonProperty("id") public String id; - @com.fasterxml.jackson.annotation.JsonProperty("node-type") @JsonProperty("node-type") public String nodeType; @JsonProperty("url") @@ -29,10 +25,34 @@ public class VnfResult { @JsonProperty("properties") public ServiceProperties properties; @JsonProperty("related-to") - @com.fasterxml.jackson.annotation.JsonProperty("related-to") public List relatedTo = null; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); + + @JsonProperty("id") + public void setJsonId(String id) { + this.id = id; + } + + @JsonProperty("node-type") + public void setJsonNodeType(String nodeType) { + this.nodeType = nodeType; + } + + @JsonProperty("url") + public void setJsonUrl(String url) { + this.url = url; + } + + @JsonProperty("properties") + public void setJsonProperties(ServiceProperties properties) { + this.properties = properties; + } + + @JsonProperty("related-to") + public void setJsonRelatedTo(List relatedTo) { + this.relatedTo = relatedTo; + } @JsonAnyGetter public Map getAdditionalProperties() { @@ -40,7 +60,7 @@ public class VnfResult { } @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { + public void setJsonAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/interfaces/AaiModelWithRelationships.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/interfaces/AaiModelWithRelationships.java new file mode 100644 index 000000000..77fe4ceac --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/interfaces/AaiModelWithRelationships.java @@ -0,0 +1,7 @@ +package org.onap.vid.aai.model.interfaces; + +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList; + +public interface AaiModelWithRelationships { + RelationshipList getRelationshipList(); +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java index f5625ce21..f4401ab3a 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java @@ -22,12 +22,14 @@ package org.onap.vid.aai.util; import com.att.eelf.configuration.EELFLogger; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.aai.ResponseWithRequestInfo; import org.onap.vid.aai.exceptions.InvalidPropertyException; import org.onap.vid.utils.Logging; +import org.onap.vid.utils.Unchecked; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; @@ -37,6 +39,7 @@ import javax.ws.rs.client.Invocation; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.UnsupportedEncodingException; +import java.net.URI; import java.net.URLEncoder; import java.util.Optional; import java.util.UUID; @@ -55,7 +58,6 @@ public class AAIRestInterface { protected final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("aai"); - /** The client. */ private Client client = null; @@ -105,9 +107,9 @@ public class AAIRestInterface { return URLEncoder.encode(nodeKey, "UTF-8").replaceAll("\\+", "%20"); } - private void initRestClient() { - initRestClient(false); - } + protected void initRestClient() { + initRestClient(false); + } private void initRestClient(boolean propagateExceptions) { @@ -160,47 +162,61 @@ public class AAIRestInterface { * @param xml the xml * @return the string */ - public ResponseWithRequestInfo RestGet(String fromAppId, String transId, String requestUri, boolean xml) { + public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml) { return RestGet(fromAppId, transId, requestUri, xml, false); } - public ResponseWithRequestInfo RestGet(String fromAppId, String transId, String requestUri, boolean xml, boolean propagateExceptions) { - String methodName = "RestGet"; - String url = systemPropertyHelper.getFullServicePath(requestUri); + public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml, boolean propagateExceptions) { + return doRest(fromAppId, transId, requestUri, null, HttpMethod.GET, xml, propagateExceptions); + } + + public ResponseWithRequestInfo doRest(String fromAppId, String transId, URI requestUri, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) { + String url = null; + String methodName = "Rest"+method.name(); try { + + url = systemPropertyHelper.getFullServicePath(requestUri); + initRestClient(propagateExceptions); logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING); logger.debug(EELFLoggerDelegate.debugLogger, url + " for the get REST API"); - Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); + Logging.logRequest(outgoingRequestsLogger, method, url, payload); final Response response; - Invocation.Builder requestBuilder = client.target(url) - .request() - .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) - .header(TRANSACTION_ID_HEADER, transId) - .header(FROM_APP_ID_HEADER, fromAppId) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId()); - response = systemPropertyHelper.isClientCertEnabled() ? - requestBuilder.get() : authenticateRequest(requestBuilder).get(); - Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response); - - if (response.getStatusInfo().equals(Response.Status.OK)) { + Invocation.Builder requestBuilder = client.target(url) + .request() + .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) + .header(TRANSACTION_ID_HEADER, transId) + .header(FROM_APP_ID_HEADER, fromAppId) + .header("Content-Type", MediaType.APPLICATION_JSON) + .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId()); + + requestBuilder = systemPropertyHelper.isClientCertEnabled() ? + requestBuilder : authenticateRequest(requestBuilder); + + Invocation restInvocation = StringUtils.isEmpty(payload) ? + requestBuilder.build(method.name()) : + requestBuilder.build(method.name(), Entity.entity(payload, MediaType.APPLICATION_JSON)); + + response = restInvocation.invoke(); + Logging.logResponse(outgoingRequestsLogger, method, url, response); + + if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { logger.debug(EELFLoggerDelegate.debugLogger, methodName + SUCCESSFUL_API_MESSAGE); logger.info(EELFLoggerDelegate.errorLogger, methodName + SUCCESSFUL_API_MESSAGE); } else { logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response)); } - return new ResponseWithRequestInfo(response, url, HttpMethod.GET); + return new ResponseWithRequestInfo(response, url, method); } catch (Exception e) { logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e)); if (propagateExceptions) { - throw new ExceptionWithRequestInfo(HttpMethod.GET, defaultIfNull(url, requestUri), e); - } else { - return new ResponseWithRequestInfo(null, url, HttpMethod.GET); - } + throw new ExceptionWithRequestInfo(method, defaultIfNull(url, requestUri.toASCIIString()), e); + } else { + return new ResponseWithRequestInfo(null, url, method); + } } } @@ -222,7 +238,7 @@ public class AAIRestInterface { transId += ":" + UUID.randomUUID().toString(); logger.debug(methodName + START_STRING); Boolean response = false; - String url = systemPropertyHelper.getFullServicePath(path);; + String url = systemPropertyHelper.getFullServicePath(path); try { initRestClient(); @@ -263,37 +279,11 @@ public class AAIRestInterface { * @param path the path * @param payload the payload * @param xml the xml + * @param propagateExceptions * @return the string */ - public Response RestPut(String fromAppId, String path, String payload, boolean xml) { - String methodName = "RestPut"; - String url=systemPropertyHelper.getFullServicePath(path); - String transId = UUID.randomUUID().toString(); - logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING); - - Response response = null; - try { - initRestClient(); - Logging.logRequest(outgoingRequestsLogger, HttpMethod.PUT, url, payload); - response = authenticateRequest(client.target(url) - .request() - .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) - .header(TRANSACTION_ID_HEADER, transId) - .header(FROM_APP_ID_HEADER, fromAppId)) - .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId()) - .put(Entity.entity(payload, MediaType.APPLICATION_JSON)); - Logging.logResponse(outgoingRequestsLogger, HttpMethod.PUT, url, response); - - if (response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) { - logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName)); - logger.debug(EELFLoggerDelegate.debugLogger, getValidResponseLogMessage(methodName)); - } else { - logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response)); - } - } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e)); - } - return response; + public ResponseWithRequestInfo RestPut(String fromAppId, String path, String payload, boolean xml, boolean propagateExceptions) { + return doRest(fromAppId, UUID.randomUUID().toString(), Unchecked.toURI(path), payload, HttpMethod.PUT, xml, propagateExceptions); } @@ -313,13 +303,13 @@ public class AAIRestInterface { String transId = UUID.randomUUID().toString(); logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING); - Response response = null; + Response response = null; try { initRestClient(); Logging.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload); - response = authenticateRequest(client.target(systemPropertyHelper.getServiceBasePath(path)) + response = authenticateRequest(client.target(url) .request() - .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) + .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) .header(TRANSACTION_ID_HEADER, transId) .header(FROM_APP_ID_HEADER, fromAppId)) .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId()) diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java new file mode 100644 index 000000000..8fa6f6c6d --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java @@ -0,0 +1,89 @@ +package org.onap.vid.aai.util; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vid.model.aaiTree.*; +import org.onap.vid.mso.model.ModelInfo; +import org.onap.vid.services.AAITreeNodeBuilder; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +import static java.util.function.Function.identity; +import static java.util.stream.Collectors.counting; +import static java.util.stream.Collectors.groupingBy; +import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.A_LA_CARTE; + +@Component +public class AAITreeConverter { + + public static final String VNF_TYPE = "vnf-type"; + public static final String NETWORK_TYPE = "network-type"; + + public static final String IS_BASE_VF_MODULE = "is-base-vf-module"; + + public enum ModelType { + service, + vnf, + network, + instanceGroup, + vfModule + } + + public ServiceInstance convertTreeToUIModel(AAITreeNode rootNode, String globalCustomerId, String serviceType, String instantiationType) { + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setInstanceId(rootNode.getId()); + serviceInstance.setInstanceName(rootNode.getName()); + serviceInstance.setOrchStatus(rootNode.getOrchestrationStatus()); + serviceInstance.setGlobalSubscriberId(globalCustomerId); + serviceInstance.setSubscriptionServiceType(serviceType); + serviceInstance.setIsALaCarte(StringUtils.equals(instantiationType, A_LA_CARTE)); + + serviceInstance.setModelInfo(createModelInfo(rootNode, ModelType.service)); + + //set children: vnf, network,group + rootNode.getChildren().forEach(child -> { + if (child.getType().equals(AAITreeNodeBuilder.GENERIC_VNF)) { + serviceInstance.getVnfs().put(child.getUniqueNodeKey(), Vnf.from(child)); + } else if (child.getType().equals(AAITreeNodeBuilder.NETWORK)) { + serviceInstance.getNetworks().put(child.getUniqueNodeKey(), Network.from(child)); + } else if (child.getType().equals(AAITreeNodeBuilder.INSTANCE_GROUP)) { + serviceInstance.getVnfGroups().put(child.getUniqueNodeKey(), VnfGroup.from(child)); + } + }); + + serviceInstance.setExistingVNFCounterMap( + serviceInstance.getVnfs().entrySet().stream() + .map(k -> k.getValue().getModelInfo().getModelVersionId()) + .collect(groupingBy(identity(), counting())) + ); + + serviceInstance.setExistingNetworksCounterMap( + serviceInstance.getNetworks().entrySet().stream() + .map(k -> k.getValue().getModelInfo().getModelVersionId()) + .filter(Objects::nonNull) + .collect(groupingBy(identity(), counting())) + ); + + + serviceInstance.setExistingVnfGroupCounterMap( + serviceInstance.getVnfGroups().entrySet().stream() + .map(k -> k.getValue().getModelInfo().getModelVersionId()) + .filter(Objects::nonNull) + .collect(groupingBy(identity(), counting())) + ); + + return serviceInstance; + } + + private static ModelInfo createModelInfo(AAITreeNode aaiNode, ModelType modelType) { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelType(modelType.name()); + modelInfo.setModelName(aaiNode.getModelName()); + modelInfo.setModelVersion(aaiNode.getModelVersion()); + modelInfo.setModelVersionId(aaiNode.getModelVersionId()); + modelInfo.setModelInvariantId(aaiNode.getModelInvariantId()); + modelInfo.setModelCustomizationId(aaiNode.getModelCustomizationId()); + + return modelInfo; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheConfig.kt b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheConfig.kt new file mode 100644 index 000000000..0ff604144 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheConfig.kt @@ -0,0 +1,52 @@ +package org.onap.vid.aai.util + +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.KotlinModule +import com.google.common.collect.ImmutableMap +import org.springframework.stereotype.Component + +//I use a regular kotlin class because I want that when jackson read +//a json with null values (or missing fields) they would get default values. +//for other cases it's better to use data class for POJO class +//for more information you can read here : +//https://github.com/FasterXML/jackson-module-kotlin/issues/130 +class CacheConfig constructor( + isActive: Boolean?, + expireAfterWriteHours: Long?, + refreshAfterWriteSeconds: Long?) { + val isActive: Boolean = isActive ?: true + val expireAfterWriteHours: Long = expireAfterWriteHours ?: 24L + val refreshAfterWriteSeconds: Long = refreshAfterWriteSeconds ?: 10L + + companion object { + val defaultCacheConfig = CacheConfig(null, null, null) + } + +} + + +interface CacheConfigProvider { + fun getCacheConfig(cacheName:String): CacheConfig +} + +@Component +class CacheConfigProviderImpl() : CacheConfigProvider { + private val mapper = ObjectMapper().apply { registerModule(KotlinModule()) } + + private fun readMapOfCacheConfig(): Map { + val configInputStream = CacheConfigProviderImpl::class.java.classLoader.getResourceAsStream("cacheConfig.json") + + return if (configInputStream == null) { + ImmutableMap.of() + } else { + mapper.readValue(configInputStream, object : TypeReference>() {}) + } + } + + override fun getCacheConfig(cacheName: String): CacheConfig { + return readMapOfCacheConfig()[cacheName] ?: CacheConfig.defaultCacheConfig + } +} + + diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProvider.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProvider.java new file mode 100644 index 000000000..63615f492 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProvider.java @@ -0,0 +1,37 @@ +package org.onap.vid.aai.util; + +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; + +public interface CacheProvider { + String KEY_DELIMITER = "!@#'"; + /* + Returns the cache associated with given name; creates one if wasn't any + */ + Cache aaiClientCacheFor(String name, Function loader); + + /* + reset cache if exist. Otherwise do nothing + */ + void resetCache(String name); + + interface Cache { + V get(K key); + } + + static String compileKey(List args) { + return compileKey(args.toArray(new String[0])); + } + + static String compileKey(String... args) { + return Stream.of(args).map(arg->defaultIfNull(arg, "")).collect( Collectors.joining( KEY_DELIMITER ) ); + } + + static String[] decompileKey(String key) { + return key.split(KEY_DELIMITER); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProviderWithLoadingCache.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProviderWithLoadingCache.java new file mode 100644 index 000000000..26a3ebf25 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProviderWithLoadingCache.java @@ -0,0 +1,100 @@ +package org.onap.vid.aai.util; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.UncheckedExecutionException; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.jetbrains.annotations.NotNull; +import org.onap.vid.properties.Features; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.togglz.core.manager.FeatureManager; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; + +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; + +@Component +public class CacheProviderWithLoadingCache implements CacheProvider { + + private final ExecutorService cacheReloadPool; + private final FeatureManager featureManager; + private final CacheConfigProvider cacheConfigProvider; + private final ConcurrentHashMap caches; + + + @Autowired + public CacheProviderWithLoadingCache(FeatureManager featureManager, CacheConfigProvider cacheConfigProvider) { + this.featureManager = featureManager; + this.cacheConfigProvider = cacheConfigProvider; + this.cacheReloadPool = Executors.newFixedThreadPool(3); + this.caches = new ConcurrentHashMap<>(); + } + + /* + Returns the cache associated with given name; creates one if wasn't any + */ + @Override + public Cache aaiClientCacheFor(String name, Function loader) { + return (Cache) caches.computeIfAbsent(name, s -> buildAaiClientCacheFrom(loader, name)); + } + + @Override + public void resetCache(String name) { + caches.remove(name); + } + + /* + Creates and returns a Cache that use provided `loader` to fetch values for + search keys, and stores the result for reuse over a certain time. + The cache will not use any stored key if FLAG_1810_AAI_LOCAL_CACHE is turned off. + In that case, `loader` will be invoked for any `get()` request from the cache. The + cache adheres the flag in real-time; so no restart is required. + */ + protected Cache buildAaiClientCacheFrom(Function loader, String name) { + final LoadingCache activeCache = buildAaiClientActiveCacheFrom(loader, name); + + // this works because Cache interface has only a single method: "get()" + // can be replaced with new anonimous class; e.g.: + // return new Cache() { ... } + return key -> { + if (featureManager.isActive(Features.FLAG_1810_AAI_LOCAL_CACHE) && + defaultIfNull(cacheConfigProvider.getCacheConfig(name).isActive(), true)) { + try { + return activeCache.getUnchecked(key); + } + catch (UncheckedExecutionException exception) { + return ExceptionUtils.rethrow(exception.getCause()); + } + } else { + activeCache.invalidateAll(); + activeCache.cleanUp(); + return loader.apply(key); + } + }; + } + + private LoadingCache buildAaiClientActiveCacheFrom(Function loader, String name) { + return createCacheBuilder(name).build(createAsyncReloadingCacheLoaderFrom(loader)); + + } + + @NotNull + protected CacheBuilder createCacheBuilder(String name) { + CacheConfig cacheConfig = cacheConfigProvider.getCacheConfig(name); + return CacheBuilder.newBuilder() + .maximumSize(1000) + .expireAfterWrite(cacheConfig.getExpireAfterWriteHours(), TimeUnit.HOURS) + .refreshAfterWrite(cacheConfig.getRefreshAfterWriteSeconds(), TimeUnit.SECONDS); + } + + private CacheLoader createAsyncReloadingCacheLoaderFrom(Function loader) { + return CacheLoader.asyncReloading(CacheLoader.from(loader::apply), cacheReloadPool); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java index 15f81439b..489d2f1b6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java @@ -22,11 +22,16 @@ package org.onap.vid.aai.util; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.HttpUrlConnectorProvider; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.aai.exceptions.HttpClientBuilderException; +import org.onap.vid.properties.Features; +import org.togglz.core.manager.FeatureManager; +import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -47,16 +52,19 @@ public class HttpsAuthClient { private final SystemPropertyHelper systemPropertyHelper; private final SSLContextProvider sslContextProvider; - public HttpsAuthClient(String certFilePath, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider) { + public HttpsAuthClient(String certFilePath, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider, FeatureManager featureManager) { this.certFilePath = certFilePath; this.systemPropertyHelper = systemPropertyHelper; this.sslContextProvider = sslContextProvider; + this.featureManager = featureManager; } private final String certFilePath; + FeatureManager featureManager; + /** The logger. */ - static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsAuthClient.class); + static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(org.onap.vid.aai.util.HttpsAuthClient.class); /** @@ -70,7 +78,7 @@ public class HttpsAuthClient { try { setSystemProperties(); - ignoreHostname(); + optionallyVerifyHostname(); return systemPropertyHelper.isClientCertEnabled() ? getTrustedClient(config, getKeystorePath(), systemPropertyHelper.getDecryptedKeystorePassword(), mode) @@ -83,8 +91,8 @@ public class HttpsAuthClient { } - private void ignoreHostname() { - HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true); + private void optionallyVerifyHostname() { + HttpsURLConnection.setDefaultHostnameVerifier(getHostnameVerifier()); } private Client getUntrustedClient(ClientConfig config) { @@ -94,12 +102,20 @@ public class HttpsAuthClient { private Client getTrustedClient(ClientConfig config, String keystorePath, String keystorePassword, HttpClientMode httpClientMode) throws HttpClientBuilderException { return ClientBuilder.newBuilder() .sslContext(sslContextProvider.getSslContext(keystorePath, keystorePassword, httpClientMode)) - .hostnameVerifier((s, sslSession) -> true) + .hostnameVerifier(getHostnameVerifier()) .withConfig(config) .build() .register(CustomJacksonJaxBJsonProvider.class); } + protected HostnameVerifier getHostnameVerifier() { + if(featureManager.isActive(Features.FLAG_EXP_USE_DEFAULT_HOST_NAME_VERIFIER)){ + return new DefaultHostnameVerifier(); + } + + return new NoopHostnameVerifier(); + } + private String getKeystorePath() { return getCertificatesPath() + FileSystems.getDefault().getSeparator() + systemPropertyHelper.getAAIKeystoreFilename(); } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java deleted file mode 100644 index d1f1cfc86..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.aai.util; - -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContextBuilder; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.eclipse.jetty.util.security.Password; -import org.onap.vid.exceptions.GenericUncheckedException; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; - -import javax.net.ssl.SSLContext; -import java.io.FileInputStream; -import java.security.GeneralSecurityException; -import java.security.KeyManagementException; -import java.security.KeyStore; - - -/** - * The Class HttpsComponentsClient. - */ -public class HttpsComponentsClient{ - - static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsComponentsClient.class); - - /** - * Gets the client. - * - * @param certFilePath the cert file path - * @return the client - * @throws KeyManagementException the key management exception - */ - public static CloseableHttpClient getClient(String certFilePath) { - CloseableHttpClient httpclient = null; - try { - - String truststore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_TRUSTSTORE_FILENAME); - String truststore_password = SystemProperties.getProperty(AAIProperties.AAI_TRUSTSTORE_PASSWD_X); - String decrypted_truststore_password = Password.deobfuscate(truststore_password); - String keystore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_FILENAME); - String keystore_password = SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_PASSWD_X); - String decrypted_keystore_password = Password.deobfuscate(keystore_password); - - SSLContextBuilder sslContextB = new SSLContextBuilder(); - - KeyStore ks = KeyStore.getInstance("PKCS12"); - char[] pwd = decrypted_keystore_password.toCharArray(); - - try(FileInputStream fin = new FileInputStream(keystore_path)) { - ks.load(fin, pwd); - } - catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up keystore"); - logger.error(EELFLoggerDelegate.errorLogger, "Error loading keystore materials: (keystore path: {}, obfuascated keystore password: {})", keystore_path, keystore_password); - throw new GenericUncheckedException(e); - } - - sslContextB.loadKeyMaterial(ks, pwd); - - KeyStore ts = KeyStore.getInstance("JKS"); - char[] pwd1 = decrypted_truststore_password.toCharArray(); - - try(FileInputStream fin1 = new FileInputStream(truststore_path)) { - ts.load(fin1, pwd1); - } - catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up truststore"); - logger.error(EELFLoggerDelegate.errorLogger, "Error loading truststore materials: (truststore path: {}, obfuascated truststore password: {})", truststore_path, truststore_password); - throw new GenericUncheckedException(e); - } - - sslContextB.loadTrustMaterial(ts); - sslContextB.loadKeyMaterial(ks, pwd); - sslContextB.useTLS(); - - SSLContext sslcontext = sslContextB.build(); - - SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory( - sslcontext, - new String[] { "TLSv1.1", "TLSv1.2" }, - null, - SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER ); - - httpclient = HttpClients.custom() - .setSSLSocketFactory(sslFactory) - .build(); - - - } catch (GeneralSecurityException e) { - throw new GenericUncheckedException(e); - } - return httpclient; - } - - - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java index cfc56d187..b39c20315 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java @@ -48,8 +48,8 @@ public class JettyObfuscationConversionCommandLineUtil { System.out.println(encoded); } else if (cmd.hasOption("d")) { toProcess = cmd.getOptionValue("d"); - String decoded_str = Password.deobfuscate(toProcess); - System.out.println(decoded_str); + String decodedStr = Password.deobfuscate(toProcess); + System.out.println(decodedStr); } else { usage(); } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/ServiceInstanceStandardQuery.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/ServiceInstanceStandardQuery.java new file mode 100644 index 000000000..22743bbf9 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/ServiceInstanceStandardQuery.java @@ -0,0 +1,93 @@ +package org.onap.vid.aai.util; + +import com.google.common.collect.ImmutableMap; +import org.apache.commons.text.StrSubstitutor; +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.*; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; +import org.onap.vid.utils.Multival; +import org.onap.vid.utils.Unchecked; + +import javax.inject.Inject; +import java.net.URI; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toSet; + +public class ServiceInstanceStandardQuery { + + private static final String SERVICE_INSTANCE_URI_TEMPLATE = "" + + "business/customers/customer/${global-customer-id}" + + "/service-subscriptions/service-subscription/${service-type}" + + "/service-instances/service-instance/${service-instance-id}"; + + private final AaiClientInterface aaiClient; + + @Inject + public ServiceInstanceStandardQuery(AaiClientInterface aaiClient) { + this.aaiClient = aaiClient; + } + + public ServiceInstance fetchServiceInstance(String globalCustomerId, String serviceType, String serviceInstanceId) { + final String serviceInstanceUri = getServiceInstanceUri(globalCustomerId, serviceType, serviceInstanceId); + + return fetchServiceInstance(Unchecked.toURI(serviceInstanceUri)); + } + + ServiceInstance fetchServiceInstance(URI serviceInstanceUri) { + return objectByUri(ServiceInstance.class, serviceInstanceUri); + } + + protected T objectByUri(Class clazz, URI aaiResourceUri) { + return aaiClient.typedAaiGet(aaiResourceUri, clazz); + } + + public Multival fetchRelatedVnfs(ServiceInstance serviceInstance) { + return fetchRelated("service", serviceInstance, "generic-vnf", Vnf.class); + } + + public Multival fetchRelatedL3Networks(String sourceType, K source) { + return fetchRelated(sourceType, source, "l3-network", Network.class); + } + + public Multival fetchRelatedVlanTags(Network network) { + return fetchRelated("network", network, "vlan-tag", Vlan.class); + } + + private String getServiceInstanceUri(String globalCustomerId, String serviceType, String serviceInstanceId) { + return new StrSubstitutor(ImmutableMap.of( + "global-customer-id", globalCustomerId, + "service-type", serviceType, + "service-instance-id", serviceInstanceId + )).replace(SERVICE_INSTANCE_URI_TEMPLATE); + } + + private Multival fetchRelated(String sourceType, K source, String destType, Class destClass) { + return Multival.of( + sourceType, + source, + destType, + fetchRelatedInner(source, destType, destClass) + ); + } + + private Set fetchRelatedInner(K source, String destType, Class destClass) { + return getURIsOf(source, relationship -> relatedTo(relationship, destType)) + .map(destUri -> objectByUri(destClass, destUri)) + .collect(toSet()); + } + + protected Stream getURIsOf(AaiModelWithRelationships aaiModel, Predicate predicate) { + return aaiModel.getRelationshipList().getRelationship().stream() + .filter(predicate) + .map(r -> r.relatedLink) + .map(Unchecked::toURI); + } + + protected static boolean relatedTo(Relationship r, String relationshipName) { + return relationshipName.equals(r.getRelatedTo()); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/SystemPropertyHelper.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/SystemPropertyHelper.java index 4d43d3ba2..939bfe5b6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/util/SystemPropertyHelper.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/SystemPropertyHelper.java @@ -23,8 +23,10 @@ package org.onap.vid.aai.util; import org.eclipse.jetty.util.security.Password; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.aai.exceptions.InvalidPropertyException; +import org.onap.vid.utils.Unchecked; import java.io.UnsupportedEncodingException; +import java.net.URI; import java.util.Base64; import java.util.Optional; @@ -74,6 +76,15 @@ public class SystemPropertyHelper { return getAAIServerUrl().orElse("") + path; } + public String getFullServicePath(URI requestUri) { + // resolve() will merge two paths, handling the restiveness: + // Especially if requestUri starts with a '/' -- result will be + // AAI_SERVER_URL host, post, etc., and the path will be just + // requestUri. + return Unchecked.toURI(getAAIServerUrl().orElse("")) + .resolve(requestUri).toASCIIString(); + } + public String getServiceBasePath(String path) { return getAAIServerBaseUrl().orElse("") + path; } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java index fdbf2c288..d26a1b278 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/AsdcClient.java @@ -50,4 +50,5 @@ public interface AsdcClient { * @throws AsdcCatalogException the asdc catalog exception */ Path getServiceToscaModel(UUID uuid) throws AsdcCatalogException; + } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/SecureServices.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/SecureServices.java index a6aa3de6f..6eaf37b9d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/SecureServices.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/SecureServices.java @@ -1,7 +1,6 @@ package org.onap.vid.asdc.beans; import java.util.Collection; -import java.util.List; /** * Created by Oren on 6/27/17. diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Input.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Input.java index 590284928..d66591c3b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Input.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Input.java @@ -20,10 +20,11 @@ package org.onap.vid.asdc.beans.tosca; +import com.fasterxml.jackson.annotation.JsonInclude; import org.onap.sdc.toscaparser.api.Property; -import java.util.List; import java.util.ArrayList; +import java.util.List; // TODO: Auto-generated Javadoc /** @@ -36,6 +37,7 @@ public class Input { this.description = input.getDescription(); this._default = input.getDefault(); this.inputProperties = new InputProperties(properties); + this.fromInputName = input.getName(); } /** The type. */ @@ -51,7 +53,9 @@ public class Input { private Input entry_schema; private InputProperties inputProperties; - + + private String fromInputName; + /** The constraints */ private List constraints; @@ -63,12 +67,12 @@ public class Input { private String templateUUID; private String templateInvariantUUID; private String templateCustomizationUUID; - + /** * Instantiates a new input. */ public Input() { - constraints = new ArrayList(); + constraints = new ArrayList<>(); } /** @@ -160,6 +164,11 @@ public class Input { return inputProperties; } + @JsonInclude(JsonInclude.Include.NON_NULL) + public String getFromInputName() { + return fromInputName; + } + public void setInputProperties(InputProperties inputProperties) { this.inputProperties = inputProperties; } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/InputProperties.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/InputProperties.java index bc2513ea9..c5fe8b90e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/InputProperties.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/InputProperties.java @@ -17,13 +17,10 @@ public class InputProperties { for(Property property: properties) { if (property.getName().equals("source_type")) { this.sourceType = (String)property.getValue(); - continue; } else if (property.getName().equals("param_name")) { this.paramName = (String)property.getValue(); - continue; } else if (property.getName().equals("vf_module_label")) { this.vfModuleLabel = getPropertyValueAsString(property); - continue; } } } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/NodeTemplate.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/NodeTemplate.java index 28210b2ec..23c0a1094 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/NodeTemplate.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/NodeTemplate.java @@ -20,8 +20,8 @@ package org.onap.vid.asdc.beans.tosca; -import java.util.Map; import java.util.HashMap; +import java.util.Map; /** * The Class NodeTemplate. @@ -41,7 +41,7 @@ public class NodeTemplate { private Object requirements; public NodeTemplate () { - properties = new HashMap(); + properties = new HashMap<>(); } /** * Gets the type. diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Property.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Property.java index 74b00bdf7..a15c55ff5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Property.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/Property.java @@ -43,7 +43,7 @@ public class Property { /** * Instantiates a new property. */ - Property() {} + private Property() {} /** * Gets the type. diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/SubstitutionMappings.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/SubstitutionMappings.java index 70779c5f2..4ce30239c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/SubstitutionMappings.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/SubstitutionMappings.java @@ -41,8 +41,8 @@ public class SubstitutionMappings { * Instantiates a new substitution mappings. */ public SubstitutionMappings() { - capabilities = new HashMap (); - requirements = new HashMap (); + capabilities = new HashMap<> (); + requirements = new HashMap<> (); } /** diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/TopologyTemplate.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/TopologyTemplate.java index 70830715e..b24627d1f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/TopologyTemplate.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/TopologyTemplate.java @@ -45,9 +45,9 @@ public class TopologyTemplate { */ public TopologyTemplate() { substitution_mappings = new SubstitutionMappings(); - inputs = new HashMap (); - node_templates = new HashMap (); - groups = new HashMap (); + inputs = new HashMap<> (); + node_templates = new HashMap<> (); + groups = new HashMap<> (); } /** diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/ToscaCsar.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/ToscaCsar.java index 678583573..4cf2f7975 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/ToscaCsar.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/ToscaCsar.java @@ -43,7 +43,7 @@ public class ToscaCsar { private final ToscaModel parent; /** The children. */ - private Collection children = new LinkedList (); + private Collection children = new LinkedList<> (); /** * Instantiates a new builder. diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/ToscaMeta.java b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/ToscaMeta.java index a7a6c6296..ad8834015 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/ToscaMeta.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/beans/tosca/ToscaMeta.java @@ -20,6 +20,8 @@ package org.onap.vid.asdc.beans.tosca; +import org.onap.vid.asdc.AsdcCatalogException; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -27,8 +29,6 @@ import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; -import org.onap.vid.asdc.AsdcCatalogException; - /** * The Class ToscaMeta. */ @@ -45,7 +45,7 @@ public class ToscaMeta { * @throws AsdcCatalogException the asdc catalog exception */ private ToscaMeta(Builder builder) throws IOException, AsdcCatalogException { - metadata = new HashMap (); + metadata = new HashMap<> (); read(builder.inputStream); } @@ -113,10 +113,7 @@ public class ToscaMeta { metadata.put(entry[0], entry[1].substring(1)); } } - } catch (IOException e) { - metadata.clear(); - throw e; - } catch (AsdcCatalogException e) { + } catch (IOException | AsdcCatalogException e) { metadata.clear(); throw e; } diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java index 108d9c06a..bcb201d2e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java @@ -1,31 +1,22 @@ package org.onap.vid.asdc.local; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.json.JSONArray; import org.json.JSONObject; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.asdc.AsdcClient; import org.onap.vid.asdc.beans.Service; -import org.onap.vid.asdc.beans.tosca.ToscaCsar; -import org.onap.vid.asdc.beans.tosca.ToscaMeta; -import org.onap.vid.asdc.beans.tosca.ToscaModel; import org.onap.vid.exceptions.GenericUncheckedException; -import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.Map; import java.util.UUID; -import java.util.zip.ZipFile; /** * The Class LocalAsdcClient. @@ -117,7 +108,7 @@ public class LocalAsdcClient implements AsdcClient { /* (non-Javadoc) * @see org.onap.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) */ - public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException { + public Path getServiceToscaModel(UUID serviceUuid) { String toscaModelURL = null; @@ -145,49 +136,6 @@ public class LocalAsdcClient implements AsdcClient { } } - /** - * Gets the tosca model. - * - * @param csarInputStream the csar input stream - * @return the tosca model - * @throws AsdcCatalogException the asdc catalog exception - */ - private ToscaCsar getToscaModel(InputStream csarInputStream) throws AsdcCatalogException { - final Path csarFile; - - try { - csarFile = Files.createTempFile("csar", ".zip"); - Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new AsdcCatalogException("Caught IOException while creating CSAR", e); - } - - try (final ZipFile csar = new ZipFile(csarFile.toFile())) { - - final InputStream toscaMetaStream = csar.getInputStream(csar.getEntry("TOSCA-Metadata/TOSCA.meta")); - final ToscaMeta toscaMeta = new ToscaMeta.Builder(toscaMetaStream).build(); - final String entryDefinitions = toscaMeta.get("Entry-Definitions"); - final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions)); - - final Yaml yaml = new Yaml(); - final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class); - - final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel); - - for (Map> imports : parentModel.getImports()) { - for (Map.Entry> entry : imports.entrySet()) { - final InputStream toscaChildEntryYamlStream = csar.getInputStream(csar.getEntry("Definitions/" + entry.getValue().get("file"))); - final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); - csarBuilder.addVnf(childModel); - } - } - - return csarBuilder.build(); - } catch (IOException e) { - throw new AsdcCatalogException("Caught IOException while processing CSAR", e); - } - } - /** * The Class Builder. */ diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt new file mode 100644 index 000000000..79ab0459a --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt @@ -0,0 +1,43 @@ +package org.onap.vid.asdc.parser + +import org.onap.vid.model.* +import org.springframework.stereotype.Component + +@Component +class ServiceModelInflator { + + data class Names (val modelCustomizationName: String?, val modelKey: String?) + + fun toNamesByVersionId(model: ServiceModel): Map { + return emptyMap() + .plus(inflate(model.networks)) + .plus(inflate(model.vnfs)) + .plus(inflate(model.vnfGroups)) + } + + private fun inflate(instances: Map): Map { + return instances.entries.map { inflate(it.key, it.value) }.fold(emptyMap()) { acc, it -> acc.plus(it) } + } + + private fun inflate(modelKey: String, vnf: VNF): Map { + return mapOf(vnf.uuid to Names(vnf.modelCustomizationName, modelKey)) + .plus(inflate(vnf.vfModules)) + .plus(inflate(vnf.volumeGroups)) + } + + private fun inflate(modelKey: String, instance: Any?): Map { + return when (instance) { + is Network -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey)) + is VfModule -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey)) + is VolumeGroup -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey)) + is ResourceGroup -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey)) + is VNF -> inflate(modelKey, instance) + + else -> { + // sink + emptyMap() + } + } + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaNamingPolicy.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaNamingPolicy.java new file mode 100644 index 000000000..ca2601034 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaNamingPolicy.java @@ -0,0 +1,28 @@ +package org.onap.vid.asdc.parser; + +import org.apache.commons.lang3.StringUtils; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Property; + +import java.util.Map; + +public class ToscaNamingPolicy { + + public static String isUserProvidingServiceNameOptional(ISdcCsarHelper csarHelper){ + return csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.ECOMP_GENERATED_NAMING); + } + + private static Object isPropertyContainsEcompGeneratedNaming(Property property) { + return ((Map) (property.getValue())).get(ToscaParserImpl2.Constants.ECOMP_GENERATED_NAMING_PROPERTY); + } + + public static String getEcompNamingValueForNode(NodeTemplate node, String parentProperty) { + return node.getPropertiesObjects().stream() + .filter(property -> StringUtils.equals(property.getName(), parentProperty)) + .findFirst() + .map(ToscaNamingPolicy::isPropertyContainsEcompGeneratedNaming) + .map(Object::toString) + .orElse("false"); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java index 27445c0f3..ef57ccb65 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java @@ -16,6 +16,7 @@ import org.yaml.snakeyaml.error.YAMLException; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -92,7 +93,7 @@ public class ToscaParserImpl implements ToscaParser { final ToscaModel asdcServiceToscaModel = toscaCsar.getParent(); serviceModel.setService(ServiceModel.extractService(asdcServiceToscaModel, service)); - + serviceModel.setFabricConfigurations(Collections.emptyMap()); populateVnfsAndNetwork(methodName, isNewFlow, vnfs, networks, asdcServiceToscaModel, serviceModel); @@ -180,8 +181,6 @@ public class ToscaParserImpl implements ToscaParser { } private ServiceModel getCustomizedServices(ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) { - String methodName = "asdcServiceToscaModel"; - // asdcServiceToscaModel should have vf modules and vol groups populated // at this point but // they are not associated with the VNFs diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java index 57d80ce9d..53ec4036b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java @@ -1,11 +1,12 @@ package org.onap.vid.asdc.parser; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.enums.FilterType; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.onap.sdc.tosca.parser.impl.FilterType; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.onap.sdc.tosca.parser.impl.SdcTypes; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.*; import org.onap.sdc.toscaparser.api.elements.Metadata; @@ -15,87 +16,112 @@ import org.onap.vid.model.*; import java.nio.file.Path; import java.util.*; -import java.util.stream.Collectors; +import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.VF_MODULE_LABEL; public class ToscaParserImpl2 { - - public class Constants { - public final static String UUID = "UUID"; - public final static String DESCRIPTION = "description"; - public final static String SERVICE_TYPE = "serviceType"; - public final static String SERVICE_ROLE = "serviceRole"; - public final static String ECOMP_GENERATED_NAMING = "ecompGeneratedNaming"; - - public final static String CUSTOMIZATION_UUID = "customizationUUID"; - public final static String VF_MODULE_MODEL_VERSION = "vfModuleModelVersion"; - public final static String VF_MODULE_MODEL_CUSTOMIZATION_UUID = "vfModuleModelCustomizationUUID"; - public final static String VOLUME_GROUP = "volume_group"; - public final static String VF_MODULE_MODEL_INVARIANT_UUID = "vfModuleModelInvariantUUID"; - public final static String VF_MODULE_MODEL_UUID = "vfModuleModelUUID"; - public final static String INVARIANT_UUID = "invariantUUID"; - public final static String VERSION = "version"; - public final static String NAME = "name"; - public final static String CATEGORY = "category"; - public final static String VF_MODULE_MODEL_NAME = "vfModuleModelName"; - public final static String GET_INPUT = "get_input"; - public final static String TYPE = "type"; - - public final static String INSTANTIATION_TYPE = "instantiationType"; + + private final VidNotionsBuilder vidNotionsBuilder; + + public class Constants { + public static final String UUID = "UUID"; + public static final String DESCRIPTION = "description"; + public static final String SERVICE_TYPE = "serviceType"; + public static final String SERVICE_ROLE = "serviceRole"; + public static final String ECOMP_GENERATED_NAMING = "ecompGeneratedNaming"; + + public static final String CUSTOMIZATION_UUID = "customizationUUID"; + public static final String VF_MODULE_MODEL_VERSION = "vfModuleModelVersion"; + public static final String VF_MODULE_MODEL_CUSTOMIZATION_UUID = "vfModuleModelCustomizationUUID"; + public static final String VOLUME_GROUP = "volume_group"; + public static final String VF_MODULE_MODEL_INVARIANT_UUID = "vfModuleModelInvariantUUID"; + public static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUID"; + public static final String INVARIANT_UUID = "invariantUUID"; + public static final String VERSION = "version"; + public static final String NAME = "name"; + public static final String CATEGORY = "category"; + public static final String VF_MODULE_MODEL_NAME = "vfModuleModelName"; + public static final String GET_INPUT = "get_input"; + public static final String TYPE = "type"; + + public static final String INSTANTIATION_TYPE = "instantiationType"; //instantiation type - public final static String BOTH = "Both"; - public final static String MACRO = "Macro"; - public final static String A_LA_CARTE = "A-La-Carte"; - public final static String CLIENT_CONFIG = "ClientConfig"; + public static final String BOTH = "Both"; + public static final String MACRO = "Macro"; + public static final String A_LA_CARTE = "A-La-Carte"; + public static final String CLIENT_CONFIG = "ClientConfig"; + + //service role + public static final String GROUPING = "GROUPING"; //group properties - public final static String MIN_VF_MODULE_INSTANCES = "min_vf_module_instances"; - public final static String MAX_VF_MODULE_INSTANCES = "max_vf_module_instances"; - public final static String INITIAL_COUNT = "initial_count"; - public final static String VF_MODULE_LABEL = "vf_module_label"; + public static final String MIN_VF_MODULE_INSTANCES = "min_vf_module_instances"; + public static final String MAX_VF_MODULE_INSTANCES = "max_vf_module_instances"; + public static final String INITIAL_COUNT = "initial_count"; + public static final String VF_MODULE_LABEL = "vf_module_label"; + public static final String VF_MODULE_TYPE = "vf_module_type"; //collection resource properties - public final static String SUBCATEGORY = "subcategory"; - public final static String RESOURCE_VENDOR = "resourceVendor"; - public final static String RESOURCE_VENDOR_RELEASE = "resourceVendorRelease"; - public final static String RESOURCE_VENDOR_MODEL_NUMBER = "resourceVendorModelNumber"; - public final static String ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION = "org.openecomp.groups.NetworkCollection"; - public final static String NETWORK_COLLECTION_FUNCTION = "network_collection_function"; - public final static String NETWORK_COLLECTION_DESCRIPTION = "network_collection_description"; + public static final String SUBCATEGORY = "subcategory"; + public static final String RESOURCE_VENDOR = "resourceVendor"; + public static final String RESOURCE_VENDOR_RELEASE = "resourceVendorRelease"; + public static final String RESOURCE_VENDOR_MODEL_NUMBER = "resourceVendorModelNumber"; + public static final String ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION = "org.openecomp.groups.NetworkCollection"; + public static final String NETWORK_COLLECTION_FUNCTION = "network_collection_function"; + public static final String NETWORK_COLLECTION_DESCRIPTION = "network_collection_description"; //vfc instance group properties - public final static String VFC_INSTANCE_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup"; - public final static String VFC_PARENT_PORT_ROLE = "vfc_parent_port_role"; - public final static String SUBINTERFACE_ROLE = "subinterface_role"; - public final static String VFC_INSTANCE_GROUP_FUNCTION = "vfc_instance_group_function"; + public static final String VFC_INSTANCE_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup"; + public static final String VFC_PARENT_PORT_ROLE = "vfc_parent_port_role"; + public static final String SUBINTERFACE_ROLE = "subinterface_role"; + public static final String VFC_INSTANCE_GROUP_FUNCTION = "vfc_instance_group_function"; + + public static final String FABRIC_CONFIGURATION_TYPE = "org.openecomp.nodes.FabricConfiguration"; + + public static final String RESOURCE_GROUP_TYPE = "org.openecomp.groups.ResourceInstanceGroup"; + public static final String RESOURCE_GROUP_CONTAINED_TYPE = "contained_resource_type"; + + public static final String VNF_GROUP = "VnfGroup"; + + public static final String NAMING_POLICY_TYPE = "org.openecomp.policies.External"; + + public static final String ECOMP_GENERATED_NAMING_PROPERTY = "ecomp_generated_naming"; } - - public ToscaParserImpl2() {} - public ServiceModel makeServiceModel(Path path, Service asdcServiceMetadata) throws SdcToscaParserException { + public ToscaParserImpl2(VidNotionsBuilder vidNotionsBuilder) { + this.vidNotionsBuilder = vidNotionsBuilder; + } + + public ServiceModel makeServiceModel(Path path, Service asdcServiceMetadata) throws SdcToscaParserException { ServiceModel serviceModel = new ServiceModel(); - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(),false); + ISdcCsarHelper sdcCsarHelper = getSdcCsarHelper(path); + List policiesTargets = extractNamingPoliciesTargets(sdcCsarHelper); serviceModel.setService(extractServiceFromCsar(asdcServiceMetadata, sdcCsarHelper)); serviceModel.setVolumeGroups(extractVolumeGroups(sdcCsarHelper)); serviceModel.setVfModules(extractVfModuleFromCsar(sdcCsarHelper)); - serviceModel.setVnfs(extractVnfsFromCsar(sdcCsarHelper)); - serviceModel.setConfigurations(extractPortMirroringConfigFromCsar(sdcCsarHelper)); - serviceModel.setServiceProxies(extractServiceProxyFromCsar(sdcCsarHelper)); - serviceModel.setNetworks(extractNetworksFromCsar(sdcCsarHelper)); - serviceModel.setPnfs(extractPnfsFromCsar(sdcCsarHelper)); - serviceModel.setCollectionResource(extractCRFromCsar(sdcCsarHelper)); + serviceModel.setVnfs(extractVnfsFromCsar(sdcCsarHelper, policiesTargets)); + serviceModel.setConfigurations(extractPortMirroringConfigFromCsar(sdcCsarHelper, policiesTargets)); + serviceModel.setServiceProxies(extractServiceProxyFromCsar(sdcCsarHelper, policiesTargets)); + serviceModel.setNetworks(extractNetworksFromCsar(sdcCsarHelper, policiesTargets)); + serviceModel.setPnfs(extractPnfsFromCsar(sdcCsarHelper, policiesTargets)); + serviceModel.setCollectionResource(extractCRFromCsar(sdcCsarHelper, policiesTargets)); + serviceModel.setFabricConfigurations(extractFabricConfigFromCsar(sdcCsarHelper, policiesTargets)); + serviceModel.setVnfGroups(extractVnfGroupsFromCsar(sdcCsarHelper, policiesTargets)); + serviceModel.getService().setVidNotions(vidNotionsBuilder.buildVidNotions(sdcCsarHelper, serviceModel)); return serviceModel; } + public ISdcCsarHelper getSdcCsarHelper(Path path) throws SdcToscaParserException { + SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); + return factory.getSdcCsarHelper(path.toFile().getAbsolutePath(), false); + } - - private org.onap.vid.model.Service extractServiceFromCsar(Service asdcServiceMetadata, ISdcCsarHelper csarHelper) throws SdcToscaParserException { - org.onap.vid.model.Service service = new org.onap.vid.model.Service(); + private org.onap.vid.model.Service extractServiceFromCsar(Service asdcServiceMetadata, ISdcCsarHelper csarHelper) { + org.onap.vid.model.Service service = new org.onap.vid.model.Service(); service.setName(csarHelper.getServiceMetadata().getValue(Constants.NAME)); service.setCategory(csarHelper.getServiceMetadata().getValue(Constants.CATEGORY)); @@ -104,21 +130,25 @@ public class ToscaParserImpl2 { service.setVersion(asdcServiceMetadata.getVersion()); service.setDescription(csarHelper.getServiceMetadata().getValue(Constants.DESCRIPTION)); service.setInputs(inputsListToInputsMap(csarHelper.getInputsWithAnnotations())); - service.setServiceEcompNaming(csarHelper.getServiceMetadata().getValue(Constants.ECOMP_GENERATED_NAMING)); + service.setServiceEcompNaming(isUserProvidingServiceNameOptional(csarHelper)); service.setServiceType(csarHelper.getServiceMetadata().getValue(Constants.SERVICE_TYPE)); service.setServiceRole(csarHelper.getServiceMetadata().getValue(Constants.SERVICE_ROLE)); service.setInstantiationType(validateInstantiationType(csarHelper)); return service; } - private Map extractCRFromCsar(ISdcCsarHelper sdcCsarHelper) { - List nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); - Map collectionResourceMap = new HashMap<>(); + private String isUserProvidingServiceNameOptional(ISdcCsarHelper csarHelper) { + return ToscaNamingPolicy.isUserProvidingServiceNameOptional(csarHelper); + } + + private Map extractCRFromCsar(ISdcCsarHelper sdcCsarHelper, List policiesTargets) { + List nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); + Map collectionResourceMap = new HashMap<>(); - for(NodeTemplate nodeTemplate: nodeTemplates){ - if(nodeTemplate.getMetaData().getValue(Constants.TYPE).equals(SdcTypes.CR.getValue())) { + for (NodeTemplate nodeTemplate : nodeTemplates) { + if ( nodeTemplate.getMetaData().getValue(Constants.TYPE).equals(SdcTypes.CR.getValue()) ) { CR cr = new CR(); - populateCrFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr); + populateCrFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr, policiesTargets); collectionResourceMap.put(nodeTemplate.getName(), cr); } } @@ -126,21 +156,39 @@ public class ToscaParserImpl2 { return collectionResourceMap; } - private void populateCrFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper sdcCsarHelper, CR cr) { - populateNodeFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr); + private Map extractFabricConfigFromCsar(ISdcCsarHelper sdcCsarHelper, List policiesTargets) { + List nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); + Map fabricConfiguration = new HashMap<>(); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + List nodeTemplateChildren = sdcCsarHelper.getNodeTemplateChildren(nodeTemplate); + for (NodeTemplate nodeTemplateChild : nodeTemplateChildren) { + if ( nodeTemplateChild.getType().equals(Constants.FABRIC_CONFIGURATION_TYPE) ) { + Node node = new Node(); + fabricConfiguration.put(nodeTemplateChild.getName(), populateNodeFromNodeTemplate(nodeTemplateChild, sdcCsarHelper, node, policiesTargets)); + } + } + + } + return fabricConfiguration; + } + + + private void populateCrFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper sdcCsarHelper, CR cr, List policiesTargets) { + populateNodeFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr, policiesTargets); cr.setCustomizationUUID(nodeTemplate.getMetaData().getValue(Constants.CUSTOMIZATION_UUID)); cr.setCategory(nodeTemplate.getMetaData().getValue(Constants.CATEGORY)); - cr.setSubcategory(nodeTemplate.getMetaData().getValue(Constants.SUBCATEGORY)); - cr.setResourceVendor(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR)); - cr.setResourceVendorRelease(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_RELEASE)); - cr.setResourceVendorModelNumber(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_MODEL_NUMBER)); - cr.setNetworksCollection(getNetworksCollectionMapFromGroupsList(sdcCsarHelper, nodeTemplate)); + cr.setSubcategory(nodeTemplate.getMetaData().getValue(Constants.SUBCATEGORY)); + cr.setResourceVendor(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR)); + cr.setResourceVendorRelease(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_RELEASE)); + cr.setResourceVendorModelNumber(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_MODEL_NUMBER)); + cr.setNetworksCollection(getNetworksCollectionMapFromGroupsList(sdcCsarHelper, nodeTemplate)); } private Map getNetworksCollectionMapFromGroupsList(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { List groups = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION); - Map networksCollectionMap = new HashMap(); - for(Group group: groups){ + Map networksCollectionMap = new HashMap<>(); + for (Group group : groups) { networksCollectionMap.put(group.getName(), populateCollectionNetworkFromGroup(group, nodeTemplate)); } return networksCollectionMap; @@ -161,44 +209,46 @@ public class ToscaParserImpl2 { LinkedHashMap properties = group.getProperties(); Map nodeTemplateProperties = nodeTemplate.getProperties(); - String networkCollectionFunction = (String)((Map)(properties.get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT); - String networkCollectionDescription = (String)((Map)(properties.get(Constants.NETWORK_COLLECTION_DESCRIPTION).getValue())).get(Constants.GET_INPUT); + String networkCollectionFunction = (String) ((Map) (properties.get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT); + String networkCollectionDescription = (String) ((Map) (properties.get(Constants.NETWORK_COLLECTION_DESCRIPTION).getValue())).get(Constants.GET_INPUT); - networkCollection.getNetworkCollectionProperties().setNetworkCollectionDescription((String)nodeTemplateProperties.get(networkCollectionDescription).getValue()); - networkCollection.getNetworkCollectionProperties().setNetworkCollectionFunction((String)nodeTemplateProperties.get(networkCollectionFunction).getValue()); + networkCollection.getNetworkCollectionProperties().setNetworkCollectionDescription((String) nodeTemplateProperties.get(networkCollectionDescription).getValue()); + networkCollection.getNetworkCollectionProperties().setNetworkCollectionFunction((String) nodeTemplateProperties.get(networkCollectionFunction).getValue()); } - private Map extractVnfsFromCsar(ISdcCsarHelper csarHelper) { + private Map extractVnfsFromCsar(ISdcCsarHelper csarHelper, List policiesTargets) { List nodeTemplates = csarHelper.getServiceVfList(); - Map vnfsMaps = new HashMap(); + Map vnfsMaps = new HashMap<>(); for (NodeTemplate nodeTemplate : nodeTemplates) { VNF vnf = new VNF(); - populateNodeFromNodeTemplate(nodeTemplate, csarHelper, vnf); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, vnf, policiesTargets); vnf.setModelCustomizationName(nodeTemplate.getName()); vnf.setVfModules(getVfModulesFromVF(csarHelper, vnf.getCustomizationUuid())); vnf.setVolumeGroups(getVolumeGroupsFromVF(csarHelper, vnf.getCustomizationUuid())); vnf.setVfcInstanceGroups(getVfcInstanceGroup(csarHelper, nodeTemplate)); - + if (ToscaNamingPolicy.getEcompNamingValueForNode(nodeTemplate, "nf_naming").equals("true")) { + setEcompNamingProperty(vnf.getProperties(), "true"); + } vnfsMaps.put(nodeTemplate.getName(), vnf); } return vnfsMaps; } - private Map getVfcInstanceGroup(ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) { - List vfcList = csarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.VFC_INSTANCE_GROUP_TYPE); + private Map getVfcInstanceGroup(ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) { + List vfcList = csarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.VFC_INSTANCE_GROUP_TYPE); return vfcList.stream() - .collect(toMap(Group::getName, group -> populateVfcInstanceGroupFromGroup(group, csarHelper, nodeTemplate))); + .collect(toMap(Group::getName, group -> populateVfcInstanceGroupFromGroup(group, nodeTemplate))); } - private VfcInstanceGroup populateVfcInstanceGroupFromGroup(Group group, ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) { - VfcInstanceGroup vfcInstanceGroup = new VfcInstanceGroup(); - vfcInstanceGroup.setUuid(group.getMetadata().getValue(Constants.UUID)); - vfcInstanceGroup.setInvariantUuid(group.getMetadata().getValue(Constants.INVARIANT_UUID)); - vfcInstanceGroup.setVersion(group.getMetadata().getValue(Constants.VERSION)); - vfcInstanceGroup.setName(group.getMetadata().getValue(Constants.NAME)); - vfcInstanceGroup.setVfcInstanceGroupProperties(getVfcPropertiesFromGroup(nodeTemplate, group)); + private VfcInstanceGroup populateVfcInstanceGroupFromGroup(Group group, NodeTemplate nodeTemplate) { + VfcInstanceGroup vfcInstanceGroup = new VfcInstanceGroup(); + vfcInstanceGroup.setUuid(group.getMetadata().getValue(Constants.UUID)); + vfcInstanceGroup.setInvariantUuid(group.getMetadata().getValue(Constants.INVARIANT_UUID)); + vfcInstanceGroup.setVersion(group.getMetadata().getValue(Constants.VERSION)); + vfcInstanceGroup.setName(group.getMetadata().getValue(Constants.NAME)); + vfcInstanceGroup.setVfcInstanceGroupProperties(getVfcPropertiesFromGroup(nodeTemplate, group)); return vfcInstanceGroup; @@ -209,24 +259,24 @@ public class ToscaParserImpl2 { vfcInstanceGroupProperties.setVfcParentPortRole((String) group.getProperties().get(Constants.VFC_PARENT_PORT_ROLE).getValue()); vfcInstanceGroupProperties.setSubinterfaceRole((String) group.getProperties().get(Constants.SUBINTERFACE_ROLE).getValue()); - String networkCollectionFunction = (String)((Map)(group.getProperties().get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT); - String vfcInstanceGroupFunction = (String)((Map)(group.getProperties().get(Constants.VFC_INSTANCE_GROUP_FUNCTION).getValue())).get(Constants.GET_INPUT); + String networkCollectionFunction = (String) ((Map) (group.getProperties().get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT); + String vfcInstanceGroupFunction = (String) ((Map) (group.getProperties().get(Constants.VFC_INSTANCE_GROUP_FUNCTION).getValue())).get(Constants.GET_INPUT); - if(nodeTemplate.getProperties().get(networkCollectionFunction) != null) + if ( nodeTemplate.getProperties().get(networkCollectionFunction) != null ) vfcInstanceGroupProperties.setNetworkCollectionFunction((String) nodeTemplate.getProperties().get(networkCollectionFunction).getValue()); - if(nodeTemplate.getProperties().get(vfcInstanceGroupFunction) != null) + if ( nodeTemplate.getProperties().get(vfcInstanceGroupFunction) != null ) vfcInstanceGroupProperties.setVfcInstanceGroupFunction((String) nodeTemplate.getProperties().get(vfcInstanceGroupFunction).getValue()); return vfcInstanceGroupProperties; } - private Map extractPortMirroringConfigFromCsar(ISdcCsarHelper csarHelper) { - List nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION); + private Map extractPortMirroringConfigFromCsar(ISdcCsarHelper csarHelper, List policiesTargets) { + List nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);//TODO change to Map configMaps = new HashMap<>(); for (NodeTemplate nodeTemplate : nodeTemplates) { PortMirroringConfig pmConfig = new PortMirroringConfig(); - populateNodeFromNodeTemplate(nodeTemplate, csarHelper, pmConfig); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, pmConfig, policiesTargets); pmConfig.setModelCustomizationName(nodeTemplate.getName()); pmConfig.setRequirementAssignments(nodeTemplate.getRequirements()); @@ -236,38 +286,38 @@ public class ToscaParserImpl2 { } return configMaps; - } + } - private Map extractServiceProxyFromCsar(ISdcCsarHelper csarHelper) { + private Map extractServiceProxyFromCsar(ISdcCsarHelper csarHelper, List policiesTargets) { List nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY); - Map serviceProxies = new HashMap<>(); - for (NodeTemplate nodeTemplate: nodeTemplates) { - ServiceProxy serviceProxy = new ServiceProxy(); - populateNodeFromNodeTemplate(nodeTemplate, csarHelper, serviceProxy); + return nodeTemplates.stream() + .collect(toMap(NodeTemplate::getName, node -> getServiceProxyFromNodeTemplate(node, csarHelper, policiesTargets))); + } - Map metadata = nodeTemplate.getMetaData().getAllProperties(); - serviceProxy.setSourceModelUuid(metadata.get("sourceModelUuid")); - serviceProxy.setSourceModelInvariant(metadata.get("sourceModelInvariant")); - serviceProxy.setSourceModelName(metadata.get("sourceModelName")); + private ServiceProxy getServiceProxyFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, List policiesTargets) { + ServiceProxy serviceProxy = new ServiceProxy(); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, serviceProxy, policiesTargets); - serviceProxies.put(nodeTemplate.getName(), serviceProxy); - } + Map metadata = nodeTemplate.getMetaData().getAllProperties(); + serviceProxy.setSourceModelUuid(metadata.get("sourceModelUuid")); + serviceProxy.setSourceModelInvariant(metadata.get("sourceModelInvariant")); + serviceProxy.setSourceModelName(metadata.get("sourceModelName")); - return serviceProxies; + return serviceProxy; } - private void setSourceAndCollectorProxyNodes(ISdcCsarHelper csarHelper, PortMirroringConfig portMirroringConfig, NodeTemplate nodeTemplate) { - RequirementAssignments requirementAssignments = nodeTemplate.getRequirements(); + private void setSourceAndCollectorProxyNodes(ISdcCsarHelper csarHelper, PortMirroringConfig portMirroringConfig, NodeTemplate nodeTemplate) { + RequirementAssignments requirementAssignments = nodeTemplate.getRequirements(); List sourceNodes = getRequirementsNodesNames(requirementAssignments.getRequirementsByName("source").getAll()); portMirroringConfig.setSourceNodes(sourceNodes); List collectorNodes = getRequirementsNodesNames(requirementAssignments.getRequirementsByName("collector").getAll()); - if (!collectorNodes.isEmpty()) { // vprobe + if ( !collectorNodes.isEmpty() ) { // vprobe portMirroringConfig.setCollectorNodes(collectorNodes); } else { // pprobe - configuration by policy String collectorNodeName = csarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "collector_node"); - if (collectorNodeName != null) { + if ( collectorNodeName != null ) { portMirroringConfig.setCollectorNodes(Arrays.asList(collectorNodeName)); portMirroringConfig.setConfigurationByPolicy(true); } @@ -277,8 +327,8 @@ public class ToscaParserImpl2 { private List getRequirementsNodesNames(List requirements) { List requirementsNodes = new ArrayList<>(); - if (requirements != null && requirements.size() > 0) { - requirementsNodes = requirements.stream().map(RequirementAssignment::getNodeTemplateName).collect(Collectors.toList()); + if ( !CollectionUtils.isEmpty(requirements) ) { + requirementsNodes = requirements.stream().map(RequirementAssignment::getNodeTemplateName).collect(toList()); } return requirementsNodes; @@ -301,26 +351,29 @@ public class ToscaParserImpl2 { return Boolean.valueOf(group.getPropertyValue(Constants.VOLUME_GROUP).toString()); } - private Map extractNetworksFromCsar(ISdcCsarHelper csarHelper) { + private Map extractNetworksFromCsar(ISdcCsarHelper csarHelper, List policiesTargets) { List nodeTemplates = csarHelper.getServiceVlList(); - Map networksMap = new HashMap(); + Map networksMap = new HashMap<>(); for (NodeTemplate nodeTemplate : nodeTemplates) { Network newNetwork = new Network(); - populateNodeFromNodeTemplate(nodeTemplate, csarHelper, newNetwork); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, newNetwork, policiesTargets); newNetwork.setModelCustomizationName(nodeTemplate.getName()); + if (ToscaNamingPolicy.getEcompNamingValueForNode(nodeTemplate, "exVL_naming").equals("true")) { + setEcompNamingProperty(newNetwork.getProperties(), "true"); + } networksMap.put(nodeTemplate.getName(), newNetwork); } return networksMap; - } + } - private Map extractPnfsFromCsar(ISdcCsarHelper csarHelper) { + private Map extractPnfsFromCsar(ISdcCsarHelper csarHelper, List policiesTargets) { List nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.PNF); HashMap pnfHashMap = new HashMap<>(); for (NodeTemplate nodeTemplate : nodeTemplates) { Node pnf = new Node(); - populateNodeFromNodeTemplate(nodeTemplate, csarHelper, pnf); + populateNodeFromNodeTemplate(nodeTemplate, csarHelper, pnf, policiesTargets); pnfHashMap.put(nodeTemplate.getName(), pnf); } return pnfHashMap; @@ -352,13 +405,13 @@ public class ToscaParserImpl2 { Map inputs = new HashMap<>(); for (org.onap.sdc.toscaparser.api.parameters.Input input : inputList) { //Set only inputs without annotation to the service level - if(input.getAnnotations() == null) + if ( input.getAnnotations() == null ) inputs.put(input.getName(), convertInput(input, new org.onap.vid.asdc.beans.tosca.Input(), null)); } return inputs; } - private Node populateNodeFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode) { + private Node populateNodeFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode, List policiesTargets) { newNode.setCustomizationUuid(csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); newNode.setDescription(nodeTemplate.getMetaData().getValue(Constants.DESCRIPTION)); newNode.setInvariantUuid(nodeTemplate.getMetaData().getValue(Constants.INVARIANT_UUID)); @@ -367,19 +420,21 @@ public class ToscaParserImpl2 { newNode.setVersion(nodeTemplate.getMetaData().getValue(Constants.VERSION)); newNode.setInputs(extractInputsAndCommandsForNodeTemplate(nodeTemplate, csarHelper, newNode)); newNode.setType(nodeTemplate.getMetaData().getValue(Constants.TYPE)); - Map propertiesMap = setPropertiesOfVnf(nodeTemplate.getPropertiesObjects()); + Map propertiesMap = nodeTemplate.getPropertiesObjects().stream() + .collect(toMap(Property::getName, p -> p.getValue().toString())); + setEcompNamingProperty(propertiesMap, String.valueOf(policiesTargets.contains(nodeTemplate.getName()))); newNode.setProperties(propertiesMap); return newNode; } - private VfModule populateVfModuleFromGroup(Group group, ISdcCsarHelper csarHelper){ + private VfModule populateVfModuleFromGroup(Group group, ISdcCsarHelper csarHelper) { VfModule vfModule = new VfModule(); extractBasicPropertiesForGroup(vfModule, group, csarHelper); vfModule.setVolumeGroupAllowed(isVolumeGroup(group)); return vfModule; } - private VolumeGroup populateVolumeGroupFromGroup(Group group, ISdcCsarHelper csarHelper){ + private VolumeGroup populateVolumeGroupFromGroup(Group group, ISdcCsarHelper csarHelper) { VolumeGroup volumeGroup = new VolumeGroup(); extractBasicPropertiesForGroup(volumeGroup, group, csarHelper); return volumeGroup; @@ -398,30 +453,39 @@ public class ToscaParserImpl2 { } - private Map extractVfInputsFromCsarByAnnotation(ISdcCsarHelper csarHelper, org.onap.vid.model.Group group) { + private Map extractVfInputsFromCsarByAnnotation(ISdcCsarHelper csarHelper, org.onap.vid.model.Group group) { Map inputMap = new HashMap<>(); - if(group.getProperties().getVfModuleLabel() != null){ + if ( group.getProperties().getVfModuleLabel() != null ) { List inputsList = csarHelper.getInputsWithAnnotations(); - for(Input input: inputsList){ - if(input.getAnnotations() != null){ - List annotationProperties = input.getAnnotations().get("source").getProperties(); - if(isInputMatchesToGroup(annotationProperties, group)){ - inputMap.put(input.getName(), new org.onap.vid.asdc.beans.tosca.Input(input ,annotationProperties)); - } - } + for (Input input : inputsList) { + extractVfModuleInput(group, inputMap, input); } } return inputMap; } + private void extractVfModuleInput(org.onap.vid.model.Group group, Map inputMap, Input input) { + if ( input.getAnnotations() != null ) { + List annotationProperties = input.getAnnotations().get("source").getProperties(); + if ( isInputMatchesToGroup(annotationProperties, group) ) { + final org.onap.vid.asdc.beans.tosca.Input vfModuleInput = new org.onap.vid.asdc.beans.tosca.Input(input, annotationProperties); + if ( vfModuleInput.getInputProperties() != null && vfModuleInput.getInputProperties().getParamName() != null ) { + inputMap.put(vfModuleInput.getInputProperties().getParamName(), vfModuleInput); + } else { + inputMap.put(input.getName(), vfModuleInput); + } + } + } + } + - private boolean isInputMatchesToGroup(List annotationProperties, org.onap.vid.model.Group group){ - for(Property property: annotationProperties){ - if(property.getName().equals(VF_MODULE_LABEL)){ + private boolean isInputMatchesToGroup(List annotationProperties, org.onap.vid.model.Group group) { + for (Property property : annotationProperties) { + if ( property.getName().equals(VF_MODULE_LABEL) ) { final Object values = property.getValue(); final String vfModuleLabel = group.getProperties().getVfModuleLabel(); - if (values instanceof List) { - if (listContainsAsString((List) values, vfModuleLabel)) return true; + if ( values instanceof List ) { + if ( listContainsAsString((List) values, vfModuleLabel) ) return true; } else { return getPropertyValueAsString(property).equals(vfModuleLabel); } @@ -432,7 +496,7 @@ public class ToscaParserImpl2 { private boolean listContainsAsString(List list, String value) { for (Object v : list) { - if (StringUtils.equals(v.toString(), value)) { + if ( StringUtils.equals(v.toString(), value) ) { return true; } } @@ -443,37 +507,45 @@ public class ToscaParserImpl2 { return removeSquareBrackets(property.getValue().toString()); } - private String removeSquareBrackets(String stringWithSquareBrackets){ + private String removeSquareBrackets(String stringWithSquareBrackets) { return stringWithSquareBrackets.replaceAll("(^\\[|\\]$)", ""); } - private GroupProperties extractVfModuleProperties(Group group, ISdcCsarHelper csarHelper){ + private GroupProperties extractVfModuleProperties(Group group, ISdcCsarHelper csarHelper) { GroupProperties vfModuleProperties = new GroupProperties(); - if(csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES) != null) - vfModuleProperties.setMinCountInstances((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES)); - if(csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES) != null) - vfModuleProperties.setMaxCountInstances((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES)); - if(csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT) != null) - vfModuleProperties.setInitialCount((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT)); - if(csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL) != null) + if ( csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES) != null ) + vfModuleProperties.setMinCountInstances((Integer) csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES)); + if ( csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES) != null ) + vfModuleProperties.setMaxCountInstances((Integer) csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES)); + if ( csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT) != null ) + vfModuleProperties.setInitialCount((Integer) csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT)); + if ( csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL) != null ) vfModuleProperties.setVfModuleLabel((String) csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL)); + vfModuleProperties.setBaseModule(isModuleTypeIsBaseObjectSafe(csarHelper.getGroupPropertyAsObject(group, Constants.VF_MODULE_TYPE))); return vfModuleProperties; } + public static boolean isModuleTypeIsBaseObjectSafe(Object vfModuleTypeValue) { + return (vfModuleTypeValue instanceof String) && (isModuleTypeIsBase((String) vfModuleTypeValue)); + } + + protected static boolean isModuleTypeIsBase(String vfModuleTypeValue) { + return "Base".equalsIgnoreCase(vfModuleTypeValue); + } - private Map extractInputsAndCommandsForNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode){ + private Map extractInputsAndCommandsForNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode) { Map inputMap = new HashMap<>(); Map commandPropertyMap = new HashMap<>(); List inputs = csarHelper.getServiceInputs(); - Map properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.GET_INPUT); + Map properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.GET_INPUT); for (Map.Entry property : properties.entrySet()) { String inputKey = property.getValue(); String key = extractInputValue(inputKey); - for (Input input: inputs){ - if(input.getName().equals(key)){ + for (Input input : inputs) { + if ( input.getName().equals(key) ) { org.onap.vid.asdc.beans.tosca.Input localInput = new org.onap.vid.asdc.beans.tosca.Input(); localInput = convertInput(input, localInput, nodeTemplate); String name = property.getKey(); @@ -487,7 +559,7 @@ public class ToscaParserImpl2 { } private String extractInputValue(String inputKey) { - return inputKey.substring(inputKey.indexOf(":") + 1); + return inputKey.substring(inputKey.indexOf(':') + 1); } private org.onap.vid.asdc.beans.tosca.Input convertInput(Input parserInput, org.onap.vid.asdc.beans.tosca.Input localInput, NodeTemplate nodeTemplate){ @@ -497,7 +569,7 @@ public class ToscaParserImpl2 { localInput.setType(parserInput.getType()); localInput.setConstraints(parserInput.getConstraints()); // localInput.setentry_schema() - + //if inputs of inner nodeTemplate - tell its details if(nodeTemplate != null) { Metadata metadata = nodeTemplate.getMetaData(); @@ -506,11 +578,11 @@ public class ToscaParserImpl2 { localInput.setTemplateInvariantUUID(metadata.getValue("invariantUUID")); localInput.setTemplateCustomizationUUID(metadata.getValue("customizationUUID")); } - + return localInput; } - private CommandProperty extractCommands(String displayName, String inputName){ + private CommandProperty extractCommands(String displayName, String inputName) { CommandProperty commandProperty = new CommandProperty(); commandProperty.setDisplayName(displayName); commandProperty.setCommand(Constants.GET_INPUT); @@ -518,19 +590,8 @@ public class ToscaParserImpl2 { return commandProperty; } - private Map setPropertiesOfVnf(List properties) { - Map propertiesMap = new HashMap(); - for (Property property : properties) { - //special handling to necessary sub-property "ecomp_generated_naming" - if(property.getName().equals("nf_naming")){ - final Object ecompGeneratedNaming = ((Map) (property.getValue())).get("ecomp_generated_naming"); - if (ecompGeneratedNaming != null) { - propertiesMap.put("ecomp_generated_naming", ecompGeneratedNaming.toString()); - } - } - propertiesMap.put(property.getName(), property.getValue().toString()); - } - return propertiesMap; + private void setEcompNamingProperty(Map propertiesMap, String isUserProvidingVnfNameOptional) { + propertiesMap.put(Constants.ECOMP_GENERATED_NAMING_PROPERTY, isUserProvidingVnfNameOptional); } private String validateInstantiationType(ISdcCsarHelper csarHelper){ @@ -545,5 +606,43 @@ public class ToscaParserImpl2 { return validatedInstantiationType; } + private Map extractVnfGroupsFromCsar(ISdcCsarHelper csarHelper, List policiesTargets) { + List resourceGroups = csarHelper.getGroupsOfTopologyTemplateByToscaGroupType(Constants.RESOURCE_GROUP_TYPE); + + return resourceGroups.stream() + .filter(group -> group.getProperties().get(Constants.RESOURCE_GROUP_CONTAINED_TYPE).getValue().equals("VF")) + .collect(toMap(Group::getName, group -> parseResourceGroup(group, csarHelper, policiesTargets))); + } + + private ResourceGroup parseResourceGroup(Group group, ISdcCsarHelper csarHelper, List policiesTargets) { + return new ResourceGroup( + Constants.VNF_GROUP, + group.getMetadata().getValue(Constants.INVARIANT_UUID), + group.getMetadata().getValue(Constants.UUID), + group.getMetadata().getValue(Constants.VERSION), + group.getMetadata().getValue(Constants.NAME), + group.getMetadata().getValue(Constants.NAME), + getPropertiesOfResourceGroup(group.getProperties(), policiesTargets.contains(group.getName())), + csarHelper.getGroupMembersFromTopologyTemplate(group.getName()).stream() + .collect(toMap(NodeTemplate::getName, node -> getServiceProxyFromNodeTemplate(node, csarHelper, policiesTargets))) + ); + } + + private Map getPropertiesOfResourceGroup(Map properties, boolean hasPolicyTarget) { + Map propertiesMap = properties.entrySet().stream() + .collect(toMap(Map.Entry::getKey, e -> e.getValue().getValue())); + propertiesMap.put(Constants.ECOMP_GENERATED_NAMING_PROPERTY, String.valueOf(hasPolicyTarget)); + return propertiesMap; + } + + public List extractNamingPoliciesTargets(ISdcCsarHelper csarHelper) { + List policies = csarHelper.getPoliciesOfTopologyTemplateByToscaPolicyType(Constants.NAMING_POLICY_TYPE); + return policies.stream() + .filter(policy -> policy.getProperties().get(Constants.TYPE) != null && + policy.getProperties().get(Constants.TYPE).getValue() != null && + StringUtils.equalsIgnoreCase(policy.getProperties().get(Constants.TYPE).getValue().toString(), "naming")) + .flatMap(policy -> policy.getTargets().stream()) + .collect(toList()); + } } \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java new file mode 100644 index 000000000..ca0607b8a --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/VidNotionsBuilder.java @@ -0,0 +1,130 @@ +package org.onap.vid.asdc.parser; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.VidNotions; +import org.onap.vid.properties.Features; +import org.togglz.core.manager.FeatureManager; + +import static org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase; +import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; + +public class VidNotionsBuilder { + + private final FeatureManager featureManager; + + public VidNotionsBuilder(FeatureManager featureManager) { + this.featureManager = featureManager; + } + + public VidNotions buildVidNotions(ISdcCsarHelper csarHelper, ServiceModel serviceModel) { + final VidNotions.InstantiationUI instantiationUI = suggestInstantiationUI(csarHelper); + + return new VidNotions(instantiationUI, suggestModelCategory(csarHelper), suggestViewEditUI(csarHelper, serviceModel)); + } + + //UI route a-la-carte services to old UI only if InstantiationUI is LEGACY + //So any other value for InstantiationUI other than LEGACY make UI to route + //a-la-carte services to new UI + VidNotions.InstantiationUI suggestInstantiationUI(ISdcCsarHelper csarHelper) { + if(featureManager.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI) && isALaCarte(csarHelper)) { + return VidNotions.InstantiationUI.ANY_ALACARTE_NEW_UI; + } + if (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && isGrouping(csarHelper)) { + return VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING; + } + if (featureManager.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)) { + if (isUuidExactlyHardCoded1ffce89fef3f(csarHelper)) { + return VidNotions.InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de; + } else if (isALaCarte(csarHelper) && hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(csarHelper)) { + return VidNotions.InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS; + } else if (isALaCarte(csarHelper) && hasFabricConfiguration(csarHelper)) { + return VidNotions.InstantiationUI.SERVICE_WITH_FABRIC_CONFIGURATION; + } + } + + return VidNotions.InstantiationUI.LEGACY; + + } + + VidNotions.ModelCategory suggestModelCategory(ISdcCsarHelper csarHelper) { + if (isALaCarte(csarHelper) && hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(csarHelper)){ + return VidNotions.ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL; + } else if(isALaCarte(csarHelper) && hasFabricConfiguration(csarHelper)) { + return VidNotions.ModelCategory.IS_5G_FABRIC_CONFIGURATION_MODEL; + } else { + return VidNotions.ModelCategory.OTHER; + } + } + + VidNotions.InstantiationUI suggestViewEditUI(ISdcCsarHelper csarHelper, ServiceModel serviceModel) { + if (!featureManager.isActive(Features.FLAG_ASYNC_INSTANTIATION)){ + return VidNotions.InstantiationUI.LEGACY; + } + if (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && isGrouping(csarHelper)) { + return VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING; + } + + if (featureManager.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)) { + if (isMacro(serviceModel) && !isMacroExcludedFromAsyncFlow(serviceModel)) { + return VidNotions.InstantiationUI.MACRO_SERVICE; + } + VidNotions.InstantiationUI instantiationUISuggestion = suggestInstantiationUI(csarHelper); + if (instantiationUISuggestion!=VidNotions.InstantiationUI.LEGACY) { + return instantiationUISuggestion; + } + } + + return VidNotions.InstantiationUI.LEGACY; + } + + private boolean isMacro(ServiceModel serviceModel) { + return ToscaParserImpl2.Constants.MACRO.equals(serviceModel.getService().getInstantiationType()); + } + + private boolean isUuidExactlyHardCoded1ffce89fef3f(ISdcCsarHelper csarHelper) { + return equalsIgnoreCase( + csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.UUID), "95eb2c44-bff2-4e8b-ad5d-8266870b7717"); + } + + private boolean hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(ISdcCsarHelper csarHelper) { + return hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV","OVS") ; + } + + boolean hasFabricConfiguration(ISdcCsarHelper csarHelper) { + return csarHelper.getServiceNodeTemplates().stream() + .flatMap(nodeTemplate -> csarHelper.getNodeTemplateChildren(nodeTemplate).stream()) + .anyMatch(child -> child.getType().equals(ToscaParserImpl2.Constants.FABRIC_CONFIGURATION_TYPE)); + } + + boolean hasAnyNetworkWithPropertyEqualsToAnyOf(ISdcCsarHelper csarHelper, String propertyName, String... propertyValues) { + return csarHelper + .getServiceVlList().stream() + .map(NodeTemplate::getProperties) + .flatMap(props -> props.entrySet().stream()) + .filter(prop -> equalsIgnoreCase(prop.getKey(), propertyName)) + // getValue().getValue() because value is Entry, where it's inner value is what we're looking for + .anyMatch(prop -> equalsAnyIgnoreCase(prop.getValue().getValue().toString(), propertyValues)); + } + + boolean isALaCarte(ISdcCsarHelper csarHelper) { + final String instantiationType = csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.INSTANTIATION_TYPE); + return StringUtils.equalsIgnoreCase(instantiationType, ToscaParserImpl2.Constants.A_LA_CARTE); + } + + boolean isMacroExcludedFromAsyncFlow(ServiceModel serviceModel) { + return (MapUtils.isNotEmpty(serviceModel.getPnfs()) || + MapUtils.isNotEmpty(serviceModel.getCollectionResource()) || + (MapUtils.isNotEmpty(serviceModel.getNetworks()) && !featureManager.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION))); + + + } + + private boolean isGrouping(ISdcCsarHelper csarHelper) { + final String serviceRole = csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.SERVICE_ROLE); + return StringUtils.equalsIgnoreCase(serviceRole, ToscaParserImpl2.Constants.GROUPING); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/ChangeManagementRequest.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/ChangeManagementRequest.java index 1d866eecd..abfcd6f32 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/ChangeManagementRequest.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/ChangeManagementRequest.java @@ -1,13 +1,10 @@ package org.onap.vid.changeManagement; -import java.util.List; +import com.fasterxml.jackson.annotation.*; + import java.util.HashMap; +import java.util.List; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonPropertyOrder({ "requestDetails", @@ -17,17 +14,17 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; public class ChangeManagementRequest { public static class MsoChangeManagementRequest { - public final static String SOFTWARE_UPDATE = "inPlaceSoftwareUpdate"; + public static final String SOFTWARE_UPDATE = "inPlaceSoftwareUpdate"; public static final String REPLACE = "replace"; - public final static String CONFIG_UPDATE = "applyUpdatedConfig"; + public static final String CONFIG_UPDATE = "applyUpdatedConfig"; } - public final static String VNF_IN_PLACE_SOFTWARE_UPDATE = "vnf in place software update"; + public static final String VNF_IN_PLACE_SOFTWARE_UPDATE = "vnf in place software update"; public static final String UPDATE = "update"; public static final String REPLACE = "replace"; - public final static String CONFIG_UPDATE = "vnf config update"; - public final static String SCALE_OUT = "vnf scale out"; + public static final String CONFIG_UPDATE = "vnf config update"; + public static final String SCALE_OUT = "vnf scale out"; @JsonProperty("requestDetails") private List requestDetails; @@ -36,7 +33,7 @@ public class ChangeManagementRequest { private String requestType; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); @JsonProperty("requestDetails") public List getRequestDetails() { diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/CloudConfiguration.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/CloudConfiguration.java index 43d6a6a0a..b7435795c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/CloudConfiguration.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/CloudConfiguration.java @@ -1,13 +1,9 @@ package org.onap.vid.changeManagement; +import com.fasterxml.jackson.annotation.*; + import java.util.HashMap; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ @@ -20,7 +16,7 @@ public class CloudConfiguration { @JsonProperty("tenantId") private String tenantId; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); @JsonProperty("lcpCloudRegionId") public String getLcpCloudRegionId() { diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/LeanCloudConfiguration.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/LeanCloudConfiguration.java index 6011c7ebb..480ef1258 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/LeanCloudConfiguration.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/LeanCloudConfiguration.java @@ -1,20 +1,27 @@ package org.onap.vid.changeManagement; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.onap.vid.mso.model.CloudConfiguration; + /** * Created by Oren on 9/5/17. */ +@JsonInclude(JsonInclude.Include.NON_EMPTY) public class LeanCloudConfiguration { public LeanCloudConfiguration() { } - public LeanCloudConfiguration(org.onap.vid.domain.mso.CloudConfiguration cloudConfiguration) { + public LeanCloudConfiguration(CloudConfiguration cloudConfiguration) { this.tenantId = cloudConfiguration.getTenantId(); this.lcpCloudRegionId = cloudConfiguration.getLcpCloudRegionId(); + this.cloudOwner = cloudConfiguration.getCloudOwner(); } public String lcpCloudRegionId; public String tenantId; + public String cloudOwner; + } diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/ModelInfo.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/ModelInfo.java index 8f44a4bf6..ebb0ba3e3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/ModelInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/ModelInfo.java @@ -1,12 +1,9 @@ package org.onap.vid.changeManagement; + +import com.fasterxml.jackson.annotation.*; + import java.util.HashMap; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ @@ -24,7 +21,7 @@ public class ModelInfo { } - public ModelInfo(org.onap.vid.domain.mso.ModelInfo modelInfo){ + public ModelInfo(org.onap.vid.mso.model.ModelInfo modelInfo){ this.setModelType(modelInfo.getModelType().toString()); this.setModelInvariantId(modelInfo.getModelInvariantId()); this.setModelVersionId(modelInfo.getModelNameVersionId()); @@ -50,7 +47,7 @@ public class ModelInfo { @JsonProperty("modelCustomizationId") private String modelCustomizationId; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); @JsonProperty("modelType") public String getModelType() { diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/ModelInfoOfRelatedInstance.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/ModelInfoOfRelatedInstance.java index 7e8760987..7c9b709d9 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/ModelInfoOfRelatedInstance.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/ModelInfoOfRelatedInstance.java @@ -1,13 +1,9 @@ package org.onap.vid.changeManagement; +import com.fasterxml.jackson.annotation.*; + import java.util.HashMap; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ @@ -37,7 +33,7 @@ public class ModelInfoOfRelatedInstance { @JsonProperty("modelCustomizationId") private String modelCustomizationId; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); @JsonProperty("modelType") public String getModelType() { diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/RequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/RequestDetails.java index 8e1a40833..25951f257 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/RequestDetails.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/RequestDetails.java @@ -57,4 +57,9 @@ public class RequestDetails extends org.onap.vid.mso.rest.RequestDetails{ public boolean equals(Object other) { return super.equals(other); } + + @Override + public int hashCode() { + return super.hashCode(); + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/RequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/RequestInfo.java index 4aa3724af..8ecb39e4c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/RequestInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/RequestInfo.java @@ -1,13 +1,9 @@ package org.onap.vid.changeManagement; +import com.fasterxml.jackson.annotation.*; + import java.util.HashMap; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ @@ -23,7 +19,7 @@ public class RequestInfo { @JsonProperty("requestorId") private String requestorId; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); @JsonProperty("source") public String getSource() { diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/UpdateRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/UpdateRequestInfo.java index 024e9c3c1..394c8ffaf 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/UpdateRequestInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/UpdateRequestInfo.java @@ -1,6 +1,6 @@ package org.onap.vid.changeManagement; -import org.onap.vid.domain.mso.*; +import org.onap.vid.mso.model.RequestInfo; /** * Created by Oren on 9/5/17. @@ -11,7 +11,7 @@ public class UpdateRequestInfo { } - public UpdateRequestInfo(org.onap.vid.domain.mso.RequestInfo requestInfo) { + public UpdateRequestInfo(RequestInfo requestInfo) { this.requestorId = requestInfo.getRequestorId(); this.suppressRollback = requestInfo.getSuppressRollback(); this.source = requestInfo.getSource(); diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/VnfDetails.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/VnfDetails.java index 5cc2f4d32..c5a067112 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/VnfDetails.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/VnfDetails.java @@ -1,7 +1,6 @@ package org.onap.vid.changeManagement; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.MoreObjects; public class VnfDetails { diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/VnfDetailsWithWorkflows.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/VnfDetailsWithWorkflows.java index 4e172a10c..9971df913 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/VnfDetailsWithWorkflows.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/VnfDetailsWithWorkflows.java @@ -33,7 +33,13 @@ public class VnfDetailsWithWorkflows extends VnfDetails { this.workflows = workflows; } - public boolean equals(VnfDetailsWithWorkflows vnfDetailsWithWorkflows){ - return this.workflows.equals(vnfDetailsWithWorkflows.getWorkflows()); + @Override + public boolean equals(Object o) { + return super.equals(o); + } + + @Override + public int hashCode() { + return super.hashCode(); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/changeManagement/WorkflowsDetail.java b/vid-app-common/src/main/java/org/onap/vid/changeManagement/WorkflowsDetail.java index e833ecb28..0883411ee 100644 --- a/vid-app-common/src/main/java/org/onap/vid/changeManagement/WorkflowsDetail.java +++ b/vid-app-common/src/main/java/org/onap/vid/changeManagement/WorkflowsDetail.java @@ -1,7 +1,6 @@ package org.onap.vid.changeManagement; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.MoreObjects; public class WorkflowsDetail { diff --git a/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java b/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java index 8f0d59fd3..b9b2c8b73 100644 --- a/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java @@ -29,8 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.ServletContext; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; -import java.text.DateFormat; -import java.text.SimpleDateFormat; /** * General HTTP client. @@ -45,9 +43,6 @@ public class HttpBasicClient{ /** The logger. */ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpBasicClient.class); - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - /** * Obtain a basic HTTP client . * diff --git a/vid-app-common/src/main/java/org/onap/vid/client/HttpsBasicClient.java b/vid-app-common/src/main/java/org/onap/vid/client/HttpsBasicClient.java deleted file mode 100644 index 5afa0359c..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/client/HttpsBasicClient.java +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.client; - -import org.eclipse.jetty.util.security.Password; -import org.glassfish.jersey.client.ClientConfig; -import org.glassfish.jersey.client.ClientProperties; -import org.onap.vid.properties.VidProperties; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import java.io.File; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - - /** - * General SSL client using the VID tomcat keystore. It doesn't use client certificates. - */ - -public class HttpsBasicClient{ - - /** The logger. */ - static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsBasicClient.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - /** - * Retrieve an SSL client. - * - * @return Client The SSL client - * @throws Exception the exception - */ - public static Client getClient() { - String methodName = "getClient"; - ClientConfig config = new ClientConfig(); - - SSLContext ctx = null; - - try { - - config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); - - String truststore_path = SystemProperties.getProperty(VidProperties.VID_TRUSTSTORE_FILENAME); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " truststore_path=" + truststore_path); - String truststore_password = SystemProperties.getProperty(VidProperties.VID_TRUSTSTORE_PASSWD_X); - - - String decrypted_truststore_password = Password.deobfuscate(truststore_password); - //logger.debug(dateFormat.format(new Date()) + " " + methodName + " decrypted_truststore_password=" + decrypted_truststore_password); - - File tr = new File (truststore_path); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " absolute truststore path=" + tr.getAbsolutePath()); - - System.setProperty("javax.net.ssl.trustStore", truststore_path); - System.setProperty("javax.net.ssl.trustStorePassword", decrypted_truststore_password); - HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){ - public boolean verify(String string,SSLSession ssls) { - return true; - } - }); - - //May need to make the algorithm a parameter. MSO requires TLSv1.1 or TLSv1.2 - ctx = SSLContext.getInstance("TLSv1.2"); - - ctx.init(null, null, null); - //config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, - // new HTTPSProperties( , ctx)); - - return ClientBuilder.newBuilder() - .sslContext(ctx) - .hostnameVerifier(new HostnameVerifier() { - @Override - public boolean verify( String s, SSLSession sslSession ) { - return true; - } - }).withConfig(config) - .build() - .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class); - - } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting", e); - return null; - } - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java b/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java index 9e50c4456..ed1401c13 100644 --- a/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java @@ -42,11 +42,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; +import java.security.*; import java.security.cert.CertificateException; import java.util.Map; @@ -170,7 +166,7 @@ public class SyncRestClient implements SyncRestClientInterface { } private ObjectMapper defaultObjectMapper() { - org.codehaus.jackson.map.ObjectMapper objectMapper = new org.codehaus.jackson.map.ObjectMapper(); + com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); return new ObjectMapper() { @Override diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java new file mode 100644 index 000000000..c099db807 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java @@ -0,0 +1,731 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.controller; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.AaiGetVnfResponse; +import org.onap.vid.aai.AaiResponse; +import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData; +import org.onap.vid.aai.ServiceInstancesSearchResults; +import org.onap.vid.aai.SubscriberFilteredResults; +import org.onap.vid.aai.model.AaiGetInstanceGroupsByCloudRegion; +import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; +import org.onap.vid.aai.model.AaiGetPnfs.Pnf; +import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; +import org.onap.vid.aai.util.AAIRestInterface; +import org.onap.vid.model.VersionByInvariantIdsRequest; +import org.onap.vid.roles.Role; +import org.onap.vid.roles.RoleProvider; +import org.onap.vid.roles.RoleValidator; +import org.onap.vid.services.AaiService; +import org.onap.vid.utils.Unchecked; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.HandlerMapping; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +import static org.onap.vid.utils.Logging.getMethodName; + +/** + * Controller to handle a&ai requests. + */ + +@RestController +public class AaiController extends RestrictedBaseController { + + /** + * The from app id. + */ + private String fromAppId = "VidAaiController"; + /** + * The logger. + */ + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiController.class); + /** + * The model. + */ + private Map model = new HashMap<>(); + /** + * The servlet context. + */ + @Autowired + private ServletContext servletContext; + /** + * aai service + */ + @Autowired + private AaiService aaiService; + @Autowired + private RoleProvider roleProvider; + + @Autowired + private AAIRestInterface aaiRestInterface; + + /** + * Welcome method. + * + * @param request the request + * @return ModelAndView The view + */ + @RequestMapping(value = {"/subscriberSearch"}, method = RequestMethod.GET) + public ModelAndView welcome(HttpServletRequest request) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== AaiController welcome start"); + return new ModelAndView(getViewName()); + } + + @RequestMapping(value = {"/aai_get_aic_zones"}, method = RequestMethod.GET) + public ResponseEntity getAicZones(HttpServletRequest request) throws IOException { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== getAicZones controller start"); + AaiResponse response = aaiService.getAaiZones(); + return aaiResponseToResponseEntity(response); + } + + @RequestMapping(value = {"/aai_get_aic_zone_for_pnf/{globalCustomerId}/{serviceType}/{serviceId}"}, method = RequestMethod.GET) + public ResponseEntity getAicZoneForPnf(@PathVariable("globalCustomerId") String globalCustomerId ,@PathVariable("serviceType") String serviceType , @PathVariable("serviceId") String serviceId ,HttpServletRequest request) throws IOException { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== getAicZoneForPnf controller start"); + AaiResponse response = aaiService.getAicZoneForPnf(globalCustomerId , serviceType , serviceId); + return aaiResponseToResponseEntity(response); + } + + @RequestMapping(value = {"/aai_get_instance_groups_by_vnf_instance_id/{vnfInstanceId}"}, method = RequestMethod.GET) + public ResponseEntity getInstanceGroupsByVnfInstanceId(@PathVariable("vnfInstanceId") String vnfInstanceId ,HttpServletRequest request) throws IOException { + AaiResponse response = aaiService.getInstanceGroupsByVnfInstanceId(vnfInstanceId); + return aaiResponseToResponseEntity(response); + } + /** + * Get services from a&ai. + * + * @return ResponseEntity The response entity with the logged in user uuid. + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = {"/getuserID"}, method = RequestMethod.GET) + public ResponseEntity getUserID(HttpServletRequest request) { + + String userId = ControllersUtils.extractUserId(request); + + return new ResponseEntity<>(userId, HttpStatus.OK); + } + + /** + * Get services from a&ai. + * + * @return ResponseEntity The response entity + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/aai_get_services", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity doGetServices(HttpServletRequest request) throws IOException { + RoleValidator roleValidator = new RoleValidator(roleProvider.getUserRoles(request)); + + AaiResponse subscriberList = aaiService.getServices(roleValidator); + return aaiResponseToResponseEntity(subscriberList); + } + + + @RequestMapping(value = {"/aai_get_version_by_invariant_id"}, method = RequestMethod.POST) + public ResponseEntity getVersionByInvariantId(HttpServletRequest request, @RequestBody VersionByInvariantIdsRequest versions) { + Response result = aaiService.getVersionByInvariantId(versions.versions); + + return new ResponseEntity<>(result.readEntity(String.class), HttpStatus.OK); + } + + + private ResponseEntity aaiResponseToResponseEntity(AaiResponse aaiResponseData) + throws IOException { + ResponseEntity responseEntity; + ObjectMapper objectMapper = new ObjectMapper(); + if (aaiResponseData.getHttpCode() == 200) { + responseEntity = new ResponseEntity<>(objectMapper.writeValueAsString(aaiResponseData.getT()), HttpStatus.OK); + } else { + responseEntity = new ResponseEntity<>(aaiResponseData.getErrorMessage(), HttpStatus.valueOf(aaiResponseData.getHttpCode())); + } + return responseEntity; + } + + /** + * Lookup single service instance in a&ai. Get the service-subscription and customer, too, i guess? + * + * @param serviceInstanceId the service instance Id + * @return ResponseEntity The response entity + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/aai_get_service_instance/{service-instance-id}/{service-instance-type}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity doGetServiceInstance(@PathVariable("service-instance-id") String serviceInstanceId, @PathVariable("service-instance-type") String serviceInstanceType) { + Response resp = null; + + if (serviceInstanceType.equalsIgnoreCase("Service Instance Id")) { + resp = doAaiGet( + "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:" + + serviceInstanceId, false); + } else { + resp = doAaiGet( + "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:" + + serviceInstanceId, false); + } + return convertResponseToResponseEntity(resp); + } + + /** + * Get services from a&ai. + * + * @param globalCustomerId the global customer id + * @param serviceSubscriptionId the service subscription id + * @return ResponseEntity The response entity + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity doGetServices(@PathVariable("global-customer-id") String globalCustomerId, + @PathVariable("service-subscription-id") String serviceSubscriptionId) { + Response resp = doAaiGet("business/customers/customer/" + globalCustomerId + + "/service-subscriptions/service-subscription/" + serviceSubscriptionId + "?depth=0", false); + return convertResponseToResponseEntity(resp); + } + + /** + * Obtain the subscriber list from a&ai. + * + * @param fullSet the full set + * @return ResponseEntity The response entity + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/aai_get_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity doGetSubscriberList(HttpServletRequest request, @DefaultValue("n") @QueryParam("fullSet") String fullSet) throws IOException { + return getFullSubscriberList(request); + } + + /** + * Obtain the Target Prov Status from the System.Properties file. + * + * @return ResponseEntity The response entity + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/get_system_prop_vnf_prov_status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getTargetProvStatus() { + String p = SystemProperties.getProperty("aai.vnf.provstatus"); + return new ResponseEntity<>(p, HttpStatus.OK); + } + + + /** + * Obtain the Target Prov Status from the System.Properties file. + * + * @return ResponseEntity The response entity + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/get_operational_environments", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public AaiResponse getOperationalEnvironments(@RequestParam(value="operationalEnvironmentType", required = false) String operationalEnvironmentType, + @RequestParam(value="operationalEnvironmentStatus", required = false) String operationalEnvironmentStatus) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({}, {})", getMethodName(), operationalEnvironmentType, operationalEnvironmentStatus); + AaiResponse response = aaiService.getOperationalEnvironments(operationalEnvironmentType,operationalEnvironmentStatus); + if (response.getHttpCode() != 200) { + String errorMessage = getAaiErrorMessage(response.getErrorMessage()); + if(errorMessage != null) { + response = new AaiResponse<>(response.getT(), errorMessage, response.getHttpCode()); + } + } + + LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), response); + return response; + } + + /** + * Obtain the full subscriber list from a&ai. + *

+ * g @return ResponseEntity The response entity + * + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/aai_get_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getFullSubscriberList(HttpServletRequest request) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + ResponseEntity responseEntity; + RoleValidator roleValidator = new RoleValidator(roleProvider.getUserRoles(request)); + SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator); + if (subscriberList.getHttpCode() == 200) { + responseEntity = new ResponseEntity<>(objectMapper.writeValueAsString(subscriberList.getSubscriberList()), HttpStatus.OK); + } else { + responseEntity = new ResponseEntity<>(subscriberList.getErrorMessage(), HttpStatus.valueOf(subscriberList.getHttpCode())); + } + + + return responseEntity; + } + + + @RequestMapping(value = "/get_vnf_data_by_globalid_and_service_type/{globalCustomerId}/{serviceType}", + method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getVnfDataByGlobalIdAndServiceType(HttpServletRequest request, + @PathVariable("globalCustomerId") String globalCustomerId, + @PathVariable("serviceType") String serviceType) throws IOException { + + AaiResponse resp = aaiService.getVNFData(globalCustomerId, serviceType); + return aaiResponseToResponseEntity(resp); + } + + + /** + * Refresh the subscriber list from a&ai. + * + * @return ResponseEntity The response entity + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/aai_refresh_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity doRefreshSubscriberList() { + return refreshSubscriberList(); + } + + /** + * Refresh the full subscriber list from a&ai. + * + * @return ResponseEntity The response entity + * @throws IOException Signals that an I/O exception has occurred. + */ + @RequestMapping(value = "/aai_refresh_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity doRefreshFullSubscriberList() { + return refreshSubscriberList(); + } + + protected ResponseEntity refreshSubscriberList() { + Response resp = getSubscribers(); + return convertResponseToResponseEntity(resp); + } + + /** + * Get subscriber details from a&ai. + * + * @param subscriberId the subscriber id + * @return ResponseEntity The response entity + */ + @RequestMapping(value = "/aai_sub_details/{subscriberId}", method = RequestMethod.GET) + public ResponseEntity GetSubscriberDetails(HttpServletRequest request, @PathVariable("subscriberId") String subscriberId) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + ResponseEntity responseEntity; + List roles = roleProvider.getUserRoles(request); + RoleValidator roleValidator = new RoleValidator(roles); + AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator); + String httpMessage = subscriberData.getT() != null ? + objectMapper.writeValueAsString(subscriberData.getT()) : + subscriberData.getErrorMessage(); + + responseEntity = new ResponseEntity(httpMessage, HttpStatus.valueOf(subscriberData.getHttpCode())); + return responseEntity; + } + + /** + * Get service instances that match the query from a&ai. + * + * @param subscriberId the subscriber id + * @param instanceIdentifier the service instance name or id. + * @param projects the projects that are related to the instance + * @param owningEntities the owningEntities that are related to the instance + * @return ResponseEntity The response entity + */ + @RequestMapping(value = "/search_service_instances", method = RequestMethod.GET) + public ResponseEntity SearchServiceInstances(HttpServletRequest request, + @RequestParam(value="subscriberId", required = false) String subscriberId, + @RequestParam(value="serviceInstanceIdentifier", required = false) String instanceIdentifier, + @RequestParam(value="project", required = false) List projects, + @RequestParam(value="owningEntity", required = false) List owningEntities) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + ResponseEntity responseEntity; + + List roles = roleProvider.getUserRoles(request); + RoleValidator roleValidator = new RoleValidator(roles); + + AaiResponse searchResult = aaiService.getServiceInstanceSearchResults(subscriberId, instanceIdentifier, roleValidator, owningEntities, projects); + + String httpMessage = searchResult.getT() != null ? + objectMapper.writeValueAsString(searchResult.getT()) : + searchResult.getErrorMessage(); + + + if(searchResult.getT().serviceInstances.isEmpty()){ + responseEntity = new ResponseEntity(httpMessage, HttpStatus.NOT_FOUND); + + } else { + responseEntity = new ResponseEntity(httpMessage, HttpStatus.valueOf(searchResult.getHttpCode())); + + } + return responseEntity; + } + + + + /** + * Issue a named query to a&ai. + * + * @param namedQueryId the named query id + * @param globalCustomerId the global customer id + * @param serviceType the service type + * @param serviceInstance the service instance + * @return ResponseEntity The response entity + */ + @RequestMapping(value = "/aai_sub_viewedit/{namedQueryId}/{globalCustomerId}/{serviceType}/{serviceInstance}", method = RequestMethod.GET) + public ResponseEntity viewEditGetComponentList( + @PathVariable("namedQueryId") String namedQueryId, + @PathVariable("globalCustomerId") String globalCustomerId, + @PathVariable("serviceType") String serviceType, + @PathVariable("serviceInstance") String serviceInstance) { + + String componentListPayload = getComponentListPutPayload(namedQueryId, globalCustomerId, serviceType, serviceInstance); + + Response resp = doAaiPost("search/named-query", componentListPayload, false); + return convertResponseToResponseEntity(resp); + } + + /** + * Issue a named query to a&ai. + * + * @param namedQueryId the named query id + * @param globalCustomerId the global customer id + * @param serviceType the service type + * @return ResponseEntity The response entity + */ + @RequestMapping(value = "/aai_get_models_by_service_type/{namedQueryId}/{globalCustomerId}/{serviceType}", method = RequestMethod.GET) + public ResponseEntity viewEditGetComponentList( + @PathVariable("namedQueryId") String namedQueryId, + @PathVariable("globalCustomerId") String globalCustomerId, + @PathVariable("serviceType") String serviceType) { + + String componentListPayload = getModelsByServiceTypePayload(namedQueryId, globalCustomerId, serviceType); + + Response resp = doAaiPost("search/named-query", componentListPayload, false); + return convertResponseToResponseEntity(resp); + } + + @RequestMapping(value = "/aai_get_vnf_instances/{globalCustomerId}/{serviceType}/{modelVersionId}/{modelInvariantId}/{cloudRegion}", method = RequestMethod.GET) + public ResponseEntity getNodeTemplateInstances( + @PathVariable("globalCustomerId") String globalCustomerId, + @PathVariable("serviceType") String serviceType, + @PathVariable("modelVersionId") String modelVersionId, + @PathVariable("modelInvariantId") String modelInvariantId, + @PathVariable("cloudRegion") String cloudRegion) { + + AaiResponse resp = aaiService.getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion); + return new ResponseEntity<>(resp.getT(), HttpStatus.valueOf(resp.getHttpCode())); + } + + @RequestMapping(value = "/aai_get_network_collection_details/{serviceInstanceId}", method = RequestMethod.GET) + public ResponseEntity getNetworkCollectionDetails(@PathVariable("serviceInstanceId") String serviceInstanceId) throws IOException { + com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); + AaiResponse resp = aaiService.getNetworkCollectionDetails(serviceInstanceId); + + String httpMessage = resp.getT() != null ? + objectMapper.writeValueAsString(resp.getT()) : + resp.getErrorMessage(); + return new ResponseEntity<>(httpMessage, HttpStatus.valueOf(resp.getHttpCode())); + } + + @RequestMapping(value = "/aai_get_instance_groups_by_cloudregion/{cloudOwner}/{cloudRegionId}/{networkFunction}", method = RequestMethod.GET) + public ResponseEntity getInstanceGroupsByCloudRegion(@PathVariable("cloudOwner") String cloudOwner, + @PathVariable("cloudRegionId") String cloudRegionId, + @PathVariable("networkFunction") String networkFunction) throws IOException { + com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); + AaiResponse resp = aaiService.getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction); + + String httpMessage = resp.getT() != null ? + objectMapper.writeValueAsString(resp.getT()) : + resp.getErrorMessage(); + return new ResponseEntity<>(httpMessage, HttpStatus.valueOf(resp.getHttpCode())); + } + + @RequestMapping(value = "/aai_get_by_uri/**", method = RequestMethod.GET) + public ResponseEntity getByUri(HttpServletRequest request) { + + String restOfTheUrl = (String) request.getAttribute( + HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); + String formattedUri = restOfTheUrl.replaceFirst("/aai_get_by_uri/", "").replaceFirst("^aai/v[\\d]+/", ""); + + Response resp = doAaiGet(formattedUri, false); + + return convertResponseToResponseEntity(resp); + } + + + + @RequestMapping(value = "/aai_get_configuration/{configuration_id}", method = RequestMethod.GET) + public ResponseEntity getSpecificConfiguration(@PathVariable("configuration_id") String configurationId) { + + Response resp = doAaiGet("network/configurations/configuration/"+configurationId, false); + + return convertResponseToResponseEntity(resp); + } + + @RequestMapping(value = "/aai_get_service_instance_pnfs/{globalCustomerId}/{serviceType}/{serviceInstanceId}", method = RequestMethod.GET) + public List getServiceInstanceAssociatedPnfs( + @PathVariable("globalCustomerId") String globalCustomerId, + @PathVariable("serviceType") String serviceType, + @PathVariable("serviceInstanceId") String serviceInstanceId) { + + return aaiService.getServiceInstanceAssociatedPnfs(globalCustomerId, serviceType, serviceInstanceId); + } + + /** + * PNF section + */ + @RequestMapping(value = "/aai_get_pnfs/pnf/{pnf_id}", method = RequestMethod.GET) + public ResponseEntity getSpecificPnf(@PathVariable("pnf_id") String pnfId) { + AaiResponse resp; + ResponseEntity re; + try { + resp = aaiService.getSpecificPnf(pnfId); + re = new ResponseEntity<>(resp.getT(), HttpStatus.valueOf(resp.getHttpCode())); + } catch (Exception e){ + return new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + return re; + } + + + /** + * Obtain tenants for a given service type. + * + * @param globalCustomerId the global customer id + * @param serviceType the service type + * @return ResponseEntity The response entity + */ + @RequestMapping(value = "/aai_get_tenants/{global-customer-id}/{service-type}", method = RequestMethod.GET) + public ResponseEntity viewEditGetTenantsFromServiceType(HttpServletRequest request, + @PathVariable("global-customer-id") String globalCustomerId, @PathVariable("service-type") String serviceType) { + + ResponseEntity responseEntity; + try { + ObjectMapper objectMapper = new ObjectMapper(); + List roles = roleProvider.getUserRoles(request); + RoleValidator roleValidator = new RoleValidator(roles); + AaiResponse response = aaiService.getTenants(globalCustomerId, serviceType, roleValidator); + if (response.getHttpCode() == 200) { + responseEntity = new ResponseEntity(objectMapper.writeValueAsString(response.getT()), HttpStatus.OK); + } else { + responseEntity = new ResponseEntity(response.getErrorMessage(), HttpStatus.valueOf(response.getHttpCode())); + } + } catch (Exception e) { + responseEntity = new ResponseEntity("Unable to proccess getTenants reponse", HttpStatus.INTERNAL_SERVER_ERROR); + } + return responseEntity; + } + + @RequestMapping(value = "/aai_get_pnf_instances/{globalCustomerId}/{serviceType}/{modelVersionId}/{modelInvariantId}/{cloudRegion}/{equipVendor}/{equipModel}", method = RequestMethod.GET) + public ResponseEntity getPnfInstances( + @PathVariable("globalCustomerId") String globalCustomerId, + @PathVariable("serviceType") String serviceType, + @PathVariable("modelVersionId") String modelVersionId, + @PathVariable("modelInvariantId") String modelInvariantId, + @PathVariable("cloudRegion") String cloudRegion, + @PathVariable("equipVendor") String equipVendor, + @PathVariable("equipModel") String equipModel) { + + AaiResponse resp = aaiService.getPNFData(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor, equipModel); + return new ResponseEntity<>(resp.getT(), HttpStatus.valueOf(resp.getHttpCode())); + } + + @RequestMapping(value = "/aai_getPortMirroringConfigsData", method = RequestMethod.GET) + public Map getPortMirroringConfigsData( + @RequestParam ("configurationIds") List configurationIds) { + + return configurationIds.stream() + .map(id -> ImmutablePair.of(id, aaiService.getPortMirroringConfigData(id))) + .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); + } + + @RequestMapping(value = "/aai_getPortMirroringSourcePorts", method = RequestMethod.GET) + public Map getPortMirroringSourcePorts( + @RequestParam ("configurationIds") List configurationIds) { + + return configurationIds.stream() + .map(id -> ImmutablePair.of(id, aaiService.getPortMirroringSourcePorts(id))) + .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); + } + + private ResponseEntity convertResponseToResponseEntity(Response resp) { + ResponseEntity respEnt; + if (resp == null) { + respEnt = new ResponseEntity<>("Failed to fetch data from A&AI, check server logs for details.", HttpStatus.INTERNAL_SERVER_ERROR); + } else { + respEnt = new ResponseEntity<>(resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus())); + } + return respEnt; + } + + /** + * Gets the subscribers. + * + * @return the subscribers + */ + private Response getSubscribers() { + + String depth = "0"; + + Response resp = doAaiGet("business/customers?subscriber-type=INFRA&depth=" + depth, false); + if (resp != null) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== getSubscribers() resp=" + resp.getStatusInfo().toString()); + } + return resp; + } + + /** + * Send a GET request to a&ai. + * + * @param uri the uri + * @param xml the xml + * @return String The response + */ + protected Response doAaiGet(String uri, boolean xml) { + String methodName = "getSubscriberList"; + String transId = UUID.randomUUID().toString(); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " start"); + + Response resp = null; + try { + + + resp = aaiRestInterface.RestGet(fromAppId, transId, Unchecked.toURI(uri), xml).getResponse(); + + } catch (WebApplicationException e) { + final String message = e.getResponse().readEntity(String.class); + LOGGER.info(EELFLoggerDelegate.errorLogger, "<== " + "." + methodName + message); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + "." + methodName + message); + } catch (Exception e) { + LOGGER.info(EELFLoggerDelegate.errorLogger, "<== " + "." + methodName + e.toString()); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + "." + methodName + e.toString()); + } + + return resp; + } + + /** + * Send a POST request to a&ai. + * + * @param uri the uri + * @param payload the payload + * @param xml the xml + * @return String The response + */ + protected Response doAaiPost(String uri, String payload, boolean xml) { + String methodName = "getSubscriberList"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " start"); + + Response resp = null; + try { + + resp = aaiRestInterface.RestPost(fromAppId, uri, payload, xml); + + } catch (Exception e) { + LOGGER.info(EELFLoggerDelegate.errorLogger, "<== " + "." + methodName + e.toString()); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + "." + methodName + e.toString()); + } + + return resp; + } + + /** + * Gets the component list put payload. + * + * @param namedQueryId the named query id + * @param globalCustomerId the global customer id + * @param serviceType the service type + * @param serviceInstance the service instance + * @return the component list put payload + */ + private String getComponentListPutPayload(String namedQueryId, String globalCustomerId, String serviceType, String serviceInstance) { + return + " {" + + " \"instance-filters\": {" + + " \"instance-filter\": [" + + " {" + + " \"customer\": {" + + " \"global-customer-id\": \"" + globalCustomerId + "\"" + + " }," + + " \"service-instance\": {" + + " \"service-instance-id\": \"" + serviceInstance + "\"" + + " }," + + " \"service-subscription\": {" + + " \"service-type\": \"" + serviceType + "\"" + + " }" + + " }" + + " ]" + + " }," + + " \"query-parameters\": {" + + " \"named-query\": {" + + " \"named-query-uuid\": \"" + namedQueryId + "\"" + + " }" + + " }" + + "}"; + + } + + private String getModelsByServiceTypePayload(String namedQueryId, String globalCustomerId, String serviceType) { + // TODO Auto-generated method stub + return " {" + + " \"instance-filters\": {" + + " \"instance-filter\": [" + + " {" + + " \"customer\": {" + + " \"global-customer-id\": \"" + globalCustomerId + "\"" + + " }," + + " \"service-subscription\": {" + + " \"service-type\": \"" + serviceType + "\"" + + " }" + + " }" + + " ]" + + " }," + + " \"query-parameters\": {" + + " \"named-query\": {" + + " \"named-query-uuid\": \"" + namedQueryId + "\"" + + " }" + + " }" + + "}"; + + } + + private String getAaiErrorMessage(String message) { + try { + org.json.JSONObject json = new org.json.JSONObject(message); + json = json.getJSONObject("requestError").getJSONObject("serviceException"); + + return json.getString("messageId") + ": " + json.getString("text"); + + } catch (Exception e) { + return null; + } + } +} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java new file mode 100644 index 000000000..ee287703c --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.controller; + +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; +import org.onap.vid.aai.model.Permissions; +import org.onap.vid.model.aaiTree.RelatedVnf; +import org.onap.vid.roles.RoleProvider; +import org.onap.vid.services.AaiService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +/** + * Controller to handle a&ai new requests. + */ + +@RestController +public class AaiController2 extends VidRestrictedBaseController { + + private final AaiService aaiService; + private final RoleProvider roleProvider; + private final AaiClientInterface aaiClient; + + @Autowired + public AaiController2(AaiService aaiService, RoleProvider roleProvider, AaiClientInterface aaiClient) { + this.aaiService = aaiService; + this.roleProvider = roleProvider; + this.aaiClient = aaiClient; + } + + @RequestMapping(value = "/aai_get_homing_by_vfmodule/{vnfInstanceId}/{vfModuleId}", method = RequestMethod.GET) + public GetTenantsResponse getHomingDataByVfModule(@PathVariable("vnfInstanceId") String vnfInstanceId, + @PathVariable("vfModuleId") String vfModuleId){ + return aaiService.getHomingDataByVfModule(vnfInstanceId, vfModuleId); + } + + @RequestMapping(value = "/aai_get_service_instance_topology/{subscriberId}/{serviceType}/{serviceInstanceId}", + method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public String getServiceInstanceTree(@PathVariable("subscriberId") String globalCustomerId, + @PathVariable("serviceType") String serviceInstanceType, + @PathVariable("serviceInstanceId") String serviceInstanceId) { + return aaiService.getAAIServiceTree(globalCustomerId, serviceInstanceType, serviceInstanceId); + } + + @RequestMapping(value = "/aai_reset_cache/{cacheName}", method = RequestMethod.DELETE) + @ResponseStatus(HttpStatus.ACCEPTED) + public void resetCache(@PathVariable("cacheName") String cacheName) { + aaiClient.resetCache(cacheName); + } + + @RequestMapping(value = "/roles/service_permissions", method = RequestMethod.GET) + public Permissions servicePermissions(HttpServletRequest request, + @RequestParam(value = "subscriberId") String subscriberId, + @RequestParam(value = "serviceType") String serviceType) { + + final boolean isEditPermitted = roleProvider + .getUserRolesValidator(request) + .isServicePermitted(subscriberId, serviceType); + + return new Permissions(isEditPermitted); + } + + @RequestMapping(value = "/aai_search_group_members", + method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public List searchGroupMembers(@RequestParam("subscriberId") String globalCustomerId, + @RequestParam("serviceType") String serviceType, + @RequestParam("serviceInvariantId") String invariantId, + @RequestParam("groupType") String groupType, + @RequestParam("groupRole") String groupRole) { + return aaiService.searchGroupMembers(globalCustomerId, serviceType, invariantId, groupType, groupRole); + } + + +} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java new file mode 100644 index 000000000..974ac9883 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiServiceInstanceStandardQueryController.java @@ -0,0 +1,173 @@ +package org.onap.vid.controller; + + +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Network; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.ServiceInstance; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Vlan; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Vnf; +import org.onap.vid.aai.util.ServiceInstanceStandardQuery; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.VidNotions; +import org.onap.vid.properties.Features; +import org.onap.vid.services.VidService; +import org.onap.vid.utils.Multival; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.togglz.core.manager.FeatureManager; + +import javax.servlet.http.HttpServletRequest; +import java.util.Collection; +import java.util.Collections; +import java.util.UUID; + +import static java.util.stream.Collectors.toList; + + +@RestController +@RequestMapping(AaiServiceInstanceStandardQueryController.AAI_STANDARD_QUERY) +public class AaiServiceInstanceStandardQueryController extends VidRestrictedBaseController { + + public static final String AAI_STANDARD_QUERY = "aai/standardQuery"; + + private final ServiceInstanceStandardQuery serviceInstanceStandardQuery; + private final FeatureManager featureManager; + private final VidService sdcService; + + @Autowired + public AaiServiceInstanceStandardQueryController(FeatureManager featureManager, ServiceInstanceStandardQuery serviceInstanceStandardQuery, VidService sdcService) { + this.featureManager = featureManager; + this.serviceInstanceStandardQuery = serviceInstanceStandardQuery; + this.sdcService = sdcService; + } + + @RequestMapping(value = "vlansByNetworks", method = RequestMethod.GET) + public VlansByNetworksHierarchy getNetworksToVlansByServiceInstance(HttpServletRequest request, + @RequestParam("sdcModelUuid") UUID sdcModelUuid, + @RequestParam("globalCustomerId") String globalCustomerId, + @RequestParam("serviceType") String serviceType, + @RequestParam("serviceInstanceId") String serviceInstanceId + ) throws AsdcCatalogException { + if (!featureManager.isActive(Features.FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS)) { + return new VlansByNetworksHierarchy(); + } + + if (!isModelOf5g(sdcModelUuid)) { + return new VlansByNetworksHierarchy(); + } + + final ServiceInstance serviceInstance = + serviceInstanceStandardQuery.fetchServiceInstance(globalCustomerId, serviceType, serviceInstanceId); + + Multival>> l3NetworksWithVlansForVnfForService = fetchVnfsForService(serviceInstance); + Multival> l3NetworksWithVlansForService = fetchNetworksForService(serviceInstance); + + // translate to response's format + return new VlansByNetworksHierarchy( + l3NetworksWithVlansForService.getValues().stream().map(this::translateNetworksFormat + ).collect(toList()), + + l3NetworksWithVlansForVnfForService.getValues().stream().map(vnfWithNetworks -> + new VnfVlansByNetworks(vnfWithNetworks.getKey().getVnfId(), + vnfWithNetworks.getValues().stream().map(this::translateNetworksFormat + ).collect(toList()) + ) + ).collect(toList()) + ); + } + + private Multival>> fetchVnfsForService(ServiceInstance serviceInstance) { + final Multival vnfsForService = + serviceInstanceStandardQuery.fetchRelatedVnfs(serviceInstance); + + final Multival> vnfsWithL3NetworksForService = + vnfsForService.mapEachVal(vnf -> serviceInstanceStandardQuery.fetchRelatedL3Networks("vnf", vnf)); + + return vnfsWithL3NetworksForService.mapEachVal(vnfMulti-> + vnfMulti.mapEachVal(serviceInstanceStandardQuery::fetchRelatedVlanTags) + ); + + } + + private Multival> fetchNetworksForService(ServiceInstance serviceInstance) { + final Multival l3NetworksForService = + serviceInstanceStandardQuery.fetchRelatedL3Networks("service", serviceInstance); + + return l3NetworksForService.mapEachVal(serviceInstanceStandardQuery::fetchRelatedVlanTags); + } + + private NetworksToVlans translateNetworksFormat(Multival networkWithVlan) { + return new NetworksToVlans( + networkWithVlan.getKey().getNetworkId(), + networkWithVlan.getKey().getNetworkName(), + networkWithVlan.getKey().getNetworkType(), + networkWithVlan.getKey().getOrchestrationStatus(), + networkWithVlan.getValues().stream().map( + vlan -> new NetworksToVlans.Vlan(vlan.getVlanIdInner()) + ).collect(toList()) + ); + } + + protected boolean isModelOf5g(UUID sdcModelUuid) throws AsdcCatalogException { + final ServiceModel serviceModel = sdcService.getService(sdcModelUuid.toString()); + if (serviceModel == null) { + throw new GenericUncheckedException("Internal error while fetching Service Model: " + sdcModelUuid); + } + VidNotions.ModelCategory serviceModelCategory = serviceModel.getService().getVidNotions().getModelCategory(); + return serviceModelCategory.equals(VidNotions.ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL) || + serviceModelCategory.equals(VidNotions.ModelCategory.IS_5G_FABRIC_CONFIGURATION_MODEL); + } + + protected static class VlansByNetworksHierarchy { + public final Collection serviceNetworks; + public final Collection vnfNetworks; + + public VlansByNetworksHierarchy() { + this(Collections.emptySet(), Collections.emptySet()); + } + + public VlansByNetworksHierarchy(Collection serviceNetworks, Collection vnfNetworks) { + this.serviceNetworks = serviceNetworks; + this.vnfNetworks = vnfNetworks; + } + } + + protected static class VnfVlansByNetworks { + public final String vnfId; + public final Collection networks; + + public VnfVlansByNetworks(String vnfId, Collection networks) { + this.vnfId = vnfId; + this.networks = networks; + } + } + + protected static class NetworksToVlans { + public final String networkId; + public final String name; + public final String nodeType; + public final String nodeStatus; + public final Collection vlans; + + private NetworksToVlans(String networkId, String name, String nodeType, String nodeStatus, Collection vlans) { + this.networkId = networkId; + this.name = name; + this.nodeType = nodeType; + this.nodeStatus = nodeStatus; + this.vlans = vlans; + } + + private static class Vlan { + public final String vlanIdInner; + + private Vlan(String vlanIdInner) { + this.vlanIdInner = vlanIdInner; + } + } + + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncControllerForTests.java b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncControllerForTests.java new file mode 100644 index 000000000..a67686a90 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncControllerForTests.java @@ -0,0 +1,48 @@ +package org.onap.vid.controller; + +import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.model.ExceptionResponse; +import org.onap.vid.model.JobModel; +import org.onap.vid.services.BulkInstantiationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.ws.rs.WebApplicationException; +import java.util.UUID; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; + +@RestController +@RequestMapping("asyncForTests") +public class AsyncControllerForTests extends VidRestrictedBaseController { + + private BulkInstantiationService bulkInstantiationService; + + @Autowired + public AsyncControllerForTests(BulkInstantiationService bulkInstantiationService) { + this.bulkInstantiationService = bulkInstantiationService; + } + + @RequestMapping(value = "/job/{uuid}", method = RequestMethod.GET) + public JobModel getJob(@PathVariable UUID uuid) { + return bulkInstantiationService.getJob(uuid); + } + + @RequestMapping(value = "/error", method = RequestMethod.GET) + public void throwError() { + throw new GenericUncheckedException("dummy error"); + } + + @ExceptionHandler({IllegalArgumentException.class}) + @ResponseStatus(value=BAD_REQUEST) + private ExceptionResponse exceptionHandlerBadRequest(Exception e) { + return ControllersUtils.handleException(e, LOGGER); + } + + @ExceptionHandler(WebApplicationException.class) + private ResponseEntity webApplicationExceptionHandler(WebApplicationException e) { + return ControllersUtils.handleWebApplicationException(e, LOGGER); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java new file mode 100644 index 000000000..dcfc13b3b --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java @@ -0,0 +1,104 @@ +package org.onap.vid.controller; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.exceptions.OperationNotAllowedException; +import org.onap.vid.model.ExceptionResponse; +import org.onap.vid.model.JobAuditStatus; +import org.onap.vid.model.ServiceInfo; +import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; +import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.onap.vid.services.AuditService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; +import java.util.UUID; + +import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED; + + +@RestController +@RequestMapping(AsyncInstantiationController.ASYNC_INSTANTIATION) +public class AsyncInstantiationController extends VidRestrictedBaseController { + + public static final String ASYNC_INSTANTIATION = "asyncInstantiation"; + + protected final AsyncInstantiationBusinessLogic asyncInstantiationBL; + + protected ObjectMapper objectMapper = new ObjectMapper(); + + @Autowired + protected AuditService auditService; + + @Autowired + public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL) { + this.asyncInstantiationBL = asyncInstantiationBL; + } + + @ExceptionHandler(OperationNotAllowedException.class) + @ResponseStatus(value=METHOD_NOT_ALLOWED) + public ExceptionResponse illegalStateExceptionHandler(Exception e) { + return ControllersUtils.handleException(e, LOGGER); + } + + /** + * Gets the new services status. + * @param request the request + * @return the services list + */ + @RequestMapping(method = RequestMethod.GET) + public List getServicesInfo(HttpServletRequest request) { + return asyncInstantiationBL.getAllServicesInfo(); + } + + @RequestMapping(value = "bulk", method = RequestMethod.POST) + public MsoResponseWrapper2> createBulkOfServices(@RequestBody ServiceInstantiation request, HttpServletRequest httpServletRequest) { + //Push to DB according the model + try { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "incoming ServiceInstantiation request: "+ objectMapper.writeValueAsString(request)); + } + catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to log incoming ServiceInstantiation request ", e); + } + String userId = ControllersUtils.extractUserId(httpServletRequest); + List uuids = asyncInstantiationBL.pushBulkJob(request, userId); + + return new MsoResponseWrapper2(200, uuids); + } + + @RequestMapping(value = "job/{jobId}", method = RequestMethod.DELETE) + public void deleteServiceInfo(@PathVariable("jobId") UUID jobId) { + asyncInstantiationBL.deleteJob(jobId); + } + + @RequestMapping(value = "hide/{jobId}", method = RequestMethod.POST) + public void hideServiceInfo(@PathVariable("jobId") UUID jobId) { + asyncInstantiationBL.hideServiceInfo(jobId); + } + + @RequestMapping(value = "auditStatus/{jobId}", method = RequestMethod.GET) + public List getJobAuditStatus(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId, @RequestParam(value="source") JobAuditStatus.SourceStatus source){ + return asyncInstantiationBL.getAuditStatuses(jobId, source); + } + + @RequestMapping(value = "auditStatus/{jobId}/mso", method = RequestMethod.GET) + public List getJobMsoAuditStatusForAlaCarte(HttpServletRequest request, + @PathVariable(value="jobId") UUID jobId, + @RequestParam(value="requestId", required = false) UUID requestId, + @RequestParam(value="serviceInstanceId", required = false) UUID serviceInstanceId){ + if (serviceInstanceId != null) { + return auditService.getAuditStatusFromMsoByServiceInstanceId(jobId, serviceInstanceId); + } + if (requestId != null){ + return auditService.getAuditStatusFromMsoByRequestId(jobId, requestId); + } + return auditService.getAuditStatusFromMsoByJobId(jobId); + + } + + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/ChangeManagementController.java b/vid-app-common/src/main/java/org/onap/vid/controller/ChangeManagementController.java new file mode 100644 index 000000000..90a175f65 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/ChangeManagementController.java @@ -0,0 +1,213 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.controller; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.onap.portalsdk.core.controller.UnRestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.changeManagement.*; +import org.onap.vid.exceptions.NotFoundException; +import org.onap.vid.model.ExceptionResponse; +import org.onap.vid.model.MsoExceptionResponse; +import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.mso.MsoResponseWrapperInterface; +import org.onap.vid.mso.rest.Request; +import org.onap.vid.services.ChangeManagementService; +import org.onap.vid.services.WorkflowService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.WebApplicationException; +import java.util.Collection; +import java.util.Collections; + +import static org.onap.vid.utils.Logging.getMethodName; +import static org.springframework.http.HttpStatus.*; + +/** + * Controller to handle ChangeManagement feature requests. + */ +@RestController +@RequestMapping(ChangeManagementController.CHANGE_MANAGEMENT) +public class ChangeManagementController extends UnRestrictedBaseController { + public static final String VNF_WORKFLOW_RELATION = "vnf_workflow_relation"; + public static final String CHANGE_MANAGEMENT = "change-management"; + public static final String GET_VNF_WORKFLOW_RELATION = "get_vnf_workflow_relation"; + public static final String SCHEDULER_BY_SCHEDULE_ID = "/scheduler/schedules/{scheduleId}"; + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ChangeManagementController.class); + private String fromAppId; + private final WorkflowService workflowService; + private final ChangeManagementService changeManagementService; + private final ObjectMapper objectMapper; + + + @Autowired + public ChangeManagementController(WorkflowService workflowService, ChangeManagementService changeManagementService, ObjectMapper objectMapper) { + this.fromAppId = "VidChangeManagementController"; + this.workflowService = workflowService; + this.changeManagementService = changeManagementService; + this.objectMapper = objectMapper; + } + + @RequestMapping(value = {"/workflow"}, method = RequestMethod.GET) + public ResponseEntity> getWorkflow(@RequestParam("vnfs") Collection vnfs) { + Collection result = this.workflowService.getWorkflowsForVNFs(vnfs); + return new ResponseEntity<>(result, OK); + } + + @RequestMapping(value = {"/mso"}, method = RequestMethod.GET) + public ResponseEntity> getMSOChangeManagements() { + + Collection result = this.changeManagementService.getMSOChangeManagements(); + return new ResponseEntity<>(result, OK); + } + + @RequestMapping(value = "/workflow/{vnfName}", method = RequestMethod.POST) + public ResponseEntity changeManagement(HttpServletRequest request, + @PathVariable("vnfName") String vnfName, + @RequestBody ChangeManagementRequest changeManagmentRequest) + throws Exception { + return this.changeManagementService.doChangeManagement(changeManagmentRequest, vnfName); + } + + @RequestMapping(value = "/uploadConfigUpdateFile", method = RequestMethod.POST) + public @ResponseBody ResponseEntity uploadConfigUpdateFile(@RequestPart("file") MultipartFile file) + throws Exception { + try { + String jsonString = this.changeManagementService.uploadConfigUpdateFile(file); + return new ResponseEntity<>(jsonString, HttpStatus.OK); + } + catch(WebApplicationException e){ + return new ResponseEntity<>(handleException(e), HttpStatus.valueOf(e.getResponse().getStatus())); + } + catch (Exception e) { + return new ResponseEntity<>(handleException(e), INTERNAL_SERVER_ERROR); + } + } + + + @RequestMapping(value = {"/scheduler"}, method = RequestMethod.GET) + public ResponseEntity getSchedulerChangeManagements() { + ArrayNode result = this.changeManagementService.getSchedulerChangeManagements(); + return new ResponseEntity<>(result, OK); + } + + @RequestMapping(value = {SCHEDULER_BY_SCHEDULE_ID}, method = RequestMethod.DELETE) + public ResponseEntity deleteSchedule(@PathVariable("scheduleId") String scheduleId) { + Pair result = this.changeManagementService.deleteSchedule(scheduleId); + return ResponseEntity.status(result.getRight()).build(); + } + + + @RequestMapping(value = {GET_VNF_WORKFLOW_RELATION}, method = RequestMethod.POST) + public ResponseEntity getWorkflows(@RequestBody GetVnfWorkflowRelationRequest getVnfWorkflowRelationRequest) { + try { + GetWorkflowsResponse response = new GetWorkflowsResponse(changeManagementService.getWorkflowsForVnf(getVnfWorkflowRelationRequest)); + return ResponseEntity.status(OK).body(response); + } + catch (NotFoundException exception) { + LOGGER.error(exception.getMessage(), exception); + return new ResponseEntity<>(new VnfWorkflowRelationResponse(Collections.singletonList(exception.getMessage())),HttpStatus.NOT_FOUND); + } + catch (Exception exception) { + return handleException(exception, "Failed to get workflows for vnf"); + } + } + + @RequestMapping(value = {VNF_WORKFLOW_RELATION}, method = RequestMethod.POST) + public ResponseEntity createWorkflowRelation(@RequestBody VnfWorkflowRelationRequest vnfWorkflowRelationRequest) { + VnfWorkflowRelationResponse vnfWorkflowRelationResponse; + try { + vnfWorkflowRelationResponse = changeManagementService.addVnfWorkflowRelation(vnfWorkflowRelationRequest); + } + catch (Exception exception) { + return handleException(exception, "Failed to add vnf to workflow relation"); + } + + return new ResponseEntity<>(vnfWorkflowRelationResponse, OK); + } + + @RequestMapping(value = {VNF_WORKFLOW_RELATION}, method = RequestMethod.GET) + public ResponseEntity getAllWorkflowRelation() { + + try { + VnfWorkflowRelationAllResponse vnfWorkflowRelationAllResponse = changeManagementService.getAllVnfWorkflowRelations(); + return new ResponseEntity<>(vnfWorkflowRelationAllResponse, OK); + } + catch (Exception exception) { + return handleException(exception, "Failed to get all vnf to workflow relations"); + } + } + + @RequestMapping(value = {VNF_WORKFLOW_RELATION}, method = RequestMethod.DELETE) + public ResponseEntity deleteWorkflowRelation(@RequestBody VnfWorkflowRelationRequest vnfWorkflowRelationRequest) { + VnfWorkflowRelationResponse vnfWorkflowRelationResponse; + try { + vnfWorkflowRelationResponse = changeManagementService.deleteVnfWorkflowRelation(vnfWorkflowRelationRequest); + } + catch (Exception exception) { + return handleException(exception, "Failed to delete vnf from workflow relation"); + } + + return new ResponseEntity<>(vnfWorkflowRelationResponse, OK); + } + + private ResponseEntity handleException(Exception exception, String msg) { + LOGGER.error(msg, exception); + return new ResponseEntity<>(new VnfWorkflowRelationResponse(Collections.singletonList(msg)), HttpStatus.INTERNAL_SERVER_ERROR); + } + + + private ExceptionResponse handleException(Exception e) { + return ControllersUtils.handleException(e, LOGGER); + } + + @ExceptionHandler(Exception.class) + @ResponseStatus(value=OK) //return 200 for Backwards compatibility with the previous responses to scheduler + private MsoResponseWrapperInterface exceptionHandler(Exception e) { + return exceptionHandler(e, INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler({ + javax.ws.rs.BadRequestException.class, + }) + @ResponseStatus(value = OK) //return 200 for Backwards compatibility with the previous responses to scheduler + public MsoResponseWrapperInterface clientDerivedExceptionAsBadRequest(Exception e) { + // same handler, different HTTP Code + return exceptionHandler(e, BAD_REQUEST); + } + + private MsoResponseWrapperInterface exceptionHandler(Exception e, HttpStatus httpStatus) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodName(), ExceptionUtils.getMessage(e), e); + MsoResponseWrapper2 responseWrapper2 = new MsoResponseWrapper2<>(httpStatus.value(), new MsoExceptionResponse(e)); + return responseWrapper2; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java b/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java new file mode 100644 index 000000000..9be6ad51f --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java @@ -0,0 +1,45 @@ +package org.onap.vid.controller; + +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.model.ExceptionResponse; +import org.springframework.http.ResponseEntity; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import javax.ws.rs.WebApplicationException; + +import static org.onap.vid.utils.Logging.getMethodCallerName; + +public class ControllersUtils { + + + public static String extractUserId(HttpServletRequest request) { + String userId = ""; + HttpSession session = request.getSession(); + if (session != null) { + User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)); + if (user != null) { + //userId = user.getHrid(); + userId = user.getLoginId(); + if (userId == null) + userId = user.getOrgUserId(); + } + } + return userId; + } + + public static ExceptionResponse handleException(Exception e, EELFLoggerDelegate logger) { + logger.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodCallerName(), ExceptionUtils.getMessage(e), e); + + ExceptionResponse exceptionResponse = new ExceptionResponse(e); + return exceptionResponse; + } + + public static ResponseEntity handleWebApplicationException(WebApplicationException e, EELFLoggerDelegate logger) { + return ResponseEntity.status(e.getResponse().getStatus()).body(ControllersUtils.handleException(e, logger)); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/FeatureTogglingController.java b/vid-app-common/src/main/java/org/onap/vid/controller/FeatureTogglingController.java new file mode 100644 index 000000000..a90e71d48 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/FeatureTogglingController.java @@ -0,0 +1,29 @@ +package org.onap.vid.controller; + +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.vid.properties.Features; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; + +@RestController +@RequestMapping("flags") +public class FeatureTogglingController extends RestrictedBaseController { + + @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody Map getFeatureToggles() + { + HashMap flags = new HashMap <>(); + for(Features flag : Features.values()){ + flags.put(flag.name(), flag.isActive()); + } + return flags; + + + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/HealthCheckController.java b/vid-app-common/src/main/java/org/onap/vid/controller/HealthCheckController.java new file mode 100644 index 000000000..2c42da279 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/HealthCheckController.java @@ -0,0 +1,135 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.controller; + +import org.onap.portalsdk.core.controller.UnRestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.dao.FnAppDoaImpl; +import org.onap.vid.model.GitRepositoryState; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; + +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.OK; + +/** + * Controller for user profile view. The view is restricted to authenticated + * users. The view name resolves to page user_profile.jsp which uses Angular. + */ + +@RestController +@RequestMapping("/") +public class HealthCheckController extends UnRestrictedBaseController { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(HealthCheckController.class); + private static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + private static final String GIT_PROPERTIES_FILENAME = "git.properties"; + private FnAppDoaImpl fnAppDoaImpl; + + @Autowired + public HealthCheckController(FnAppDoaImpl fnAppDoaImpl) { + this.fnAppDoaImpl = fnAppDoaImpl; + } + + /** + * Obtain the HealthCheck Status from the System.Properties file. + * Used by IDNS for redundancy + * + * @return ResponseEntity The response entity + */ + @RequestMapping(value = "/healthCheck", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public HealthStatus getHealthCheckStatusForIDNS() { + return createCorrespondingStatus(); + } + + /** + * Obtain the HealthCheck Status from the System.Properties file. + * + * @return ResponseEntity The response entity + */ + @RequestMapping(value = "rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public HealthStatus getHealthCheck( + @PathVariable("User-Agent") String UserAgent, + @PathVariable("X-ECOMP-RequestID") String ECOMPRequestID) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "User-Agent ", UserAgent); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "X-ECOMP-RequestID ", ECOMPRequestID); + return createCorrespondingStatus(); + } + + @RequestMapping(value = "/commitInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public GitRepositoryState getCommitInfo() throws IOException { + Properties properties = new Properties(); + properties.load(getClass().getClassLoader().getResourceAsStream(GIT_PROPERTIES_FILENAME)); + return new GitRepositoryState(properties); + } + + private HealthStatus createCorrespondingStatus() { + logData(); + try { + int count = fnAppDoaImpl.getProfileCount(getUrl(), getUsername(), getPassword()); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "count:::", count); + return okStatus(); + } catch (Exception ex) { + String errorMsg = ex.getMessage(); + LOGGER.error(EELFLoggerDelegate.errorLogger, errorMsg); + return errorStatus(errorMsg); + } + } + + private void logData() { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check"); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::", getUrl()); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::", getUsername()); + } + + private HealthStatus okStatus() { + return new HealthStatus(OK, dateFormat.format(new Date()), "health check succeeded"); + } + + private HealthStatus errorStatus(String msg) { + return new HealthStatus(INTERNAL_SERVER_ERROR, dateFormat.format( + new Date()), "health check failed: " + msg); + } + + private String getUrl() { + return SystemProperties.getProperty("db.connectionURL"); + } + + private String getUsername() { + return SystemProperties.getProperty("db.userName"); + } + + private String getPassword() { + return SystemProperties.getProperty("db.password"); + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/HealthStatus.java b/vid-app-common/src/main/java/org/onap/vid/controller/HealthStatus.java new file mode 100644 index 000000000..14372b5de --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/HealthStatus.java @@ -0,0 +1,31 @@ +package org.onap.vid.controller; + +import org.springframework.http.HttpStatus; + +/** + * Model for JSON response with health-check results. + */ +public final class HealthStatus { + + private final int statusCode; + private final String detailedMsg; + private final String date; + + public HealthStatus(HttpStatus code, String date, String detailedMsg) { + this.statusCode = code.value(); + this.detailedMsg = detailedMsg; + this.date = date; + } + + public int getStatusCode() { + return statusCode; + } + + public String getDetailedMsg() { + return detailedMsg; + } + + public String getDate() { + return date; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java b/vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java new file mode 100644 index 000000000..698ea5469 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/LoggerController.java @@ -0,0 +1,115 @@ +package org.onap.vid.controller; + +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.core.Appender; +import ch.qos.logback.core.FileAppender; +import ch.qos.logback.core.spi.AppenderAttachable; +import org.apache.commons.io.input.ReversedLinesFileReader; +import org.apache.commons.lang3.StringUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.model.ExceptionResponse; +import org.onap.vid.roles.Role; +import org.onap.vid.roles.RoleProvider; +import org.onap.vid.utils.Streams; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.NotAuthorizedException; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Objects; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.att.eelf.configuration.Configuration.GENERAL_LOGGER_NAME; + + +@RestController +@RequestMapping("logger") +public class LoggerController extends RestrictedBaseController { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(LoggerController.class); + + @Autowired + RoleProvider roleProvider; + + @RequestMapping(value = "/{loggerName:audit|error|metrics}", method = RequestMethod.GET) + public String getLog(@PathVariable String loggerName, HttpServletRequest request, + @RequestParam(value="limit", defaultValue = "5000") Integer limit) throws IOException { + + List roles = roleProvider.getUserRoles(request); + boolean userPermitted = roleProvider.userPermissionIsReadLogs(roles); + if (!userPermitted) { + throw new NotAuthorizedException("User not authorized to get logs"); + } + + String logfilePath = getLogfilePath(loggerName); + + try (final ReversedLinesFileReader reader = new ReversedLinesFileReader(new File(logfilePath))) { + Supplier reverseLinesSupplier = () -> { + try { + return reader.readLine(); + } catch (NullPointerException e) { + // EOF Reached + return null; + } catch (IOException e) { + throw new InternalServerErrorException("error while reading " + logfilePath, e); + } + }; + + return Streams.takeWhile( + Stream.generate(reverseLinesSupplier), + line -> !StringUtils.contains(line, "Logging is started")) + .limit(limit) + .limit(5_000) + .filter(Objects::nonNull) + .collect(Collectors.joining("\n")); + } + } + + private String getLogfilePath(String loggerName) { + /* + Find the requested logger, and pull all of it's appenders. + Find the first of the appenders that is a FileAppender, and return it's + write-out filename. + */ + LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); + return context.getLoggerList().stream() + .filter(logger -> logger.getName().equals(GENERAL_LOGGER_NAME + "." + loggerName)) + .flatMap(this::pullSubAppenders) + .flatMap(appender -> { + // Appender might be "attachable", if so - roll-up its sub-appenders + return (appender instanceof AppenderAttachable) ? + pullSubAppenders((AppenderAttachable) appender) : Stream.of(appender); + }) + .filter(appender -> appender instanceof FileAppender) + .map(appender -> (FileAppender) appender) + .map(FileAppender::getFile) + .findFirst() + .orElseThrow(() -> new InternalServerErrorException("logfile for " + loggerName + " not found")); + } + + private Stream> pullSubAppenders(AppenderAttachable logger) { + return Streams.fromIterator(logger.iteratorForAppenders()); + } + + @ExceptionHandler({ NotAuthorizedException.class }) + @ResponseStatus(HttpStatus.UNAUTHORIZED) + public String notAuthorizedHandler(NotAuthorizedException e) { + return "UNAUTHORIZED"; + } + + @ExceptionHandler({ IOException.class, InternalServerErrorException.class }) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public ExceptionResponse ioExceptionHandler(Exception e) { + return ControllersUtils.handleException(e, LOGGER); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/MaintenanceController.java b/vid-app-common/src/main/java/org/onap/vid/controller/MaintenanceController.java new file mode 100644 index 000000000..40b7834d4 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/MaintenanceController.java @@ -0,0 +1,152 @@ +package org.onap.vid.controller; + +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ + * 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========================================================= + */ + +import org.onap.portalsdk.core.controller.UnRestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.category.AddCategoryOptionResponse; +import org.onap.vid.category.AddCategoryOptionsRequest; +import org.onap.vid.category.CategoryParameterOptionRep; +import org.onap.vid.category.CategoryParametersResponse; +import org.onap.vid.model.CategoryParameter.Family; +import org.onap.vid.model.CategoryParameterOption; +import org.onap.vid.services.CategoryParameterService; +import org.onap.vid.services.CategoryParameterServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.ws.rs.ForbiddenException; + +import static org.onap.vid.utils.Logging.getMethodCallerName; + +/** + * Controler for APIs that are used only by vid operators + */ + +@RestController +@RequestMapping("maintenance") +public class MaintenanceController extends UnRestrictedBaseController { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(MaintenanceController.class); + private CategoryParameterService categoryParameterService; + + @Autowired + public MaintenanceController(CategoryParameterService categoryParameterService) { + this.categoryParameterService = categoryParameterService; + } + + /** + * Add list of options to one category parameter + */ + @RequestMapping(value = "/category_parameter/{categoryName}", method = RequestMethod.POST) + public ResponseEntity addCategoryOptions(@PathVariable String categoryName, + @RequestBody AddCategoryOptionsRequest option) { + debugStartLog(); + try { + AddCategoryOptionResponse response = categoryParameterService + .createCategoryParameterOptions(categoryName, option); + HttpStatus httpStatus = response.getErrors().isEmpty() ? HttpStatus.OK : HttpStatus.MULTI_STATUS; + debugEndLog(response); + return createResponseWithBody(httpStatus, response); + } catch (CategoryParameterServiceImpl.UnfoundedCategoryException exception) { + return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); + } catch (RuntimeException exception) { + LOGGER.error("failed to add option to parameter category " + categoryName, exception); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + @RequestMapping(value = "/category_parameter/{categoryName}", method = RequestMethod.PUT) + public ResponseEntity updateNameForOption(@PathVariable String categoryName, + @RequestBody CategoryParameterOptionRep option) { + debugStartLog(); + try { + AddCategoryOptionResponse response = categoryParameterService + .updateCategoryParameterOption(categoryName, option); + HttpStatus httpStatus = response.getErrors().isEmpty() ? HttpStatus.OK : HttpStatus.MULTI_STATUS; + debugEndLog(response); + return createResponseWithBody(httpStatus, response); + } catch (ForbiddenException exception) { + return createResponseWithBody(HttpStatus.FORBIDDEN, new AddCategoryOptionResponse(exception.getMessage())); + } catch (CategoryParameterServiceImpl.UnfoundedCategoryException | CategoryParameterServiceImpl.UnfoundedCategoryOptionException exception) { + return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); + + } catch (CategoryParameterServiceImpl.AlreadyExistOptionNameException exception) { + return createResponseWithBody(HttpStatus.CONFLICT, new AddCategoryOptionResponse(exception.getMessage())); + + } catch (RuntimeException exception) { + LOGGER.error("failed to update option to parameter category " + categoryName, exception); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + /** + * Gets the owning entity properties. + */ + @RequestMapping(value = "/category_parameter", method = RequestMethod.GET) + public ResponseEntity getCategoryParameter(@RequestParam(value = "familyName", required = true) Family familyName) { + debugStartLog(); + try { + CategoryParametersResponse response = categoryParameterService.getCategoryParameters(familyName); + debugEndLog(response); + return ResponseEntity.ok().body(response); + } catch (RuntimeException exception) { + LOGGER.error("failed to retrieve category parameter list from DB.", exception); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + /** + * Delete option of the category. + */ + @RequestMapping(value = "/delete_category_parameter/{categoryName}", method = RequestMethod.DELETE) + public ResponseEntity deleteCategoryOption(@PathVariable String categoryName, + @RequestBody CategoryParameterOption option) { + debugStartLog(); + + try { + categoryParameterService.deleteCategoryOption(categoryName, option); + debugEndLog(HttpStatus.OK); + return ResponseEntity.status(HttpStatus.OK).build(); + } catch (CategoryParameterServiceImpl.UnfoundedCategoryException exception) { + return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); + } catch (RuntimeException exception) { + LOGGER.error("failed to add/update owning entity option", exception); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } + + private ResponseEntity createResponseWithBody(HttpStatus status, AddCategoryOptionResponse response) { + return ResponseEntity.status(status).body(response); + } + + private void debugStartLog() { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodCallerName()); + } + + private void debugEndLog(Object response) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodCallerName(), response); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java new file mode 100644 index 000000000..7f90d6a43 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.vid.controller; + +import io.joshworks.restclient.http.mapper.ObjectMapper; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.client.SyncRestClient; +import org.onap.vid.factories.MsoRequestFactory; +import org.onap.vid.mso.MsoBusinessLogic; +import org.onap.vid.mso.MsoBusinessLogicImpl; +import org.onap.vid.mso.MsoInterface; +import org.onap.vid.mso.MsoProperties; +import org.onap.vid.mso.rest.MsoRestClientNew; +import org.onap.vid.services.CloudOwnerService; +import org.onap.vid.services.CloudOwnerServiceImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.togglz.core.manager.FeatureManager; + + +@Configuration +public class MsoConfig { + + @Bean + public MsoRequestFactory createRequestDetailsFactory(){ + return new MsoRequestFactory(); + } + + @Bean + public MsoRestClientNew msoClient(ObjectMapper unirestObjectMapper){ + // Satisfy both interfaces -- MsoInterface and RestMsoImplementation + return new MsoRestClientNew(new SyncRestClient(unirestObjectMapper), SystemProperties.getProperty( + MsoProperties.MSO_SERVER_URL)); + } + + @Bean + public MsoBusinessLogic getMsoBusinessLogic(MsoInterface msoClient, FeatureManager featureManager){ + return new MsoBusinessLogicImpl(msoClient, featureManager); + } + + @Bean + public CloudOwnerService cloudOwnerService(AaiClientInterface aaiClient, FeatureManager featureManager) { + return new CloudOwnerServiceImpl(aaiClient, featureManager); + } + + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java b/vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java new file mode 100644 index 000000000..716267afa --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/MsoController.java @@ -0,0 +1,705 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.controller; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.model.ExceptionResponse; +import org.onap.vid.model.SoftDeleteRequest; +import org.onap.vid.mso.MsoBusinessLogic; +import org.onap.vid.mso.MsoResponseWrapper; +import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.mso.rest.Request; +import org.onap.vid.mso.rest.RequestDetails; +import org.onap.vid.mso.rest.RequestDetailsWrapper; +import org.onap.vid.mso.rest.Task; +import org.onap.vid.services.CloudOwnerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.List; + +import static org.onap.vid.utils.Logging.getMethodName; + +/** + * The Class MsoController. + */ +@RestController +@RequestMapping("mso") +public class MsoController extends RestrictedBaseController { + + /** + * The logger. + */ + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(MsoController.class); + + /** + * The Constant SVC_INSTANCE_ID. + */ + public static final String SVC_INSTANCE_ID = ""; + public static final String REQUEST_TYPE = ""; + + /** + * The Constant CONFIGURATION_ID + */ + public static final String CONFIGURATION_ID = ""; + + /** + * The Constant VNF_INSTANCE_ID. + */ + public static final String VNF_INSTANCE_ID = ""; + public static final String START_LOG = " start"; + + private final MsoBusinessLogic msoBusinessLogic; + private final CloudOwnerService cloudOwnerService; + + @Autowired + public MsoController(MsoBusinessLogic msoBusinessLogic, CloudOwnerService cloudOwnerService) { + this.msoBusinessLogic = msoBusinessLogic; + this.cloudOwnerService = cloudOwnerService; + } + + /** + * Creates the svc instance. + * + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST) + public ResponseEntity createSvcInstance(HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + String methodName = "createSvcInstance"; + + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + // always return OK, the MSO status code is embedded in the body + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.createSvcInstance(msoRequest); + + return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK)); + + } + + /** + * Creates the e2e svc instance. + * + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_create_e2e_svc_instance", method = RequestMethod.POST) + public ResponseEntity createE2eSvcInstance(HttpServletRequest request, @RequestBody LinkedHashMap msoRequest) { + String methodName = "createE2eSvcInstance"; + + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + // always return OK, the MSO status code is embedded in the body + + //cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.createE2eSvcInstance(msoRequest.get("requestDetails")); + + return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK)); + + } + + /** + * Creates the vnf. + * + * @param serviceInstanceId the service instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST) + public ResponseEntity createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.createVnf(msoRequest, serviceInstanceId); + + // always return OK, the MSO status code is embedded in the body + + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + + } + + /** + * Creates the nw instance. + * + * @param serviceInstanceId the service instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST) + public ResponseEntity createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + String methodName = "createNwInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId); + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.createNwInstance(msoRequest, serviceInstanceId); + + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + + } + + /** + * Creates the volume group instance. + * + * @param serviceInstanceId the service instance id + * @param vnfInstanceId the vnf instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST) + public ResponseEntity createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, + HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + String methodName = "createVolumeGroupInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.createVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Creates the vf module instance. + * + * @param serviceInstanceId the service instance id + * @param vnfInstanceId the vnf instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST) + public ResponseEntity createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, + @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + String methodName = "createVfModuleInstance"; + + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.createVfModuleInstance(msoRequest, serviceInstanceId, vnfInstanceId); + + // always return OK, the MSO status code is embedded in the body + + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Creates a configuration instance. + * + * @param serviceInstanceId the service instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_create_configuration_instance/{serviceInstanceId}/configurations/", method = RequestMethod.POST) + public ResponseEntity createConfigurationInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, + HttpServletRequest request, @RequestBody RequestDetailsWrapper msoRequest) { + String methodName = "createConfigurationInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest.getRequestDetails()); + MsoResponseWrapper w = msoBusinessLogic.createConfigurationInstance(msoRequest, serviceInstanceId); + + // always return OK, the MSO status code is embedded in the body + + return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK)); + } + + /** + * Delete E2e svc instance. + * + * @param serviceInstanceId the service instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_delete_e2e_svc_instance/{serviceInstanceId}", method = RequestMethod.POST) + public ResponseEntity deleteE2eSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, + HttpServletRequest request, @RequestBody LinkedHashMap msoRequest) { + + LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), msoRequest); + MsoResponseWrapper w = msoBusinessLogic.deleteE2eSvcInstance(msoRequest.get("requestDetails"), serviceInstanceId); + // always return OK, the MSO status code is embedded in the body + + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + + } + + /** + * Delete svc instance. + * + * @param serviceInstanceId the service instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + + @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST) + public String deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, + HttpServletRequest request, @RequestBody RequestDetails msoRequest, + @RequestParam(value = "serviceStatus") String serviceStatus) { + + LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), msoRequest); + MsoResponseWrapper w = msoBusinessLogic.deleteSvcInstance(msoRequest, serviceInstanceId, serviceStatus); + // always return OK, the MSO status code is embedded in the body + + return w.getResponse(); + } + + /** + * Delete vnf. + * + * @param serviceInstanceId the service instance id + * @param vnfInstanceId the vnf instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST) + + public ResponseEntity deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, + HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + String methodName = "deleteVnf"; + + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.deleteVnf(msoRequest, serviceInstanceId, vnfInstanceId); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + + } + + /** + * Delete configuration instance + * @param serviceInstanceId the service instance id + * @param configurationId the configuration id + * @param msoRequest the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "mso_delete_configuration/{serviceInstanceId}/configurations/{configurationId}", + method = RequestMethod.POST) + public ResponseEntity deleteConfiguration( + @PathVariable("serviceInstanceId") String serviceInstanceId, + @PathVariable ("configurationId") String configurationId, + @RequestBody RequestDetailsWrapper msoRequest) { + + String methodName = "deleteConfiguration"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, + "<== " + methodName + START_LOG); + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest.getRequestDetails()); + MsoResponseWrapper w = msoBusinessLogic.deleteConfiguration(msoRequest, serviceInstanceId, configurationId); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Activate configuration instance + * @param serviceInstanceId the service instace id + * @param configurationId the configuration id + * @param msoRequest the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "mso_activate_configuration/{serviceInstanceId}/configurations/{configurationId}", + method = RequestMethod.POST) + public ResponseEntity activateConfiguration( + @PathVariable("serviceInstanceId") String serviceInstanceId, + @PathVariable("configurationId") String configurationId, + @RequestBody RequestDetails msoRequest) { + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.setConfigurationActiveStatus(msoRequest, serviceInstanceId, configurationId, true); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Deactivate configuration instance + * @param serviceInstanceId the service instace id + * @param configurationId the configuration id + * @param msoRequest the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "mso_deactivate_configuration/{serviceInstanceId}/configurations/{configurationId}", + method = RequestMethod.POST) + public ResponseEntity deactivateConfiguration( + @PathVariable("serviceInstanceId") String serviceInstanceId, + @PathVariable("configurationId") String configurationId, + @RequestBody RequestDetails msoRequest) { + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.setConfigurationActiveStatus(msoRequest, serviceInstanceId, configurationId, false); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Disable port on configuration instance + * @param serviceInstanceId the service instance id + * @param configurationId the configuration instance id + * @param msoRequest the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "mso_disable_port_configuration/{serviceInstanceId}/configurations/{configurationId}", + method = RequestMethod.POST) + public ResponseEntity disablePortOnConfiguration( + @PathVariable("serviceInstanceId") String serviceInstanceId, + @PathVariable("configurationId") String configurationId, + @RequestBody RequestDetails msoRequest) { + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.setPortOnConfigurationStatus(msoRequest, serviceInstanceId, configurationId, false); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Enable port on configuration instance + * @param serviceInstanceId the service instance id + * @param configurationId the configuration instance id + * @param msoRequest the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "mso_enable_port_configuration/{serviceInstanceId}/configurations/{configurationId}", + method = RequestMethod.POST) + public ResponseEntity enablePortOnConfiguration( + @PathVariable("serviceInstanceId") String serviceInstanceId, + @PathVariable("configurationId") String configurationId, + @RequestBody RequestDetails msoRequest) { + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.setPortOnConfigurationStatus(msoRequest, serviceInstanceId, configurationId, true); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Delete vf module. + * + * @param serviceInstanceId the service instance id + * @param vnfInstanceId the vnf instance id + * @param vfModuleId the vf module id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee + @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST) + public ResponseEntity deleteVfModule( + @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, + @PathVariable("vfModuleId") String vfModuleId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + + String methodName = "deleteVfModule"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.deleteVfModule(msoRequest, serviceInstanceId, vnfInstanceId, vfModuleId); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Delete volume group instance. + * + * @param serviceInstanceId the service instance id + * @param vnfInstanceId the vnf instance id + * @param volumeGroupId the volume group id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupId}", method = RequestMethod.POST) + public ResponseEntity deleteVolumeGroupInstance( + @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, @PathVariable("volumeGroupId") String volumeGroupId, + HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + String methodName = "deleteVolumeGroupInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.deleteVolumeGroupInstance(msoRequest, serviceInstanceId, vnfInstanceId, volumeGroupId); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Delete nw instance. + * + * @param serviceInstanceId the service instance id + * @param networkInstanceId the network instance id + * @param request the request + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST) + public ResponseEntity deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, + @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request, @RequestBody RequestDetails msoRequest) { + String methodName = "deleteNwInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + cloudOwnerService.enrichRequestWithCloudOwner(msoRequest); + MsoResponseWrapper w = msoBusinessLogic.deleteNwInstance(msoRequest, serviceInstanceId, networkInstanceId); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Gets the orchestration request. + * + * @param requestId the request id + * @param request the request + * @return the orchestration request + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET) + public ResponseEntity getOrchestrationRequest(@PathVariable("requestId") String requestId, + HttpServletRequest request) { + + String methodName = "getOrchestrationRequest"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + + MsoResponseWrapper w = msoBusinessLogic.getOrchestrationRequest(requestId); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * Gets the orchestration requests. + * + * @param filterString the filter string + * @param request the request + * @return the orchestration requests + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET) + public ResponseEntity getOrchestrationRequests(@PathVariable("filterString") String filterString, + HttpServletRequest request) { + + String methodName = "getOrchestrationRequests"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + + MsoResponseWrapper w = msoBusinessLogic.getOrchestrationRequests(filterString); + + // always return OK, the MSO status code is embedded in the body + return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); + } + + /** + * activate to a pnf instance. + * + * @param serviceInstanceId the id of the service. + * @param requestDetails the body of the request. + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_activate_service_instance/{serviceInstanceId}", method = RequestMethod.POST) + public ResponseEntity activateServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @RequestBody RequestDetails requestDetails) { + String methodName = "activateServiceInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + MsoResponseWrapper w = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true); + return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); + } + + /** + * deactivate a service instance. + * + * @param serviceInstanceId the id of the service. + * @param requestDetails the body of the request. + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_deactivate_service_instance/{serviceInstanceId}", method = RequestMethod.POST) + public ResponseEntity deactivateServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @RequestBody RequestDetails requestDetails) { + String methodName = "deactivateServiceInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + MsoResponseWrapper w = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false); + return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); + } + + /** + * Gets the orchestration requests for the dashboard. + * currently its all the orchestration requests with RequestType updateInstance or replaceInstance. + * @return the orchestration requests + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_get_orch_reqs/dashboard", method = RequestMethod.GET) + public List getOrchestrationRequestsForDashboard() { + + String methodName = "getOrchestrationRequestsForDashboard"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + + return msoBusinessLogic.getOrchestrationRequestsForDashboard(); + } + + /** + * Gets the Manual Tasks for the given request id. + * + * @param originalRequestId the id of the original request. + * @return the tasks + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_get_man_task/{originalRequestId}", method = RequestMethod.GET) + public List getManualTasksByRequestId(@PathVariable("originalRequestId") String originalRequestId) { + + String methodName = "getManualTasksByRequestId"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + return msoBusinessLogic.getManualTasksByRequestId(originalRequestId); + } + + /** + * Complete the manual task. + * + * @param taskId the id of the task to complete. + * @param requestDetails the body of the request. + * @return the response entity + * @throws Exception the exception + */ + @RequestMapping(value = "/mso_post_man_task/{taskId}", method = RequestMethod.POST) + public ResponseEntity manualTaskComplete(@PathVariable("taskId") String taskId , @RequestBody RequestDetails requestDetails) { + + String methodName = "manualTaskComplete"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + MsoResponseWrapper w = msoBusinessLogic.completeManualTask(requestDetails, taskId); + return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); + } + + @RequestMapping(value = "/mso_remove_relationship/{serviceInstanceId}", method = RequestMethod.POST) + public ResponseEntity removeRelationshipFromServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId , + @RequestBody RequestDetails requestDetails) { + + String methodName = "removeRelationshipFromServiceInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + MsoResponseWrapper w; + try { + w = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId); + } catch (Exception e){ + LOGGER.error("Internal error when calling MSO controller logic for {}", methodName, e); + return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); + } + + @RequestMapping(value = "/mso_add_relationship/{serviceInstanceId}", method = RequestMethod.POST) + public ResponseEntity addRelationshipToServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId , + @RequestBody RequestDetails requestDetails) { + + String methodName = "addRelationshipToServiceInstance"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + MsoResponseWrapper w; + try { + w = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId); + } catch (Exception e){ + LOGGER.error("Internal error when calling MSO controller logic for {}", methodName, e); + return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); + } + + @RequestMapping(value = "/mso_activate_fabric_configuration/{serviceInstanceId}", method = RequestMethod.POST) + public MsoResponseWrapper2 activateFabricConfiguration( + @PathVariable("serviceInstanceId") String serviceInstanceId , + @RequestBody RequestDetails requestDetails) { + + String methodName = "activateFabricConfiguration"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + return msoBusinessLogic.activateFabricConfiguration(serviceInstanceId, requestDetails); + } + + @RequestMapping(value = "/mso_vfmodule_soft_delete/{serviceInstanceId}/{vnfInstanceId}/{vfModuleInstanceId}", method = RequestMethod.POST) + public MsoResponseWrapper2 deactivateAndCloudDelete( + @PathVariable("serviceInstanceId") String serviceInstanceId, + @PathVariable("vnfInstanceId") String vnfInstanceId, + @PathVariable("vfModuleInstanceId") String vfModuleInstanceId, + @RequestBody SoftDeleteRequest softDeleteRequest) { + + String methodName = "deactivateAndCloudDelete"; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + START_LOG); + + RequestDetails requestDetails = msoBusinessLogic.buildRequestDetailsForSoftDelete(softDeleteRequest); + + cloudOwnerService.enrichRequestWithCloudOwner(requestDetails); + return msoBusinessLogic.deactivateAndCloudDelete(serviceInstanceId, vnfInstanceId, vfModuleInstanceId, requestDetails); + } + + + /** + * Exception handler. + * + * @param e the e + * @param response the response + * @throws IOException Signals that an I/O exception has occurred. + */ + @ExceptionHandler(Exception.class) + private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException { + + ControllersUtils.handleException(e, LOGGER); + + response.setContentType("application/json; charset=UTF-8"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + + ExceptionResponse exceptionResponse = new ExceptionResponse(); + exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", "")); + exceptionResponse.setMessage(e.getMessage()); + + response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse)); + + response.flushBuffer(); + + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/OperationalEnvironmentController.java b/vid-app-common/src/main/java/org/onap/vid/controller/OperationalEnvironmentController.java new file mode 100644 index 000000000..21aef6858 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/OperationalEnvironmentController.java @@ -0,0 +1,362 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.vid.controller; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.MoreObjects; +import io.joshworks.restclient.http.HttpResponse; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.model.ExceptionResponse; +import org.onap.vid.model.RequestReferencesContainer; +import org.onap.vid.mso.MsoBusinessLogic; +import org.onap.vid.mso.MsoInterface; +import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; +import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo; +import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails; +import org.onap.vid.mso.rest.RequestDetails; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.MissingServletRequestParameterException; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.onap.vid.utils.Logging.getMethodCallerName; +import static org.onap.vid.utils.Logging.getMethodName; + +@RestController +@RequestMapping("operationalEnvironment") +public class OperationalEnvironmentController extends VidRestrictedBaseController { + + private final MsoInterface restMso; + private final MsoBusinessLogic msoBusinessLogic; + + private static final Pattern RECOVERY_ACTION_MESSAGE_PATTERN = Pattern.compile("from String \"(.*)\": value not"); + + + @Autowired + public OperationalEnvironmentController(MsoBusinessLogic msoBusinessLogic, MsoInterface msoClientInterface) { + this.restMso = msoClientInterface; + this.msoBusinessLogic = msoBusinessLogic; + } + + @RequestMapping(value = "/create", method = RequestMethod.POST) + public MsoResponseWrapper2 createOperationalEnvironment(HttpServletRequest request, @RequestBody OperationalEnvironmentCreateBody operationalEnvironment) { + debugStart(operationalEnvironment); + String userId = ControllersUtils.extractUserId(request); + RequestDetailsWrapper requestDetailsWrapper = msoBusinessLogic.convertParametersToRequestDetails(operationalEnvironment, userId); + String path = msoBusinessLogic.getOperationalEnvironmentCreationPath(); + + HttpResponse msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); + debugEnd(msoResponse); + return new MsoResponseWrapper2<>(msoResponse); + } + + @RequestMapping(value = "/activate", method = RequestMethod.POST) + public MsoResponseWrapper2 activate(HttpServletRequest request, + @RequestParam("operationalEnvironment") String operationalEnvironmentId, + @RequestBody OperationalEnvironmentActivateBody activateRequest) throws MissingServletRequestParameterException { + + verifyIsNotEmpty(operationalEnvironmentId, "operationalEnvironment"); + + //manifest is null in case of wrong manifest structure (deserialization failure of the manifest) + if (activateRequest.getManifest()==null || activateRequest.getManifest().getServiceModelList()==null) { + throw new BadManifestException("Manifest structure is wrong"); + } + + String userId = ControllersUtils.extractUserId(request); + + OperationalEnvironmentActivateInfo activateInfo = new OperationalEnvironmentActivateInfo(activateRequest, userId, operationalEnvironmentId); + debugStart(activateInfo); + + String path = msoBusinessLogic.getOperationalEnvironmentActivationPath(activateInfo); + RequestDetailsWrapper requestDetailsWrapper = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(activateInfo); + + HttpResponse msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); + + debugEnd(msoResponse); + return new MsoResponseWrapper2<>(msoResponse); + } + + @RequestMapping(value = "/deactivate", method = RequestMethod.POST) + public MsoResponseWrapper2 deactivate(HttpServletRequest request, + @RequestParam("operationalEnvironment") String operationalEnvironmentId, + @RequestBody Map deactivationRequest) throws MissingServletRequestParameterException { + + verifyIsNotEmpty(operationalEnvironmentId, "operationalEnvironment"); + + String userId = ControllersUtils.extractUserId(request); + + OperationalEnvironmentDeactivateInfo deactivateInfo = new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId); + debugStart(deactivateInfo); + + String path = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(deactivateInfo); + RequestDetailsWrapper requestDetailsWrapper = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(deactivateInfo); + + HttpResponse msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); + + debugEnd(msoResponse); + return new MsoResponseWrapper2<>(msoResponse); + } + + @RequestMapping(value = "/requestStatus", method = RequestMethod.GET) + public MsoResponseWrapper2 status(HttpServletRequest request, @RequestParam("requestId") String requestId) throws MissingServletRequestParameterException { + + debugStart(requestId); + + verifyIsNotEmpty(requestId, "requestId"); + String path = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId); + + HttpResponse msoResponse = restMso.get(path, HashMap.class); + + LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), msoResponse); + return new MsoResponseWrapper2<>(msoResponse); + } + + @ExceptionHandler({ + org.springframework.web.bind.MissingServletRequestParameterException.class, + BadManifestException.class + }) + @ResponseStatus(value = HttpStatus.BAD_REQUEST) + public ExceptionResponse clientDerivedExceptionAsBadRequest(Exception e) { + // same handler, different HTTP Code + return exceptionHandler(e); + } + + @ExceptionHandler({ + org.springframework.http.converter.HttpMessageNotReadableException.class, + }) + @ResponseStatus(value = HttpStatus.BAD_REQUEST) + public ExceptionResponse handlingHttpMessageNotReadableException(Exception e) { + //in case of wrong value in manifest for RecoveryAction the message contains the class name. + //The wrong value is in also part of this messages + //within the pattern of: String value '': value not + //so we use regex to find the wrong value + if (e.getMessage().contains(OperationalEnvironmentRecoveryAction.class.getName())) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodName(), ExceptionUtils.getMessage(e), e); + String message = "Wrong value for RecoveryAction in manifest. Allowed options are: "+OperationalEnvironmentRecoveryAction.options; + + Matcher matcher = RECOVERY_ACTION_MESSAGE_PATTERN.matcher(e.getMessage()); + if (matcher.find()) { + String wrongValue = matcher.group(1); + message = message+". Wrong value is: "+wrongValue; + } + return new ExceptionResponse(new BadManifestException(message)); + } + return exceptionHandler(e); + } + + + public enum OperationalEnvironmentRecoveryAction { + abort, + retry, + skip; + + public static final String options = Stream.of(OperationalEnvironmentRecoveryAction.values()).map(OperationalEnvironmentRecoveryAction::name).collect(Collectors.joining(", ")); + } + + public static class ActivateServiceModel { + private String serviceModelVersionId; + private OperationalEnvironmentRecoveryAction recoveryAction; + + public ActivateServiceModel() { + } + + public ActivateServiceModel(String serviceModelVersionId, OperationalEnvironmentRecoveryAction recoveryAction) { + this.serviceModelVersionId = serviceModelVersionId; + this.recoveryAction = recoveryAction; + } + + public String getServiceModelVersionId() { + return serviceModelVersionId; + } + + public void setServiceModelVersionId(String serviceModelVersionId) { + this.serviceModelVersionId = serviceModelVersionId; + } + + public OperationalEnvironmentRecoveryAction getRecoveryAction() { + return recoveryAction; + } + + public void setRecoveryAction(OperationalEnvironmentRecoveryAction recoveryAction) { + this.recoveryAction = recoveryAction; + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class OperationalEnvironmentManifest { + + + private List serviceModelList; + + public OperationalEnvironmentManifest() { + } + + public OperationalEnvironmentManifest(List serviceModelList) { + this.serviceModelList = serviceModelList; + } + + public List getServiceModelList() { + return serviceModelList; + } + + public void setServiceModelList(List serviceModelList) { + this.serviceModelList = serviceModelList; + } + } + + public static class OperationalEnvironmentActivateBody { + private final String relatedInstanceId; + private final String relatedInstanceName; + private final String workloadContext; + private final OperationalEnvironmentManifest manifest; + + public OperationalEnvironmentActivateBody(@JsonProperty(value = "relatedInstanceId", required = true) String relatedInstanceId, + @JsonProperty(value = "relatedInstanceName", required = true) String relatedInstanceName, + @JsonProperty(value = "workloadContext", required = true) String workloadContext, + @JsonProperty(value = "manifest", required = true) OperationalEnvironmentManifest manifest) { + this.relatedInstanceId = relatedInstanceId; + this.relatedInstanceName = relatedInstanceName; + this.workloadContext = workloadContext; + this.manifest = manifest; + } + + + public String getRelatedInstanceId() { + return relatedInstanceId; + } + + public String getRelatedInstanceName() { + return relatedInstanceName; + } + + public String getWorkloadContext() { + return workloadContext; + } + + public OperationalEnvironmentManifest getManifest() { + return manifest; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("relatedInstanceId", relatedInstanceId) + .add("relatedInstanceName", relatedInstanceName) + .add("workloadContext", workloadContext) + .add("manifest", manifest) + .toString(); + } + } + + public static class OperationalEnvironmentCreateBody { + private final String instanceName; + private final String ecompInstanceId; + private final String ecompInstanceName; + private final String operationalEnvironmentType; + private final String tenantContext; + private final String workloadContext; + + public OperationalEnvironmentCreateBody(@JsonProperty(value = "instanceName", required = true) String instanceName, + @JsonProperty(value = "ecompInstanceId", required = true) String ecompInstanceId, + @JsonProperty(value = "ecompInstanceName", required = true) String ecompInstanceName, + @JsonProperty(value = "operationalEnvironmentType", required = true) String operationalEnvironmentType, + @JsonProperty(value = "tenantContext", required = true) String tenantContext, + @JsonProperty(value = "workloadContext", required = true) String workloadContext) { + this.instanceName = instanceName; + this.ecompInstanceId = ecompInstanceId; + this.ecompInstanceName = ecompInstanceName; + this.operationalEnvironmentType = operationalEnvironmentType; + this.tenantContext = tenantContext; + this.workloadContext = workloadContext; + } + + public String getInstanceName() { + return instanceName; + } + + public String getEcompInstanceId() { + return ecompInstanceId; + } + + public String getEcompInstanceName() { + return ecompInstanceName; + } + + public String getOperationalEnvironmentType() { + return operationalEnvironmentType; + } + + public String getTenantContext() { + return tenantContext; + } + + public String getWorkloadContext() { + return workloadContext; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("instanceName", instanceName) + .add("ecompInstanceId", ecompInstanceId) + .add("ecompInstanceName", ecompInstanceName) + .add("operationalEnvironmentType", operationalEnvironmentType) + .add("tenantContext", tenantContext) + .add("workloadContext", workloadContext) + .toString(); + } + } + + private void debugEnd(HttpResponse msoResponse) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodCallerName(), msoResponse); + } + + private void debugStart(Object requestInfo) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodCallerName(), requestInfo); + } + + private void verifyIsNotEmpty(String fieldValue, String fieldName) throws MissingServletRequestParameterException { + if (StringUtils.isEmpty(fieldValue)) { + throw new MissingServletRequestParameterException(fieldName, "String"); + } + } + + public static class BadManifestException extends RuntimeException { + public BadManifestException(String message) { + super(message); + } + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/ProbeController.java b/vid-app-common/src/main/java/org/onap/vid/controller/ProbeController.java new file mode 100644 index 000000000..1324ebb12 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/ProbeController.java @@ -0,0 +1,42 @@ +package org.onap.vid.controller; + +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.vid.aai.AaiClient; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.mso.MsoBusinessLogic; +import org.onap.vid.scheduler.SchedulerService; +import org.onap.vid.services.VidService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("probe") +public class ProbeController extends RestrictedBaseController { + + private final AaiClient aaiClient; + private final VidService vidService; + private final MsoBusinessLogic msoBusinessLogic; + private final SchedulerService schedulerService; + + @Autowired + public ProbeController(AaiClient aaiClient, VidService vidService, MsoBusinessLogic msoBusinessLogic, SchedulerService schedulerService) { + this.aaiClient = aaiClient; + this.vidService = vidService; + this.msoBusinessLogic = msoBusinessLogic; + this.schedulerService = schedulerService; + } + + @RequestMapping(method= RequestMethod.GET) + public List getProbe() { + List componentStatuses = new ArrayList<>(); + componentStatuses.add(aaiClient.probeAaiGetAllSubscribers()); + componentStatuses.add(schedulerService.probeGetSchedulerChangeManagements()); + return componentStatuses; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/PropertyController.java b/vid-app-common/src/main/java/org/onap/vid/controller/PropertyController.java new file mode 100644 index 000000000..2f8d6e299 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/PropertyController.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.controller; + +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.category.CategoryParametersResponse; +import org.onap.vid.model.CategoryParameter.Family; +import org.onap.vid.services.CategoryParameterService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; + +import static org.onap.vid.utils.Logging.getMethodName; + +/** + * The Class PropertyController. + */ +@RestController +public class PropertyController extends RestrictedBaseController{ + + + /** The logger. */ + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(PropertyController.class); + + @Autowired + protected CategoryParameterService categoryParameterService; + + + /** + * Welcome. + * + * @param request the request + * @return the model and view + */ + @RequestMapping(value = {"/propertyhome" }, method = RequestMethod.GET) + public ModelAndView welcome(HttpServletRequest request) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== PropertyController welcome start"); + return new ModelAndView(getViewName()); + } + + /** + * Gets the property. + * + * @param name the name + * @param defaultvalue the defaultvalue + * @param request the request + * @return the property + * @throws Exception the exception + */ + @RequestMapping(value = "/get_property/{name}/{defaultvalue}", method = RequestMethod.GET) + public ResponseEntity getProperty (@PathVariable("name") String name, @PathVariable("defaultvalue") String defaultvalue, + HttpServletRequest request) { + + String methodName = "getProperty"; + ResponseEntity resp = null; + String pvalue = null; + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " start"); + + try { + // convert "_" to "." in the property name + if (name == null || name.length() == 0 ) { + return ( new ResponseEntity (defaultvalue, HttpStatus.OK)); + } + // convert "_" to "." in the property name + String propertyName = name.replace('_', '.'); + pvalue = SystemProperties.getProperty(propertyName); + if ( ( pvalue == null ) || ( pvalue.length() == 0 ) ) { + pvalue = defaultvalue; + } + resp = new ResponseEntity<>(pvalue, HttpStatus.OK); + } + catch (Exception e) { + LOGGER.info(EELFLoggerDelegate.errorLogger, "<== " + "." + methodName + e.toString()); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + "." + methodName + e.toString()); + throw e; + } + LOGGER.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " returning " + pvalue); + return ( resp ); + } + + /** + * Gets the owning entity properties. + * @param request the request + * @return the property + * @throws Exception the exception + */ + @RequestMapping(value = "/category_parameter", method = RequestMethod.GET) + public ResponseEntity getCategoryParameter(HttpServletRequest request, @RequestParam(value="familyName", required = true) Family familyName) { + LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName()); + try { + CategoryParametersResponse response = categoryParameterService.getCategoryParameters(familyName); + LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), response); + return new ResponseEntity<>(response, HttpStatus.OK); + } + catch (Exception exception) { + LOGGER.error("failed to retrieve category parameter list from DB.", exception); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/RoleGeneratorController.java b/vid-app-common/src/main/java/org/onap/vid/controller/RoleGeneratorController.java new file mode 100644 index 000000000..78f1e37d5 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/RoleGeneratorController.java @@ -0,0 +1,26 @@ +package org.onap.vid.controller; + +import org.onap.portalsdk.core.controller.UnRestrictedBaseController; +import org.onap.vid.services.RoleGeneratorService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class RoleGeneratorController extends UnRestrictedBaseController { + @Autowired + private RoleGeneratorService roleGeneratorService; + public static final String GENERATE_ROLE_SCRIPT = "generateRoleScript"; + @RequestMapping(value = GENERATE_ROLE_SCRIPT +"/{firstRun}", method = RequestMethod.GET ) + public ResponseEntity generateRoleScript (@PathVariable("firstRun") boolean firstRun) { + ResponseEntity response = null; + String query = roleGeneratorService.generateRoleScript(firstRun); + response = new ResponseEntity<>(query, HttpStatus.OK); + return response; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/VersionController.java b/vid-app-common/src/main/java/org/onap/vid/controller/VersionController.java new file mode 100644 index 000000000..ba879ed16 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/VersionController.java @@ -0,0 +1,63 @@ +package org.onap.vid.controller; + + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang3.StringUtils; +import org.onap.portalsdk.core.controller.UnRestrictedBaseController; +import org.onap.portalsdk.core.util.SystemProperties; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.inject.Inject; +import javax.servlet.ServletContext; +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.apache.commons.lang3.StringUtils.substringAfterLast; + +@RestController +@RequestMapping("version") +public class VersionController extends UnRestrictedBaseController { + + private final ServletContext servletContext; + + @Inject + public VersionController(ServletContext servletContext) { + this.servletContext = servletContext; + } + + @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + public Map getVersionAndFeatures() + { + String features = SystemProperties.getProperty("features.set.filename"); + String version; + try { + final URL resource = servletContext.getResource("/app/vid/scripts/constants/version.json"); + HashMap versionFile = new HashMap <>(); + ObjectMapper mapper = new ObjectMapper(); + versionFile.putAll(mapper.readValue(resource, new TypeReference>() {})); + version = versionFile.get("Version"); + } catch (IOException e) { + version = "Error retrieving build number"; + } + String majorVersion = getDisplayVersion(features, version); + return ImmutableMap.of("Features", features, "Build", version, "DisplayVersion", majorVersion); + } + + String getDisplayVersion(String features, String build) { + Matcher matcher = Pattern.compile("([^/]+?)(\\.features|$)").matcher(features); + final String majorByFeatures = matcher.find() ? matcher.group(1) : features; + + final String buildByVersion = StringUtils.defaultIfBlank(substringAfterLast(build, "."), build); + + return StringUtils.join(majorByFeatures, ".", buildByVersion); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/VidController.java b/vid-app-common/src/main/java/org/onap/vid/controller/VidController.java new file mode 100644 index 000000000..40d0f4629 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/VidController.java @@ -0,0 +1,114 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.controller; + +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.asdc.beans.SecureServices; +import org.onap.vid.exceptions.VidServiceUnavailableException; +import org.onap.vid.model.PombaInstance.PombaRequest; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.roles.Role; +import org.onap.vid.roles.RoleProvider; +import org.onap.vid.services.AaiService; +import org.onap.vid.services.PombaService; +import org.onap.vid.services.VidService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@RestController +public class VidController extends RestrictedBaseController { + + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class); + + private final VidService vidService; + private final AaiService aaiService; + private final RoleProvider roleProvider; + private final PombaService pombaService; + + @Autowired + public VidController(VidService vidService, AaiService aaiService, RoleProvider roleProvider, + PombaService pombaService) { + this.vidService = vidService; + this.aaiService = aaiService; + this.roleProvider = roleProvider; + this.pombaService = pombaService; + } + + /** + * @param request the request + * @return the services + */ + @RequestMapping(value = {"/rest/models/services"}, method = RequestMethod.GET) + public SecureServices getServices(HttpServletRequest request) { + LOG.info("Start API for browse ASDC was called"); + SecureServices secureServices = new SecureServices(); + List roles = roleProvider.getUserRoles(request); + secureServices.setServices(aaiService.getServicesByDistributionStatus()); + secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles)); + return secureServices; + } + + + /** + * @param uuid the uuid + * @return the services + * @throws VidServiceUnavailableException the vid service unavailable exception + */ + @RequestMapping(value = {"/rest/models/services/{uuid}"}, method = RequestMethod.GET) + public ServiceModel getService(@PathVariable("uuid") String uuid) throws VidServiceUnavailableException { + try { + return vidService.getService(uuid); + } catch (AsdcCatalogException e) { + LOG.error("Failed to retrieve service definitions from SDC. Error: " + e.getMessage(), e); + throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e); + } + } + + @RequestMapping(value = "/rest/models/reset", method = RequestMethod.POST) + @ResponseStatus(HttpStatus.ACCEPTED) + public void invalidateServiceModelCache() { + vidService.invalidateServiceCache(); + } + + /** + * @return the services view + * @throws VidServiceUnavailableException the vid service unavailable exception + */ + // FIX ME: Circular view path [serviceModels]: would dispatch back to the current handler URL [/serviceModels] again. + @RequestMapping(value = {"/serviceModels"}, method = RequestMethod.GET) + public ModelAndView getServicesView() { + return new ModelAndView("serviceModels"); + } + + @RequestMapping(value = {"/rest/models/services/verifyService"}, method = RequestMethod.POST) + public void verifyServiceInstance(@RequestBody PombaRequest pombaRequest) { + pombaService.verify(pombaRequest); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/VidRestrictedBaseController.java b/vid-app-common/src/main/java/org/onap/vid/controller/VidRestrictedBaseController.java new file mode 100644 index 000000000..e13cf4512 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/VidRestrictedBaseController.java @@ -0,0 +1,42 @@ +package org.onap.vid.controller; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.exception.ExceptionUtils; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.model.ExceptionResponse; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +import static org.onap.vid.utils.Logging.getMethodCallerName; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; + +public abstract class VidRestrictedBaseController extends RestrictedBaseController { + + protected final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(this.getClass().getName()); + + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + @ResponseBody + public ResponseEntity handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodCallerName(), ExceptionUtils.getMessage(e), e); + Class type = e.getRequiredType(); + String message; + if (type.isEnum()) { + message = "The parameter " + e.getName() + " must have a value among : " + StringUtils.join(type.getEnumConstants(), ", "); + } + else { + message = "The parameter " + e.getName() + " must be of type " + type.getTypeName(); + } + return new ResponseEntity(message, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(Exception.class) + @ResponseStatus(value=INTERNAL_SERVER_ERROR) + public ExceptionResponse exceptionHandler(Exception e) { + return ControllersUtils.handleException(e, LOGGER); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/ViewLogController.java b/vid-app-common/src/main/java/org/onap/vid/controller/ViewLogController.java new file mode 100644 index 000000000..4956c5b1e --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/ViewLogController.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.controller; + +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import java.text.DateFormat; +import java.text.SimpleDateFormat; + + +/** + * The Class ViewLogController. + */ +@RestController +public class ViewLogController extends RestrictedBaseController{ + + /** The logger. */ + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ViewLogController.class); + + /** The Constant dateFormat. */ + static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + + /** The servlet context. */ + private @Autowired ServletContext servletContext; + + /** + * Welcome. + * + * @param request the request + * @return the model and view + */ + @RequestMapping(value = {"/viewlog" }, method = RequestMethod.GET) + public ModelAndView welcome(HttpServletRequest request) { + + return new ModelAndView(getViewName()); + } + + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java new file mode 100644 index 000000000..68d5b71d0 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WebConfig.java @@ -0,0 +1,193 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.controller; + +import com.fasterxml.jackson.core.JsonProcessingException; +import io.joshworks.restclient.http.mapper.ObjectMapper; +import org.onap.vid.aai.*; +import org.onap.vid.aai.model.PortDetailsTranslator; +import org.onap.vid.aai.util.*; +import org.onap.vid.asdc.AsdcClient; +import org.onap.vid.asdc.parser.ToscaParserImpl2; +import org.onap.vid.asdc.parser.VidNotionsBuilder; +import org.onap.vid.asdc.rest.SdcRestClient; +import org.onap.vid.client.SyncRestClient; +import org.onap.vid.client.SyncRestClientInterface; +import org.onap.vid.properties.AsdcClientConfiguration; +import org.onap.vid.scheduler.SchedulerService; +import org.onap.vid.scheduler.SchedulerServiceImpl; +import org.onap.vid.services.*; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.togglz.core.manager.FeatureManager; + +import javax.servlet.ServletContext; +import java.io.File; +import java.io.IOException; + +@Configuration +public class WebConfig { + + /** + * Gets the object mapper. + * + * @return the object mapper + */ + @Bean + public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() { + return new com.fasterxml.jackson.databind.ObjectMapper(); + } + + + @Bean + public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) { + return new VidServiceImpl(asdcClient, featureManager); + } + + @Bean + public SchedulerService schedulerService(ChangeManagementService changeManagementService) { + return new SchedulerServiceImpl(changeManagementService); + } + + @Bean + public AaiService getAaiService() { + return new AaiServiceImpl(); + } + + @Bean + public AaiResponseTranslator aaiResponseTranslator() { + return new AaiResponseTranslator(); + } + + @Bean + public PortDetailsTranslator portDetailsTranslator() { + return new PortDetailsTranslator(); + } + + @Bean + public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) { + return new AaiClient(restController, portsDetailsTranslator, cacheProvider); + } + + @Bean(name = "aaiRestInterface") + public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) { + return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper); + } + + @Bean + public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) { + return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper); + } + + @Bean + public SSLContextProvider sslContextProvider() { + return new SSLContextProvider(); + } + + @Bean + public SystemPropertyHelper systemPropertyHelper() { + return new SystemPropertyHelper(); + } + + @Bean + public ServletRequestHelper servletRequestHelper() { + return new ServletRequestHelper(); + } + + @Bean + public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) { + final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath(); + return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager); + } + + @Bean + public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) { + String auth = asdcClientConfiguration.getAsdcClientAuth(); + String host = asdcClientConfiguration.getAsdcClientHost(); + String protocol = asdcClientConfiguration.getAsdcClientProtocol(); + int port = asdcClientConfiguration.getAsdcClientPort(); + + return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient); + } + + @Bean + public SyncRestClientInterface syncRestClient() { + return new SyncRestClient(); + } + + @Bean + public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) { + return new VidNotionsBuilder(featureManager); + } + + @Bean + public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) { + return new ToscaParserImpl2(vidNotionsBuilder); + } + + @Bean + public PombaService getVerifyServiceInstanceService() { + return new PombaServiceImpl(); + } + + @Bean + public PombaClientInterface getVerifyServiceInstanceClientInterface() { + return new PombaClientImpl(); + } + + @Bean + public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) { + return new ServiceInstanceStandardQuery(aaiClient); + } + + @Bean + public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper){ + return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier()); + } + + @Bean + public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) { + return new ObjectMapper() { + + @Override + public T readValue(String s, Class aClass) { + try { + return objectMapper.readValue(s, aClass); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public String writeValue(Object o) { + try { + return objectMapper.writeValueAsString(o); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + }; + + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/filter/ClientCredentialsFilter.java b/vid-app-common/src/main/java/org/onap/vid/controller/filter/ClientCredentialsFilter.java index d4c7e3c5f..cba36a795 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/filter/ClientCredentialsFilter.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/filter/ClientCredentialsFilter.java @@ -20,7 +20,7 @@ import java.io.IOException; @WebFilter(urlPatterns = "/change-management/workflow/*") public class ClientCredentialsFilter extends GenericFilterBean { - private final static EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ClientCredentialsFilter.class); + private static final EELFLoggerDelegate filterLogger = EELFLoggerDelegate.getLogger(ClientCredentialsFilter.class); @Override @@ -33,12 +33,12 @@ public class ClientCredentialsFilter extends GenericFilterBean { String actualAuthorization = ((HttpServletRequest)request).getHeader("Authorization"); if (verifyClientCredentials(actualAuthorization, expectedAuthorization)) { - LOGGER.warn(EELFLoggerDelegate.debugLogger,"Client credentials authenticated."); + filterLogger.warn(EELFLoggerDelegate.debugLogger,"Client credentials authenticated."); chain.doFilter(request, response); return; } - LOGGER.warn(EELFLoggerDelegate.debugLogger,"Client did not provide the expected credentials."); + filterLogger.warn(EELFLoggerDelegate.debugLogger,"Client did not provide the expected credentials."); ((HttpServletResponse) response).sendError(401); } @@ -46,13 +46,13 @@ public class ClientCredentialsFilter extends GenericFilterBean { { if (StringUtils.isEmpty(expectedAuthorization)) { - LOGGER.warn(EELFLoggerDelegate.debugLogger,String.format("Expected Authorization is not configured (key: %s)", SchedulerProperties.SCHEDULER_BASIC_AUTH)); + filterLogger.warn(EELFLoggerDelegate.debugLogger,String.format("Expected Authorization is not configured (key: %s)", SchedulerProperties.SCHEDULER_BASIC_AUTH)); return true; } if (StringUtils.isEmpty(actualAuthorization)) { - LOGGER.warn(EELFLoggerDelegate.debugLogger,"Authorization header is missing."); + filterLogger.warn(EELFLoggerDelegate.debugLogger,"Authorization header is missing."); return false; } diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseEcompRequestIdFilter.java b/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseEcompRequestIdFilter.java index 7501b1032..9c1cb4633 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseEcompRequestIdFilter.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/filter/PromiseEcompRequestIdFilter.java @@ -3,7 +3,6 @@ package org.onap.vid.controller.filter; import com.google.common.collect.ImmutableList; import org.apache.commons.lang3.StringUtils; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.springframework.web.filter.GenericFilterBean; import javax.servlet.FilterChain; @@ -24,8 +23,7 @@ import static org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID; @WebFilter(urlPatterns = "/*") public class PromiseEcompRequestIdFilter extends GenericFilterBean { - private final static EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(PromiseEcompRequestIdFilter.class); - private final static String REQUEST_ID_RESPONSE_HEADER = ECOMP_REQUEST_ID + "-echo"; + private static final String REQUEST_ID_RESPONSE_HEADER = ECOMP_REQUEST_ID + "-echo"; @Override @@ -48,13 +46,19 @@ public class PromiseEcompRequestIdFilter extends GenericFilterBean { final HttpServletRequest httpRequest = (HttpServletRequest) request; final String originalRequestId = httpRequest.getHeader(ECOMP_REQUEST_ID); - if (StringUtils.isEmpty(originalRequestId)) { + if (StringUtils.isEmpty(originalRequestId) || !verifyAndValidateUuid(originalRequestId)) { request = new PromiseEcompRequestIdRequestWrapper(httpRequest); } return request; } + public static boolean verifyAndValidateUuid(String value) + { + String uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; + return value.matches(uuidRegex); + } + private static class PromiseEcompRequestIdRequestWrapper extends HttpServletRequestWrapper { private final UUID requestId; @@ -81,12 +85,17 @@ public class PromiseEcompRequestIdFilter extends GenericFilterBean { @Override public Enumeration getHeaderNames() { + + if (null == super.getHeader(ECOMP_REQUEST_ID)) { return Collections.enumeration(ImmutableList.builder() .add(ECOMP_REQUEST_ID) .addAll(Collections.list(super.getHeaderNames())) .build()); } + return super.getHeaderNames(); + } + private boolean isRequestIdHeaderName(String name) { return ECOMP_REQUEST_ID.equalsIgnoreCase(name); } diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/test/TestAaiController.java b/vid-app-common/src/main/java/org/onap/vid/controller/test/TestAaiController.java index c57d93cb9..511e8631b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/test/TestAaiController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/test/TestAaiController.java @@ -20,7 +20,7 @@ package org.onap.vid.controller.test; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.onap.vid.model.ExceptionResponse; import org.springframework.web.bind.annotation.*; diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/test/TestAsdcController.java b/vid-app-common/src/main/java/org/onap/vid/controller/test/TestAsdcController.java index ae6396475..da79ef9b0 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/test/TestAsdcController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/test/TestAsdcController.java @@ -20,7 +20,7 @@ package org.onap.vid.controller.test; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.onap.vid.model.ExceptionResponse; import org.springframework.web.bind.annotation.*; diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/test/TestMsoController.java b/vid-app-common/src/main/java/org/onap/vid/controller/test/TestMsoController.java index ba4476fa6..4cb0d6c16 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/test/TestMsoController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/test/TestMsoController.java @@ -20,7 +20,7 @@ package org.onap.vid.controller.test; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.onap.vid.model.ExceptionResponse; import org.springframework.http.HttpStatus; diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/AaiController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/AaiController.java deleted file mode 100644 index 1a426ed29..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/AaiController.java +++ /dev/null @@ -1,763 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.controllers; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.codehaus.jackson.map.ObjectMapper; -import org.onap.vid.aai.AaiResponse; -import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData; -import org.onap.vid.aai.ServiceInstancesSearchResults; -import org.onap.vid.aai.SubscriberData; -import org.onap.vid.aai.SubscriberFilteredResults; -import org.onap.vid.aai.model.AaiGetInstanceGroupsByCloudRegion; -import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; -import org.onap.vid.aai.model.AaiGetPnfs.Pnf; -import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; -import org.onap.vid.aai.util.AAIRestInterface; -import org.onap.vid.model.VersionByInvariantIdsRequest; -import org.onap.vid.roles.Role; -import org.onap.vid.roles.RoleProvider; -import org.onap.vid.roles.RoleValidator; -import org.onap.vid.services.AaiService; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.HandlerMapping; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.QueryParam; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.stream.Collectors; - -import static org.onap.vid.utils.Logging.getMethodName; - -/** - * Controller to handle a&ai requests. - */ - -@RestController -public class AaiController extends RestrictedBaseController { - /** - * The Constant dateFormat. - */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - /** - * The from app id. - */ - protected String fromAppId = "VidAaiController"; - /** - * The logger. - */ - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiController.class); - /** - * The model. - */ - private Map model = new HashMap(); - /** - * The servlet context. - */ - @Autowired - private ServletContext servletContext; - /** - * aai service - */ - @Autowired - private AaiService aaiService; - @Autowired - private RoleProvider roleProvider; - - @Autowired - private AAIRestInterface aaiRestInterface; - - /** - * Welcome method. - * - * @param request the request - * @return ModelAndView The view - */ - @RequestMapping(value = {"/subscriberSearch"}, method = RequestMethod.GET) - public ModelAndView welcome(HttpServletRequest request) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== AaiController welcome start"); - return new ModelAndView(getViewName()); - } - - @RequestMapping(value = {"/aai_get_aic_zones"}, method = RequestMethod.GET) - public ResponseEntity getAicZones(HttpServletRequest request) throws IOException { - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== getAicZones controller start"); - AaiResponse response = aaiService.getAaiZones(); - return aaiResponseToResponseEntity(response); - } - - @RequestMapping(value = {"/aai_get_aic_zone_for_pnf/{globalCustomerId}/{serviceType}/{serviceId}"}, method = RequestMethod.GET) - public ResponseEntity getAicZoneForPnf(@PathVariable("globalCustomerId") String globalCustomerId ,@PathVariable("serviceType") String serviceType , @PathVariable("serviceId") String serviceId ,HttpServletRequest request) throws IOException { - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== getAicZoneForPnf controller start"); - AaiResponse response = aaiService.getAicZoneForPnf(globalCustomerId , serviceType , serviceId); - return aaiResponseToResponseEntity(response); - } - - @RequestMapping(value = {"/aai_get_instance_groups_by_vnf_instance_id/{vnfInstanceId}"}, method = RequestMethod.GET) - public ResponseEntity getInstanceGroupsByVnfInstanceId(@PathVariable("vnfInstanceId") String vnfInstanceId ,HttpServletRequest request) throws IOException { - AaiResponse response = aaiService.getInstanceGroupsByVnfInstanceId(vnfInstanceId); - return aaiResponseToResponseEntity(response); - } - /** - * Get services from a&ai. - * - * @return ResponseEntity The response entity with the logged in user uuid. - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = {"/getuserID"}, method = RequestMethod.GET) - public ResponseEntity getUserID(HttpServletRequest request) { - - String userId = ControllersUtils.extractUserId(request); - - return new ResponseEntity(userId, HttpStatus.OK); - } - - /** - * Get services from a&ai. - * - * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/aai_get_services", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity doGetServices(HttpServletRequest request) throws IOException { - RoleValidator roleValidator = new RoleValidator(roleProvider.getUserRoles(request)); - - AaiResponse subscriberList = aaiService.getServices(roleValidator); - ResponseEntity responseEntity = aaiResponseToResponseEntity(subscriberList); - - return responseEntity; - } - - - @RequestMapping(value = {"/aai_get_version_by_invariant_id"}, method = RequestMethod.POST) - public ResponseEntity getVersionByInvariantId(HttpServletRequest request, @RequestBody VersionByInvariantIdsRequest versions) { - ResponseEntity responseEntity; - ObjectMapper objectMapper = new ObjectMapper(); - - Response result = aaiService.getVersionByInvariantId(versions.versions); - - return new ResponseEntity(result.readEntity(String.class), HttpStatus.OK); - } - - - private ResponseEntity aaiResponseToResponseEntity(AaiResponse aaiResponseData) - throws IOException { - ResponseEntity responseEntity; - ObjectMapper objectMapper = new ObjectMapper(); - if (aaiResponseData.getHttpCode() == 200) { - responseEntity = new ResponseEntity(objectMapper.writeValueAsString(aaiResponseData.getT()), HttpStatus.OK); - } else { - responseEntity = new ResponseEntity(aaiResponseData.getErrorMessage(), HttpStatus.valueOf(aaiResponseData.getHttpCode())); - } - return responseEntity; - } - - /** - * Lookup single service instance in a&ai. Get the service-subscription and customer, too, i guess? - * - * @param serviceInstanceId the service instance Id - * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/aai_get_service_instance/{service-instance-id}/{service-instance-type}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity doGetServiceInstance(@PathVariable("service-instance-id") String serviceInstanceId, @PathVariable("service-instance-type") String serviceInstanceType) { - Response resp = null; - - if (serviceInstanceType.equalsIgnoreCase("Service Instance Id")) { - resp = doAaiGet( - "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:" - + serviceInstanceId, false); - } else { - resp = doAaiGet( - "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:" - + serviceInstanceId, false); - } - return convertResponseToResponseEntity(resp); - } - - /** - * Get services from a&ai. - * - * @param globalCustomerId the global customer id - * @param serviceSubscriptionId the service subscription id - * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity doGetServices(@PathVariable("global-customer-id") String globalCustomerId, - @PathVariable("service-subscription-id") String serviceSubscriptionId) { - Response resp = doAaiGet("business/customers/customer/" + globalCustomerId - + "/service-subscriptions/service-subscription/" + serviceSubscriptionId + "?depth=0", false); - return convertResponseToResponseEntity(resp); - } - - /** - * Obtain the subscriber list from a&ai. - * - * @param fullSet the full set - * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/aai_get_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity doGetSubscriberList(HttpServletRequest request, @DefaultValue("n") @QueryParam("fullSet") String fullSet) throws IOException { - return getFullSubscriberList(request); - } - - /** - * Obtain the Target Prov Status from the System.Properties file. - * - * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/get_system_prop_vnf_prov_status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getTargetProvStatus() { - String p = SystemProperties.getProperty("aai.vnf.provstatus"); - return new ResponseEntity(p, HttpStatus.OK); - } - - - /** - * Obtain the Target Prov Status from the System.Properties file. - * - * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/get_operational_environments", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public AaiResponse getOperationalEnvironments(@RequestParam(value="operationalEnvironmentType", required = false) String operationalEnvironmentType, - @RequestParam(value="operationalEnvironmentStatus", required = false) String operationalEnvironmentStatus) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({}, {})", getMethodName(), operationalEnvironmentType, operationalEnvironmentStatus); - AaiResponse response = aaiService.getOperationalEnvironments(operationalEnvironmentType,operationalEnvironmentStatus); - if (response.getHttpCode() != 200) { - String errorMessage = getAaiErrorMessage(response.getErrorMessage()); - if(errorMessage != null) { - response = new AaiResponse(response.getT(), errorMessage, response.getHttpCode()); - } - } - - LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), response); - return response; - } - - /** - * Obtain the full subscriber list from a&ai. - *

- * g @return ResponseEntity The response entity - * - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/aai_get_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getFullSubscriberList(HttpServletRequest request) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - ResponseEntity responseEntity; - RoleValidator roleValidator = new RoleValidator(roleProvider.getUserRoles(request)); - SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator); - if (subscriberList.getHttpCode() == 200) { - responseEntity = new ResponseEntity(objectMapper.writeValueAsString(subscriberList.getSubscriberList()), HttpStatus.OK); - } else { - responseEntity = new ResponseEntity(subscriberList.getErrorMessage(), HttpStatus.valueOf(subscriberList.getHttpCode())); - } - - - return responseEntity; - } - - - @RequestMapping(value = "/get_vnf_data_by_globalid_and_service_type/{globalCustomerId}/{serviceType}", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getVnfDataByGlobalIdAndServiceType(HttpServletRequest request, - @PathVariable("globalCustomerId") String globalCustomerId, - @PathVariable("serviceType") String serviceType) { - - Response resp = aaiService.getVNFData(globalCustomerId, serviceType); - return convertResponseToResponseEntity(resp); - } - - - /** - * Refresh the subscriber list from a&ai. - * - * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/aai_refresh_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity doRefreshSubscriberList() { - Response resp = getSubscribers(false); - return convertResponseToResponseEntity(resp); - } - - /** - * Refresh the full subscriber list from a&ai. - * - * @return ResponseEntity The response entity - * @throws IOException Signals that an I/O exception has occurred. - */ - @RequestMapping(value = "/aai_refresh_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity doRefreshFullSubscriberList() { - Response resp = getSubscribers(false); - return convertResponseToResponseEntity(resp); - } - - /** - * Get subscriber details from a&ai. - * - * @param subscriberId the subscriber id - * @return ResponseEntity The response entity - */ - @RequestMapping(value = "/aai_sub_details/{subscriberId}", method = RequestMethod.GET) - public ResponseEntity GetSubscriberDetails(HttpServletRequest request, @PathVariable("subscriberId") String subscriberId) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - ResponseEntity responseEntity; - List roles = roleProvider.getUserRoles(request); - RoleValidator roleValidator = new RoleValidator(roles); - AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator); - String httpMessage = subscriberData.getT() != null ? - objectMapper.writeValueAsString(subscriberData.getT()) : - subscriberData.getErrorMessage(); - - responseEntity = new ResponseEntity(httpMessage, HttpStatus.valueOf(subscriberData.getHttpCode())); - return responseEntity; - } - - /** - * Get service instances that match the query from a&ai. - * - * @param subscriberId the subscriber id - * @param instanceIdentifier the service instance name or id. - * @param projects the projects that are related to the instance - * @param owningEntities the owningEntities that are related to the instance - * @return ResponseEntity The response entity - */ - @RequestMapping(value = "/search_service_instances", method = RequestMethod.GET) - public ResponseEntity SearchServiceInstances(HttpServletRequest request, - @RequestParam(value="subscriberId", required = false) String subscriberId, - @RequestParam(value="serviceInstanceIdentifier", required = false) String instanceIdentifier, - @RequestParam(value="project", required = false) List projects, - @RequestParam(value="owningEntity", required = false) List owningEntities) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - ResponseEntity responseEntity; - - List roles = roleProvider.getUserRoles(request); - RoleValidator roleValidator = new RoleValidator(roles); - - AaiResponse searchResult = aaiService.getServiceInstanceSearchResults(subscriberId, instanceIdentifier, roleValidator, owningEntities, projects); - - String httpMessage = searchResult.getT() != null ? - objectMapper.writeValueAsString(searchResult.getT()) : - searchResult.getErrorMessage(); - - - if(searchResult.getT().serviceInstances.size() == 0){ - responseEntity = new ResponseEntity(httpMessage, HttpStatus.NOT_FOUND); - - } else { - responseEntity = new ResponseEntity(httpMessage, HttpStatus.valueOf(searchResult.getHttpCode())); - - } - return responseEntity; - } - - - - /** - * Issue a named query to a&ai. - * - * @param namedQueryId the named query id - * @param globalCustomerId the global customer id - * @param serviceType the service type - * @param serviceInstance the service instance - * @return ResponseEntity The response entity - */ - @RequestMapping(value = "/aai_sub_viewedit/{namedQueryId}/{globalCustomerId}/{serviceType}/{serviceInstance}", method = RequestMethod.GET) - public ResponseEntity viewEditGetComponentList( - @PathVariable("namedQueryId") String namedQueryId, - @PathVariable("globalCustomerId") String globalCustomerId, - @PathVariable("serviceType") String serviceType, - @PathVariable("serviceInstance") String serviceInstance) { - - String componentListPayload = getComponentListPutPayload(namedQueryId, globalCustomerId, serviceType, serviceInstance); - - Response resp = doAaiPost("search/named-query", componentListPayload, false); - return convertResponseToResponseEntity(resp); - } - - @RequestMapping(value = "/aai_get_vnf_data/{globalCustomerId}/{serviceType}/{serviceInstanceId}", method = RequestMethod.GET) - public AaiResponse getVnfData( - @PathVariable("globalCustomerId") String globalCustomerId, - @PathVariable("serviceType") String serviceType, - @PathVariable("serviceInstanceId") String serviceInstanceId) { - - return aaiService.getVNFData(globalCustomerId, serviceType, serviceInstanceId); - - } - - - /** - * Issue a named query to a&ai. - * - * @param namedQueryId the named query id - * @param globalCustomerId the global customer id - * @param serviceType the service type - * @return ResponseEntity The response entity - */ - @RequestMapping(value = "/aai_get_models_by_service_type/{namedQueryId}/{globalCustomerId}/{serviceType}", method = RequestMethod.GET) - public ResponseEntity viewEditGetComponentList( - @PathVariable("namedQueryId") String namedQueryId, - @PathVariable("globalCustomerId") String globalCustomerId, - @PathVariable("serviceType") String serviceType) { - - String componentListPayload = getModelsByServiceTypePayload(namedQueryId, globalCustomerId, serviceType); - - Response resp = doAaiPost("search/named-query", componentListPayload, false); - return convertResponseToResponseEntity(resp); - } - - @RequestMapping(value = "/aai_get_vnf_instances/{globalCustomerId}/{serviceType}/{modelVersionId}/{modelInvariantId}/{cloudRegion}", method = RequestMethod.GET) - public ResponseEntity getNodeTemplateInstances( - @PathVariable("globalCustomerId") String globalCustomerId, - @PathVariable("serviceType") String serviceType, - @PathVariable("modelVersionId") String modelVersionId, - @PathVariable("modelInvariantId") String modelInvariantId, - @PathVariable("cloudRegion") String cloudRegion) { - - AaiResponse resp = aaiService.getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion); - return new ResponseEntity(resp.getT(), HttpStatus.valueOf(resp.getHttpCode())); - } - - @RequestMapping(value = "/aai_get_network_collection_details/{serviceInstanceId}", method = RequestMethod.GET) - public ResponseEntity getNetworkCollectionDetails(@PathVariable("serviceInstanceId") String serviceInstanceId) throws IOException { - com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); - AaiResponse resp = aaiService.getNetworkCollectionDetails(serviceInstanceId); - - String httpMessage = resp.getT() != null ? - objectMapper.writeValueAsString(resp.getT()) : - resp.getErrorMessage(); - return new ResponseEntity(httpMessage, HttpStatus.valueOf(resp.getHttpCode())); - } - - @RequestMapping(value = "/aai_get_instance_groups_by_cloudregion/{cloudOwner}/{cloudRegionId}/{networkFunction}", method = RequestMethod.GET) - public ResponseEntity getInstanceGroupsByCloudRegion(@PathVariable("cloudOwner") String cloudOwner, - @PathVariable("cloudRegionId") String cloudRegionId, - @PathVariable("networkFunction") String networkFunction) throws IOException { - com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); - AaiResponse resp = aaiService.getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction); - - String httpMessage = resp.getT() != null ? - objectMapper.writeValueAsString(resp.getT()) : - resp.getErrorMessage(); - return new ResponseEntity(httpMessage, HttpStatus.valueOf(resp.getHttpCode())); - } - - @RequestMapping(value = "/aai_get_by_uri/**", method = RequestMethod.GET) - public ResponseEntity getByUri(HttpServletRequest request) { - - String restOfTheUrl = (String) request.getAttribute( - HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); - String formattedUri = restOfTheUrl.replaceFirst("/aai_get_by_uri/", "").replaceFirst("^aai/v[\\d]+/", ""); - - Response resp = doAaiGet(formattedUri, false); - - return convertResponseToResponseEntity(resp); - } - - - - @RequestMapping(value = "/aai_get_configuration/{configuration_id}", method = RequestMethod.GET) - public ResponseEntity getSpecificConfiguration(@PathVariable("configuration_id") String configurationId) { - - Response resp = doAaiGet("network/configurations/configuration/"+configurationId, false); - - return convertResponseToResponseEntity(resp); - } - - @RequestMapping(value = "/aai_get_service_instance_pnfs/{globalCustomerId}/{serviceType}/{serviceInstanceId}", method = RequestMethod.GET) - public List getServiceInstanceAssociatedPnfs( - @PathVariable("globalCustomerId") String globalCustomerId, - @PathVariable("serviceType") String serviceType, - @PathVariable("serviceInstanceId") String serviceInstanceId) { - - return aaiService.getServiceInstanceAssociatedPnfs(globalCustomerId, serviceType, serviceInstanceId); - } - - /** - * PNF section - */ - @RequestMapping(value = "/aai_get_pnfs/pnf/{pnf_id}", method = RequestMethod.GET) - public ResponseEntity getSpecificPnf(@PathVariable("pnf_id") String pnfId) { - //logger.trace(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), pnfId); - AaiResponse resp; - ResponseEntity re; - try { - resp = aaiService.getSpecificPnf(pnfId); - re = new ResponseEntity(resp.getT(), HttpStatus.valueOf(resp.getHttpCode())); - } catch (Exception e){ - return new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } - //logger.trace(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), resp.getHttpCode()); - return re; - } - - - /** - * Obtain tenants for a given service type. - * - * @param globalCustomerId the global customer id - * @param serviceType the service type - * @return ResponseEntity The response entity - */ - @RequestMapping(value = "/aai_get_tenants/{global-customer-id}/{service-type}", method = RequestMethod.GET) - public ResponseEntity viewEditGetTenantsFromServiceType(HttpServletRequest request, - @PathVariable("global-customer-id") String globalCustomerId, @PathVariable("service-type") String serviceType) { - - ResponseEntity responseEntity; - try { - ObjectMapper objectMapper = new ObjectMapper(); - List roles = roleProvider.getUserRoles(request); - RoleValidator roleValidator = new RoleValidator(roles); - AaiResponse response = aaiService.getTenants(globalCustomerId, serviceType, roleValidator); - if (response.getHttpCode() == 200) { - responseEntity = new ResponseEntity(objectMapper.writeValueAsString(response.getT()), HttpStatus.OK); - } else { - responseEntity = new ResponseEntity(response.getErrorMessage(), HttpStatus.valueOf(response.getHttpCode())); - } - } catch (Exception e) { - responseEntity = new ResponseEntity("Unable to proccess getTenants reponse", HttpStatus.INTERNAL_SERVER_ERROR); - } - return responseEntity; - } - - @RequestMapping(value = "/aai_get_pnf_instances/{globalCustomerId}/{serviceType}/{modelVersionId}/{modelInvariantId}/{cloudRegion}/{equipVendor}/{equipModel}", method = RequestMethod.GET) - public ResponseEntity getPnfInstances( - @PathVariable("globalCustomerId") String globalCustomerId, - @PathVariable("serviceType") String serviceType, - @PathVariable("modelVersionId") String modelVersionId, - @PathVariable("modelInvariantId") String modelInvariantId, - @PathVariable("cloudRegion") String cloudRegion, - @PathVariable("equipVendor") String equipVendor, - @PathVariable("equipModel") String equipModel) { - - AaiResponse resp = aaiService.getPNFData(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor, equipModel); - return new ResponseEntity(resp.getT(), HttpStatus.valueOf(resp.getHttpCode())); - } - - @RequestMapping(value = "/aai_getPortMirroringConfigsData", method = RequestMethod.GET) - public Map getPortMirroringConfigsData( - @RequestParam ("configurationIds") List configurationIds) { - - return configurationIds.stream() - .map(id -> ImmutablePair.of(id, aaiService.getPortMirroringConfigData(id))) - .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); - } - - @RequestMapping(value = "/aai_getPortMirroringSourcePorts", method = RequestMethod.GET) - public Map getPortMirroringSourcePorts( - @RequestParam ("configurationIds") List configurationIds) { - - return configurationIds.stream() - .map(id -> ImmutablePair.of(id, aaiService.getPortMirroringSourcePorts(id))) - .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); - } - - private ResponseEntity convertResponseToResponseEntity(Response resp) { - ResponseEntity respEnt; - ObjectMapper objectMapper = new ObjectMapper(); - if (resp == null) { - respEnt = new ResponseEntity("Failed to fetch data from A&AI, check server logs for details.", HttpStatus.INTERNAL_SERVER_ERROR); - } else { - respEnt = new ResponseEntity(resp.readEntity(String.class), HttpStatus.valueOf(resp.getStatus())); - } - return respEnt; - } - - /** - * Gets the subscribers. - * - * @param isFullSet the is full set - * @return the subscribers - */ - private Response getSubscribers(boolean isFullSet) { - - String depth = "0"; - - Response resp = doAaiGet("business/customers?subscriber-type=INFRA&depth=" + depth, false); - if (resp != null) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString()); - } - return resp; - } - - /** - * Gets the subscriber details. - * - * @param subscriberId the subscriber id - * @return the subscriber details - */ - private Response getSubscriberDetails(String subscriberId) { - Response resp = doAaiGet("business/customers/customer/" + subscriberId + "?depth=2", false); - //String resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId, false); - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscriberDetails() resp=" + resp.getStatusInfo().toString()); - return resp; - } - - /** - * Send a GET request to a&ai. - * - * @param uri the uri - * @param xml the xml - * @return String The response - */ - protected Response doAaiGet(String uri, boolean xml) { - String methodName = "getSubscriberList"; - String transId = UUID.randomUUID().toString(); - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - Response resp = null; - try { - - - resp = aaiRestInterface.RestGet(fromAppId, transId, uri, xml).getResponse(); - - } catch (WebApplicationException e) { - final String message = e.getResponse().readEntity(String.class); - LOGGER.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message); - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message); - } catch (Exception e) { - LOGGER.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - } - - return resp; - } - - /** - * Send a POST request to a&ai. - * - * @param uri the uri - * @param payload the payload - * @param xml the xml - * @return String The response - */ - protected Response doAaiPost(String uri, String payload, boolean xml) { - String methodName = "getSubscriberList"; - String transId = UUID.randomUUID().toString(); - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - Response resp = null; - try { - - resp = aaiRestInterface.RestPost(fromAppId, uri, payload, xml); - - } catch (Exception e) { - LOGGER.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - } - - return resp; - } - - /** - * Gets the component list put payload. - * - * @param namedQueryId the named query id - * @param globalCustomerId the global customer id - * @param serviceType the service type - * @param serviceInstance the service instance - * @return the component list put payload - */ - private String getComponentListPutPayload(String namedQueryId, String globalCustomerId, String serviceType, String serviceInstance) { - return - " {" + - " \"instance-filters\": {" + - " \"instance-filter\": [" + - " {" + - " \"customer\": {" + - " \"global-customer-id\": \"" + globalCustomerId + "\"" + - " }," + - " \"service-instance\": {" + - " \"service-instance-id\": \"" + serviceInstance + "\"" + - " }," + - " \"service-subscription\": {" + - " \"service-type\": \"" + serviceType + "\"" + - " }" + - " }" + - " ]" + - " }," + - " \"query-parameters\": {" + - " \"named-query\": {" + - " \"named-query-uuid\": \"" + namedQueryId + "\"" + - " }" + - " }" + - "}"; - - } - - private String getModelsByServiceTypePayload(String namedQueryId, String globalCustomerId, String serviceType) { - // TODO Auto-generated method stub - return " {" + - " \"instance-filters\": {" + - " \"instance-filter\": [" + - " {" + - " \"customer\": {" + - " \"global-customer-id\": \"" + globalCustomerId + "\"" + - " }," + - " \"service-subscription\": {" + - " \"service-type\": \"" + serviceType + "\"" + - " }" + - " }" + - " ]" + - " }," + - " \"query-parameters\": {" + - " \"named-query\": {" + - " \"named-query-uuid\": \"" + namedQueryId + "\"" + - " }" + - " }" + - "}"; - - } - - private String getAaiErrorMessage(String message) { - try { - org.json.JSONObject json = new org.json.JSONObject(message); - json = json.getJSONObject("requestError").getJSONObject("serviceException"); - - return json.getString("messageId") + ": " + json.getString("text"); - - } catch (Exception e) { - return null; - } - } -} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/AsyncControllerForTests.java b/vid-app-common/src/main/java/org/onap/vid/controllers/AsyncControllerForTests.java deleted file mode 100644 index c4d829328..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/AsyncControllerForTests.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.onap.vid.controllers; - -import org.onap.vid.exceptions.GenericUncheckedException; -import org.onap.vid.model.ExceptionResponse; -import org.onap.vid.model.JobBulk; -import org.onap.vid.model.JobModel; -import org.onap.vid.services.BulkInstantiationService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; - -import javax.ws.rs.WebApplicationException; -import java.util.Map; -import java.util.UUID; - -import static org.springframework.http.HttpStatus.BAD_REQUEST; - -@RestController -@RequestMapping("asyncForTests") -public class AsyncControllerForTests extends VidRestrictedBaseController { - - private BulkInstantiationService bulkInstantiationService; - - @Autowired - public AsyncControllerForTests(BulkInstantiationService bulkInstantiationService) { - this.bulkInstantiationService = bulkInstantiationService; - } - - @RequestMapping(method = RequestMethod.POST) - public JobBulk createAsyncJob(@RequestBody Map body) { - return bulkInstantiationService.saveBulk(body); - } - - @RequestMapping(value = "/job/{uuid}", method = RequestMethod.GET) - public JobModel getJob(@PathVariable UUID uuid) { - return bulkInstantiationService.getJob(uuid); - } - - @RequestMapping(value = "/error", method = RequestMethod.GET) - public void throwError() { - throw new GenericUncheckedException("dummy error"); - } - - @ExceptionHandler({IllegalArgumentException.class}) - @ResponseStatus(value=BAD_REQUEST) - private ExceptionResponse exceptionHandlerBadRequest(Exception e) { - return ControllersUtils.handleException(e, LOGGER); - } - - @ExceptionHandler(WebApplicationException.class) - private ResponseEntity webApplicationExceptionHandler(WebApplicationException e) { - return ControllersUtils.handleWebApplicationException(e, LOGGER); - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/AsyncInstantiationController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/AsyncInstantiationController.java deleted file mode 100644 index c5621a307..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/AsyncInstantiationController.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.onap.vid.controllers; - - -import org.onap.vid.exceptions.OperationNotAllowedException; -import org.onap.vid.model.ExceptionResponse; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.exception.ExceptionUtils; - -import org.onap.vid.model.JobAuditStatus; -import org.onap.vid.model.ServiceInfo; -import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; -import org.onap.vid.mso.MsoResponseWrapper2; -import org.onap.vid.services.AsyncInstantiationBusinessLogic; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.UUID; -import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED; - - -@RestController -@RequestMapping(AsyncInstantiationController.ASYNC_INSTANTIATION) -public class AsyncInstantiationController extends VidRestrictedBaseController { - - public static final String ASYNC_INSTANTIATION = "asyncInstantiation"; - - protected final AsyncInstantiationBusinessLogic asyncInstantiationBL; - - @Autowired - public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL) { - this.asyncInstantiationBL = asyncInstantiationBL; - } - - @ExceptionHandler(OperationNotAllowedException.class) - @ResponseStatus(value=METHOD_NOT_ALLOWED) - public ExceptionResponse illegalStateExceptionHandler(Exception e) { - return ControllersUtils.handleException(e, LOGGER); - } - - /** - * Gets the new services status. - * @param request the request - * @return the services list - */ - @RequestMapping(method = RequestMethod.GET) - public List getServicesInfo(HttpServletRequest request) { - return asyncInstantiationBL.getAllServicesInfo(); - } - - @RequestMapping(value = "bulk", method = RequestMethod.POST) - public MsoResponseWrapper2> createBulkOfServices(@RequestBody ServiceInstantiation request, HttpServletRequest httpServletRequest) { - //Push to DB according the model - - String userId = ControllersUtils.extractUserId(httpServletRequest); - List uuids = asyncInstantiationBL.pushBulkJob(request, userId); - - return new MsoResponseWrapper2(200, uuids); - } - - @RequestMapping(value = "job/{jobId}", method = RequestMethod.DELETE) - public void deleteServiceInfo(@PathVariable("jobId") UUID jobId) { - asyncInstantiationBL.deleteJob(jobId); - } - - @RequestMapping(value = "hide/{jobId}", method = RequestMethod.POST) - public void hideServiceInfo(@PathVariable("jobId") UUID jobId) { - asyncInstantiationBL.hideServiceInfo(jobId); - } - - @RequestMapping(value = "auditStatus/{jobId}", method = RequestMethod.GET) - public List getJobAuditStatus(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId, @RequestParam(value="source") JobAuditStatus.SourceStatus source){ - return asyncInstantiationBL.getAuditStatuses(jobId, source); - } - - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/ChangeManagementController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/ChangeManagementController.java deleted file mode 100644 index 88875b510..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/ChangeManagementController.java +++ /dev/null @@ -1,227 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright © 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright 2018 Nokia - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.controllers; - -import static org.onap.vid.utils.Logging.getMethodName; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; -import static org.springframework.http.HttpStatus.OK; - -import com.fasterxml.jackson.databind.ObjectMapper; -import java.util.Collection; -import java.util.Collections; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.WebApplicationException; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.json.simple.JSONArray; -import org.onap.portalsdk.core.controller.UnRestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.changeManagement.ChangeManagementRequest; -import org.onap.vid.changeManagement.GetVnfWorkflowRelationRequest; -import org.onap.vid.changeManagement.GetWorkflowsResponse; -import org.onap.vid.changeManagement.VnfWorkflowRelationAllResponse; -import org.onap.vid.changeManagement.VnfWorkflowRelationRequest; -import org.onap.vid.changeManagement.VnfWorkflowRelationResponse; -import org.onap.vid.exceptions.NotFoundException; -import org.onap.vid.model.ExceptionResponse; -import org.onap.vid.model.MsoExceptionResponse; -import org.onap.vid.mso.MsoResponseWrapper2; -import org.onap.vid.mso.MsoResponseWrapperInterface; -import org.onap.vid.mso.rest.Request; -import org.onap.vid.services.ChangeManagementService; -import org.onap.vid.services.WorkflowService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -/** - * Controller to handle ChangeManagement feature requests. - */ -@RestController -@RequestMapping(ChangeManagementController.CHANGE_MANAGEMENT) -public class ChangeManagementController extends UnRestrictedBaseController { - public static final String VNF_WORKFLOW_RELATION = "vnf_workflow_relation"; - public static final String CHANGE_MANAGEMENT = "change-management"; - public static final String GET_VNF_WORKFLOW_RELATION = "get_vnf_workflow_relation"; - public static final String SCHEDULER_BY_SCHEDULE_ID = "/scheduler/schedules/{scheduleId}"; - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ChangeManagementController.class); - private String fromAppId; - private final WorkflowService workflowService; - private final ChangeManagementService changeManagementService; - private final ObjectMapper objectMapper; - - - @Autowired - public ChangeManagementController(WorkflowService workflowService, ChangeManagementService changeManagementService, ObjectMapper objectMapper) { - this.fromAppId = "VidChangeManagementController"; - this.workflowService = workflowService; - this.changeManagementService = changeManagementService; - this.objectMapper = objectMapper; - } - - @RequestMapping(value = {"/workflow"}, method = RequestMethod.GET) - public ResponseEntity> getWorkflow(@RequestParam("vnfs") Collection vnfs) { - Collection result = this.workflowService.getWorkflowsForVNFs(vnfs); - return new ResponseEntity<>(result, OK); - } - - @RequestMapping(value = {"/mso"}, method = RequestMethod.GET) - public ResponseEntity> getMSOChangeManagements() { - - Collection result = this.changeManagementService.getMSOChangeManagements(); - return new ResponseEntity<>(result, OK); - } - - @RequestMapping(value = "/workflow/{vnfName}", method = RequestMethod.POST) - public ResponseEntity changeManagement(HttpServletRequest request, @PathVariable("vnfName") String vnfName, - @RequestBody ChangeManagementRequest changeManagmentRequest) - throws Exception { - return this.changeManagementService.doChangeManagement(changeManagmentRequest, vnfName); - } - - @RequestMapping(value = "/uploadConfigUpdateFile", method = RequestMethod.POST) - public @ResponseBody ResponseEntity uploadConfigUpdateFile(@RequestPart("file") MultipartFile file) - throws Exception { - try { - String jsonString = this.changeManagementService.uploadConfigUpdateFile(file); - return new ResponseEntity<>(jsonString, HttpStatus.OK); - } - catch(WebApplicationException e){ - return new ResponseEntity<>(handleException(e), HttpStatus.valueOf(e.getResponse().getStatus())); - } - catch (Exception e) { - return new ResponseEntity<>(handleException(e), INTERNAL_SERVER_ERROR); - } - } - - - @RequestMapping(value = {"/scheduler"}, method = RequestMethod.GET) - public ResponseEntity getSchedulerChangeManagements() { - JSONArray result = this.changeManagementService.getSchedulerChangeManagements(); - return new ResponseEntity<>(result, OK); - } - - @RequestMapping(value = {SCHEDULER_BY_SCHEDULE_ID}, method = RequestMethod.DELETE) - public ResponseEntity deleteSchedule(@PathVariable("scheduleId") String scheduleId) { - Pair result = this.changeManagementService.deleteSchedule(scheduleId); - return ResponseEntity.status(result.getRight()).build(); - } - - - @RequestMapping(value = {GET_VNF_WORKFLOW_RELATION}, method = RequestMethod.POST) - public ResponseEntity getWorkflows(@RequestBody GetVnfWorkflowRelationRequest getVnfWorkflowRelationRequest) { - try { - GetWorkflowsResponse response = new GetWorkflowsResponse(changeManagementService.getWorkflowsForVnf(getVnfWorkflowRelationRequest)); - return ResponseEntity.status(OK).body(response); - } - catch (NotFoundException exception) { - LOGGER.error(exception.getMessage(), exception); - return new ResponseEntity<>(new VnfWorkflowRelationResponse(Collections.singletonList(exception.getMessage())),HttpStatus.NOT_FOUND); - } - catch (Exception exception) { - return handleException(exception, "Failed to get workflows for vnf"); - } - } - - @RequestMapping(value = {VNF_WORKFLOW_RELATION}, method = RequestMethod.POST) - public ResponseEntity createWorkflowRelation(@RequestBody VnfWorkflowRelationRequest vnfWorkflowRelationRequest) { - VnfWorkflowRelationResponse vnfWorkflowRelationResponse; - try { - vnfWorkflowRelationResponse = changeManagementService.addVnfWorkflowRelation(vnfWorkflowRelationRequest); - } - catch (Exception exception) { - return handleException(exception, "Failed to add vnf to workflow relation"); - } - - return new ResponseEntity<>(vnfWorkflowRelationResponse, OK); - } - - @RequestMapping(value = {VNF_WORKFLOW_RELATION}, method = RequestMethod.GET) - public ResponseEntity getAllWorkflowRelation() { - - try { - VnfWorkflowRelationAllResponse vnfWorkflowRelationAllResponse = changeManagementService.getAllVnfWorkflowRelations(); - return new ResponseEntity<>(vnfWorkflowRelationAllResponse, OK); - } - catch (Exception exception) { - return handleException(exception, "Failed to get all vnf to workflow relations"); - } - } - - @RequestMapping(value = {VNF_WORKFLOW_RELATION}, method = RequestMethod.DELETE) - public ResponseEntity deleteWorkflowRelation(@RequestBody VnfWorkflowRelationRequest vnfWorkflowRelationRequest) { - VnfWorkflowRelationResponse vnfWorkflowRelationResponse; - try { - vnfWorkflowRelationResponse = changeManagementService.deleteVnfWorkflowRelation(vnfWorkflowRelationRequest); - } - catch (Exception exception) { - return handleException(exception, "Failed to delete vnf from workflow relation"); - } - - return new ResponseEntity<>(vnfWorkflowRelationResponse, OK); - } - - private ResponseEntity handleException(Exception exception, String msg) { - LOGGER.error(msg, exception); - return new ResponseEntity<>(new VnfWorkflowRelationResponse(Collections.singletonList(msg)), HttpStatus.INTERNAL_SERVER_ERROR); - } - - - private ExceptionResponse handleException(Exception e) { - return ControllersUtils.handleException(e, LOGGER); - } - - @ExceptionHandler(Exception.class) - @ResponseStatus(value=OK) //return 200 for Backwards compatibility with the previous responses to scheduler - private MsoResponseWrapperInterface exceptionHandler(Exception e) { - return exceptionHandler(e, INTERNAL_SERVER_ERROR); - } - - @ExceptionHandler({ - javax.ws.rs.BadRequestException.class, - }) - @ResponseStatus(value = OK) //return 200 for Backwards compatibility with the previous responses to scheduler - public MsoResponseWrapperInterface clientDerivedExceptionAsBadRequest(Exception e) { - // same handler, different HTTP Code - return exceptionHandler(e, BAD_REQUEST); - } - - private MsoResponseWrapperInterface exceptionHandler(Exception e, HttpStatus httpStatus) { - LOGGER.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodName(), ExceptionUtils.getMessage(e), e); - MsoResponseWrapper2 responseWrapper2 = new MsoResponseWrapper2<>(httpStatus.value(), new MsoExceptionResponse(e)); - return responseWrapper2; - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java b/vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java deleted file mode 100644 index 1abe300ef..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.onap.vid.controllers; - -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.onap.portalsdk.core.domain.User; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.model.ExceptionResponse; -import org.slf4j.MDC; -import org.springframework.http.ResponseEntity; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; -import javax.ws.rs.WebApplicationException; - -import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; -import static org.onap.vid.utils.Logging.getMethodName; - -public class ControllersUtils { - - - public static String extractUserId(HttpServletRequest request) { - String userId = ""; - HttpSession session = request.getSession(); - if (session != null) { - User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)); - if (user != null) { - //userId = user.getHrid(); - userId = user.getLoginId(); - if (userId == null) - userId = user.getOrgUserId(); - } - } - return userId; - } - - public static ExceptionResponse handleException(Exception e, EELFLoggerDelegate logger) { - logger.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodName(), ExceptionUtils.getMessage(e), e); - - ExceptionResponse exceptionResponse = new ExceptionResponse(e); - return exceptionResponse; - } - - public static ResponseEntity handleWebApplicationException(WebApplicationException e, EELFLoggerDelegate logger) { - return ResponseEntity.status(e.getResponse().getStatus()).body(ControllersUtils.handleException(e, logger)); - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/FeatureTogglingController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/FeatureTogglingController.java deleted file mode 100644 index 36dfdaa0a..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/FeatureTogglingController.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.onap.vid.controllers; - -import org.onap.vid.properties.Features; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; - -import java.util.HashMap; -import java.util.Map; - -@RestController -@RequestMapping("flags") -public class FeatureTogglingController extends RestrictedBaseController { - - @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody Map getFeatureToggles() - { - HashMap flags = new HashMap (); - for(Features flag : Features.values()){ - flags.put(flag.name(), flag.isActive()); - } - return flags; - - - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/HealthCheckController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/HealthCheckController.java deleted file mode 100644 index 86e832ba7..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/HealthCheckController.java +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.controllers; - -import org.onap.portalsdk.core.controller.UnRestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.dao.FnAppDoaImpl; -import org.onap.vid.model.GitRepositoryState; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Properties; - -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; -import static org.springframework.http.HttpStatus.OK; - -/** - * Controller for user profile view. The view is restricted to authenticated - * users. The view name resolves to page user_profile.jsp which uses Angular. - */ - -@RestController -@RequestMapping("/") -public class HealthCheckController extends UnRestrictedBaseController { - - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(HealthCheckController.class); - private static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - private static final String GIT_PROPERTIES_FILENAME = "git.properties"; - private FnAppDoaImpl fnAppDoaImpl; - - @Autowired - public HealthCheckController(FnAppDoaImpl fnAppDoaImpl) { - this.fnAppDoaImpl = fnAppDoaImpl; - } - - /** - * Obtain the HealthCheck Status from the System.Properties file. - * Used by IDNS for redundancy - * - * @return ResponseEntity The response entity - */ - @RequestMapping(value = "/healthCheck", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public HealthStatus getHealthCheckStatusForIDNS() { - return createCorrespondingStatus(); - } - - /** - * Obtain the HealthCheck Status from the System.Properties file. - * - * @return ResponseEntity The response entity - */ - @RequestMapping(value = "rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public HealthStatus getHealthCheck( - @PathVariable("User-Agent") String UserAgent, - @PathVariable("X-ECOMP-RequestID") String ECOMPRequestID) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "User-Agent ", UserAgent); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "X-ECOMP-RequestID ", ECOMPRequestID); - return createCorrespondingStatus(); - } - - @RequestMapping(value = "/commitInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public GitRepositoryState getCommitInfo() throws IOException { - Properties properties = new Properties(); - properties.load(getClass().getClassLoader().getResourceAsStream(GIT_PROPERTIES_FILENAME)); - return new GitRepositoryState(properties); - } - - private HealthStatus createCorrespondingStatus() { - logData(); - try { - int count = fnAppDoaImpl.getProfileCount(getUrl(), getUsername(), getPassword()); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "count:::", count); - return okStatus(); - } catch (Exception ex) { - String errorMsg = ex.getMessage(); - LOGGER.error(EELFLoggerDelegate.errorLogger, errorMsg); - return errorStatus(errorMsg); - } - } - - private void logData() { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "Performing health check"); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "URL::", getUrl()); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "username::", getUsername()); - } - - private HealthStatus okStatus() { - return new HealthStatus(OK, dateFormat.format(new Date()), "health check succeeded"); - } - - private HealthStatus errorStatus(String msg) { - return new HealthStatus(INTERNAL_SERVER_ERROR, dateFormat.format( - new Date()), "health check failed: " + msg); - } - - private String getUrl() { - return SystemProperties.getProperty("db.connectionURL"); - } - - private String getUsername() { - return SystemProperties.getProperty("db.userName"); - } - - private String getPassword() { - return SystemProperties.getProperty("db.password"); - } -} - diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/HealthStatus.java b/vid-app-common/src/main/java/org/onap/vid/controllers/HealthStatus.java deleted file mode 100644 index 6056c2898..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/HealthStatus.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.onap.vid.controllers; - -import org.springframework.http.HttpStatus; - -/** - * Model for JSON response with health-check results. - */ -public final class HealthStatus { - - private final int statusCode; - private final String detailedMsg; - private final String date; - - public HealthStatus(HttpStatus code, String date, String detailedMsg) { - this.statusCode = code.value(); - this.detailedMsg = detailedMsg; - this.date = date; - } - - public int getStatusCode() { - return statusCode; - } - - public String getDetailedMsg() { - return detailedMsg; - } - - public String getDate() { - return date; - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/LoggerController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/LoggerController.java deleted file mode 100644 index 14d027216..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/LoggerController.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.onap.vid.controllers; - -import ch.qos.logback.classic.LoggerContext; -import ch.qos.logback.core.Appender; -import ch.qos.logback.core.FileAppender; -import ch.qos.logback.core.spi.AppenderAttachable; -import org.apache.commons.io.input.ReversedLinesFileReader; -import org.apache.commons.lang3.StringUtils; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.model.ExceptionResponse; -import org.onap.vid.roles.Role; -import org.onap.vid.roles.RoleProvider; -import org.onap.vid.utils.Streams; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.InternalServerErrorException; -import javax.ws.rs.NotAuthorizedException; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Objects; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static com.att.eelf.configuration.Configuration.GENERAL_LOGGER_NAME; - - -@RestController -@RequestMapping("logger") -public class LoggerController extends RestrictedBaseController { - - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(LoggerController.class); - - @Autowired - RoleProvider roleProvider; - - @RequestMapping(value = "/{loggerName:audit|error|metrics}", method = RequestMethod.GET) - public String getLog(@PathVariable String loggerName, HttpServletRequest request, - @RequestParam(value="limit", defaultValue = "5000") Integer limit) throws IOException { - - List roles = roleProvider.getUserRoles(request); - boolean userPermitted = roleProvider.userPermissionIsReadLogs(roles); - if (!userPermitted) { - throw new NotAuthorizedException("User not authorized to get logs"); - } - - String logfilePath = getLogfilePath(loggerName); - - try (final ReversedLinesFileReader reader = new ReversedLinesFileReader(new File(logfilePath))) { - Supplier reverseLinesSupplier = () -> { - try { - return reader.readLine(); - } catch (NullPointerException e) { - // EOF Reached - return null; - } catch (IOException e) { - throw new InternalServerErrorException("error while reading " + logfilePath, e); - } - }; - - return Streams.takeWhile( - Stream.generate(reverseLinesSupplier), - line -> !StringUtils.contains(line, "Logging is started")) - .limit(limit) - .limit(5_000) - .filter(Objects::nonNull) - .collect(Collectors.joining("\n")); - } - } - - private String getLogfilePath(String loggerName) { - /* - Find the requested logger, and pull all of it's appenders. - Find the first of the appenders that is a FileAppender, and return it's - write-out filename. - */ - LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); - return context.getLoggerList().stream() - .filter(logger -> logger.getName().equals(GENERAL_LOGGER_NAME + "." + loggerName)) - .flatMap(this::pullSubAppenders) - .flatMap(appender -> { - // Appender might be "attachable", if so - roll-up its sub-appenders - return (appender instanceof AppenderAttachable) ? - pullSubAppenders((AppenderAttachable) appender) : Stream.of(appender); - }) - .filter(appender -> appender instanceof FileAppender) - .map(appender -> (FileAppender) appender) - .map(FileAppender::getFile) - .findFirst() - .orElseThrow(() -> new InternalServerErrorException("logfile for " + loggerName + " not found")); - } - - private Stream> pullSubAppenders(AppenderAttachable logger) { - return Streams.fromIterator(logger.iteratorForAppenders()); - } - - @ExceptionHandler({ NotAuthorizedException.class }) - @ResponseStatus(HttpStatus.UNAUTHORIZED) - public String notAuthorizedHandler(NotAuthorizedException e) { - return "UNAUTHORIZED"; - } - - @ExceptionHandler({ IOException.class, InternalServerErrorException.class }) - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public ExceptionResponse ioExceptionHandler(Exception e) { - return org.onap.vid.controllers.ControllersUtils.handleException(e, LOGGER); - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/MaintenanceController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/MaintenanceController.java deleted file mode 100644 index 1a3eb42fa..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/MaintenanceController.java +++ /dev/null @@ -1,156 +0,0 @@ -package org.onap.vid.controllers; - -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright © 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright 2018 Nokia - * ================================================================================ - * 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========================================================= - */ - -import static org.onap.vid.utils.Logging.getMethodCallerName; - -import javax.ws.rs.ForbiddenException; -import org.onap.portalsdk.core.controller.UnRestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.category.AddCategoryOptionResponse; -import org.onap.vid.category.AddCategoryOptionsRequest; -import org.onap.vid.category.CategoryParameterOptionRep; -import org.onap.vid.category.CategoryParametersResponse; -import org.onap.vid.model.CategoryParameter.Family; -import org.onap.vid.model.CategoryParameterOption; -import org.onap.vid.services.CategoryParameterService; -import org.onap.vid.services.CategoryParameterServiceImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * Controler for APIs that are used only by vid operators - */ - -@RestController -@RequestMapping("maintenance") -public class MaintenanceController extends UnRestrictedBaseController { - - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(MaintenanceController.class); - private CategoryParameterService categoryParameterService; - - @Autowired - public MaintenanceController(CategoryParameterService categoryParameterService) { - this.categoryParameterService = categoryParameterService; - } - - /** - * Add list of options to one category parameter - */ - @RequestMapping(value = "/category_parameter/{categoryName}", method = RequestMethod.POST) - public ResponseEntity addCategoryOptions(@PathVariable String categoryName, - @RequestBody AddCategoryOptionsRequest option) { - debugStartLog(); - try { - AddCategoryOptionResponse response = categoryParameterService - .createCategoryParameterOptions(categoryName, option); - HttpStatus httpStatus = response.getErrors().isEmpty() ? HttpStatus.OK : HttpStatus.MULTI_STATUS; - debugEndLog(response); - return createResponseWithBody(httpStatus, response); - } catch (CategoryParameterServiceImpl.UnfoundedCategoryException exception) { - return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); - } catch (RuntimeException exception) { - LOGGER.error("failed to add option to parameter category " + categoryName, exception); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - } - - @RequestMapping(value = "/category_parameter/{categoryName}", method = RequestMethod.PUT) - public ResponseEntity updateNameForOption(@PathVariable String categoryName, - @RequestBody CategoryParameterOptionRep option) { - debugStartLog(); - try { - AddCategoryOptionResponse response = categoryParameterService - .updateCategoryParameterOption(categoryName, option); - HttpStatus httpStatus = response.getErrors().isEmpty() ? HttpStatus.OK : HttpStatus.MULTI_STATUS; - debugEndLog(response); - return createResponseWithBody(httpStatus, response); - } catch (ForbiddenException exception) { - return createResponseWithBody(HttpStatus.FORBIDDEN, new AddCategoryOptionResponse(exception.getMessage())); - } catch (CategoryParameterServiceImpl.UnfoundedCategoryException | CategoryParameterServiceImpl.UnfoundedCategoryOptionException exception) { - return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); - - } catch (CategoryParameterServiceImpl.AlreadyExistOptionNameException exception) { - return createResponseWithBody(HttpStatus.CONFLICT, new AddCategoryOptionResponse(exception.getMessage())); - - } catch (RuntimeException exception) { - LOGGER.error("failed to update option to parameter category " + categoryName, exception); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - } - - /** - * Gets the owning entity properties. - */ - @RequestMapping(value = "/category_parameter", method = RequestMethod.GET) - public ResponseEntity getCategoryParameter(@RequestParam(value = "familyName", required = true) Family familyName) { - debugStartLog(); - try { - CategoryParametersResponse response = categoryParameterService.getCategoryParameters(familyName); - debugEndLog(response); - return ResponseEntity.ok().body(response); - } catch (RuntimeException exception) { - LOGGER.error("failed to retrieve category parameter list from DB.", exception); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - } - - /** - * Delete option of the category. - */ - @RequestMapping(value = "/delete_category_parameter/{categoryName}", method = RequestMethod.DELETE) - public ResponseEntity deleteCategoryOption(@PathVariable String categoryName, - @RequestBody CategoryParameterOption option) { - debugStartLog(); - - try { - categoryParameterService.deleteCategoryOption(categoryName, option); - debugEndLog(HttpStatus.OK); - return ResponseEntity.status(HttpStatus.OK).build(); - } catch (CategoryParameterServiceImpl.UnfoundedCategoryException exception) { - return createResponseWithBody(HttpStatus.NOT_FOUND, new AddCategoryOptionResponse(exception.getMessage())); - } catch (RuntimeException exception) { - LOGGER.error("failed to add/update owning entity option", exception); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - } - - private ResponseEntity createResponseWithBody(HttpStatus status, AddCategoryOptionResponse response) { - return ResponseEntity.status(status).body(response); - } - - private void debugStartLog() { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodCallerName()); - } - - private void debugEndLog(Object response) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodCallerName(), response); - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/MsoConfig.java b/vid-app-common/src/main/java/org/onap/vid/controllers/MsoConfig.java deleted file mode 100644 index 020018ade..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/MsoConfig.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.vid.controllers; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.portalsdk.core.util.SystemProperties; - -import org.onap.vid.client.SyncRestClient; -import org.onap.vid.factories.MsoRequestFactory; -import org.onap.vid.mso.MsoBusinessLogic; -import org.onap.vid.mso.MsoBusinessLogicImpl; -import org.onap.vid.mso.MsoInterface; -import org.onap.vid.mso.MsoProperties; -import org.onap.vid.mso.rest.MsoRestClientNew; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.togglz.core.manager.FeatureManager; - - -@Configuration -public class MsoConfig { - - /** - * Gets the object mapper. - * - * @return the object mapper - */ - @Bean - public ObjectMapper getObjectMapper() { - return new ObjectMapper(); - } - - @Bean - public MsoRequestFactory createRequestDetailsFactory(){ - return new MsoRequestFactory(); - } - - @Bean - public MsoInterface getMsoClient(){ - return new MsoRestClientNew(new SyncRestClient(MsoInterface.objectMapper()), SystemProperties.getProperty( - MsoProperties.MSO_SERVER_URL)); - } - - @Bean - public MsoBusinessLogic getMsoBusinessLogic(MsoInterface msoClient, FeatureManager featureManager){ - return new MsoBusinessLogicImpl(msoClient, featureManager); - } - - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/MsoController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/MsoController.java deleted file mode 100644 index 62c64b75c..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/MsoController.java +++ /dev/null @@ -1,693 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.controllers; - - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.vid.model.ExceptionResponse; -import org.onap.vid.mso.MsoBusinessLogic; -import org.onap.vid.mso.MsoResponseWrapper; -import org.onap.vid.mso.rest.Request; -import org.onap.vid.mso.rest.RequestDetails; -import org.onap.vid.mso.rest.RequestDetailsWrapper; -import org.onap.vid.mso.rest.Task; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; - -import static org.onap.vid.utils.Logging.getMethodName; - -//import java.util.UUID; -//import org.springframework.http.ResponseEntity; -//import org.springframework.http.RequestEntity; - -/** - * The Class MsoController. - */ -@RestController -@RequestMapping("mso") -public class MsoController extends RestrictedBaseController { - - /** - * The logger. - */ - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(MsoController.class); - - /** - * The Constant dateFormat. - */ - private final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - /** - * The Constant SVC_INSTANCE_ID. - */ - public final static String SVC_INSTANCE_ID = ""; - public final static String REQUEST_TYPE = ""; - - /** - * The Constant CONFIGURATION_ID - */ - public final static String CONFIGURATION_ID = ""; - - /** - * The Constant VNF_INSTANCE_ID. - */ - public final static String VNF_INSTANCE_ID = ""; - - private final MsoBusinessLogic msoBusinessLogic; - - @Autowired - public MsoController(MsoBusinessLogic msoBusinessLogic) { - this.msoBusinessLogic = msoBusinessLogic; - } - - /** - * Creates the svc instance. - * - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_create_svc_instance", method = RequestMethod.POST) - public ResponseEntity createSvcInstance(HttpServletRequest request, @RequestBody RequestDetails mso_request) { - String methodName = "createSvcInstance"; - - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - // always return OK, the MSO status code is embedded in the body - - MsoResponseWrapper w = msoBusinessLogic.createSvcInstance(mso_request); - - return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK)); - - } - - /** - * Creates the e2e svc instance. - * - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_create_e2e_svc_instance", method = RequestMethod.POST) - public ResponseEntity createE2eSvcInstance(HttpServletRequest request, @RequestBody LinkedHashMap mso_request) { - String methodName = "createE2eSvcInstance"; - - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - // always return OK, the MSO status code is embedded in the body - - MsoResponseWrapper w = msoBusinessLogic.createE2eSvcInstance(mso_request.get("requestDetails")); - - return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK)); - - } - - /** - * Creates the vnf. - * - * @param serviceInstanceId the service instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_create_vnf_instance/{serviceInstanceId}", method = RequestMethod.POST) - public ResponseEntity createVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) { - - MsoResponseWrapper w = msoBusinessLogic.createVnf(mso_request, serviceInstanceId); - - // always return OK, the MSO status code is embedded in the body - - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - - } - - /** - * Creates the nw instance. - * - * @param serviceInstanceId the service instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_create_nw_instance/{serviceInstanceId}", method = RequestMethod.POST) - public ResponseEntity createNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) { - String methodName = "createNwInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start, serviceInstanceId = " + serviceInstanceId); - - MsoResponseWrapper w = msoBusinessLogic.createNwInstance(mso_request, serviceInstanceId); - - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - - } - - /** - * Creates the volume group instance. - * - * @param serviceInstanceId the service instance id - * @param vnfInstanceId the vnf instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_create_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST) - public ResponseEntity createVolumeGroupInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, - HttpServletRequest request, @RequestBody RequestDetails mso_request) { - String methodName = "createVolumeGroupInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.createVolumeGroupInstance(mso_request, serviceInstanceId, vnfInstanceId); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Creates the vf module instance. - * - * @param serviceInstanceId the service instance id - * @param vnfInstanceId the vnf instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_create_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST) - public ResponseEntity createVfModuleInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, - @PathVariable("vnfInstanceId") String vnfInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) { - String methodName = "createVfModuleInstance"; - - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.createVfModuleInstance(mso_request, serviceInstanceId, vnfInstanceId); - - // always return OK, the MSO status code is embedded in the body - - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Creates a configuration instance. - * - * @param serviceInstanceId the service instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_create_configuration_instance/{serviceInstanceId}/configurations/", method = RequestMethod.POST) - public ResponseEntity createConfigurationInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, - HttpServletRequest request, @RequestBody RequestDetailsWrapper mso_request) { - String methodName = "createConfigurationInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.createConfigurationInstance(mso_request, serviceInstanceId); - - // always return OK, the MSO status code is embedded in the body - - return (new ResponseEntity<>(w.getResponse(), HttpStatus.OK)); - } - - /** - * Delete E2e svc instance. - * - * @param serviceInstanceId the service instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_delete_e2e_svc_instance/{serviceInstanceId}", method = RequestMethod.POST) - public ResponseEntity deleteE2eSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, - HttpServletRequest request, @RequestBody LinkedHashMap mso_request) { - - String methodName = "deleteE2eSvcInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), mso_request); - - MsoResponseWrapper w = msoBusinessLogic.deleteE2eSvcInstance(mso_request.get("requestDetails"), serviceInstanceId); - - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); - // always return OK, the MSO status code is embedded in the body - - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - - } - - /** - * Delete svc instance. - * - * @param serviceInstanceId the service instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - - @RequestMapping(value = "/mso_delete_svc_instance/{serviceInstanceId}", method = RequestMethod.POST) - public String deleteSvcInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, - HttpServletRequest request, @RequestBody RequestDetails mso_request, - @RequestParam(value = "serviceStatus") String serviceStatus) { - - String methodName = "deleteSvcInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName(), mso_request); - MsoResponseWrapper w = msoBusinessLogic.deleteSvcInstance(mso_request, serviceInstanceId, serviceStatus); - // always return OK, the MSO status code is embedded in the body - - return w.getResponse(); - } - - /** - * Delete vnf. - * - * @param serviceInstanceId the service instance id - * @param vnfInstanceId the vnf instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_delete_vnf_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}", method = RequestMethod.POST) - - public ResponseEntity deleteVnf(@PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, - HttpServletRequest request, @RequestBody RequestDetails mso_request) { - String methodName = "deleteVnf"; - - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.deleteVnf(mso_request, serviceInstanceId, vnfInstanceId); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - - } - - /** - * Delete configuration instance - * @param serviceInstanceId the service instance id - * @param configurationId the configuration id - * @param mso_request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "mso_delete_configuration/{serviceInstanceId}/configurations/{configurationId}", - method = RequestMethod.POST) - public ResponseEntity deleteConfiguration( - @PathVariable("serviceInstanceId") String serviceInstanceId, - @PathVariable ("configurationId") String configurationId, - @RequestBody RequestDetailsWrapper mso_request) { - - String methodName = "deleteConfiguration"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, - dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.deleteConfiguration(mso_request, serviceInstanceId, configurationId); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Activate configuration instance - * @param serviceInstanceId the service instace id - * @param configurationId the configuration id - * @param mso_request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "mso_activate_configuration/{serviceInstanceId}/configurations/{configurationId}", - method = RequestMethod.POST) - public ResponseEntity activateConfiguration( - @PathVariable("serviceInstanceId") String serviceInstanceId, - @PathVariable("configurationId") String configurationId, - @RequestBody RequestDetails mso_request) { - - MsoResponseWrapper w = msoBusinessLogic.setConfigurationActiveStatus(mso_request, serviceInstanceId, configurationId, true); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Deactivate configuration instance - * @param serviceInstanceId the service instace id - * @param configurationId the configuration id - * @param mso_request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "mso_deactivate_configuration/{serviceInstanceId}/configurations/{configurationId}", - method = RequestMethod.POST) - public ResponseEntity deactivateConfiguration( - @PathVariable("serviceInstanceId") String serviceInstanceId, - @PathVariable("configurationId") String configurationId, - @RequestBody RequestDetails mso_request) { - - MsoResponseWrapper w = msoBusinessLogic.setConfigurationActiveStatus(mso_request, serviceInstanceId, configurationId, false); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Disable port on configuration instance - * @param serviceInstanceId the service instance id - * @param configurationId the configuration instance id - * @param mso_request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "mso_disable_port_configuration/{serviceInstanceId}/configurations/{configurationId}", - method = RequestMethod.POST) - public ResponseEntity disablePortOnConfiguration( - @PathVariable("serviceInstanceId") String serviceInstanceId, - @PathVariable("configurationId") String configurationId, - @RequestBody RequestDetails mso_request) { - - MsoResponseWrapper w = msoBusinessLogic.setPortOnConfigurationStatus(mso_request, serviceInstanceId, configurationId, false); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Enable port on configuration instance - * @param serviceInstanceId the service instance id - * @param configurationId the configuration instance id - * @param mso_request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "mso_enable_port_configuration/{serviceInstanceId}/configurations/{configurationId}", - method = RequestMethod.POST) - public ResponseEntity enablePortOnConfiguration( - @PathVariable("serviceInstanceId") String serviceInstanceId, - @PathVariable("configurationId") String configurationId, - @RequestBody RequestDetails mso_request) { - - MsoResponseWrapper w = msoBusinessLogic.setPortOnConfigurationStatus(mso_request, serviceInstanceId, configurationId, true); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Delete vf module. - * - * @param serviceInstanceId the service instance id - * @param vnfInstanceId the vnf instance id - * @param vfModuleId the vf module id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - //mso_delete_vf_module/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe9000-0009-9999/vfmodules/abeeee-abeeee-abeeee - @RequestMapping(value = "/mso_delete_vfmodule_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleId}", method = RequestMethod.POST) - public ResponseEntity deleteVfModule( - @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, - @PathVariable("vfModuleId") String vfModuleId, HttpServletRequest request, @RequestBody RequestDetails mso_request) { - - String methodName = "deleteVfModule"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.deleteVfModule(mso_request, serviceInstanceId, vnfInstanceId, vfModuleId); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Delete volume group instance. - * - * @param serviceInstanceId the service instance id - * @param vnfInstanceId the vnf instance id - * @param volumeGroupId the volume group id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_delete_volumegroup_instance/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups/{volumeGroupId}", method = RequestMethod.POST) - public ResponseEntity deleteVolumeGroupInstance( - @PathVariable("serviceInstanceId") String serviceInstanceId, @PathVariable("vnfInstanceId") String vnfInstanceId, @PathVariable("volumeGroupId") String volumeGroupId, - HttpServletRequest request, @RequestBody RequestDetails mso_request) { - String methodName = "deleteVolumeGroupInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.deleteVolumeGroupInstance(mso_request, serviceInstanceId, vnfInstanceId, volumeGroupId); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Delete nw instance. - * - * @param serviceInstanceId the service instance id - * @param networkInstanceId the network instance id - * @param request the request - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_delete_nw_instance/{serviceInstanceId}/networks/{networkInstanceId}", method = RequestMethod.POST) - public ResponseEntity deleteNwInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, - @PathVariable("networkInstanceId") String networkInstanceId, HttpServletRequest request, @RequestBody RequestDetails mso_request) { - String methodName = "deleteNwInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.deleteNwInstance(mso_request, serviceInstanceId, networkInstanceId); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Gets the orchestration request. - * - * @param requestId the request id - * @param request the request - * @return the orchestration request - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_get_orch_req/{requestId}", method = RequestMethod.GET) - public ResponseEntity getOrchestrationRequest(@PathVariable("requestId") String requestId, - HttpServletRequest request) { - - String methodName = "getOrchestrationRequest"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - - MsoResponseWrapper w = msoBusinessLogic.getOrchestrationRequest(requestId); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * Gets the orchestration requests. - * - * @param filterString the filter string - * @param request the request - * @return the orchestration requests - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_get_orch_reqs/{filterString}", method = RequestMethod.GET) - public ResponseEntity getOrchestrationRequests(@PathVariable("filterString") String filterString, - HttpServletRequest request) { - - String methodName = "getOrchestrationRequests"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - - MsoResponseWrapper w = msoBusinessLogic.getOrchestrationRequests(filterString); - - // always return OK, the MSO status code is embedded in the body - return (new ResponseEntity(w.getResponse(), HttpStatus.OK)); - } - - /** - * activate to a pnf instance. - * - * @param serviceInstanceId the id of the service. - * @param requestDetails the body of the request. - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_activate_service_instance/{serviceInstanceId}", method = RequestMethod.POST) - public ResponseEntity activateServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @RequestBody RequestDetails requestDetails) { - String methodName = "activateServiceInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, true); - return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); - } - - /** - * deactivate a service instance. - * - * @param serviceInstanceId the id of the service. - * @param requestDetails the body of the request. - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_deactivate_service_instance/{serviceInstanceId}", method = RequestMethod.POST) - public ResponseEntity deactivateServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId, @RequestBody RequestDetails requestDetails) { - String methodName = "deactivateServiceInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.setServiceInstanceStatus(requestDetails, serviceInstanceId, false); - return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); - } - - /** - * Gets the orchestration requests for the dashboard. - * currently its all the orchestration requests with RequestType updateInstance or replaceInstance. - * @return the orchestration requests - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_get_orch_reqs/dashboard", method = RequestMethod.GET) - public List getOrchestrationRequestsForDashboard() { - - String methodName = "getOrchestrationRequestsForDashboard"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - - return msoBusinessLogic.getOrchestrationRequestsForDashboard(); - } - - /** - * Gets the Manual Tasks for the given request id. - * - * @param originalRequestId the id of the original request. - * @return the tasks - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_get_man_task/{originalRequestId}", method = RequestMethod.GET) - public List getManualTasksByRequestId(@PathVariable("originalRequestId") String originalRequestId) { - - String methodName = "getManualTasksByRequestId"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - return msoBusinessLogic.getManualTasksByRequestId(originalRequestId); - } - - /** - * Complete the manual task. - * - * @param taskId the id of the task to complete. - * @param requestDetails the body of the request. - * @return the response entity - * @throws Exception the exception - */ - @RequestMapping(value = "/mso_post_man_task/{taskId}", method = RequestMethod.POST) - public ResponseEntity manualTaskComplete(@PathVariable("taskId") String taskId , @RequestBody RequestDetails requestDetails) { - - String methodName = "manualTaskComplete"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w = msoBusinessLogic.completeManualTask(requestDetails, taskId); - return new ResponseEntity(w.getResponse(), HttpStatus.OK); - } - - @RequestMapping(value = "/mso_remove_relationship/{serviceInstanceId}", method = RequestMethod.POST) - public ResponseEntity removeRelationshipFromServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId , - @RequestBody RequestDetails requestDetails) { - - String methodName = "removeRelationshipFromServiceInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w; - try { - w = msoBusinessLogic.removeRelationshipFromServiceInstance(requestDetails, serviceInstanceId); - } catch (Exception e){ - LOGGER.error("Internal error when calling MSO controller logic for {}", methodName, e); - return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } - return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); - } - - @RequestMapping(value = "/mso_add_relationship/{serviceInstanceId}", method = RequestMethod.POST) - public ResponseEntity addRelationshipToServiceInstance(@PathVariable("serviceInstanceId") String serviceInstanceId , - @RequestBody RequestDetails requestDetails) { - - String methodName = "addRelationshipToServiceInstance"; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - MsoResponseWrapper w; - try { - w = msoBusinessLogic.addRelationshipToServiceInstance(requestDetails, serviceInstanceId); - } catch (Exception e){ - LOGGER.error("Internal error when calling MSO controller logic for {}", methodName, e); - return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } - return new ResponseEntity<>(w.getResponse(), HttpStatus.OK); - } - - /** - * Exception handler. - * - * @param e the e - * @param response the response - * @throws IOException Signals that an I/O exception has occurred. - */ - @ExceptionHandler(Exception.class) - private void exceptionHandler(Exception e, HttpServletResponse response) throws IOException { - - /* - * The following "logger.error" lines "should" be sufficient for logging the exception. - * However, the console output in my Eclipse environment is NOT showing ANY of the - * logger statements in this class. Thus the temporary "e.printStackTrace" statement - * is also included. - */ - - String methodName = "exceptionHandler"; - LOGGER.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); - LOGGER.error(EELFLoggerDelegate.errorLogger, sw.toString()); - - /* - * Temporary - IF the above mentioned "logger.error" glitch is resolved ... - * this statement could be removed since it would then likely result in duplicate - * trace output. - */ - e.printStackTrace(System.err); - - response.setContentType("application/json; charset=UTF-8"); - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - - ExceptionResponse exceptionResponse = new ExceptionResponse(); - exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", "")); - exceptionResponse.setMessage(e.getMessage()); - - response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse)); - - response.flushBuffer(); - - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/OperationalEnvironmentController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/OperationalEnvironmentController.java deleted file mode 100644 index 6a4527cb4..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/OperationalEnvironmentController.java +++ /dev/null @@ -1,362 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.vid.controllers; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.MoreObjects; -import io.joshworks.restclient.http.HttpResponse; -import java.util.HashMap; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.onap.vid.changeManagement.RequestDetailsWrapper; -import org.onap.vid.model.ExceptionResponse; -import org.onap.vid.model.RequestReferencesContainer; -import org.onap.vid.mso.MsoBusinessLogic; -import org.onap.vid.mso.MsoInterface; -import org.onap.vid.mso.MsoResponseWrapper2; -import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; -import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo; -import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails; -import org.onap.vid.mso.rest.RequestDetails; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.MissingServletRequestParameterException; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.onap.vid.utils.Logging.getMethodCallerName; -import static org.onap.vid.utils.Logging.getMethodName; - -@RestController -@RequestMapping("operationalEnvironment") -public class OperationalEnvironmentController extends VidRestrictedBaseController { - - private final MsoInterface restMso; - private final MsoBusinessLogic msoBusinessLogic; - - private static final Pattern RECOVERY_ACTION_MESSAGE_PATTERN = Pattern.compile("String value \'(.*)\': value not"); - - - @Autowired - public OperationalEnvironmentController(MsoBusinessLogic msoBusinessLogic, MsoInterface msoClientInterface) { - this.restMso = msoClientInterface; - this.msoBusinessLogic = msoBusinessLogic; - } - - @RequestMapping(value = "/create", method = RequestMethod.POST) - public MsoResponseWrapper2 createOperationalEnvironment(HttpServletRequest request, @RequestBody OperationalEnvironmentCreateBody operationalEnvironment) { - debugStart(operationalEnvironment); - String userId = ControllersUtils.extractUserId(request); - RequestDetailsWrapper requestDetailsWrapper = msoBusinessLogic.convertParametersToRequestDetails(operationalEnvironment, userId); - String path = msoBusinessLogic.getOperationalEnvironmentCreationPath(); - - HttpResponse msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); - debugEnd(msoResponse); - return new MsoResponseWrapper2<>(msoResponse); - } - - @RequestMapping(value = "/activate", method = RequestMethod.POST) - public MsoResponseWrapper2 activate(HttpServletRequest request, - @RequestParam("operationalEnvironment") String operationalEnvironmentId, - @RequestBody OperationalEnvironmentActivateBody activateRequest) throws MissingServletRequestParameterException { - - verifyIsNotEmpty(operationalEnvironmentId, "operationalEnvironment"); - - //manifest is null in case of wrong manifest structure (deserialization failure of the manifest) - if (activateRequest.getManifest()==null || activateRequest.getManifest().getServiceModelList()==null) { - throw new BadManifestException("Manifest structure is wrong"); - } - - String userId = ControllersUtils.extractUserId(request); - - OperationalEnvironmentActivateInfo activateInfo = new OperationalEnvironmentActivateInfo(activateRequest, userId, operationalEnvironmentId); - debugStart(activateInfo); - - String path = msoBusinessLogic.getOperationalEnvironmentActivationPath(activateInfo); - RequestDetailsWrapper requestDetailsWrapper = msoBusinessLogic.createOperationalEnvironmentActivationRequestDetails(activateInfo); - - HttpResponse msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); - - debugEnd(msoResponse); - return new MsoResponseWrapper2<>(msoResponse); - } - - @RequestMapping(value = "/deactivate", method = RequestMethod.POST) - public MsoResponseWrapper2 deactivate(HttpServletRequest request, - @RequestParam("operationalEnvironment") String operationalEnvironmentId, - @RequestBody Map deactivationRequest) throws MissingServletRequestParameterException { - - verifyIsNotEmpty(operationalEnvironmentId, "operationalEnvironment"); - - String userId = ControllersUtils.extractUserId(request); - - OperationalEnvironmentDeactivateInfo deactivateInfo = new OperationalEnvironmentDeactivateInfo(userId, operationalEnvironmentId); - debugStart(deactivateInfo); - - String path = msoBusinessLogic.getOperationalEnvironmentDeactivationPath(deactivateInfo); - RequestDetailsWrapper requestDetailsWrapper = msoBusinessLogic.createOperationalEnvironmentDeactivationRequestDetails(deactivateInfo); - - HttpResponse msoResponse = restMso.post(path, requestDetailsWrapper, RequestReferencesContainer.class); - - debugEnd(msoResponse); - return new MsoResponseWrapper2<>(msoResponse); - } - - @RequestMapping(value = "/requestStatus", method = RequestMethod.GET) - public MsoResponseWrapper2 status(HttpServletRequest request, @RequestParam("requestId") String requestId) throws MissingServletRequestParameterException { - - debugStart(requestId); - - verifyIsNotEmpty(requestId, "requestId"); - String path = msoBusinessLogic.getCloudResourcesRequestsStatusPath(requestId); - - HttpResponse msoResponse = restMso.get(path, HashMap.class); - - LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), msoResponse); - return new MsoResponseWrapper2<>(msoResponse); - } - - @ExceptionHandler({ - org.springframework.web.bind.MissingServletRequestParameterException.class, - BadManifestException.class - }) - @ResponseStatus(value = HttpStatus.BAD_REQUEST) - public ExceptionResponse clientDerivedExceptionAsBadRequest(Exception e) { - // same handler, different HTTP Code - return exceptionHandler(e); - } - - @ExceptionHandler({ - org.springframework.http.converter.HttpMessageNotReadableException.class, - }) - @ResponseStatus(value = HttpStatus.BAD_REQUEST) - public ExceptionResponse handlingHttpMessageNotReadableException(Exception e) { - //in case of wrong value in manifest for RecoveryAction the message contains the class name. - //The wrong value is in also part of this messages - //within the pattern of: String value '': value not - //so we use regex to find the wrong value - if (e.getMessage().contains(OperationalEnvironmentRecoveryAction.class.getName())) { - LOGGER.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodName(), ExceptionUtils.getMessage(e), e); - String message = "Wrong value for RecoveryAction in manifest. Allowed options are: "+OperationalEnvironmentRecoveryAction.options; - - Matcher matcher = RECOVERY_ACTION_MESSAGE_PATTERN.matcher(e.getMessage()); - if (matcher.find()) { - String wrongValue = matcher.group(1); - message = message+". Wrong value is: "+wrongValue; - } - return new ExceptionResponse(new BadManifestException(message)); - } - return exceptionHandler(e); - } - - - public enum OperationalEnvironmentRecoveryAction { - abort, - retry, - skip; - - public static final String options = Stream.of(OperationalEnvironmentRecoveryAction.values()).map(OperationalEnvironmentRecoveryAction::name).collect(Collectors.joining(", ")); - } - - public static class ActivateServiceModel { - private String serviceModelVersionId; - private OperationalEnvironmentRecoveryAction recoveryAction; - - public ActivateServiceModel() { - } - - public ActivateServiceModel(String serviceModelVersionId, OperationalEnvironmentRecoveryAction recoveryAction) { - this.serviceModelVersionId = serviceModelVersionId; - this.recoveryAction = recoveryAction; - } - - public String getServiceModelVersionId() { - return serviceModelVersionId; - } - - public void setServiceModelVersionId(String serviceModelVersionId) { - this.serviceModelVersionId = serviceModelVersionId; - } - - public OperationalEnvironmentRecoveryAction getRecoveryAction() { - return recoveryAction; - } - - public void setRecoveryAction(OperationalEnvironmentRecoveryAction recoveryAction) { - this.recoveryAction = recoveryAction; - } - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static class OperationalEnvironmentManifest { - - - private List serviceModelList; - - public OperationalEnvironmentManifest() { - } - - public OperationalEnvironmentManifest(List serviceModelList) { - this.serviceModelList = serviceModelList; - } - - public List getServiceModelList() { - return serviceModelList; - } - - public void setServiceModelList(List serviceModelList) { - this.serviceModelList = serviceModelList; - } - } - - public static class OperationalEnvironmentActivateBody { - private final String relatedInstanceId; - private final String relatedInstanceName; - private final String workloadContext; - private final OperationalEnvironmentManifest manifest; - - public OperationalEnvironmentActivateBody(@JsonProperty(value = "relatedInstanceId", required = true) String relatedInstanceId, - @JsonProperty(value = "relatedInstanceName", required = true) String relatedInstanceName, - @JsonProperty(value = "workloadContext", required = true) String workloadContext, - @JsonProperty(value = "manifest", required = true) OperationalEnvironmentManifest manifest) { - this.relatedInstanceId = relatedInstanceId; - this.relatedInstanceName = relatedInstanceName; - this.workloadContext = workloadContext; - this.manifest = manifest; - } - - - public String getRelatedInstanceId() { - return relatedInstanceId; - } - - public String getRelatedInstanceName() { - return relatedInstanceName; - } - - public String getWorkloadContext() { - return workloadContext; - } - - public OperationalEnvironmentManifest getManifest() { - return manifest; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("relatedInstanceId", relatedInstanceId) - .add("relatedInstanceName", relatedInstanceName) - .add("workloadContext", workloadContext) - .add("manifest", manifest) - .toString(); - } - } - - public static class OperationalEnvironmentCreateBody { - private final String instanceName; - private final String ecompInstanceId; - private final String ecompInstanceName; - private final String operationalEnvironmentType; - private final String tenantContext; - private final String workloadContext; - - public OperationalEnvironmentCreateBody(@JsonProperty(value = "instanceName", required = true) String instanceName, - @JsonProperty(value = "ecompInstanceId", required = true) String ecompInstanceId, - @JsonProperty(value = "ecompInstanceName", required = true) String ecompInstanceName, - @JsonProperty(value = "operationalEnvironmentType", required = true) String operationalEnvironmentType, - @JsonProperty(value = "tenantContext", required = true) String tenantContext, - @JsonProperty(value = "workloadContext", required = true) String workloadContext) { - this.instanceName = instanceName; - this.ecompInstanceId = ecompInstanceId; - this.ecompInstanceName = ecompInstanceName; - this.operationalEnvironmentType = operationalEnvironmentType; - this.tenantContext = tenantContext; - this.workloadContext = workloadContext; - } - - public String getInstanceName() { - return instanceName; - } - - public String getEcompInstanceId() { - return ecompInstanceId; - } - - public String getEcompInstanceName() { - return ecompInstanceName; - } - - public String getOperationalEnvironmentType() { - return operationalEnvironmentType; - } - - public String getTenantContext() { - return tenantContext; - } - - public String getWorkloadContext() { - return workloadContext; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("instanceName", instanceName) - .add("ecompInstanceId", ecompInstanceId) - .add("ecompInstanceName", ecompInstanceName) - .add("operationalEnvironmentType", operationalEnvironmentType) - .add("tenantContext", tenantContext) - .add("workloadContext", workloadContext) - .toString(); - } - } - - private void debugEnd(HttpResponse msoResponse) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodCallerName(), msoResponse); - } - - private void debugStart(Object requestInfo) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodCallerName(), requestInfo); - } - - private void verifyIsNotEmpty(String fieldValue, String fieldName) throws MissingServletRequestParameterException { - if (StringUtils.isEmpty(fieldValue)) { - throw new MissingServletRequestParameterException(fieldName, "String"); - } - } - - public static class BadManifestException extends RuntimeException { - public BadManifestException(String message) { - super(message); - } - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/PolicyController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/PolicyController.java deleted file mode 100644 index 80b4739d5..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/PolicyController.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.controllers; - -import org.json.simple.JSONObject; -import org.onap.vid.policy.*; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletRequest; -import java.util.UUID; - -/** - * Controller to handle Policy requests. - */ - -@RestController -public class PolicyController extends RestrictedBaseController{ - - /** The logger. */ - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(PolicyController.class); - - @RequestMapping(value="/get_policy",method = RequestMethod.POST) - public ResponseEntity getPolicyInfo( HttpServletRequest request, @RequestBody JSONObject policy_request) { - - LOGGER.debug("#####################POLICY API CALL STARTED ###############"+ PolicyProperties.POLICY_GET_CONFIG_VAL); - LOGGER.debug("#####################Policy Request ###############"+policy_request.toString()); - - String path = PolicyProperties.getProperty(PolicyProperties.POLICY_GET_CONFIG_VAL); - PolicyResponseWrapper policyResWrapper = getPolicyConfig(policy_request,path); - - LOGGER.debug("$$$$$$$$$$$$$$$$$$$$$$ " + new ResponseEntity(policyResWrapper.getResponse(), HttpStatus.OK).toString()); - - return ( new ResponseEntity(policyResWrapper.getResponse(), HttpStatus.valueOf(policyResWrapper.getStatus())) ); - } - - protected static PolicyResponseWrapper getPolicyConfig(JSONObject request, String path) { - String methodName = "getPolicyConfig"; - String uuid = UUID.randomUUID().toString(); - LOGGER.debug( "starting getPolicyConfig "); - - try { - //STARTING REST API CALL AS AN FACTORY INSTACE - PolicyRestInterfaceIfc restController = PolicyRestInterfaceFactory.getInstance(); - - RestObject restObjStr = new RestObject(); - String str = new String(); - restObjStr.set(str); - restController.Post(str, request, uuid, path, restObjStr ); - PolicyResponseWrapper policyRespWrapper = PolicyUtil.wrapResponse (restObjStr); - - LOGGER.debug( "<== " + methodName + " w=" + policyRespWrapper.getResponse()); - return policyRespWrapper; - } catch (Exception e) { - LOGGER.debug( "EXCEPTION in getPolicyConfig <== " + "." + methodName + e.toString()); - throw e; - } - } -} - diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/ProbeController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/ProbeController.java deleted file mode 100644 index a2145de39..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/ProbeController.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.onap.vid.controllers; - -import org.onap.vid.aai.AaiClient; -import org.onap.vid.model.probes.ExternalComponentStatus; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import java.util.ArrayList; -import java.util.List; - -@RestController -@RequestMapping("probe") -public class ProbeController extends RestrictedBaseController { - @Autowired - private AaiClient aaiClient; - - @RequestMapping(method= RequestMethod.GET) - public List getProbe(){ - List componentStatuses = new ArrayList<>(); - componentStatuses.add(aaiClient.probeAaiGetAllSubscribers()); - return componentStatuses; - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/PropertyController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/PropertyController.java deleted file mode 100644 index 2c823863c..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/PropertyController.java +++ /dev/null @@ -1,132 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.controllers; - -import org.onap.vid.category.CategoryParametersResponse; -import org.onap.vid.model.CategoryParameter.Family; -import org.onap.vid.services.CategoryParameterService; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static org.onap.vid.utils.Logging.getMethodName; - -/** - * The Class PropertyController. - */ -@RestController -public class PropertyController extends RestrictedBaseController{ - - - /** The logger. */ - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(PropertyController.class); - - /** The Constant dateFormat. */ - final protected static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - @Autowired - protected CategoryParameterService categoryParameterService; - - - /** - * Welcome. - * - * @param request the request - * @return the model and view - */ - @RequestMapping(value = {"/propertyhome" }, method = RequestMethod.GET) - public ModelAndView welcome(HttpServletRequest request) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== PropertyController welcome start"); - return new ModelAndView(getViewName()); - } - - /** - * Gets the property. - * - * @param name the name - * @param defaultvalue the defaultvalue - * @param request the request - * @return the property - * @throws Exception the exception - */ - @RequestMapping(value = "/get_property/{name}/{defaultvalue}", method = RequestMethod.GET) - public ResponseEntity getProperty (@PathVariable("name") String name, @PathVariable("defaultvalue") String defaultvalue, - HttpServletRequest request) { - - String methodName = "getProperty"; - ResponseEntity resp = null; - String pvalue = null; - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); - - try { - // convert "_" to "." in the property name - if (name == null || name.length() == 0 ) { - return ( new ResponseEntity (defaultvalue, HttpStatus.OK)); - } - // convert "_" to "." in the property name - String propertyName = name.replace('_', '.'); - pvalue = SystemProperties.getProperty(propertyName); - if ( ( pvalue == null ) || ( pvalue.length() == 0 ) ) { - pvalue = defaultvalue; - } - resp = new ResponseEntity(pvalue, HttpStatus.OK); - } - catch (Exception e) { - LOGGER.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - throw e; - } - LOGGER.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " returning " + pvalue); - return ( resp ); - } - - /** - * Gets the owning entity properties. - * @param request the request - * @return the property - * @throws Exception the exception - */ - @RequestMapping(value = "/category_parameter", method = RequestMethod.GET) - public ResponseEntity getCategoryParameter(HttpServletRequest request, @RequestParam(value="familyName", required = true) Family familyName) { - LOGGER.debug(EELFLoggerDelegate.debugLogger, "start {}({})", getMethodName()); - try { - CategoryParametersResponse response = categoryParameterService.getCategoryParameters(familyName); - LOGGER.debug(EELFLoggerDelegate.debugLogger, "end {}() => {}", getMethodName(), response); - return new ResponseEntity<>(response, HttpStatus.OK); - } - catch (Exception exception) { - LOGGER.error("failed to retrieve category parameter list from DB.", exception); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); - } - } - - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/RoleGeneratorController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/RoleGeneratorController.java deleted file mode 100644 index dd6388d8d..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/RoleGeneratorController.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.onap.vid.controllers; - -import org.onap.vid.services.RoleGeneratorService; -import org.onap.portalsdk.core.controller.UnRestrictedBaseController; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class RoleGeneratorController extends UnRestrictedBaseController { - @Autowired - private RoleGeneratorService roleGeneratorService; - public static final String GENERATE_ROLE_SCRIPT = "generateRoleScript"; - @RequestMapping(value = GENERATE_ROLE_SCRIPT +"/{firstRun}", method = RequestMethod.GET ) - public ResponseEntity generateRoleScript (@PathVariable("firstRun") boolean firstRun) { - ResponseEntity response = null; - String query = roleGeneratorService.generateRoleScript(firstRun); - response = new ResponseEntity(query, HttpStatus.OK); - return response; - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/VidController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/VidController.java deleted file mode 100644 index b9d67b6df..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/VidController.java +++ /dev/null @@ -1,114 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright 2018 Nokia - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.controllers; - -import org.onap.vid.asdc.AsdcCatalogException; -import org.onap.vid.asdc.beans.SecureServices; -import org.onap.vid.exceptions.VidServiceUnavailableException; -import org.onap.vid.model.PombaInstance.PombaRequest; -import org.onap.vid.model.ServiceModel; -import org.onap.vid.roles.Role; -import org.onap.vid.roles.RoleProvider; -import org.onap.vid.services.AaiService; -import org.onap.vid.services.PombaService; -import org.onap.vid.services.VidService; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -@RestController -public class VidController extends RestrictedBaseController { - - private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidController.class); - - private final VidService vidService; - private final AaiService aaiService; - private final RoleProvider roleProvider; - private final PombaService pombaService; - - @Autowired - public VidController(VidService vidService, AaiService aaiService, RoleProvider roleProvider, - PombaService pombaService) { - this.vidService = vidService; - this.aaiService = aaiService; - this.roleProvider = roleProvider; - this.pombaService = pombaService; - } - - /** - * @param request the request - * @return the services - */ - @RequestMapping(value = {"/rest/models/services"}, method = RequestMethod.GET) - public SecureServices getServices(HttpServletRequest request) { - LOG.info("Start API for browse ASDC was called"); - SecureServices secureServices = new SecureServices(); - List roles = roleProvider.getUserRoles(request); - secureServices.setServices(aaiService.getServicesByDistributionStatus()); - secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles)); - return secureServices; - } - - - /** - * @param uuid the uuid - * @return the services - * @throws VidServiceUnavailableException the vid service unavailable exception - */ - @RequestMapping(value = {"/rest/models/services/{uuid}"}, method = RequestMethod.GET) - public ServiceModel getService(@PathVariable("uuid") String uuid) throws VidServiceUnavailableException { - try { - return vidService.getService(uuid); - } catch (AsdcCatalogException e) { - LOG.error("Failed to retrieve service definitions from SDC. Error: " + e.getMessage(), e); - throw new VidServiceUnavailableException("Failed to retrieve service definitions from SDC", e); - } - } - - @RequestMapping(value = "/rest/models/reset", method = RequestMethod.POST) - @ResponseStatus(HttpStatus.ACCEPTED) - public void invalidateServiceModelCache() { - vidService.invalidateServiceCache(); - } - - /** - * @return the services view - * @throws VidServiceUnavailableException the vid service unavailable exception - */ - // FIX ME: Circular view path [serviceModels]: would dispatch back to the current handler URL [/serviceModels] again. - @RequestMapping(value = {"/serviceModels"}, method = RequestMethod.GET) - public ModelAndView getServicesView() { - return new ModelAndView("serviceModels"); - } - - @RequestMapping(value = {"/rest/models/services/verifyService"}, method = RequestMethod.POST) - public void verifyServiceInstance(@RequestBody PombaRequest pombaRequest) { - pombaService.verify(pombaRequest); - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/VidRestrictedBaseController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/VidRestrictedBaseController.java deleted file mode 100644 index b520bc025..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/VidRestrictedBaseController.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.onap.vid.controllers; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.exception.ExceptionUtils; -import org.onap.vid.model.ExceptionResponse; -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; - -import static org.onap.vid.utils.Logging.getMethodCallerName; -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; - -public abstract class VidRestrictedBaseController extends RestrictedBaseController { - - protected final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(this.getClass().getName()); - - @ExceptionHandler(MethodArgumentTypeMismatchException.class) - @ResponseBody - public ResponseEntity handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { - LOGGER.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodCallerName(), ExceptionUtils.getMessage(e), e); - Class type = e.getRequiredType(); - String message; - if (type.isEnum()) { - message = "The parameter " + e.getName() + " must have a value among : " + StringUtils.join(type.getEnumConstants(), ", "); - } - else { - message = "The parameter " + e.getName() + " must be of type " + type.getTypeName(); - } - ResponseEntity response = new ResponseEntity(message, HttpStatus.BAD_REQUEST); - return response; - } - - @ExceptionHandler(Exception.class) - @ResponseStatus(value=INTERNAL_SERVER_ERROR) - public ExceptionResponse exceptionHandler(Exception e) { - return ControllersUtils.handleException(e, LOGGER); - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/ViewLogController.java b/vid-app-common/src/main/java/org/onap/vid/controllers/ViewLogController.java deleted file mode 100644 index a95f0add3..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/ViewLogController.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.controllers; - -import org.onap.portalsdk.core.controller.RestrictedBaseController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import java.text.DateFormat; -import java.text.SimpleDateFormat; - - -/** - * The Class ViewLogController. - */ -@RestController -public class ViewLogController extends RestrictedBaseController{ - - /** The logger. */ - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ViewLogController.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - /** The servlet context. */ - private @Autowired ServletContext servletContext; - - /** - * Welcome. - * - * @param request the request - * @return the model and view - */ - @RequestMapping(value = {"/viewlog" }, method = RequestMethod.GET) - public ModelAndView welcome(HttpServletRequest request) { - - return new ModelAndView(getViewName()); - } - - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java b/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java deleted file mode 100644 index 56dce9ac7..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/controllers/WebConfig.java +++ /dev/null @@ -1,226 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.controllers; - -import com.fasterxml.jackson.core.JsonProcessingException; -import io.joshworks.restclient.http.mapper.ObjectMapper; -import java.io.IOException; -import org.onap.vid.aai.AaiClient; -import org.onap.vid.aai.AaiClientInterface; -import org.onap.vid.aai.AaiOverTLSClient; -import org.onap.vid.aai.AaiOverTLSClientInterface; -import org.onap.vid.aai.AaiOverTLSPropertySupplier; -import org.onap.vid.aai.AaiResponseTranslator; -import org.onap.vid.aai.PombaClientImpl; -import org.onap.vid.aai.PombaClientInterface; -import org.onap.vid.aai.PombaRestInterface; -import org.onap.vid.aai.model.PortDetailsTranslator; -import org.onap.vid.aai.util.AAIRestInterface; -import org.onap.vid.aai.util.HttpsAuthClient; -import org.onap.vid.aai.util.SSLContextProvider; -import org.onap.vid.aai.util.ServletRequestHelper; -import org.onap.vid.aai.util.SystemPropertyHelper; -import org.onap.vid.asdc.AsdcClient; -import org.onap.vid.asdc.parser.ToscaParserImpl2; -import org.onap.vid.asdc.rest.SdcRestClient; -import org.onap.vid.client.SyncRestClient; -import org.onap.vid.client.SyncRestClientInterface; -import org.onap.vid.properties.AsdcClientConfiguration; -import org.onap.vid.services.AaiService; -import org.onap.vid.services.AaiServiceImpl; -import org.onap.vid.services.PombaService; -import org.onap.vid.services.PombaServiceImpl; -import org.onap.vid.services.VidService; -import org.onap.vid.services.VidServiceImpl; -import org.onap.vid.scheduler.SchedulerRestInterface; -import org.onap.vid.scheduler.SchedulerRestInterfaceIfc; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.togglz.core.manager.FeatureManager; - -import javax.servlet.ServletContext; -import java.io.File; - -@Configuration -public class WebConfig { - - /** - * Gets the object mapper. - * - * @return the object mapper - */ - @Bean - public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() { - return new com.fasterxml.jackson.databind.ObjectMapper(); - } - - - @Bean - public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) { - return new VidServiceImpl(asdcClient, featureManager); - } - - @Bean - public AaiService getAaiService() { - return new AaiServiceImpl(); - } - - @Bean - public AaiResponseTranslator aaiResponseTranslator() { - return new AaiResponseTranslator(); - } - - @Bean - public PortDetailsTranslator portDetailsTranslator() { - return new PortDetailsTranslator(); - } - - @Bean - public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator) { - return new AaiClient(restController, portsDetailsTranslator); - } - - @Bean(name = "aaiRestInterface") - public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) { - return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper); - } - - @Bean - public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) { - return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper); - } - - @Bean - public SSLContextProvider sslContextProvider() { - return new SSLContextProvider(); - } - - @Bean - public SystemPropertyHelper systemPropertyHelper() { - return new SystemPropertyHelper(); - } - - @Bean - public ServletRequestHelper servletRequestHelper() { - return new ServletRequestHelper(); - } - - @Bean - public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider) { - final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath(); - return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider); - } - - @Bean - public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) { - String auth = asdcClientConfiguration.getAsdcClientAuth(); - String host = asdcClientConfiguration.getAsdcClientHost(); - String protocol = asdcClientConfiguration.getAsdcClientProtocol(); - int port = asdcClientConfiguration.getAsdcClientPort(); - - return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient); - } - - @Bean - public SyncRestClientInterface syncRestClient() { - return new SyncRestClient(); - } - - @Bean - public ToscaParserImpl2 getToscaParser() { - return new ToscaParserImpl2(); - } - - @Bean - public PombaService getVerifyServiceInstanceService() { - return new PombaServiceImpl(); - } - - @Bean - public PombaClientInterface getVerifyServiceInstanceClientInterface() { - return new PombaClientImpl(); - } - - @Bean - public SchedulerRestInterfaceIfc getSchedulerRestInterface(){ - return new SchedulerRestInterface(); - } - - @Bean(name = "aaiClientForFasterXmlMapping") - public AaiOverTLSClientInterface getAaiClientForFasterXmlMapping(){ - ObjectMapper objectMapper = new ObjectMapper() { - - com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper(); - - @Override - public T readValue(String s, Class aClass) { - try { - return om.readValue(s, aClass); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public String writeValue(Object o) { - try { - return om.writeValueAsString(o); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - }; - - return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier()); - } - - - @Bean(name = "aaiClientForCodehausMapping") - public AaiOverTLSClientInterface getAaiClientForCodehausMapping() { - - ObjectMapper objectMapper = new ObjectMapper() { - - org.codehaus.jackson.map.ObjectMapper om = new org.codehaus.jackson.map.ObjectMapper(); - - @Override - public T readValue(String s, Class aClass) { - try { - return om.readValue(s, aClass); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public String writeValue(Object o) { - try { - return om.writeValueAsString(o); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - }; - - return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier()); - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/Job.java b/vid-app-common/src/main/java/org/onap/vid/job/Job.java index 77f348dc6..144c96ca4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/Job.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/Job.java @@ -1,6 +1,7 @@ package org.onap.vid.job; import com.fasterxml.jackson.annotation.JsonIgnore; +import org.onap.vid.job.impl.JobSharedData; import java.util.Map; import java.util.UUID; @@ -18,30 +19,49 @@ public interface Job { @JsonIgnore Map getData(); + JobSharedData getSharedData(); + void setTypeAndData(JobType jobType, Map data); UUID getTemplateId(); void setTemplateId(UUID templateId); + Integer getIndexInBulk(); + void setIndexInBulk(Integer indexInBulk); JobType getType(); enum JobStatus { - COMPLETED(true), - FAILED(true), + COMPLETED(true, false), + FAILED(true, true), IN_PROGRESS(false), + RESOURCE_IN_PROGRESS(false), PAUSE(false), PENDING(false), - STOPPED(true); + STOPPED(true, true), + COMPLETED_WITH_ERRORS(true, true), + COMPLETED_WITH_NO_ACTION(true, false), + CREATING(false); private final Boolean finalStatus; public Boolean isFinal(){return finalStatus;} + private final Boolean failure; + public Boolean isFailure() { + return failure; + } + JobStatus(Boolean finalStatus) { - this.finalStatus = finalStatus ; + this(finalStatus, false); } + + JobStatus(Boolean finalStatus, boolean failure) { + this.finalStatus = finalStatus; + this.failure = failure; + } + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/JobAdapter.java b/vid-app-common/src/main/java/org/onap/vid/job/JobAdapter.java index 1701092b3..f281f98a0 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/JobAdapter.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/JobAdapter.java @@ -1,9 +1,8 @@ package org.onap.vid.job; -import org.onap.vid.model.JobBulk; +import org.onap.vid.job.impl.JobSharedData; import org.onap.vid.model.JobModel; -import java.util.List; import java.util.Map; import java.util.UUID; @@ -13,14 +12,12 @@ import java.util.UUID; public interface JobAdapter { JobModel toModel(Job job); - JobBulk toModelBulk(List jobList); + Job createServiceInstantiationJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, String optimisticUniqueServiceInstanceName, Integer indexInBulk); - List createBulkOfJobs(Map bulkRequest); - - Job createJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, Integer indexInBulk); + Job createChildJob(JobType jobType, Job.JobStatus jobStatus, AsyncJobRequest request, JobSharedData parentSharedData, Map jobData); // Marks types that are an AsyncJob payload - public interface AsyncJobRequest { + interface AsyncJobRequest { } } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/JobCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/JobCommand.java index c32645cad..7f62bcac6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/JobCommand.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/JobCommand.java @@ -1,7 +1,8 @@ package org.onap.vid.job; +import org.onap.vid.job.impl.JobSharedData; + import java.util.Map; -import java.util.UUID; /** @@ -13,11 +14,11 @@ public interface JobCommand { /** * Initialize the command state - * @param jobUuid Parent job's uuid - * @param data An input to be set into the command. Each implementation may expect different keys in the map. + * @param sharedData shared data cross all job commands + * @param commandData An input to be set into the command. Each implementation may expect different keys in the map. * @return Returns itself */ - default JobCommand init(UUID jobUuid, Map data) { + default JobCommand init(JobSharedData sharedData, Map commandData) { return this; } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/JobException.java b/vid-app-common/src/main/java/org/onap/vid/job/JobException.java new file mode 100644 index 000000000..ca389b039 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/JobException.java @@ -0,0 +1,16 @@ +package org.onap.vid.job; + +import java.util.UUID; + +public class JobException extends RuntimeException { + private final UUID jobUuid; + + public JobException(String message, UUID jobUuid, Throwable cause) { + super(message, cause); + this.jobUuid = jobUuid; + } + + public UUID getJobUuid() { + return jobUuid; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/JobType.java b/vid-app-common/src/main/java/org/onap/vid/job/JobType.java index 9846d2775..e856ba0d4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/JobType.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/JobType.java @@ -6,15 +6,33 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.onap.vid.utils.Streams.not; + public enum JobType { HttpCall(HttpCallCommand.class), AggregateState(AggregateStateCommand.class), - ServiceInstantiation(ServiceInstantiationCommand.class), - InProgressStatus(InProgressStatusCommand.class), + ServiceInstantiation(MacroServiceInstantiationCommand.class), + MacroServiceInstantiation(MacroServiceInstantiationCommand.class), + ALaCarteServiceInstantiation(ALaCarteServiceInstantiationCommand.class), + ALaCarteService(ALaCarteServiceCommand.class), + VnfInstantiation(VnfInstantiationCommand.class), + VfmoduleInstantiation(VfmoduleInstantiationCommand.class), + VolumeGroupInstantiation(VolumeGroupInstantiationCommand.class), + VolumeGroupInProgressStatus(VolumeGroupInProgressStatusCommand.class), + NetworkInstantiation(NetworkInstantiationCommand.class), + InstanceGroupInstantiation(InstanceGroupInstantiationCommand.class), + InstanceGroup(InstanceGroupCommand.class), + InProgressStatus(ServiceInProgressStatusCommand.class), + ResourceInProgressStatus(ResourceInProgressStatusCommand.class), + VnfInProgressStatus(VnfInProgressStatusCommand.class), + Watching(WatchingCommand.class), + WatchingBaseModule(WatchingCommandBaseModule.class), NoOp(NoOpCommand.class); - private static final Map REVERSE_MAP = Stream.of(values()).collect(Collectors.toMap(t -> t.getCommandClass(), t -> t)); + private static final Map REVERSE_MAP = Stream.of(values()) + .filter(not(jobType -> jobType.equals(ServiceInstantiation))) + .collect(Collectors.toMap(t -> t.getCommandClass(), t -> t)); private final Class commandClass; diff --git a/vid-app-common/src/main/java/org/onap/vid/job/JobsBrokerService.java b/vid-app-common/src/main/java/org/onap/vid/job/JobsBrokerService.java index 856f50b2e..98925d072 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/JobsBrokerService.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/JobsBrokerService.java @@ -18,4 +18,6 @@ public interface JobsBrokerService { void delete(UUID jobId); + boolean mute(UUID jobId); + } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt new file mode 100644 index 000000000..f88e9d65e --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt @@ -0,0 +1,122 @@ +package org.onap.vid.job.command + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate +import org.onap.vid.changeManagement.RequestDetailsWrapper +import org.onap.vid.job.* +import org.onap.vid.model.Action +import org.onap.vid.model.serviceInstantiation.ServiceInstantiation +import org.onap.vid.mso.RestMsoImplementation +import org.onap.vid.mso.model.ServiceDeletionRequestDetails +import org.onap.vid.properties.VidProperties +import org.onap.vid.services.AsyncInstantiationBusinessLogic +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.http.HttpMethod +import org.springframework.stereotype.Component +import java.time.ZonedDateTime +import java.time.temporal.ChronoUnit +import java.util.* + +class ServiceExpiryChecker : ExpiryChecker { + + override fun isExpired(jobStartTime: ZonedDateTime?): Boolean { + val now = ZonedDateTime.now() + val maxHoursInProgress = VidProperties.getLongProperty(VidProperties.VID_JOB_MAX_HOURS_IN_PROGRESS) + val hoursBetween = ChronoUnit.HOURS.between(jobStartTime, now) + return maxHoursInProgress in 1..hoursBetween + } +} + + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +class ALaCarteServiceCommand @Autowired constructor( + inProgressStatusService: InProgressStatusService, + watchChildrenJobsBL: WatchChildrenJobsBL, + private val asyncInstantiationBL: AsyncInstantiationBusinessLogic, + private val jobsBrokerService: JobsBrokerService, + msoResultHandlerService: MsoResultHandlerService, + private val jobAdapter: JobAdapter, + restMso: RestMsoImplementation +) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService, watchChildrenJobsBL), JobCommand { + + override fun getExpiryChecker(): ExpiryChecker { + return ServiceExpiryChecker(); + } + + companion object { + private val LOGGER = EELFLoggerDelegate.getLogger(ALaCarteServiceCommand::class.java) + } + + override fun getRequest(): ServiceInstantiation { + return msoResultHandlerService.getRequest(sharedData) + } + + override fun createChildren(): Job.JobStatus { + val dataForChild = buildDataForChild(getRequest())//.plus(ACTION_PHASE to actionPhase) + + val childJobType = when (actionPhase) { + Action.Create -> JobType.InstanceGroupInstantiation + Action.Delete -> JobType.InstanceGroup + else -> return Job.JobStatus.COMPLETED + } + + childJobs = getRequest().vnfGroups + .map { jobAdapter.createChildJob(childJobType, Job.JobStatus.CREATING, it.value, sharedData, dataForChild) } + .map { jobsBrokerService.add(it) } + .map { it.toString() } + + return Job.JobStatus.COMPLETED_WITH_NO_ACTION + } + + private fun buildDataForChild(request: ServiceInstantiation): Map { + val commandParentData = CommandParentData() + commandParentData.addInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID, request.instanceId) + commandParentData.addModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO, request.modelInfo) + return commandParentData.parentData + } + + override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan { + TODO("not implemented") + } + + override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan { + val requestDetailsWrapper = generateServiceDeletionRequest() + val path = asyncInstantiationBL.getServiceDeletionPath(getRequest().instanceId) + return MsoRestCallPlan(HttpMethod.DELETE, path, Optional.of(requestDetailsWrapper), Optional.empty(), + "delete instance with id ${getRequest().instanceId}") + + } + + override fun handleInProgressStatus(jobStatus: Job.JobStatus): Job.JobStatus { + if (jobStatus==Job.JobStatus.FAILED) { + asyncInstantiationBL.handleFailedInstantiation(sharedData.jobUuid) + return jobStatus + } + + asyncInstantiationBL.updateServiceInfoAndAuditStatus(sharedData.jobUuid, jobStatus) + return if (jobStatus == Job.JobStatus.PAUSE) Job.JobStatus.IN_PROGRESS else jobStatus + } + + + private fun generateServiceDeletionRequest(): RequestDetailsWrapper { + return asyncInstantiationBL.generateALaCarteServiceDeletionRequest( + sharedData.jobUuid, getRequest(), sharedData.userId + ) + } + + override fun getExternalInProgressStatus() = Job.JobStatus.IN_PROGRESS + + override fun isServiceCommand(): Boolean = true + + override fun onFinal(jobStatus: Job.JobStatus) { + asyncInstantiationBL.updateServiceInfoAndAuditStatus(sharedData.jobUuid, jobStatus) + } + + override fun onInitial(phase: Action) { + if (phase== Action.Delete) { + asyncInstantiationBL.updateServiceInfoAndAuditStatus(sharedData.jobUuid, Job.JobStatus.IN_PROGRESS) + } + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceInstantiationCommand.java new file mode 100644 index 000000000..8a1346d2e --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceInstantiationCommand.java @@ -0,0 +1,21 @@ +package org.onap.vid.job.command; + +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.job.JobCommand; +import org.onap.vid.mso.model.ServiceInstantiationRequestDetails; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ALaCarteServiceInstantiationCommand extends ServiceInstantiationCommand implements JobCommand { + + @Override + protected RequestDetailsWrapper generateServiceInstantiationRequest() { + return asyncInstantiationBL.generateALaCarteServiceInstantiationRequest( + getSharedData().getJobUuid(), getRequest(), optimisticUniqueServiceInstanceName, getSharedData().getUserId() + ); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/BaseInProgressStatusCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/BaseInProgressStatusCommand.java new file mode 100644 index 000000000..a035708f2 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/BaseInProgressStatusCommand.java @@ -0,0 +1,95 @@ +package org.onap.vid.job.command; + +import com.google.common.collect.ImmutableMap; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.job.*; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.mso.RestMsoImplementation; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.rest.AsyncRequestStatus; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.togglz.core.manager.FeatureManager; + +import javax.inject.Inject; +import java.util.Map; + +public abstract class BaseInProgressStatusCommand extends BaseInstantiationCommand implements JobCommand { + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BaseInProgressStatusCommand.class); + + @Inject + protected AsyncInstantiationBusinessLogic asyncInstantiationBL; + + @Inject + protected JobsBrokerService jobsBrokerService; + + @Inject + protected JobAdapter jobAdapter; + + @Inject + protected RestMsoImplementation restMso; + + @Inject + protected FeatureManager featureManager; + + @Inject + protected InProgressStatusService inProgressStatusService; + + + protected String requestId; + + protected String instanceId; + + + @Override + public NextCommand call() { + + try { + Job.JobStatus jobStatus = inProgressStatusService.call(getExpiryChecker(), getSharedData(), requestId); + return processJobStatus(jobStatus); + } catch (javax.ws.rs.ProcessingException e) { + // Retry when we can't connect MSO during getStatus + LOGGER.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, will retry: {}", requestId, e, e); + return new NextCommand(Job.JobStatus.IN_PROGRESS, this); + } catch (InProgressStatusService.BadResponseFromMso e) { + return handleFailedMsoResponse(e.getMsoResponse()); + } + catch (RuntimeException e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, stopping: {}", requestId, e, e); + return new NextCommand(Job.JobStatus.STOPPED, this); + } + } + + protected abstract ExpiryChecker getExpiryChecker(); + + abstract NextCommand processJobStatus(Job.JobStatus jobStatus); + + private NextCommand handleFailedMsoResponse(RestObject msoResponse) { + inProgressStatusService.handleFailedMsoResponse(getSharedData().getJobUuid(), requestId, msoResponse); + return new NextCommand(Job.JobStatus.IN_PROGRESS, this); + } + + @Override + public BaseInProgressStatusCommand init(JobSharedData sharedData, Map commandData) { + return init(sharedData, (String) commandData.get("requestId"), (String) commandData.get("instanceId")); + } + + + protected BaseInProgressStatusCommand init(JobSharedData sharedData, + String requestId, + String instanceId) { + init(sharedData); + this.requestId = requestId; + this.instanceId = instanceId; + return this; + } + + @Override + public Map getData() { + return ImmutableMap.of( + "requestId", requestId, + "instanceId", instanceId + ); + } + + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/BaseInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/BaseInstantiationCommand.java new file mode 100644 index 000000000..6f78eafab --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/BaseInstantiationCommand.java @@ -0,0 +1,18 @@ +package org.onap.vid.job.command; + +import org.onap.vid.job.impl.JobSharedData; + +import java.util.Map; + + +public abstract class BaseInstantiationCommand extends CommandBase{ + + + protected CommandParentData commandParentData = new CommandParentData(); + + protected BaseInstantiationCommand init(JobSharedData sharedData, Map commandData) { + super.init(sharedData); + commandParentData.initParentData(commandData); + return this; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/BaseRootCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/BaseRootCommand.java new file mode 100644 index 000000000..4930c94c3 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/BaseRootCommand.java @@ -0,0 +1,41 @@ +package org.onap.vid.job.command; + +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.model.RequestReferencesContainer; +import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; +import org.onap.vid.mso.RestObject; + +import javax.inject.Inject; + + +public abstract class BaseRootCommand extends CommandBase{ + + @Inject + private MsoResultHandlerService msoResultHandlerService; + + @Override + protected CommandBase init(JobSharedData sharedData) { + super.init(sharedData); + return this; + } + + protected ServiceInstantiation getRequest() { + return msoResultHandlerService.getRequest(getSharedData()); + } + + protected NextCommand handleRootResponse(RestObject msoResponse){ + MsoResult msoResult = msoResultHandlerService.handleRootResponse(getSharedData().getJobUuid(), msoResponse); + return new NextCommand(msoResult.getJobStatus(), + (msoResult.getMsoResourceIds()!=null) ? + new ServiceInProgressStatusCommand(getSharedData(), msoResult.getMsoResourceIds()) : + null + ); + + } + + protected NextCommand handleCommandFailed() { + return new NextCommand(msoResultHandlerService.handleRootCommandFailed(getSharedData().getJobUuid()).getJobStatus()); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/BaseWatchingCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/BaseWatchingCommand.java new file mode 100644 index 000000000..b619eddfd --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/BaseWatchingCommand.java @@ -0,0 +1,70 @@ +package org.onap.vid.job.command; + +import org.apache.commons.lang3.ObjectUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.job.Job; +import org.onap.vid.job.JobCommand; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class BaseWatchingCommand extends BaseInstantiationCommand implements JobCommand { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BaseWatchingCommand.class); + + @Inject + protected AsyncInstantiationBusinessLogic asyncInstantiationBL; + + @Inject + private WatchChildrenJobsBL watchChildrenJobsBL; + + private List childrenJobsIds; + + protected boolean isService; + + public BaseWatchingCommand() {} + + public BaseWatchingCommand(JobSharedData sharedData, List childrenJobsIds, boolean isService) { + init(sharedData, childrenJobsIds, isService); + } + + @Override + public NextCommand call() { + Job.JobStatus cumulativeJobsStatus = watchChildrenJobsBL.cumulateJobStatus( + watchChildrenJobsBL.retrieveChildrenJobsStatus(childrenJobsIds), + Job.JobStatus.COMPLETED); + return getNextCommand(cumulativeJobsStatus); + } + + protected abstract NextCommand getNextCommand(Job.JobStatus cumulativeJobsStatus); + + @Override + public BaseWatchingCommand init(JobSharedData sharedData, Map commandData) { + return init( + sharedData, + (List) commandData.get("childrenJobs"), + (boolean) commandData.get("isService") + ); + } + + protected BaseWatchingCommand init(JobSharedData sharedData, List childrenJobsIds, boolean isService) { + super.init(sharedData); + this.childrenJobsIds = ObjectUtils.defaultIfNull(childrenJobsIds, new ArrayList<>()); + this.isService = isService; + return this; + } + + @Override + public Map getData() { + Map data = new HashMap<>(); + data.put("childrenJobs", childrenJobsIds); + data.put("isService", isService); + return data; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandBase.java b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandBase.java new file mode 100644 index 000000000..163106c09 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandBase.java @@ -0,0 +1,27 @@ +package org.onap.vid.job.command; + +import org.onap.vid.job.impl.JobSharedData; + +import javax.inject.Inject; + + +public abstract class CommandBase { + + @Inject + protected CommandUtils commandUtils; + + private JobSharedData sharedData; + + protected CommandBase init(JobSharedData sharedData) { + this.setSharedData(sharedData); + return this; + } + + public JobSharedData getSharedData() { + return sharedData; + } + + private void setSharedData(JobSharedData sharedData) { + this.sharedData = sharedData; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandParentData.java b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandParentData.java new file mode 100644 index 000000000..25c197278 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandParentData.java @@ -0,0 +1,80 @@ +package org.onap.vid.job.command; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.vid.mso.model.ModelInfo; + +import java.util.HashMap; +import java.util.Map; + +public class CommandParentData { + + + public enum CommandDataKey{ + SERVICE_MODEL_INFO, + SERVICE_INSTANCE_ID, + VNF_INSTANCE_ID, + VNF_MODEL_INFO, + VG_INSTANCE_ID, + ; + } + + private static final String RESOURCE_INSTANCE_IDS = "resourceInstancesIds"; + private static final String RESOURCE_MODEL_INFOS = "resourceModelInfos"; + + private final TypeReference> mapCommandKeyToString = + new TypeReference> () {}; + + private final TypeReference> mapCommandKeyToModelInfo = + new TypeReference> () {}; + + + private ObjectMapper objectMapper = new ObjectMapper(); + + private Map getModelInfosByCommandData(Map commandData) { + Object object = commandData.get(RESOURCE_MODEL_INFOS); + if (object != null) { + return objectMapper.convertValue(object, mapCommandKeyToModelInfo); + } + return null; + } + + private Map getInstanceIdsByCommandData(Map commandData) { + Object object = commandData.get(RESOURCE_INSTANCE_IDS); + if (object != null) { + return objectMapper.convertValue(object, mapCommandKeyToString); + } + return null; + } + + public Map getParentData() { + Map data = new HashMap<>(); + data.put(RESOURCE_INSTANCE_IDS, resourceInstancesIds); + data.put(RESOURCE_MODEL_INFOS, resourceModelInfos); + return data; + } + private Map resourceInstancesIds = new HashMap<>(); + private Map resourceModelInfos = new HashMap<>(); + + public void addModelInfo(CommandDataKey modelInfoKey, ModelInfo modelInfo) { + resourceModelInfos.put(modelInfoKey, modelInfo); + } + + public void addInstanceId(CommandDataKey instanceIdKey, String instanceId) { + resourceInstancesIds.put(instanceIdKey, instanceId); + } + public ModelInfo getModelInfo(CommandDataKey modelInfoKey) { + return resourceModelInfos.get(modelInfoKey); + } + + public String getInstanceId(CommandDataKey instanceIdKey) { + return resourceInstancesIds.get(instanceIdKey); + } + + public CommandParentData initParentData(Map commandData) { + resourceModelInfos = getModelInfosByCommandData(commandData); + resourceInstancesIds = getInstanceIdsByCommandData(commandData); + return this; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java new file mode 100644 index 000000000..497eafda9 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java @@ -0,0 +1,46 @@ +package org.onap.vid.job.command; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.services.VidService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CommandUtils { + + private final VidService vidService; + + @Autowired + public CommandUtils(VidService vidService) { + this.vidService = vidService; + } + + public boolean isVfModuleBaseModule(String serviceModelUuid, String vfModuleModelUUID) throws AsdcCatalogException{ + ServiceModel serviceModel = vidService.getService(serviceModelUuid); + + if (serviceModel==null) { + throw new AsdcCatalogException("Failed to retrieve model with uuid "+serviceModelUuid +" from SDC"); + } + + if (serviceModel.getVfModules() == null) { + throw createAsdcCatalogVfModuleModelUUIDNotFoundException(serviceModelUuid, vfModuleModelUUID); + } + + return serviceModel.getVfModules() + .values() + .stream() + .filter(vfModule -> StringUtils.equals(vfModule.getUuid(), vfModuleModelUUID)) + .findFirst() + .orElseThrow(() -> createAsdcCatalogVfModuleModelUUIDNotFoundException(serviceModelUuid, vfModuleModelUUID)) + .getProperties() + .getBaseModule(); + } + + private AsdcCatalogException createAsdcCatalogVfModuleModelUUIDNotFoundException(String serviceModelUuid, String vfModuleModelUUID) { + return new AsdcCatalogException("Failed to find vfModuleModelUUID: " + vfModuleModelUUID + + "in model with uuid: " + serviceModelUuid); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ExpiryChecker.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ExpiryChecker.java new file mode 100644 index 000000000..1ae5d2185 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ExpiryChecker.java @@ -0,0 +1,8 @@ +package org.onap.vid.job.command; + +import java.time.ZonedDateTime; + +public interface ExpiryChecker { + + boolean isExpired(ZonedDateTime jobStartTime); +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/HttpCallCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/HttpCallCommand.java index 5951d7c83..7ee48a8e1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/HttpCallCommand.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/HttpCallCommand.java @@ -4,13 +4,13 @@ import com.google.common.collect.ImmutableMap; import org.onap.vid.job.Job; import org.onap.vid.job.JobCommand; import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; -import javax.ws.rs.core.Response; import java.util.Map; import java.util.UUID; @@ -30,13 +30,13 @@ public class HttpCallCommand implements JobCommand { @Override public NextCommand call() { - final Response response = ClientBuilder.newClient().target(url).request().post(Entity.text(uuid.toString())); + ClientBuilder.newClient().target(url).request().post(Entity.text(uuid.toString())); return new NextCommand(Job.JobStatus.COMPLETED); } @Override - public HttpCallCommand init(UUID jobUuid, Map data) { - return init((String) data.get("url"), jobUuid); + public HttpCallCommand init(JobSharedData sharedData, Map commandData) { + return init((String) commandData.get("url"), sharedData.getJobUuid()); } private HttpCallCommand init(String url, UUID jobUuid) { diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java deleted file mode 100644 index 6685a63d6..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.vid.job.command; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.ImmutableMap; -import io.joshworks.restclient.http.HttpResponse; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.job.Job.JobStatus; -import org.onap.vid.job.JobCommand; -import org.onap.vid.job.NextCommand; -import org.onap.vid.mso.MsoInterface; -import org.onap.vid.mso.rest.AsyncRequestStatus; -import org.onap.vid.services.AsyncInstantiationBusinessLogic; -import org.onap.vid.services.AuditService; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -import javax.inject.Inject; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; - - -@Component -@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class InProgressStatusCommand implements JobCommand { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(InProgressStatusCommand.class); - - @Inject - private AsyncInstantiationBusinessLogic asyncInstantiationBL; - - @Inject - private MsoInterface restMso; - - @Inject - private AuditService auditService; - - private String requestId; - - private UUID jobUuid; - - public InProgressStatusCommand() { - } - - InProgressStatusCommand(UUID jobUuid, String requestId) { - init(jobUuid, requestId); - } - - InProgressStatusCommand(AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic, MsoInterface msoInterface, AuditService auditService, UUID jobUuid, String requestId) { - this(jobUuid, requestId); - this.asyncInstantiationBL = asyncInstantiationBusinessLogic; - this.restMso = msoInterface; - this.auditService = auditService; - } - - @Override - public NextCommand call() { - - try { - String path = asyncInstantiationBL.getOrchestrationRequestsPath() + "/" + requestId; - HttpResponse msoResponse = restMso.get(path, AsyncRequestStatus.class); - - - JobStatus jobStatus; - if (msoResponse.getStatus() >= 400 || msoResponse.getBody() == null) { - auditService.setFailedAuditStatusFromMso(jobUuid, requestId, msoResponse.getStatus(), Objects.toString(msoResponse.getBody())); - LOGGER.error(EELFLoggerDelegate.errorLogger, - "Failed to get orchestration status for {}. Status code: {}, Body: {}", - requestId, msoResponse.getStatus(), Objects.toString(msoResponse.getRawBody())); - return new NextCommand(JobStatus.IN_PROGRESS, this); - } else { - jobStatus = asyncInstantiationBL.calcStatus(msoResponse.getBody()); - } - - asyncInstantiationBL.auditMsoStatus(jobUuid, msoResponse.getBody().request); - - - if (jobStatus == JobStatus.FAILED) { - asyncInstantiationBL.handleFailedInstantiation(jobUuid); - } else { - asyncInstantiationBL.updateServiceInfoAndAuditStatus(jobUuid, jobStatus); - } - //in case of JobStatus.PAUSE we leave the job itself as IN_PROGRESS, for keep tracking job progress - if (jobStatus == JobStatus.PAUSE) { - return new NextCommand(JobStatus.IN_PROGRESS, this); - } - return new NextCommand(jobStatus, this); - } catch (javax.ws.rs.ProcessingException e) { - // Retry when we can't connect MSO during getStatus - LOGGER.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, will retry: {}", requestId, e, e); - return new NextCommand(JobStatus.IN_PROGRESS, this); - } catch (RuntimeException e) { - LOGGER.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, stopping: {}", requestId, e, e); - return new NextCommand(JobStatus.STOPPED, this); - } - } - - @Override - public InProgressStatusCommand init(UUID jobUuid, Map data) { - return init(jobUuid, (String) data.get("requestId")); - } - - private InProgressStatusCommand init(UUID jobUuid, String requestId) { - this.requestId = requestId; - this.jobUuid = jobUuid; - return this; - } - - @Override - public Map getData() { - return ImmutableMap.of("requestId", requestId); - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java new file mode 100644 index 000000000..4799f0087 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java @@ -0,0 +1,87 @@ +package org.onap.vid.job.command; + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.job.Job; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.mso.RestMsoImplementation; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.rest.AsyncRequestStatus; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.onap.vid.services.AuditService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeParseException; +import java.util.UUID; + +import static org.onap.vid.utils.TimeUtils.parseZonedDateTime; + +@Service +public class InProgressStatusService { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(InProgressStatusService.class); + + private final AsyncInstantiationBusinessLogic asyncInstantiationBL; + + private final RestMsoImplementation restMso; + + private final AuditService auditService; + + @Autowired + public InProgressStatusService(AsyncInstantiationBusinessLogic asyncInstantiationBL, RestMsoImplementation restMso, AuditService auditService) { + this.asyncInstantiationBL = asyncInstantiationBL; + this.restMso = restMso; + this.auditService = auditService; + } + + + public Job.JobStatus call(ExpiryChecker expiryChecker, JobSharedData sharedData, String requestId) { + + RestObject asyncRequestStatus = getAsyncRequestStatus(requestId); + asyncInstantiationBL.auditMsoStatus(sharedData.getRootJobId(), asyncRequestStatus.get().request); + Job.JobStatus jobStatus = asyncInstantiationBL.calcStatus(asyncRequestStatus.get()); + ZonedDateTime jobStartTime = getZonedDateTime(asyncRequestStatus, requestId); + jobStatus = expiryChecker.isExpired(jobStartTime) ? Job.JobStatus.FAILED : jobStatus; + return jobStatus; + } + + private RestObject getAsyncRequestStatus(String requestId) { + String path = asyncInstantiationBL.getOrchestrationRequestsPath()+"/"+requestId; + RestObject msoResponse = restMso.GetForObject(path, AsyncRequestStatus.class); + if (msoResponse.getStatusCode() >= 400 || msoResponse.get() == null) { + throw new BadResponseFromMso(msoResponse); + } + return msoResponse; + } + + public void handleFailedMsoResponse(UUID jobUUID, String requestId, RestObject msoResponse) { + auditService.setFailedAuditStatusFromMso(jobUUID, requestId, msoResponse.getStatusCode(), msoResponse.getRaw()); + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Failed to get orchestration status for {}. Status code: {}, Body: {}", + requestId, msoResponse.getStatusCode(), msoResponse.getRaw()); + } + + public static class BadResponseFromMso extends RuntimeException { + private final RestObject msoResponse; + + public BadResponseFromMso(RestObject msoResponse) { + this.msoResponse = msoResponse; + } + + public RestObject getMsoResponse() { + return msoResponse; + } + } + + private ZonedDateTime getZonedDateTime(RestObject asyncRequestStatusResponse, String requestId) { + ZonedDateTime jobStartTime; + try { + jobStartTime = parseZonedDateTime(asyncRequestStatusResponse.get().request.startTime); + } catch (DateTimeParseException | NullPointerException e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to parse start time for {}, body: {}. Current time will be used", requestId, asyncRequestStatusResponse.getRaw(), e); + jobStartTime = ZonedDateTime.now(); + } + return jobStartTime; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/InstanceGroupCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/InstanceGroupCommand.kt new file mode 100644 index 000000000..36da5084b --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/InstanceGroupCommand.kt @@ -0,0 +1,59 @@ +package org.onap.vid.job.command + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate +import org.onap.vid.job.Job +import org.onap.vid.job.JobAdapter +import org.onap.vid.job.JobCommand +import org.onap.vid.model.serviceInstantiation.InstanceGroup +import org.onap.vid.mso.RestMsoImplementation +import org.onap.vid.services.AsyncInstantiationBusinessLogic +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.http.HttpMethod +import org.springframework.stereotype.Component +import java.util.* + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +class InstanceGroupCommand @Autowired constructor( + private val asyncInstantiationBL: AsyncInstantiationBusinessLogic, + restMso: RestMsoImplementation, + msoResultHandlerService: MsoResultHandlerService, + inProgressStatusService:InProgressStatusService, + watchChildrenJobsBL: WatchChildrenJobsBL +) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService, watchChildrenJobsBL), JobCommand { + + companion object { + private val LOGGER = EELFLoggerDelegate.getLogger(InstanceGroupCommand::class.java) + } + + override fun createChildren(): Job.JobStatus { + return Job.JobStatus.COMPLETED_WITH_NO_ACTION + } + + override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan { + val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID) + val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO) + + val instantiatePath = asyncInstantiationBL.getInstanceGroupInstantiationPath() + + val requestDetailsWrapper = asyncInstantiationBL.generateInstanceGroupInstantiationRequest( + request as InstanceGroup, + serviceModelInfo, serviceInstanceId, + userId + ) + + val actionDescription = "create instance group in $serviceInstanceId" + + return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription) + } + + override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan { + val path = asyncInstantiationBL.getInstanceGroupDeletePath(getRequest().instanceId) + return MsoRestCallPlan(HttpMethod.DELETE, path, Optional.empty(), Optional.of(userId), + "delete instance group with id ${getRequest().instanceId}") + + } + +} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/InstanceGroupInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/InstanceGroupInstantiationCommand.java new file mode 100644 index 000000000..17b3f3552 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/InstanceGroupInstantiationCommand.java @@ -0,0 +1,47 @@ +package org.onap.vid.job.command;//package org.onap.vid.job.command; + +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.model.Action; +import org.onap.vid.model.serviceInstantiation.InstanceGroup; +import org.onap.vid.mso.model.InstanceGroupInstantiationRequestDetails; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class InstanceGroupInstantiationCommand extends ResourceInstantiationCommand { + + @Inject + private AsyncInstantiationBusinessLogic asyncInstantiationBL; + + @Override + protected String getRequestPath() { + return asyncInstantiationBL.getInstanceGroupInstantiationPath(); + } + + @Override + protected RequestDetailsWrapper generateMSORequest(JobAdapter.AsyncJobRequest request, String userId) { + return asyncInstantiationBL.generateInstanceGroupInstantiationRequest( + (InstanceGroup) getSharedData().getRequest(), + commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO), + commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID), + getSharedData().getUserId() + ); + } + + @Override + protected String getJobAuditMSOStatus() { + return "INSTANCE_GROUP_REQUESTED"; + } + + @Override + protected boolean shouldInstantiateMyself() { + return Action.Create == ((InstanceGroup) getSharedData().getRequest()).getAction(); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/JobCommandFactory.java b/vid-app-common/src/main/java/org/onap/vid/job/command/JobCommandFactory.java index 1e613c58b..5661663b2 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/JobCommandFactory.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/JobCommandFactory.java @@ -34,7 +34,7 @@ public class JobCommandFactory { public JobCommand toCommand(Job job) { final JobCommand command = jobFactory.apply(job.getType().getCommandClass()); - command.init(job.getUuid(), job.getData()); + command.init(job.getSharedData(), job.getData()); return command; } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceInstantiationCommand.java new file mode 100644 index 000000000..e03f9b8d7 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceInstantiationCommand.java @@ -0,0 +1,26 @@ +package org.onap.vid.job.command; + +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.job.JobCommand; +import org.onap.vid.mso.model.ServiceInstantiationRequestDetails; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class MacroServiceInstantiationCommand extends ServiceInstantiationCommand implements JobCommand { + + public MacroServiceInstantiationCommand() { + // empty constructor + } + + @Override + protected RequestDetailsWrapper generateServiceInstantiationRequest() { + return asyncInstantiationBL.generateMacroServiceInstantiationRequest( + getSharedData().getJobUuid(), getRequest(), optimisticUniqueServiceInstanceName, getSharedData().getUserId() + ); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/MsoResult.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoResult.kt new file mode 100644 index 000000000..95f520f80 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoResult.kt @@ -0,0 +1,9 @@ +package org.onap.vid.job.command + +import org.onap.vid.job.Job + +data class MsoResourceIds (val requestId:String, val instanceId:String) + +val EMPTY_MSO_RESOURCE_ID = MsoResourceIds("","") + +data class MsoResult @JvmOverloads constructor(val jobStatus: Job.JobStatus, val msoResourceIds: MsoResourceIds = EMPTY_MSO_RESOURCE_ID) diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/MsoResultHandlerService.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoResultHandlerService.kt new file mode 100644 index 000000000..9760f667f --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoResultHandlerService.kt @@ -0,0 +1,66 @@ +package org.onap.vid.job.command + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate +import org.onap.vid.job.Job +import org.onap.vid.job.impl.JobSharedData +import org.onap.vid.model.RequestReferencesContainer +import org.onap.vid.model.serviceInstantiation.ServiceInstantiation +import org.onap.vid.mso.RestObject +import org.onap.vid.services.AsyncInstantiationBusinessLogic +import org.onap.vid.services.AuditService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service +import java.util.* + +@Service +class MsoResultHandlerService +@Autowired constructor(private val asyncInstantiationBL: AsyncInstantiationBusinessLogic, private val auditService: AuditService) { + + companion object { + private val LOGGER = EELFLoggerDelegate.getLogger(MsoResultHandlerService::class.java) + } + + fun getRequest(jobSharedData: JobSharedData): ServiceInstantiation { + return jobSharedData.request as ServiceInstantiation + } + + fun handleRootResponse(jobUUID: UUID, msoResponse: RestObject): MsoResult { + return if (msoResponse.statusCode in 200..399) { + val jobStatus = Job.JobStatus.IN_PROGRESS + val msoResourceIds = MsoResourceIds(msoResponse.get().requestReferences.requestId, msoResponse.get().requestReferences.instanceId) + asyncInstantiationBL.auditVidStatus(jobUUID, jobStatus) + setInitialRequestAuditStatusFromMso(jobUUID, msoResourceIds.requestId) + asyncInstantiationBL.updateServiceInfo(jobUUID) { x -> + x.jobStatus = jobStatus + x.serviceInstanceId = msoResourceIds.instanceId + x.msoRequestId = UUID.fromString(msoResourceIds.requestId) + } + MsoResult(jobStatus, msoResourceIds) + } else { + auditService.setFailedAuditStatusFromMso(jobUUID, null, msoResponse.statusCode, msoResponse.raw) + handleRootCommandFailed(jobUUID) + } + } + + fun handleResponse(msoResponse: RestObject, actionDescription: String): MsoResult { + return if (msoResponse.statusCode in 200..399) { + val msoResourceIds = MsoResourceIds(msoResponse.get().requestReferences.requestId, msoResponse.get().requestReferences.instanceId) + LOGGER.debug("Successfully sent $actionDescription. Request id: ${msoResourceIds.requestId}") + MsoResult(Job.JobStatus.COMPLETED_WITH_NO_ACTION, msoResourceIds) + } else { + LOGGER.debug("Failed to $actionDescription. Details: ${msoResponse.raw}") + MsoResult(Job.JobStatus.FAILED) + } + } + + + fun handleRootCommandFailed(jobUUID: UUID): MsoResult { + asyncInstantiationBL.handleFailedInstantiation(jobUUID) + return MsoResult(Job.JobStatus.FAILED) + } + + private fun setInitialRequestAuditStatusFromMso(jobUUID: UUID, requestId: String) { + val initialMsoRequestStatus = "REQUESTED" + asyncInstantiationBL.auditMsoStatus(jobUUID, initialMsoRequestStatus, requestId, null) + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/NetworkInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/NetworkInstantiationCommand.java new file mode 100644 index 000000000..401bab723 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/NetworkInstantiationCommand.java @@ -0,0 +1,41 @@ +package org.onap.vid.job.command; + +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.model.serviceInstantiation.Network; +import org.onap.vid.mso.model.NetworkInstantiationRequestDetails; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class NetworkInstantiationCommand extends ResourceInstantiationCommand { + + @Inject + private AsyncInstantiationBusinessLogic asyncInstantiationBL; + + @Override + protected String getRequestPath() { + return asyncInstantiationBL.getNetworkInstantiationPath(commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID)); + } + + @Override + protected RequestDetailsWrapper generateMSORequest(JobAdapter.AsyncJobRequest request, String userId) { + return asyncInstantiationBL.generateNetworkInstantiationRequest( + (Network) getSharedData().getRequest(), + commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO), + commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID), + getSharedData().getUserId() + ); + } + + @Override + protected String getJobAuditMSOStatus() { + return "NETWORK_REQUESTED"; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt new file mode 100644 index 000000000..6dfcbdf3a --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt @@ -0,0 +1,324 @@ +package org.onap.vid.job.command + +import com.fasterxml.jackson.module.kotlin.convertValue +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate +import org.onap.vid.changeManagement.RequestDetailsWrapper +import org.onap.vid.job.Job +import org.onap.vid.job.Job.JobStatus +import org.onap.vid.job.JobAdapter +import org.onap.vid.job.JobCommand +import org.onap.vid.job.NextCommand +import org.onap.vid.job.impl.JobSharedData +import org.onap.vid.model.Action +import org.onap.vid.model.RequestReferencesContainer +import org.onap.vid.model.serviceInstantiation.BaseResource +import org.onap.vid.mso.RestMsoImplementation +import org.onap.vid.utils.JACKSON_OBJECT_MAPPER +import org.onap.vid.utils.getEnumFromMapOfStrings +import org.springframework.http.HttpMethod +import java.util.* + +const val INTERNAL_STATE = "internalState" +const val ACTION_PHASE = "actionPhase" +const val CHILD_JOBS = "childJobs" +const val MSO_RESOURCE_ID = "msoResourceIds" +const val CUMULATIVE_STATUS = "cumulativeStatus" + +enum class InternalState constructor(val immediate:Boolean=false) { + INITIAL, + CREATING_CHILDREN(true), + WATCHING, + DELETE_MYSELF, + CREATE_MYSELF, + IN_PROGRESS, + TERMINAL +} + +data class NextInternalState(val nextActionPhase: Action, val nextInternalState: InternalState) + + +data class MsoRestCallPlan( + val httpMethod: HttpMethod, + val path: String, + val payload: Optional>, + val userId: Optional, + val actionDescription: String +) + +abstract class ResourceCommand( + protected val restMso: RestMsoImplementation, + protected val inProgressStatusService: InProgressStatusService, + protected val msoResultHandlerService: MsoResultHandlerService, + protected val watchChildrenJobsBL: WatchChildrenJobsBL +) : CommandBase(), JobCommand { + + companion object { + private val Logger = EELFLoggerDelegate.getLogger(ResourceCommand::class.java) + } + + abstract fun createChildren():JobStatus + + abstract fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan + + abstract fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan + + private val commandByInternalState: Map JobStatus> = hashMapOf( + Pair(InternalState.CREATING_CHILDREN, ::createChildren), + Pair(InternalState.WATCHING, ::watchChildren), + Pair(InternalState.CREATE_MYSELF, ::createMyself), + Pair(InternalState.DELETE_MYSELF, ::deleteMyself), + Pair(InternalState.IN_PROGRESS, ::inProgress) + ) + + private lateinit var internalState:InternalState + protected lateinit var actionPhase: Action + private var commandParentData: CommandParentData = CommandParentData() + private var msoResourceIds: MsoResourceIds = EMPTY_MSO_RESOURCE_ID + protected var childJobs:List = emptyList() + private lateinit var cumulativeStatus:JobStatus + + + override fun call(): NextCommand { + var jobStatus:JobStatus = invokeCommand() + jobStatus = comulateStatusAndUpdatePropertyIfFinal(jobStatus) + + Logger.debug("command for job ${sharedData.jobUuid} invoked and finished with jobStatus $jobStatus") + if (shallStopJob(jobStatus)) { + onFinal(jobStatus) + return NextCommand(jobStatus) + } + + val (nextActionPhase, nextInternalState) = calcNextInternalState(jobStatus, internalState, actionPhase) + Logger.debug("next state for job ${sharedData.jobUuid} is $nextInternalState") + actionPhase = nextActionPhase + internalState = nextInternalState + + if (internalState==InternalState.TERMINAL) { + onFinal(jobStatus) + return NextCommand(jobStatus) + } + + jobStatus = getExternalInProgressStatus() + Logger.debug("next status for job ${sharedData.jobUuid} is $jobStatus") +// if (internalState.immediate) return call() //shortcut instead of execute another command + return NextCommand(jobStatus, this) + } + + //we want to stop in faliures, except for service witn no action, since service with no action trigger 2 phases (delete and create) + protected fun shallStopJob(jobStatus: JobStatus) = + jobStatus.isFailure && !(isServiceCommand() && getActionType()==Action.None) + + //this method is used to expose the job status after successful completion of current state + //should be override by subclass (like ServiceCommand) that need to return other default job status + protected open fun getExternalInProgressStatus() = JobStatus.RESOURCE_IN_PROGRESS + + private fun invokeCommand(): JobStatus { + return commandByInternalState.getOrDefault (internalState, ::throwIllegalState).invoke() + } + + private fun throwIllegalState():JobStatus { + throw IllegalStateException("can't find action for pashe $actionPhase and state $internalState") + } + + private fun calcNextInternalState(jobStatus: JobStatus, internalState: InternalState, actionPhase: Action): NextInternalState { + + val nextInternalState = when (actionPhase) { + Action.Delete -> calcNextStateDeletePhase(jobStatus, internalState) + Action.Create -> calcNextStateCreatePhase(jobStatus, internalState) + else -> InternalState.TERMINAL + } + + if (nextInternalState == InternalState.TERMINAL + && actionPhase == Action.Delete + && isServiceCommand()) { + // Loop over to "Create" phase + return NextInternalState(Action.Create, InternalState.INITIAL) + } + + return NextInternalState(actionPhase, nextInternalState) + + } + + //no need to refer to failed (final) states here + //This method is called only for non final states or COMPLETED + protected fun calcNextStateDeletePhase(jobStatus: JobStatus, internalState: InternalState): InternalState { + return when (internalState) { + + InternalState.CREATING_CHILDREN -> InternalState.WATCHING + + InternalState.WATCHING -> { + when { + !jobStatus.isFinal -> InternalState.WATCHING + isNeedToDeleteMyself() -> InternalState.DELETE_MYSELF + else -> InternalState.TERMINAL + } + } + + InternalState.DELETE_MYSELF -> InternalState.IN_PROGRESS + + InternalState.IN_PROGRESS -> { + if (jobStatus == Job.JobStatus.COMPLETED) InternalState.TERMINAL else InternalState.IN_PROGRESS + } + + else -> InternalState.TERMINAL + } + } + + protected fun calcNextStateCreatePhase(jobStatus: JobStatus, internalState: InternalState): InternalState { + return when (internalState) { + + InternalState.CREATE_MYSELF -> InternalState.IN_PROGRESS + + InternalState.IN_PROGRESS -> { + if (jobStatus == Job.JobStatus.COMPLETED) InternalState.CREATING_CHILDREN else InternalState.IN_PROGRESS + } + + InternalState.CREATING_CHILDREN -> InternalState.WATCHING + + InternalState.WATCHING -> { + when { + !jobStatus.isFinal -> InternalState.WATCHING + else -> InternalState.TERMINAL + } + } + + + else -> InternalState.TERMINAL + } + } + + override fun getData(): Map { + return mapOf( + ACTION_PHASE to actionPhase, + INTERNAL_STATE to internalState, + MSO_RESOURCE_ID to msoResourceIds, + CHILD_JOBS to childJobs, + CUMULATIVE_STATUS to cumulativeStatus + ) + } + + override fun init(sharedData: JobSharedData, commandData: Map): ResourceCommand { + init(sharedData) + val resourceIdsRaw:Any? = commandData[MSO_RESOURCE_ID] + commandParentData.initParentData(commandData) + msoResourceIds = + if (resourceIdsRaw != null) JACKSON_OBJECT_MAPPER.convertValue(resourceIdsRaw) + else EMPTY_MSO_RESOURCE_ID + + childJobs = JACKSON_OBJECT_MAPPER.convertValue(commandData.getOrDefault(CHILD_JOBS, emptyList())) + cumulativeStatus = getEnumFromMapOfStrings(commandData, CUMULATIVE_STATUS, JobStatus.COMPLETED_WITH_NO_ACTION) + actionPhase = getEnumFromMapOfStrings(commandData, ACTION_PHASE, Action.Delete) + internalState = calcInitialState(commandData, actionPhase) + return this + } + + private fun calcInitialState(commandData: Map, phase: Action):InternalState { + val status:InternalState = getEnumFromMapOfStrings(commandData, INTERNAL_STATE, InternalState.INITIAL) + if (status == InternalState.INITIAL) { + onInitial(phase) + return when (phase) { + Action.Delete -> InternalState.CREATING_CHILDREN + Action.Create -> if (isNeedToCreateMyself()) InternalState.CREATE_MYSELF else InternalState.CREATING_CHILDREN + else -> throw IllegalStateException("state $internalState is not supported yet") + } + } + return status + } + + //command may override it in order to do something while init state + protected open fun onInitial(phase: Action) { + //do nothing + } + + //command may override it in order to do something while final status + protected open fun onFinal(jobStatus: JobStatus) { + //do nothing + } + + protected open fun getRequest(): BaseResource { + return sharedData.request as BaseResource + } + + protected open fun getActionType(): Action { + return getRequest().action + } + + protected open fun isServiceCommand(): Boolean = false + + protected open fun isNeedToDeleteMyself(): Boolean = getActionType() == Action.Delete + + protected open fun isNeedToCreateMyself(): Boolean = getActionType() == Action.Create + + protected open fun inProgress(): Job.JobStatus { + val requestId:String = msoResourceIds.requestId; + return try { + val jobStatus = inProgressStatusService.call(getExpiryChecker(), sharedData, requestId) + handleInProgressStatus(jobStatus) + } catch (e: javax.ws.rs.ProcessingException) { + // Retry when we can't connect MSO during getStatus + Logger.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, will retry: {}", requestId, e, e) + Job.JobStatus.IN_PROGRESS; + } catch (e: InProgressStatusService.BadResponseFromMso) { + inProgressStatusService.handleFailedMsoResponse(sharedData.jobUuid, requestId, e.msoResponse) + Job.JobStatus.IN_PROGRESS + } catch (e: RuntimeException) { + Logger.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, stopping: {}", requestId, e, e) + Job.JobStatus.STOPPED + } + } + + fun createMyself(): Job.JobStatus { + val createMyselfCommand = planCreateMyselfRestCall(commandParentData, sharedData.request, sharedData.userId) + + return executeAndHandleMsoInstanceRequest(createMyselfCommand) + } + + fun deleteMyself(): Job.JobStatus { + val deleteMyselfCommand = planDeleteMyselfRestCall(commandParentData, sharedData.request, sharedData.userId) + + return executeAndHandleMsoInstanceRequest(deleteMyselfCommand) + } + + private fun executeAndHandleMsoInstanceRequest(restCallPlan: MsoRestCallPlan): JobStatus { + val msoResponse = restMso.restCall( + restCallPlan.httpMethod, + RequestReferencesContainer::class.java, + restCallPlan.payload.orElse(null), + restCallPlan.path, + restCallPlan.userId + ) + + val msoResult = if (isServiceCommand()) { + msoResultHandlerService.handleRootResponse(sharedData.jobUuid, msoResponse) + } else { + msoResultHandlerService.handleResponse(msoResponse, restCallPlan.actionDescription) + } + + this.msoResourceIds = msoResult.msoResourceIds + return msoResult.jobStatus + } + + protected open fun getExpiryChecker(): ExpiryChecker = ExpiryChecker {false} + + protected open fun handleInProgressStatus(jobStatus: JobStatus): JobStatus { + return if (jobStatus == Job.JobStatus.PAUSE) Job.JobStatus.IN_PROGRESS else jobStatus + } + + protected open fun watchChildren():JobStatus { + return watchChildrenJobsBL.retrieveChildrenJobsStatus(childJobs) + } + + private fun comulateStatusAndUpdatePropertyIfFinal(internalStateStatus: JobStatus): JobStatus { + val status = watchChildrenJobsBL.cumulateJobStatus(internalStateStatus, cumulativeStatus) + + //we want to update cumulativeStatus only for final status + if (status.isFinal) { + cumulativeStatus = status; + } + + return status + } +} + + + diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceInProgressStatusCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceInProgressStatusCommand.java new file mode 100644 index 000000000..9ab600aae --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceInProgressStatusCommand.java @@ -0,0 +1,32 @@ +package org.onap.vid.job.command; + +import org.onap.vid.job.Job; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ResourceInProgressStatusCommand extends BaseInProgressStatusCommand { + + public ResourceInProgressStatusCommand() { + } + + ResourceInProgressStatusCommand(JobSharedData sharedData, String requestId, String instanceId) { + init(sharedData, requestId, instanceId); + } + + @Override + protected ExpiryChecker getExpiryChecker() { + return x->false; + } + + @Override + protected NextCommand processJobStatus(Job.JobStatus jobStatus) { + return new NextCommand(jobStatus, this); + } + + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceInstantiationCommand.java new file mode 100644 index 000000000..c86c6f1be --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceInstantiationCommand.java @@ -0,0 +1,87 @@ +package org.onap.vid.job.command; + +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.job.Job; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.job.JobCommand; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.model.RequestReferencesContainer; +import org.onap.vid.mso.RestMsoImplementation; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.model.BaseResourceInstantiationRequestDetails; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.onap.vid.services.AuditService; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import java.util.Map; + + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public abstract class ResourceInstantiationCommand extends BaseInstantiationCommand implements JobCommand { + + + @Inject + protected RestMsoImplementation restMso; + + @Inject + private AsyncInstantiationBusinessLogic asyncInstantiationBL; + + @Inject + private AuditService auditService; + + @Override + public ResourceInstantiationCommand init(JobSharedData sharedData, Map commandData) { + super.init(sharedData, commandData); + return this; + } + + @Override + public Map getData() { + return commandParentData.getParentData(); + } + + @Override + public NextCommand call() { + if (!shouldInstantiateMyself()) { + return new NextCommand(Job.JobStatus.COMPLETED_WITH_NO_ACTION); + } + + RequestDetailsWrapper requestDetailsWrapper = generateMSORequest( + getSharedData().getRequest(), + getSharedData().getUserId() + ); + String instantiatePath = getRequestPath(); + + RestObject msoResponse = restMso.PostForObject(requestDetailsWrapper, + instantiatePath, RequestReferencesContainer.class); + + if (msoResponse.getStatusCode() >= 200 && msoResponse.getStatusCode() < 400) { + String requestId = msoResponse.get().getRequestReferences().getRequestId(); + String instanceId = msoResponse.get().getRequestReferences().getInstanceId(); + asyncInstantiationBL.auditMsoStatus(getSharedData().getRootJobId(), getJobAuditMSOStatus(), requestId, null); + return getNextCommand(requestId, instanceId); + } + else { + auditService.setFailedAuditStatusFromMso(getSharedData().getRootJobId(), null, msoResponse.getStatusCode(), msoResponse.getRaw()); + return new NextCommand(Job.JobStatus.FAILED); + } + } + protected NextCommand getNextCommand(String requestId, String instanceId){ + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new ResourceInProgressStatusCommand(getSharedData(), requestId, instanceId)); + } + + protected boolean shouldInstantiateMyself() { + return true; + } + + protected abstract String getRequestPath(); + protected abstract RequestDetailsWrapper generateMSORequest(JobAdapter.AsyncJobRequest request, String userId); + protected abstract String getJobAuditMSOStatus(); +} + + diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceWithChildrenInProgressCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceWithChildrenInProgressCommand.java new file mode 100644 index 000000000..53164f433 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceWithChildrenInProgressCommand.java @@ -0,0 +1,65 @@ +package org.onap.vid.job.command; + +import org.onap.vid.job.Job; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; + +import java.util.HashMap; +import java.util.Map; + + +public class ResourceWithChildrenInProgressCommand extends BaseInProgressStatusCommand { + + public ResourceWithChildrenInProgressCommand() { + } + + public ResourceWithChildrenInProgressCommand(JobSharedData sharedData, + String requestId, + String instanceId, + CommandParentData commandParentData) { + init(sharedData, requestId, instanceId, commandParentData); + } + + protected BaseInProgressStatusCommand init(JobSharedData sharedData, + String requestId, + String instanceId, + CommandParentData commandParentData) { + init(sharedData, requestId, instanceId); + this.commandParentData= commandParentData; + return this; + } + + + @Override + public Map getData() { + Map data = new HashMap<>(super.getData()); + data.putAll(buildDataForChild()); + return data; + } + + @Override + public BaseInProgressStatusCommand init(JobSharedData sharedData, Map commandData) { + return init( + sharedData, + (String) commandData.get("requestId"), + (String) commandData.get("instanceId"), + commandParentData.initParentData(commandData)); + } + + protected Map buildDataForChild() { + return commandParentData.getParentData(); + } + + + + @Override + protected NextCommand processJobStatus(Job.JobStatus jobStatus) { + return new NextCommand(jobStatus, this); + } + + @Override + protected ExpiryChecker getExpiryChecker() { + return x->false; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInProgressStatusCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInProgressStatusCommand.java new file mode 100644 index 000000000..ac8b5546f --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInProgressStatusCommand.java @@ -0,0 +1,100 @@ +package org.onap.vid.job.command; + +import org.apache.commons.collections.MapUtils; +import org.onap.vid.job.Job; +import org.onap.vid.job.Job.JobStatus; +import org.onap.vid.job.JobCommand; +import org.onap.vid.job.JobType; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; +import org.onap.vid.properties.Features; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ServiceInProgressStatusCommand extends BaseInProgressStatusCommand { + + public ServiceInProgressStatusCommand() { + } + + ServiceInProgressStatusCommand(JobSharedData sharedData, MsoResourceIds msoResourceIds) { + init(sharedData, msoResourceIds.getRequestId(), msoResourceIds.getInstanceId()); + } + + @Override + protected ExpiryChecker getExpiryChecker() { + return new ServiceExpiryChecker(); + } + + protected NextCommand processJobStatus(Job.JobStatus jobStatus) { + JobCommand jobCommand = this; + Job.JobStatus nextJobStatus = jobStatus; + switch (jobStatus) { + case FAILED: + asyncInstantiationBL.handleFailedInstantiation(getSharedData().getJobUuid()); + return new NextCommand(nextJobStatus, jobCommand); + case PAUSE: + nextJobStatus = Job.JobStatus.IN_PROGRESS; + break; + case COMPLETED: + ServiceInstantiation request = (ServiceInstantiation) getSharedData().getRequest(); + if (isNeedToCreateChildJobs(request)) { + List childrenJobs = getChildJobs(request); + nextJobStatus = Job.JobStatus.IN_PROGRESS; + jobCommand = new WatchingCommand(getSharedData(), childrenJobs, true); + return new NextCommand(nextJobStatus, jobCommand); + } + break; + default: // for sonar + } + asyncInstantiationBL.updateServiceInfoAndAuditStatus(getSharedData().getJobUuid(), jobStatus); + return new NextCommand(nextJobStatus, jobCommand); + } + + private List getChildJobs(ServiceInstantiation request) { + Map dataForChild = buildDataForChild(request); + + Stream vnfJobs = request.getVnfs().values().stream().map( + vnf -> jobsBrokerService.add( + jobAdapter.createChildJob(JobType.VnfInstantiation, JobStatus.CREATING , vnf, getSharedData(), dataForChild)).toString() + ); + + Stream networkJobs = request.getNetworks().values().stream().map( + network -> jobsBrokerService.add( + jobAdapter.createChildJob(JobType.NetworkInstantiation, JobStatus.CREATING , network, getSharedData(), dataForChild)).toString() + ); + + Stream instanceGroupJobs = request.getVnfGroups().values().stream().map( + instanceGroup -> jobsBrokerService.add( + jobAdapter.createChildJob(JobType.InstanceGroupInstantiation, JobStatus.CREATING , instanceGroup, getSharedData(), dataForChild)).toString() + ); + + return Stream.of(vnfJobs, networkJobs, instanceGroupJobs) + .reduce(Stream::concat) + .orElseGet(Stream::empty) + .collect(Collectors.toList()); + } + + public boolean isNeedToCreateChildJobs(ServiceInstantiation request) { + return featureManager.isActive(Features.FLAG_ASYNC_ALACARTE_VNF) && request.isALaCarte() && + ( + MapUtils.isNotEmpty(request.getVnfs()) || MapUtils.isNotEmpty(request.getNetworks()) || + (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && MapUtils.isNotEmpty(request.getVnfGroups())) + ); + } + + protected Map buildDataForChild(ServiceInstantiation request) { + commandParentData.addInstanceId(CommandDataKey.SERVICE_INSTANCE_ID, this.instanceId); + commandParentData.addModelInfo(CommandDataKey.SERVICE_MODEL_INFO, request.getModelInfo()); + return commandParentData.getParentData(); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java index 958fc115e..b40b7015c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java @@ -1,170 +1,106 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ package org.onap.vid.job.command; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; -import io.joshworks.restclient.http.HttpResponse; -import org.onap.vid.aai.exceptions.InvalidAAIResponseException; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.exceptions.MaxRetriesException; import org.onap.vid.job.Job; import org.onap.vid.job.JobCommand; import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; import org.onap.vid.model.RequestReferencesContainer; import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; -import org.onap.vid.mso.MsoInterface; +import org.onap.vid.mso.RestMsoImplementation; +import org.onap.vid.mso.RestObject; import org.onap.vid.mso.model.ServiceInstantiationRequestDetails; import org.onap.vid.services.AsyncInstantiationBusinessLogic; -import org.onap.vid.services.AuditService; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; import javax.inject.Inject; import java.util.Map; -import java.util.Objects; -import java.util.UUID; -@Component -@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ServiceInstantiationCommand implements JobCommand { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); +public abstract class ServiceInstantiationCommand extends BaseRootCommand implements JobCommand { private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ServiceInstantiationCommand.class); @Inject - private AsyncInstantiationBusinessLogic asyncInstantiationBL; - - @Inject - private AuditService auditService; + protected AsyncInstantiationBusinessLogic asyncInstantiationBL; @Inject - private MsoInterface restMso; + private RestMsoImplementation restMso; - private UUID uuid; - private ServiceInstantiation serviceInstantiationRequest; - private String userId; + protected String optimisticUniqueServiceInstanceName; public ServiceInstantiationCommand() { } - public ServiceInstantiationCommand(UUID uuid, ServiceInstantiation serviceInstantiationRequest, String userId) { - init(uuid, serviceInstantiationRequest, userId); - } - - ServiceInstantiationCommand(AsyncInstantiationBusinessLogic asyncInstantiationBL, AuditService auditService, MsoInterface msoInterface, - UUID uuid, ServiceInstantiation serviceInstantiation, String userId) { - this(uuid, serviceInstantiation, userId); - this.asyncInstantiationBL = asyncInstantiationBL; - this.auditService = auditService; - this.restMso = msoInterface; - } - @Override public NextCommand call() { RequestDetailsWrapper requestDetailsWrapper ; try { - requestDetailsWrapper = asyncInstantiationBL.generateServiceInstantiationRequest( - uuid, serviceInstantiationRequest, userId - ); + requestDetailsWrapper = generateServiceInstantiationRequest(); } + //Aai return bad response while checking names uniqueness - catch (InvalidAAIResponseException exception) { - LOGGER.error("Failed to check name uniqueness in AAI. VID will try again later", exception); - //put the job in_progress so we will keep trying to check name uniqueness in AAI - //And then send the request to MSO - return new NextCommand(Job.JobStatus.IN_PROGRESS, this); + catch (ExceptionWithRequestInfo exception) { + return handleAaiNameUniquenessBadResponse(exception); } //Vid reached to max retries while trying to find unique name in AAI catch (MaxRetriesException exception) { - LOGGER.error("Failed to find unused name in AAI. Set the job to FAILED ", exception); - return handleCommandFailed(); + return handleMaxRetryInNameUniqueness(exception); } - String path = asyncInstantiationBL.getServiceInstantiationPath(serviceInstantiationRequest); + String path = asyncInstantiationBL.getServiceInstantiationPath(getRequest()); - HttpResponse msoResponse = restMso.post(path, - requestDetailsWrapper, RequestReferencesContainer.class); + RestObject msoResponse = restMso.PostForObject(requestDetailsWrapper, + path, RequestReferencesContainer.class); + return handleRootResponse(msoResponse); - if (msoResponse.getStatus() >= 200 && msoResponse.getStatus() < 400) { - final Job.JobStatus jobStatus = Job.JobStatus.IN_PROGRESS; - final String requestId = msoResponse.getBody().getRequestReferences().getRequestId(); - final String instanceId = msoResponse.getBody().getRequestReferences().getInstanceId(); - asyncInstantiationBL.auditVidStatus(uuid, jobStatus); - setInitialRequestAuditStatusFromMso(requestId); - asyncInstantiationBL.updateServiceInfo(uuid, x-> { - x.setJobStatus(jobStatus); - x.setServiceInstanceId(instanceId); - }); - - return new NextCommand(jobStatus, new InProgressStatusCommand(uuid, requestId)); - } else { - auditService.setFailedAuditStatusFromMso(uuid,null, msoResponse.getStatus(), - Objects.toString(msoResponse.getBody())); - return handleCommandFailed(); - } + } + @Override + protected ServiceInstantiation getRequest() { + return (ServiceInstantiation) getSharedData().getRequest(); } - private void setInitialRequestAuditStatusFromMso(String requestId){ - final String initialMsoRequestStatus = "REQUESTED"; - asyncInstantiationBL.auditMsoStatus(uuid,initialMsoRequestStatus,requestId,null); + protected abstract RequestDetailsWrapper generateServiceInstantiationRequest(); + + private NextCommand handleMaxRetryInNameUniqueness(MaxRetriesException exception) { + LOGGER.error("Failed to find unused name in AAI. Set the job to FAILED ", exception); + return handleCommandFailed(); } - protected NextCommand handleCommandFailed() { - asyncInstantiationBL.handleFailedInstantiation(uuid); - return new NextCommand(Job.JobStatus.FAILED); + private NextCommand handleAaiNameUniquenessBadResponse(ExceptionWithRequestInfo exception) { + LOGGER.error("Failed to check name uniqueness in AAI. VID will try again later", exception); + //put the job in_progress so we will keep trying to check name uniqueness in AAI + //And then send the request to MSO + return new NextCommand(Job.JobStatus.IN_PROGRESS, this); } @Override - public ServiceInstantiationCommand init(UUID jobUuid, Map data) { - final Object request = data.get("request"); + public ServiceInstantiationCommand init(JobSharedData sharedData, Map commandData) { return init( - jobUuid, - OBJECT_MAPPER.convertValue(request, ServiceInstantiation.class), - (String) data.get("userId") + sharedData, + (String) commandData.get("optimisticUniqueServiceInstanceName") ); } - private ServiceInstantiationCommand init(UUID jobUuid, ServiceInstantiation serviceInstantiationRequest, String userId) { - this.uuid = jobUuid; - this.serviceInstantiationRequest = serviceInstantiationRequest; - this.userId = userId; - + protected ServiceInstantiationCommand init(JobSharedData sharedData, String optimisticUniqueServiceInstanceName) { + init(sharedData); + this.optimisticUniqueServiceInstanceName = ObjectUtils.defaultIfNull(optimisticUniqueServiceInstanceName, + (getRequest()).getInstanceName()); return this; } @Override public Map getData() { return ImmutableMap.of( - "uuid", uuid, - "request", serviceInstantiationRequest, - "userId", userId + "optimisticUniqueServiceInstanceName", optimisticUniqueServiceInstanceName ); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleInstantiationCommand.java new file mode 100644 index 000000000..a3f827e2f --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleInstantiationCommand.java @@ -0,0 +1,44 @@ +package org.onap.vid.job.command; + +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.model.serviceInstantiation.VfModule; +import org.onap.vid.mso.model.VfModuleInstantiationRequestDetails; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class VfmoduleInstantiationCommand extends ResourceInstantiationCommand { + @Inject + private AsyncInstantiationBusinessLogic asyncInstantiationBL; + + @Override + protected String getRequestPath() { + return asyncInstantiationBL.getVfmoduleInstantiationPath(commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID),commandParentData.getInstanceId(CommandDataKey.VNF_INSTANCE_ID)); + } + + @Override + protected RequestDetailsWrapper generateMSORequest(JobAdapter.AsyncJobRequest request, String userId) { + return asyncInstantiationBL.generateVfModuleInstantiationRequest( + (VfModule) getSharedData().getRequest(), + commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO), + commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID), + commandParentData.getModelInfo(CommandDataKey.VNF_MODEL_INFO), + commandParentData.getInstanceId(CommandDataKey.VNF_INSTANCE_ID), + commandParentData.getInstanceId(CommandDataKey.VG_INSTANCE_ID), + getSharedData().getUserId() + ); + } + + @Override + protected String getJobAuditMSOStatus() { + return "VF_MODULE_REQUESTED"; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VnfInProgressStatusCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfInProgressStatusCommand.java new file mode 100644 index 000000000..a6a41b1ae --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfInProgressStatusCommand.java @@ -0,0 +1,87 @@ +package org.onap.vid.job.command; + +import org.apache.commons.collections.MapUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.job.Job; +import org.onap.vid.job.JobType; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.model.serviceInstantiation.BaseResource; +import org.onap.vid.model.serviceInstantiation.VfModule; +import org.onap.vid.model.serviceInstantiation.Vnf; +import org.onap.vid.properties.Features; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class VnfInProgressStatusCommand extends ResourceWithChildrenInProgressCommand { + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VnfInProgressStatusCommand.class); + + public VnfInProgressStatusCommand(JobSharedData sharedData, + String requestId, + String instanceId, + CommandParentData commandParentData) { + super(sharedData, requestId, instanceId, commandParentData); + } + + public VnfInProgressStatusCommand() { + } + + @Override + protected NextCommand processJobStatus(Job.JobStatus jobStatus) { + if (jobStatus == Job.JobStatus.FAILED) { + return new NextCommand(jobStatus); + } + + Vnf request = (Vnf) getSharedData().getRequest(); + + if (isNeedToCreateChildJobs(jobStatus, request)) { + commandParentData.addInstanceId(CommandDataKey.VNF_INSTANCE_ID, instanceId); + commandParentData.addModelInfo(CommandDataKey.VNF_MODEL_INFO, request.getModelInfo()); + //create volume group of base module job + Map dataForChild = buildDataForChild(); + List vfModules = request.getVfModules().values().stream().flatMap(vfKey -> vfKey.values().stream()).collect(Collectors.toList()); + List vgBaseJobs = new ArrayList<>(); + for( VfModule vfModule : vfModules){ + try { + if(commandUtils.isVfModuleBaseModule(commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO).getModelVersionId(), vfModule.getModelInfo().getModelVersionId())) { + vgBaseJobs.add(jobsBrokerService.add( + jobAdapter.createChildJob(JobType.VolumeGroupInstantiation, Job.JobStatus.CREATING, vfModule, getSharedData(), dataForChild)).toString()); + } + } catch (AsdcCatalogException e) { + LOG.error("Failed to retrieve service definitions from SDC, for VfModule is BaseModule. Error: "+e.getMessage() , e); + return new NextCommand(Job.JobStatus.COMPLETED_WITH_ERRORS); + } + } + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommandBaseModule(getSharedData(), vgBaseJobs, false, commandParentData)); + } + + //in case of JobStatus.PAUSE we leave the job itself as IN_PROGRESS, for keep tracking job progress + if (jobStatus == Job.JobStatus.PAUSE) { + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, this); + } + return new NextCommand(jobStatus, this); + } + + + protected boolean isNeedToCreateChildJobs(Job.JobStatus jobStatus, BaseResource request) { + return featureManager.isActive(Features.FLAG_ASYNC_ALACARTE_VFMODULE) && + jobStatus == Job.JobStatus.COMPLETED && + MapUtils.isNotEmpty(((Vnf)request).getVfModules()); + } + + + @Override + protected ExpiryChecker getExpiryChecker() { + return x->false; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VnfInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfInstantiationCommand.java new file mode 100644 index 000000000..8853cdc14 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfInstantiationCommand.java @@ -0,0 +1,50 @@ +package org.onap.vid.job.command; + +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.job.Job; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.model.serviceInstantiation.Vnf; +import org.onap.vid.mso.model.VnfInstantiationRequestDetails; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class VnfInstantiationCommand extends ResourceInstantiationCommand { + + @Inject + private AsyncInstantiationBusinessLogic asyncInstantiationBL; + + @Override + protected String getRequestPath() { + return asyncInstantiationBL.getVnfInstantiationPath( commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID)); + } + + @Override + protected RequestDetailsWrapper generateMSORequest(JobAdapter.AsyncJobRequest request, String userId) { + return asyncInstantiationBL.generateVnfInstantiationRequest( + (Vnf) getSharedData().getRequest(), + commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO), + commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID), + getSharedData().getUserId() + ); + } + + @Override + protected String getJobAuditMSOStatus() { + return "VNF_REQUESTED"; + } + + @Override + protected NextCommand getNextCommand(String requestId, String instanceId) { + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, + new VnfInProgressStatusCommand(getSharedData(), requestId, instanceId, commandParentData)); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VolumeGroupInProgressStatusCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/VolumeGroupInProgressStatusCommand.java new file mode 100644 index 000000000..663696b32 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VolumeGroupInProgressStatusCommand.java @@ -0,0 +1,65 @@ +package org.onap.vid.job.command; + +import org.onap.vid.job.Job; +import org.onap.vid.job.JobType; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.model.serviceInstantiation.VfModule; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class VolumeGroupInProgressStatusCommand extends ResourceWithChildrenInProgressCommand { + + public VolumeGroupInProgressStatusCommand( + JobSharedData sharedData, + String requestId, + String instanceId, + CommandParentData parentData) { + super(sharedData, requestId, instanceId, parentData); + } + + public VolumeGroupInProgressStatusCommand() { + } + + @Override + protected NextCommand processJobStatus(Job.JobStatus jobStatus) { + if (jobStatus == Job.JobStatus.FAILED) { + return new NextCommand(Job.JobStatus.FAILED); + } + VfModule request = (VfModule) getSharedData().getRequest(); + + if (jobStatus == Job.JobStatus.COMPLETED) { + //vf module creation + Map dataForChild = buildDataForChild(); + List vfModuleJob = Arrays.asList(jobsBrokerService.add( + jobAdapter.createChildJob(JobType.VfmoduleInstantiation, Job.JobStatus.CREATING , request, getSharedData(), dataForChild)).toString()); + + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommand(getSharedData(), vfModuleJob, false)); + } + + //in case of JobStatus.PAUSE we leave the job itself as IN_PROGRESS, for keep tracking job progress + if (jobStatus == Job.JobStatus.PAUSE) { + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, this); + } + return new NextCommand(jobStatus, this); + } + + @Override + protected Map buildDataForChild() { + commandParentData.addInstanceId(CommandDataKey.VG_INSTANCE_ID, this.instanceId); + return super.buildDataForChild(); + } + + @Override + protected ExpiryChecker getExpiryChecker() { + return x->false; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VolumeGroupInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/VolumeGroupInstantiationCommand.java new file mode 100644 index 000000000..b2a3da472 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VolumeGroupInstantiationCommand.java @@ -0,0 +1,83 @@ +package org.onap.vid.job.command; + + +import org.apache.commons.lang3.StringUtils; +import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.job.*; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.model.serviceInstantiation.VfModule; +import org.onap.vid.mso.model.VolumeGroupRequestDetails; +import org.onap.vid.services.AsyncInstantiationBusinessLogic; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class VolumeGroupInstantiationCommand extends ResourceInstantiationCommand { + @Inject + private AsyncInstantiationBusinessLogic asyncInstantiationBL; + + @Inject + protected JobsBrokerService jobsBrokerService; + + @Inject + protected JobAdapter jobAdapter; + + @Override + protected String getRequestPath() { + return asyncInstantiationBL.getVolumeGroupInstantiationPath(commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID),commandParentData.getInstanceId(CommandDataKey.VNF_INSTANCE_ID)); + } + + @Override + protected RequestDetailsWrapper generateMSORequest(JobAdapter.AsyncJobRequest request, String userId) { + return asyncInstantiationBL.generateVolumeGroupInstantiationRequest( + (VfModule) getSharedData().getRequest(), + commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO), + commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID), + commandParentData.getModelInfo(CommandDataKey.VNF_MODEL_INFO), + commandParentData.getInstanceId(CommandDataKey.VNF_INSTANCE_ID), + getSharedData().getUserId() + ); + } + + @Override + protected NextCommand getNextCommand(String requestId, String instanceId){ + return new NextCommand( + Job.JobStatus.RESOURCE_IN_PROGRESS, + new VolumeGroupInProgressStatusCommand(getSharedData(), requestId, instanceId, commandParentData) + ); + } + + @Override + protected String getJobAuditMSOStatus() { + return "VOLUME_GROUP_REQUESTED"; + } + + @Override + public NextCommand call() { + String vgName = ((VfModule)getSharedData().getRequest()).getVolumeGroupInstanceName(); + if(StringUtils.isNotEmpty(vgName)){ + return super.call();//create volume group + }else { + //go to vf module creation + VfModule request = (VfModule) getSharedData().getRequest(); + Map dataForChild = buildDataForChild(); + List vfModuleJob = Collections.singletonList(jobsBrokerService.add( + jobAdapter.createChildJob(JobType.VfmoduleInstantiation, Job.JobStatus.CREATING, request, getSharedData(), dataForChild)).toString()); + + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommand(getSharedData(), vfModuleJob, false)); + } + + } + + private Map buildDataForChild() { + return commandParentData.getParentData(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/WatchChildrenJobsBL.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/WatchChildrenJobsBL.kt new file mode 100644 index 000000000..b31e7f92e --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/WatchChildrenJobsBL.kt @@ -0,0 +1,61 @@ +package org.onap.vid.job.command + +import org.apache.commons.lang3.StringUtils +import org.onap.portalsdk.core.service.DataAccessService +import org.onap.vid.job.Job +import org.onap.vid.job.Job.JobStatus.* +import org.onap.vid.job.impl.JobDaoImpl +import org.onap.vid.utils.DaoUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service +import java.util.* +import java.util.stream.Collectors +import java.util.stream.Stream + + +@Service +class WatchChildrenJobsBL @Autowired +constructor(private val dataAccessService: DataAccessService) { + + fun retrieveChildrenJobsStatus(childrenJobsIds: List): Job.JobStatus { + val jobs = getAllChildrenJobs(childrenJobsIds) + + val jobsStatuses = childrenJobsIds.stream() + .map { jobId -> jobs[UUID.fromString(jobId)] } + .map {when { + (it == null || it.status == null) -> Job.JobStatus.FAILED + else -> it.status + }} + + return cumulateJobStatus(jobsStatuses) + + } + + fun cumulateJobStatus(childrenComulatedStatus: Job.JobStatus, fatherJobStatus: Job.JobStatus): Job.JobStatus { + return cumulateJobStatus(Stream.of(childrenComulatedStatus, fatherJobStatus)) + } + + private fun cumulateJobStatus(jobsStatuses: Stream): Job.JobStatus { + + return jobsStatuses.reduce{ a, b -> + when { + !a.isFinal || !b.isFinal -> IN_PROGRESS + a == COMPLETED_WITH_ERRORS || b == COMPLETED_WITH_ERRORS-> COMPLETED_WITH_ERRORS + a == COMPLETED && b.isFailure -> COMPLETED_WITH_ERRORS + b == COMPLETED && a.isFailure -> COMPLETED_WITH_ERRORS + a == COMPLETED || b == COMPLETED -> COMPLETED + a.isFailure || b.isFailure -> FAILED + else -> COMPLETED_WITH_NO_ACTION + } + } .orElse(COMPLETED_WITH_NO_ACTION) + } + + private fun getAllChildrenJobs(childrenJobsIds: List): Map { + val jobs:MutableList = dataAccessService.getList(JobDaoImpl::class.java, filterByJobIds(childrenJobsIds), null, DaoUtils.getPropsMap()) as MutableList + return jobs.stream().collect(Collectors.toMap( { it.uuid }, { it })) + } + + private fun filterByJobIds(childrenJobsIds: List): String { + return " WHERE JOB_ID IN('" + StringUtils.join(childrenJobsIds, "', '") + "')" + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/WatchingCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/WatchingCommand.java new file mode 100644 index 000000000..8659cfe1a --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/WatchingCommand.java @@ -0,0 +1,33 @@ +package org.onap.vid.job.command; + +import org.onap.vid.job.Job; +import org.onap.vid.job.NextCommand; +import org.onap.vid.job.impl.JobSharedData; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class WatchingCommand extends BaseWatchingCommand { + + public WatchingCommand() {} + + public WatchingCommand(JobSharedData sharedData, List childrenJobsIds, boolean isService) { + super(sharedData, childrenJobsIds, isService); + } + + protected NextCommand getNextCommand(Job.JobStatus cumulativeJobsStatus) { + if (cumulativeJobsStatus==Job.JobStatus.IN_PROGRESS) { + return (isService) ? new NextCommand(Job.JobStatus.IN_PROGRESS, this) + : new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, this); + } + if (isService) { + asyncInstantiationBL.updateServiceInfoAndAuditStatus(getSharedData().getJobUuid(), cumulativeJobsStatus); + } + return new NextCommand(cumulativeJobsStatus); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/WatchingCommandBaseModule.java b/vid-app-common/src/main/java/org/onap/vid/job/command/WatchingCommandBaseModule.java new file mode 100644 index 000000000..8012aa9f3 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/WatchingCommandBaseModule.java @@ -0,0 +1,93 @@ +package org.onap.vid.job.command; + +import com.google.common.collect.ImmutableMap; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.job.*; +import org.onap.vid.job.command.CommandParentData.CommandDataKey; +import org.onap.vid.job.impl.JobSharedData; +import org.onap.vid.model.serviceInstantiation.VfModule; +import org.onap.vid.model.serviceInstantiation.Vnf; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class WatchingCommandBaseModule extends BaseWatchingCommand { + @Inject + protected JobsBrokerService jobsBrokerService; + + @Inject + protected JobAdapter jobAdapter; + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(WatchingCommandBaseModule.class); + + public WatchingCommandBaseModule( + JobSharedData sharedData, + List childrenJobsIds, + boolean isService, + CommandParentData commandParentData) { + super(sharedData, childrenJobsIds, isService); + this.commandParentData = commandParentData; + } + + public WatchingCommandBaseModule() { + + } + + @Override + protected NextCommand getNextCommand(Job.JobStatus cumulativeJobsStatus) { + + if (cumulativeJobsStatus== Job.JobStatus.IN_PROGRESS) { + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, this); + } + + if(cumulativeJobsStatus==Job.JobStatus.FAILED || cumulativeJobsStatus==Job.JobStatus.COMPLETED_WITH_ERRORS){ + return new NextCommand(Job.JobStatus.COMPLETED_WITH_ERRORS); + } + Vnf request = (Vnf) getSharedData().getRequest(); + Map dataForChild = buildDataForChild(); + //Create non-base Volume groups job + List vfModules = request.getVfModules().values().stream().flatMap(vfKey -> vfKey.values().stream()).collect(Collectors.toList()); + List vgNonBaseJobs = new ArrayList<>(); + for( VfModule vfModule : vfModules){ + try { + if(!commandUtils.isVfModuleBaseModule(commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO).getModelVersionId(), vfModule.getModelInfo().getModelVersionId())) { + vgNonBaseJobs.add(jobsBrokerService.add( + jobAdapter.createChildJob(JobType.VolumeGroupInstantiation, Job.JobStatus.CREATING, vfModule, getSharedData(), dataForChild)).toString()); + } + } catch (AsdcCatalogException e) { + LOG.error("Failed to retrieve service definitions from SDC, for VfModule is BaseModule. Error: "+e.getMessage() , e); + return new NextCommand(Job.JobStatus.COMPLETED_WITH_ERRORS); + } + } + return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommand(getSharedData(), vgNonBaseJobs, false)); + } + + @Override + public WatchingCommandBaseModule init(JobSharedData sharedData, Map commandData) { + super.init(sharedData, commandData); + commandParentData.initParentData(commandData); + return this; + } + + protected Map buildDataForChild() { + return commandParentData.getParentData(); + } + + @Override + public Map getData() { + return ImmutableMap.builder() + .putAll(super.getData()) + .putAll(commandParentData.getParentData()) + .build(); + } + + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java index 59f12f4c5..1050ab933 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java @@ -4,16 +4,11 @@ import com.google.common.collect.ImmutableMap; import org.onap.vid.job.Job; import org.onap.vid.job.JobAdapter; import org.onap.vid.job.JobType; -import org.onap.vid.model.JobBulk; import org.onap.vid.model.JobModel; import org.springframework.stereotype.Component; -import javax.ws.rs.BadRequestException; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.stream.Collectors; @Component public class JobAdapterImpl implements JobAdapter { @@ -28,44 +23,32 @@ public class JobAdapterImpl implements JobAdapter { } @Override - public JobBulk toModelBulk(List jobList) { - return new JobBulk(jobList.stream().map(this::toModel).collect(Collectors.toList())); - } - - @Override - public Job createJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, Integer indexInBulk) { - JobDaoImpl job = createJob(jobType, templateId, indexInBulk, ImmutableMap.of( - "request", request, - "userId", userId)); - job.setUserId(userId); + public Job createServiceInstantiationJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, String optimisticUniqueServiceInstanceName, Integer indexInBulk){ + JobDaoImpl job = createJob(jobType, Job.JobStatus.PENDING , userId); + job.setSharedData(new JobSharedData(job.getUuid(), userId, request)); + job.setTypeAndData(jobType, ImmutableMap.of( + "optimisticUniqueServiceInstanceName", optimisticUniqueServiceInstanceName + )); + job.setTemplateId(templateId); + job.setIndexInBulk(indexInBulk); return job; } @Override - public List createBulkOfJobs(Map bulkRequest) { - int count; - JobType jobType; - - try { - count = (Integer) bulkRequest.get("count"); - jobType = JobType.valueOf((String) bulkRequest.get("type")); - } catch (Exception exception) { - throw new BadRequestException(exception); - } - List jobList = new ArrayList<>(count + 1); - UUID templateId = UUID.randomUUID(); - for (int i = 0; i < count; i++) { - jobList.add(createJob(jobType, templateId, i, bulkRequest)); - } - return jobList; + public Job createChildJob(JobType jobType, Job.JobStatus jobStatus, AsyncJobRequest request, JobSharedData parentSharedData, Map jobData) { + JobDaoImpl job = createJob(jobType, jobStatus , parentSharedData.getUserId()); + job.setSharedData(new JobSharedData(job.getUuid(), request, parentSharedData)); + job.setTypeAndData(jobType, jobData); + return job; } - private JobDaoImpl createJob(JobType jobType, UUID templateId, Integer indexInBulk, Map data) { + protected JobDaoImpl createJob(JobType jobType, Job.JobStatus jobStatus, String userId) { JobDaoImpl job = new JobDaoImpl(); - job.setStatus(Job.JobStatus.PENDING); - job.setTypeAndData(jobType, data); - job.setTemplateId(templateId); - job.setIndexInBulk(indexInBulk); + job.setTypeAndData(jobType, null); + job.setStatus(jobStatus); + job.setUuid(UUID.randomUUID()); + job.setUserId(userId); return job; } + } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobDaoImpl.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobDaoImpl.java index 1ff1296c7..b301a2fbc 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobDaoImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobDaoImpl.java @@ -3,19 +3,31 @@ package org.onap.vid.job.impl; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.MoreObjects; +import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.annotations.SelectBeforeUpdate; import org.hibernate.annotations.Type; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.job.Job; +import org.onap.vid.job.JobException; import org.onap.vid.job.JobType; import org.onap.vid.model.VidBaseEntity; import javax.persistence.*; import java.io.IOException; -import java.util.*; - +import java.util.Date; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; + +/* + The following 2 annotations let hibernate to update only fields that actually have been changed. + DynamicUpdate tell hibernate to update only dirty fields. + SelectBeforeUpdate is needed since during update the entity is detached (get and update are in different sessions) +*/ +@DynamicUpdate() +@SelectBeforeUpdate() @Entity @Table(name = "vid_job") public class JobDaoImpl extends VidBaseEntity implements Job { @@ -23,7 +35,7 @@ public class JobDaoImpl extends VidBaseEntity implements Job { private static ObjectMapper objectMapper = new ObjectMapper(); private Job.JobStatus status; private JobType type; - private Map> data = new TreeMap<>(); + private JobData data = new JobData(); private UUID templateId; private UUID uuid; private String takenBy; @@ -83,16 +95,25 @@ public class JobDaoImpl extends VidBaseEntity implements Job { public void setDataRaw(String data) { try { - this.data = objectMapper.readValue(data, new TypeReference>>() { - }); + this.data = objectMapper.readValue(data, JobData.class); } catch (IOException e) { - throw new GenericUncheckedException(e); + throw new JobException("Error parsing job's data", uuid, e); } } @Transient public Map getData() { - return data.get(getType()); + return data.getCommandData().get(getType()); + } + + public void setSharedData(JobSharedData sharedData) { + this.data.setSharedData(sharedData); + } + + @Override + @Transient + public JobSharedData getSharedData() { + return this.data.getSharedData(); } @Override @@ -100,7 +121,7 @@ public class JobDaoImpl extends VidBaseEntity implements Job { // *add* the data to map, // then change state to given type this.type = jobType; - this.data.put(jobType, data); + this.data.getCommandData().put(jobType, data); } @Column(name = "TAKEN_BY") @@ -123,6 +144,7 @@ public class JobDaoImpl extends VidBaseEntity implements Job { this.templateId = templateId; } + @Override @Column(name="INDEX_IN_BULK") public Integer getIndexInBulk() { return indexInBulk; diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobData.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobData.java new file mode 100644 index 000000000..0b7a6b7cf --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobData.java @@ -0,0 +1,54 @@ +package org.onap.vid.job.impl; + +import org.onap.vid.job.JobType; + +import java.util.Map; +import java.util.Objects; +import java.util.TreeMap; + +public class JobData { + + private TreeMap> commandData; + private JobSharedData sharedData; + + public JobData() { + commandData = new TreeMap<>(); + sharedData = new JobSharedData(); + } + + public JobData(TreeMap> commandData, JobSharedData sharedData) { + this.commandData = commandData; + this.sharedData = sharedData; + } + + public TreeMap> getCommandData() { + return commandData; + } + + public void setCommandData(TreeMap> commandData) { + this.commandData = commandData; + } + + public JobSharedData getSharedData() { + return sharedData; + } + + public void setSharedData(JobSharedData sharedData) { + this.sharedData = sharedData; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof JobData)) return false; + JobData jobData = (JobData) o; + return Objects.equals(getCommandData(), jobData.getCommandData()) && + Objects.equals(getSharedData(), jobData.getSharedData()); + } + + @Override + public int hashCode() { + + return Objects.hash(getCommandData(), getSharedData()); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java index a5070fbdf..59b2f250c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java @@ -1,12 +1,12 @@ package org.onap.vid.job.impl; import com.google.common.collect.ImmutableMap; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.job.Job; import org.onap.vid.job.JobsBrokerService; import org.onap.vid.job.command.JobCommandFactory; import org.onap.vid.properties.Features; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.quartz.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.quartz.SchedulerFactoryBean; @@ -46,7 +46,9 @@ public class JobSchedulerInitializer { return; } scheduleJobWorker(Job.JobStatus.PENDING, 1); + scheduleJobWorker(Job.JobStatus.CREATING, 1); scheduleJobWorker(Job.JobStatus.IN_PROGRESS, 1); + scheduleJobWorker(Job.JobStatus.RESOURCE_IN_PROGRESS, 1); } private void scheduleJobWorker(Job.JobStatus topic, int intervalInSeconds) { diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSharedData.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSharedData.java new file mode 100644 index 000000000..8f1e45736 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSharedData.java @@ -0,0 +1,84 @@ +package org.onap.vid.job.impl; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.onap.vid.job.JobAdapter; + +import java.util.Objects; +import java.util.UUID; + +public class JobSharedData { + + protected UUID jobUuid; + protected String userId; + protected Class requestType; + protected UUID rootJobId; + + @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, property="class") + protected JobAdapter.AsyncJobRequest request; + + public JobSharedData() { + } + + public JobSharedData(UUID jobUuid, String userId, JobAdapter.AsyncJobRequest request) { + this.jobUuid = jobUuid; + this.userId = userId; + this.requestType = request.getClass(); + this.request = request; + this.rootJobId = jobUuid; + } + + public JobSharedData(UUID jobUuid, JobAdapter.AsyncJobRequest request, JobSharedData parentData) { + this(jobUuid, parentData.getUserId(), request); + rootJobId = parentData.getRootJobId() != null ? parentData.getRootJobId() : parentData.getJobUuid(); + } + + + public UUID getJobUuid() { + return jobUuid; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public Class getRequestType() { + return requestType; + } + + public void setRequestType(Class requestType) { + this.requestType = requestType; + } + + public JobAdapter.AsyncJobRequest getRequest() { + return request; + } + + public void setRequest(JobAdapter.AsyncJobRequest request) { + this.request = request; + } + + public UUID getRootJobId() { + return rootJobId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof JobSharedData)) return false; + JobSharedData that = (JobSharedData) o; + return Objects.equals(getJobUuid(), that.getJobUuid()) && + Objects.equals(getUserId(), that.getUserId()) && + Objects.equals(getRequestType(), that.getRequestType()) && + Objects.equals(getRootJobId(), that.getRootJobId()) && + Objects.equals(getRequest(), that.getRequest()); + } + + @Override + public int hashCode() { + return Objects.hash(getJobUuid(), getUserId(), getRequestType(), getRootJobId(), getRequest()); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java index aa94a2aa0..36ec4314e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java @@ -1,13 +1,11 @@ package org.onap.vid.job.impl; import org.apache.commons.lang3.StringUtils; -import org.onap.vid.job.Job; -import org.onap.vid.job.JobCommand; -import org.onap.vid.job.JobsBrokerService; -import org.onap.vid.job.NextCommand; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.job.*; import org.onap.vid.job.command.JobCommandFactory; import org.onap.vid.properties.Features; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.quartz.JobExecutionContext; import org.springframework.scheduling.quartz.QuartzJobBean; import org.springframework.stereotype.Component; @@ -52,6 +50,8 @@ public class JobWorker extends QuartzJobBean { return jobsBrokerService.pull(topic, UUID.randomUUID().toString()); } catch (Exception e) { LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to pull job from queue, breaking: {}", e, e); + tryMutingJobFromException(e); + return Optional.empty(); } } @@ -72,9 +72,7 @@ public class JobWorker extends QuartzJobBean { NextCommand nextCommand = executeCommandAndGetNext(job); - Job nextJob = setNextCommandInJob(nextCommand, job); - - return nextJob; + return setNextCommandInJob(nextCommand, job); } private NextCommand executeCommandAndGetNext(Job job) { @@ -83,7 +81,7 @@ public class JobWorker extends QuartzJobBean { final JobCommand jobCommand = jobCommandFactory.toCommand(job); nextCommand = jobCommand.call(); } catch (Exception e) { - LOGGER.error(EELFLoggerDelegate.errorLogger, "error while executing job from queue: {}", e, e); + LOGGER.error("error while executing job from queue: {}", e); nextCommand = new NextCommand(FAILED); } @@ -114,6 +112,25 @@ public class JobWorker extends QuartzJobBean { return featureManager.isActive(Features.FLAG_ASYNC_INSTANTIATION); } + private void tryMutingJobFromException(Exception e) { + // If there's JobException in the stack, read job uuid from + // the exception, and mute it in DB. + final int indexOfJobException = + ExceptionUtils.indexOfThrowable(e, JobException.class); + + if (indexOfJobException >= 0) { + try { + final JobException jobException = (JobException) ExceptionUtils.getThrowableList(e).get(indexOfJobException); + LOGGER.info(EELFLoggerDelegate.debugLogger, "muting job: {} ({})", jobException.getJobUuid(), jobException.toString()); + final boolean success = jobsBrokerService.mute(jobException.getJobUuid()); + if (!success) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to mute job {}", jobException.getJobUuid()); + } + } catch (Exception e1) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to mute job: {}", e1, e1); + } + } + } //used by quartz to inject JobsBrokerService into the job //see JobSchedulerInitializer diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java index e286cc4aa..e87478794 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java @@ -2,15 +2,15 @@ package org.onap.vid.job.impl; import org.apache.commons.lang3.StringUtils; import org.hibernate.SessionFactory; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.exceptions.OperationNotAllowedException; import org.onap.vid.job.Job; import org.onap.vid.job.JobsBrokerService; import org.onap.vid.properties.VidProperties; import org.onap.vid.utils.DaoUtils; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.service.DataAccessService; -import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -21,6 +21,8 @@ import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.*; +import static org.onap.vid.job.Job.JobStatus.CREATING; + @Service public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { @@ -56,7 +58,6 @@ public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { @Override public UUID add(Job job) { final JobDaoImpl jobDao = castToJobDaoImpl(job); - jobDao.setUuid(UUID.randomUUID()); dataAccessService.saveDomainObject(jobDao, DaoUtils.getPropsMap()); return job.getUuid(); } @@ -102,23 +103,30 @@ public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { return Timestamp.valueOf(LocalDateTime.now().minusSeconds(pollingIntervalSeconds)); } + private String selectQueryByJobStatus(Job.JobStatus topic){ + + String intervalCondition = (topic==CREATING) ? "" : (" and MODIFIED_DATE <= '" + nowMinusInterval()+"'"); + return "" + + "select * from VID_JOB" + + " where" + + // select only non-deleted in-progress jobs + " JOB_STATUS = '" + topic + "'" + + " and TAKEN_BY is null" + + " and DELETED_AT is null" + + // give some breath, don't select jos that were recently reached + intervalCondition + + // take the oldest handled one + " order by MODIFIED_DATE ASC" + + // select only one result + " limit 1"; + } + private String sqlQueryForTopic(Job.JobStatus topic) { switch (topic) { case IN_PROGRESS: - return "" + - "select * from VID_JOB" + - " where" + - // select only non-deleted in-progress jobs - " JOB_STATUS = 'IN_PROGRESS'" + - " and TAKEN_BY is null" + - " and DELETED_AT is null" + - // give some breath, don't select jos that were recently reached - " and MODIFIED_DATE <= '" + nowMinusInterval() + - // take the oldest handled one - "' order by MODIFIED_DATE ASC" + - // select only one result - " limit 1"; - + case RESOURCE_IN_PROGRESS: + case CREATING: + return selectQueryByJobStatus(topic); case PENDING: return "" + // select only pending jobs @@ -137,9 +145,10 @@ public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { // don't take jobs from templates that already in-progress/failed "and TEMPLATE_Id not in \n" + "(select TEMPLATE_Id from vid_job where" + + " TEMPLATE_Id IS NOT NULL and("+ " (JOB_STATUS='FAILED' and DELETED_AT is null)" + // failed but not deleted " or JOB_STATUS='IN_PROGRESS'" + - " or TAKEN_BY IS NOT NULL)" + " \n " + + " or TAKEN_BY IS NOT NULL))" + " \n " + // prefer older jobs, but the earlier in each bulk "order by has_any_in_progress_job, CREATED_DATE, INDEX_IN_BULK " + // select only one result @@ -233,4 +242,32 @@ public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { throw new OperationNotAllowedException("Service deletion failed"); } } + + @Override + public boolean mute(UUID jobId) { + if (jobId == null) { + return false; + } + + final String prefix = "DUMP"; + int updatedEntities; + + // Changing the topic (i.e. `job.status`) makes the job non-fetchable. + String hqlUpdate = "" + + "update JobDaoImpl job set" + + " job.status = concat('" + prefix + "_', job.status)," + + // empty `takenBy`, because some logics treat taken as in-progress + " takenBy = null" + + " where " + + " job.id = :id" + + // if prefix already on the topic -- no need to do it twice. + " and job.status NOT LIKE '" + prefix + "\\_%'"; + + updatedEntities = DaoUtils.tryWithSessionAndTransaction(sessionFactory, session -> + session.createQuery(hqlUpdate) + .setText("id", jobId.toString()) + .executeUpdate()); + + return updatedEntities != 0; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/Action.java b/vid-app-common/src/main/java/org/onap/vid/model/Action.java new file mode 100644 index 000000000..32ee01fb4 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/Action.java @@ -0,0 +1,15 @@ +package org.onap.vid.model; + +public enum Action { + Create(ServiceInfo.ServiceAction.INSTANTIATE), + Delete(ServiceInfo.ServiceAction.DELETE), + None(ServiceInfo.ServiceAction.UPDATE); + + private final ServiceInfo.ServiceAction serviceAction; + Action(ServiceInfo.ServiceAction serviceAction){ + this.serviceAction = serviceAction; + } + public ServiceInfo.ServiceAction getServiceAction() { + return serviceAction; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/CR.java b/vid-app-common/src/main/java/org/onap/vid/model/CR.java index f8c046e7f..d8ecd64be 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/CR.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/CR.java @@ -17,7 +17,7 @@ public class CR extends Node{ private String customizationUUID; - private Map networksCollection = new HashMap(); + private Map networksCollection = new HashMap<>(); diff --git a/vid-app-common/src/main/java/org/onap/vid/model/CommandProperty.java b/vid-app-common/src/main/java/org/onap/vid/model/CommandProperty.java index 4f5ee173f..e398c5428 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/CommandProperty.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/CommandProperty.java @@ -20,8 +20,6 @@ package org.onap.vid.model; -import java.util.Map; - /** * The Class Command Property. */ @@ -87,7 +85,6 @@ public class CommandProperty { } public String toString () { - String result = "displayName=" + displayName + " command=" + command + " inputName" + inputName; - return result; + return "displayName=" + displayName + " command=" + command + " inputName" + inputName; } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/Group.java b/vid-app-common/src/main/java/org/onap/vid/model/Group.java index 5f98341df..3da15879c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/Group.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/Group.java @@ -1,11 +1,13 @@ package org.onap.vid.model; import org.onap.vid.asdc.beans.tosca.Input; -import org.onap.vid.asdc.parser.ToscaParserImpl2; +import org.onap.vid.asdc.parser.ToscaParserImpl2.Constants; import java.util.Map; -public class Group { +import static org.onap.vid.asdc.parser.ToscaParserImpl2.isModuleTypeIsBaseObjectSafe; + +public class Group implements MinimalNode { /** The uuid. */ @@ -182,7 +184,11 @@ public class Group { protected static GroupProperties extractPropertiesForGroup(org.onap.vid.asdc.beans.tosca.Group group){ - String [] propertyKeys = {ToscaParserImpl2.Constants.MIN_VF_MODULE_INSTANCES, ToscaParserImpl2.Constants.MAX_VF_MODULE_INSTANCES, ToscaParserImpl2.Constants.INITIAL_COUNT}; + String [] propertyKeys = { + Constants.MIN_VF_MODULE_INSTANCES, + Constants.MAX_VF_MODULE_INSTANCES, + Constants.INITIAL_COUNT, + }; GroupProperties groupProperties = new GroupProperties(); for(String propertyKey : propertyKeys){ @@ -191,18 +197,21 @@ public class Group { setInGroupProperties(groupProperties, propertyKey, (Integer) val); } } + + groupProperties.setBaseModule(isModuleTypeIsBaseObjectSafe(group.getProperties().get(Constants.VF_MODULE_TYPE))); + return groupProperties; } private static void setInGroupProperties(GroupProperties groupProperties, String propertyKey, Integer propertyValue){ switch (propertyKey) { - case ToscaParserImpl2.Constants.MIN_VF_MODULE_INSTANCES: + case Constants.MIN_VF_MODULE_INSTANCES: groupProperties.setMinCountInstances(propertyValue); break; - case ToscaParserImpl2.Constants.MAX_VF_MODULE_INSTANCES: + case Constants.MAX_VF_MODULE_INSTANCES: groupProperties.setMaxCountInstances(propertyValue); break; - case ToscaParserImpl2.Constants.INITIAL_COUNT: + case Constants.INITIAL_COUNT: groupProperties.setInitialCount(propertyValue); break; default: diff --git a/vid-app-common/src/main/java/org/onap/vid/model/GroupProperties.java b/vid-app-common/src/main/java/org/onap/vid/model/GroupProperties.java index c7ca60069..d8a57e464 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/GroupProperties.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/GroupProperties.java @@ -5,6 +5,7 @@ public class GroupProperties { private Integer maxCountInstances; private Integer initialCount; private String vfModuleLabel; + private boolean baseModule = false; public String getVfModuleLabel() { return vfModuleLabel; @@ -30,6 +31,14 @@ public class GroupProperties { this.maxCountInstances = maxCountInstances; } + public boolean getBaseModule() { + return baseModule; + } + + public void setBaseModule(boolean baseModule) { + this.baseModule = baseModule; + } + public Integer getInitialCount() { return initialCount; } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/JobAuditStatus.java b/vid-app-common/src/main/java/org/onap/vid/model/JobAuditStatus.java index 614267990..3da41a419 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/JobAuditStatus.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/JobAuditStatus.java @@ -1,20 +1,36 @@ package org.onap.vid.model; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.annotations.SelectBeforeUpdate; import org.hibernate.annotations.Type; -import org.onap.vid.job.Job.JobStatus; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.job.Job.JobStatus; import javax.persistence.*; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.TimeZone; import java.util.UUID; +/* + The following 2 annotations let hibernate to update only fields that actually have been changed. + DynamicUpdate tell hibernate to update only dirty fields. + SelectBeforeUpdate is needed since during update the entity is detached (get and update are in different sessions) + */ +@DynamicUpdate() +@SelectBeforeUpdate() @Entity @Table(name = "vid_job_audit_status") public class JobAuditStatus extends VidBaseEntity { + public static final int MAX_ADDITIONAL_INFO_LENGTH = 2000; static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JobAuditStatus.class); + private static final String defaultFormat = "E, dd MMM yyyy HH:mm:ss z"; public JobAuditStatus(){} @@ -32,7 +48,7 @@ public class JobAuditStatus extends VidBaseEntity { public JobAuditStatus(UUID jobId, String jobStatus, SourceStatus source, UUID requestId, String additionalInfo) { this(jobId, jobStatus, source); this.requestId = requestId; - this.additionalInfo = additionalInfo; + setAdditionalInfo(additionalInfo); } public JobAuditStatus(UUID jobId, String jobStatus, SourceStatus source, UUID requestId, String additionalInfo, Date date){ @@ -40,6 +56,37 @@ public class JobAuditStatus extends VidBaseEntity { this.created = date; } + public JobAuditStatus(String instanceName, String jobStatus, UUID requestId, String additionalInfo) { + this.instanceName = instanceName; + this.jobStatus = jobStatus; + this.requestId = requestId; + this.additionalInfo = additionalInfo; + + } + + public JobAuditStatus(String instanceName, String jobStatus, UUID requestId, String additionalInfo, String date, String instanceType) { + this(instanceName, jobStatus, requestId, additionalInfo); + this.created = dateStringToDate(date); + this.instanceType = instanceType; + } + + + private Date dateStringToDate(String dateAsString){ + if (StringUtils.isEmpty(dateAsString)) { + return null; + } + + DateFormat format = new SimpleDateFormat(defaultFormat); + format.setTimeZone(TimeZone.getTimeZone("GMT")); + Date date = null ; + try { + date = format.parse(dateAsString); + } catch (ParseException e) { + logger.error("There was an error to parse the string "+ dateAsString +" to date ", e.getMessage()); + } + return date; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -74,6 +121,8 @@ public class JobAuditStatus extends VidBaseEntity { } private UUID jobId; + private String instanceName; + private String instanceType; private String jobStatus; private SourceStatus source; private UUID requestId; @@ -128,13 +177,31 @@ public class JobAuditStatus extends VidBaseEntity { this.requestId = requestId; } - @Column(name = "ADDITIONAL_INFO") + @Column(name = "ADDITIONAL_INFO", columnDefinition = "VARCHAR(2000)") public String getAdditionalInfo() { return additionalInfo; } public void setAdditionalInfo(String additionalInfo) { - this.additionalInfo = additionalInfo; + this.additionalInfo = StringUtils.substring(additionalInfo, 0, MAX_ADDITIONAL_INFO_LENGTH); + } + + @Transient + public String getInstanceName() { + return instanceName; + } + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + @Transient + public String getInstanceType() { + return instanceType; + } + + public void setInstanceType(String instanceType) { + this.instanceType = instanceType; } @Transient diff --git a/vid-app-common/src/main/java/org/onap/vid/model/MinimalNode.kt b/vid-app-common/src/main/java/org/onap/vid/model/MinimalNode.kt new file mode 100644 index 000000000..1b44e6523 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/MinimalNode.kt @@ -0,0 +1,8 @@ +package org.onap.vid.model + +interface MinimalNode { + val invariantUuid: String + val uuid: String + val version: String + val name: String +} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ModelConstants.java b/vid-app-common/src/main/java/org/onap/vid/model/ModelConstants.java index 9ceeb807e..4ee473d1b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/ModelConstants.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/ModelConstants.java @@ -25,20 +25,20 @@ package org.onap.vid.model; public class ModelConstants { /** The Constant GET_INPUT_TAG. */ - public final static String GET_INPUT_TAG = "get_input"; + public static final String GET_INPUT_TAG = "get_input"; public static final String ASDC_MODEL_NAMESPACE = "asdc.model.namespace"; public static final String ASDC_SVC_API_PATH = "sdc.svc.api.path"; public static final String ASDC_RESOURCE_API_PATH = "sdc.resource.api.path"; - public static final String DEFAULT_ASDC_MODEL_NAMESPACE = "org.onap."; + public static final String DEFAULT_ASDC_MODEL_NAMESPACE = "org.openecomp."; public static final String DEFAULT_ASDC_SVC_API_PATH = "sdc/v1/catalog/services"; public static final String DEFAULT_ASDC_RESOURCE_API_PATH = "sdc/v1/catalog/resources"; - public final static String VF_MODULE = "groups.VfModule"; - public final static String VNF = "resource.vf"; - public final static String NETWORK = "resource.vl"; + public static final String VF_MODULE = "groups.VfModule"; + public static final String VNF = "resource.vf"; + public static final String NETWORK = "resource.vl"; - public final static String ROLE_DELIMITER = "___"; + public static final String ROLE_DELIMITER = "___"; } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/NameCounter.java b/vid-app-common/src/main/java/org/onap/vid/model/NameCounter.java index aae39e440..29f5e30a0 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/NameCounter.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/NameCounter.java @@ -18,7 +18,7 @@ public class NameCounter { public NameCounter(String name) { this.name = name; - this.counter = 1; + this.counter = 0; } @Id diff --git a/vid-app-common/src/main/java/org/onap/vid/model/NewNetwork.java b/vid-app-common/src/main/java/org/onap/vid/model/NewNetwork.java index 9f1ffd356..8e130a58c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/NewNetwork.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/NewNetwork.java @@ -20,8 +20,6 @@ package org.onap.vid.model; -import org.onap.vid.asdc.beans.tosca.NodeTemplate; - /** * The Class Network. */ diff --git a/vid-app-common/src/main/java/org/onap/vid/model/NewNode.java b/vid-app-common/src/main/java/org/onap/vid/model/NewNode.java index 394f7b96c..6a185555b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/NewNode.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/NewNode.java @@ -1,22 +1,12 @@ package org.onap.vid.model; -import java.text.DateFormat; -import java.text.SimpleDateFormat; +import org.onap.vid.asdc.beans.tosca.Input; + import java.util.HashMap; import java.util.Map; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.asdc.beans.tosca.Input; - public class NewNode { - - /** The Constant LOG. */ - private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(Node.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - /** The uuid. */ private String uuid; @@ -47,8 +37,8 @@ public class NewNode { * Instantiates a new node. */ public NewNode() { - this.commands = new HashMap(); - this.properties = new HashMap(); + this.commands = new HashMap<>(); + this.properties = new HashMap<>(); } /** diff --git a/vid-app-common/src/main/java/org/onap/vid/model/NewServiceModel.java b/vid-app-common/src/main/java/org/onap/vid/model/NewServiceModel.java index e55ba4a4e..1cc6a02f1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/NewServiceModel.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/NewServiceModel.java @@ -20,27 +20,18 @@ package org.onap.vid.model; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - import org.onap.vid.asdc.beans.tosca.Group; import org.onap.vid.asdc.beans.tosca.ToscaModel; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.properties.VidProperties; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; /** * The Class ServiceModel. */ public class NewServiceModel { - - /** The Constant LOG. */ - private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(NewServiceModel.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); /** The service. */ private Service service; @@ -63,12 +54,15 @@ public class NewServiceModel { private Map configurations; + private Map fabricConfigurations; + private Map serviceProxies; private Map pnfs; private Map collectionResource; + private Map vnfGroups; /** * Instantiates a new service model. @@ -189,6 +183,14 @@ public class NewServiceModel { this.collectionResource = collectionResource; } + public Map getFabricConfigurations() { + return fabricConfigurations; + } + + public void setFabricConfigurations(Map fabricConfigurations) { + this.fabricConfigurations = fabricConfigurations; + } + /** * Extract service. * @@ -211,15 +213,14 @@ public class NewServiceModel { //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME //service.setVersion(serviceToscaModel.getMetadata().getVersion()); service.setVersion(asdcServiceMetadata.getVersion()); - return service; } public static void extractGroups (ToscaModel serviceToscaModel,NewServiceModel serviceModel) { // Get the groups. The groups may duplicate the groups that are in the VNF model and have // additional data like the VF module customization String> - final Map vfModules = new HashMap (); - final Map volumeGroups = new HashMap (); + final Map vfModules = new HashMap<> (); + final Map volumeGroups = new HashMap<> (); String asdcModelNamespace = VidProperties.getAsdcModelNamespace(); String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE; @@ -243,57 +244,15 @@ public class NewServiceModel { serviceModel.setVolumeGroups (volumeGroups); } + + public Map getVnfGroups() { + return vnfGroups; + } + + public void setVnfGroups(Map vnfGroups) { + this.vnfGroups = vnfGroups; + } /** * Populate the vf modules and volume groups that we may have under the service level under each VNF. */ -// public void associateGroups() { -// String methodName = "associateGroups()"; -// LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); -// // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts -// // with vnf + ".." -// String vnfCustomizationName = null; -// String normalizedVnfCustomizationName = null; -// String vfModuleCustomizationName = null; -// NewVNF tmpVnf = null; -// -// if ( ( getVnfs() != null ) && (!(getVnfs().isEmpty())) ) { -// for (Entry vnfComponent : getVnfs().entrySet()) { -// vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName(); -// normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName); -// -// LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + -// " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName); -// -// // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName -// -// if (( getVfModules() != null ) && (!(getVfModules().isEmpty()))) { -// for (Entry vfModuleComponent : getVfModules().entrySet()) { -// vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName(); -// -// LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + -// " VF Module customizationName=" + vfModuleCustomizationName ); -// if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) { -// -// // this vf module belongs to the VNF -// tmpVnf = vnfComponent.getValue(); -// (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue()); -// -// LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + -// " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName); -// -// // now find if this vf module has volume groups, if so, find the volume group with the same customization name and put it under the VNF -// if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) { -// if (( getVolumeGroups() != null ) && (!(getVolumeGroups().isEmpty()))) { -// if (getVolumeGroups().containsKey((vfModuleCustomizationName))) { -// (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName)); -// } -// } -// } -// } -// } -// } -// } -// } - -// } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/NewVNF.java b/vid-app-common/src/main/java/org/onap/vid/model/NewVNF.java index dba6bdc5d..1b977a944 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/NewVNF.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/NewVNF.java @@ -1,33 +1,22 @@ package org.onap.vid.model; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.asdc.beans.tosca.NodeTemplate; - public class NewVNF extends NewNode { - - /** The Constant LOG. */ - private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VNF.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); /** The pattern used to normalize VNF names */ - final static Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+"); + static final Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+"); /** The model customization name. */ private String modelCustomizationName; /** The vf modules. */ - private Map vfModules = new HashMap(); + private Map vfModules = new HashMap<>(); /** The volume groups. */ - private Map volumeGroups = new HashMap(); + private Map volumeGroups = new HashMap<>(); /** * Instantiates a newvnf. @@ -96,28 +85,6 @@ public class NewVNF extends NewNode { * @return the normalized name */ public static String normalizeName (String originalName) { - - String normalizedName = originalName.toLowerCase(); - normalizedName = COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" "); - String[] splitArr = null; - - try { - splitArr = normalizedName.split(" "); - } - catch (Exception ex ) { - return (normalizedName); - } - StringBuffer sb = new StringBuffer(); - if ( splitArr != null ) { - for (String splitElement : splitArr) { - sb.append(splitElement); - } - return (sb.toString()); - } - else { - return (normalizedName); - } - + return VNF.normalizeName(originalName); } - } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/Node.java b/vid-app-common/src/main/java/org/onap/vid/model/Node.java index 3b7abd39b..64e4cc0b8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/Node.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/Node.java @@ -20,51 +20,44 @@ package org.onap.vid.model; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.asdc.beans.tosca.Input; import org.onap.vid.asdc.beans.tosca.NodeTemplate; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; /** * The Class Node. */ -public class Node { +public class Node implements MinimalNode { /** The Constant LOG. */ private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(Node.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); /** The uuid. */ private String uuid; - + /** The invariant uuid. */ private String invariantUuid; - + /** The description. */ private String description; - + /** The name. */ private String name; - + /** The version. */ private String version; - + /** The model customization uuid. */ private String customizationUuid; - + /** The inputs. */ private Map inputs = new HashMap<>(); - + /** The get_input or other constructs from node template properties. */ private Map commands; - + /** The get_input or other constructs from node template properties. */ private Map properties; @@ -74,8 +67,8 @@ public class Node { * Instantiates a new node. */ public Node() { - this.commands = new HashMap(); - this.properties = new HashMap(); + this.commands = new HashMap<>(); + this.properties = new HashMap<>(); } /** @@ -253,7 +246,6 @@ public class Node { /** * Extract node. * - * @param modelCustomizationName the model customization name * @param nodeTemplate the node template * @return the node */ @@ -272,14 +264,14 @@ public class Node { try { // nodeTemplate.getProperties() map of String->Object for (Entry entrySet : nodeTemplate.getProperties().entrySet()) { - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " node template property: " + entrySet.getKey()); + LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " node template property: " + entrySet.getKey()); if ( entrySet.getValue() != null ) { readStringAndCommandsProperties(entrySet); } } } catch ( Exception e ) { - LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse node properties: e=" + + LOG.error(EELFLoggerDelegate.errorLogger, methodName + " Unable to parse node properties: e=" + e.toString()); } } @@ -287,7 +279,7 @@ public class Node { private void readStringAndCommandsProperties(Entry entrySet) { String key = entrySet.getKey(); String methodName = "readStringAndCommandsProperties"; - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " property: " + + LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " property: " + key + "=" + entrySet.getValue()); Class c = entrySet.getValue().getClass(); if ( c.getName().equalsIgnoreCase(String.class.getName())) { diff --git a/vid-app-common/src/main/java/org/onap/vid/model/PortMirroringConfig.java b/vid-app-common/src/main/java/org/onap/vid/model/PortMirroringConfig.java index 393c34259..6dc11ec63 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/PortMirroringConfig.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/PortMirroringConfig.java @@ -1,22 +1,12 @@ package org.onap.vid.model; import com.fasterxml.jackson.annotation.JsonIgnore; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.RequirementAssignments; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.List; public class PortMirroringConfig extends Node { - /** The Constant LOG. */ - private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(PortMirroringConfig.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - /** The model customization name. */ private String modelCustomizationName; diff --git a/vid-app-common/src/main/java/org/onap/vid/model/RequestReferencesContainer.java b/vid-app-common/src/main/java/org/onap/vid/model/RequestReferencesContainer.java index 9c12a52a6..c40dffec8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/RequestReferencesContainer.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/RequestReferencesContainer.java @@ -2,7 +2,7 @@ package org.onap.vid.model; import com.fasterxml.jackson.annotation.*; import com.google.common.base.MoreObjects; -import org.onap.vid.domain.mso.RequestReferences; +import org.onap.vid.mso.model.RequestReferences; import java.util.HashMap; import java.util.Map; @@ -12,7 +12,7 @@ public class RequestReferencesContainer { private final RequestReferences requestReferences; @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); @JsonAnyGetter public Map getAdditionalProperties() { diff --git a/vid-app-common/src/main/java/org/onap/vid/model/Resource.java b/vid-app-common/src/main/java/org/onap/vid/model/Resource.java deleted file mode 100644 index 184f9ee6e..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/model/Resource.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.model; - -/** - * The Class Resource. - */ -public class Resource { - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ResourceGroup.kt b/vid-app-common/src/main/java/org/onap/vid/model/ResourceGroup.kt new file mode 100644 index 000000000..67a766e21 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/ResourceGroup.kt @@ -0,0 +1,13 @@ +package org.onap.vid.model + +data class ResourceGroup ( + + val type: String, + override val invariantUuid: String, + override val uuid: String, + override val version: String, + override val name: String, + val modelCustomizationName: String, + val properties: Map, + val members: Map +) : MinimalNode diff --git a/vid-app-common/src/main/java/org/onap/vid/model/Service.java b/vid-app-common/src/main/java/org/onap/vid/model/Service.java index d00f58f04..27a52e6fb 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/Service.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/Service.java @@ -20,6 +20,7 @@ package org.onap.vid.model; +import com.fasterxml.jackson.annotation.JsonInclude; import org.onap.vid.asdc.beans.tosca.Input; import java.util.Map; @@ -65,7 +66,9 @@ public class Service { /** The inputs. */ private Map inputs; - + + private VidNotions vidNotions; + /** * Gets the uuid. * @@ -265,4 +268,13 @@ public class Service { public void setServiceRole(String serviceRole) { this.serviceRole = serviceRole; } + + @JsonInclude(JsonInclude.Include.NON_NULL) + public VidNotions getVidNotions() { + return vidNotions; + } + + public void setVidNotions(VidNotions vidNotions) { + this.vidNotions = vidNotions; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java index 4f04adf51..7f10f8a14 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/ServiceInfo.java @@ -1,9 +1,12 @@ package org.onap.vid.model; + import com.fasterxml.jackson.annotation.JsonProperty; + import org.hibernate.annotations.DynamicUpdate; + import org.hibernate.annotations.SelectBeforeUpdate; import org.hibernate.annotations.Type; - import org.onap.vid.job.Job; import org.onap.portalsdk.core.domain.support.DomainVo; + import org.onap.vid.job.Job; import javax.persistence.*; import java.io.Serializable; @@ -12,10 +15,23 @@ import java.util.Set; import java.util.UUID; +/* + The following 2 annotations let hibernate to update only fields that actually have been changed. + DynamicUpdate tell hibernate to update only dirty fields. + SelectBeforeUpdate is needed since during update the entity is detached (get and update are in different sessions) +*/ +@DynamicUpdate() +@SelectBeforeUpdate() @Entity @Table(name = "vid_service_info") public class ServiceInfo extends DomainVo { + public enum ServiceAction { + INSTANTIATE, + DELETE, + UPDATE + } + public void setUserId(String userId) { this.userId = userId; } @@ -23,6 +39,8 @@ public class ServiceInfo extends DomainVo { private UUID jobId; private UUID templateId; private String userId; + private UUID msoRequestId; + private boolean aLaCarte; private Job.JobStatus jobStatus; private Date statusModifiedDate; private boolean hidden; @@ -39,19 +57,22 @@ public class ServiceInfo extends DomainVo { private String regionName; private String serviceType; private String subscriberName; + private String subscriberId; private String serviceInstanceId; private String serviceInstanceName; private String serviceModelId; private String serviceModelName; private String serviceModelVersion; private Date createdBulkDate; + private ServiceAction action; public ServiceInfo(){ } - public ServiceInfo(String userId, Job.JobStatus jobStatus, boolean pause, UUID jobId, UUID templateId, String owningEntityId, String owningEntityName, String project, String aicZoneId, String aicZoneName, String tenantId, String tenantName, String regionId, String regionName, String serviceType, String subscriberName, String serviceInstanceId, String serviceInstanceName, String serviceModelId, String serviceModelName, String serviceModelVersion, Date createdBulkDate) { + public ServiceInfo(String userId, Boolean aLaCarte, Job.JobStatus jobStatus, boolean pause, UUID jobId, UUID templateId, String owningEntityId, String owningEntityName, String project, String aicZoneId, String aicZoneName, String tenantId, String tenantName, String regionId, String regionName, String serviceType, String subscriberName, String subscriberId, String serviceInstanceId, String serviceInstanceName, String serviceModelId, String serviceModelName, String serviceModelVersion, Date createdBulkDate, ServiceAction action) { this.userId = userId; + this.aLaCarte = aLaCarte; this.jobStatus = jobStatus; this.jobId = jobId; this.templateId = templateId; @@ -67,12 +88,14 @@ public class ServiceInfo extends DomainVo { this.regionName = regionName; this.serviceType = serviceType; this.subscriberName = subscriberName; + this.subscriberId = subscriberId; this.serviceInstanceId = serviceInstanceId; this.serviceInstanceName = serviceInstanceName; this.serviceModelId = serviceModelId; this.serviceModelName = serviceModelName; this.serviceModelVersion = serviceModelVersion; this.createdBulkDate = createdBulkDate; + this.action = action; } @Column(name = "JOB_ID", columnDefinition = "CHAR(36)") @@ -92,6 +115,18 @@ public class ServiceInfo extends DomainVo { return userId; } + @Column(name = "MSO_REQUEST_ID", columnDefinition = "CHAR(36)") + @Type(type="org.hibernate.type.UUIDCharType") + public UUID getMsoRequestId() { + return msoRequestId; + } + + @Column(name="IS_A_LA_CARTE") + @JsonProperty("aLaCarte") + public boolean isALaCarte() { + return aLaCarte; + } + @Column(name="JOB_STATUS") @Enumerated(EnumType.STRING) public Job.JobStatus getJobStatus() { @@ -168,6 +203,11 @@ public class ServiceInfo extends DomainVo { return subscriberName; } + @Column(name="SUBSCRIBER_ID") + public String getSubscriberId() { + return subscriberId; + } + @Column(name="SERVICE_INSTANCE_ID") public String getServiceInstanceId() { return serviceInstanceId; @@ -203,6 +243,12 @@ public class ServiceInfo extends DomainVo { return deletedAt; } + @Column(name="ACTION") + @Enumerated(EnumType.STRING) + public ServiceAction getAction() { + return action; + } + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Override @@ -261,6 +307,14 @@ public class ServiceInfo extends DomainVo { this.templateId = templateId; } + public void setMsoRequestId(UUID requestId) { + this.msoRequestId = requestId; + } + + public void setALaCarte(boolean aLaCarte) { + this.aLaCarte = aLaCarte; + } + public void setJobStatus(Job.JobStatus jobStatus) { this.jobStatus = jobStatus; } @@ -321,6 +375,10 @@ public class ServiceInfo extends DomainVo { this.subscriberName = subscriberName; } + public void setSubscriberId(String subscriberId) { + this.subscriberId = subscriberId; + } + public void setServiceInstanceId(String serviceInstanceId) { this.serviceInstanceId = serviceInstanceId; } @@ -349,6 +407,7 @@ public class ServiceInfo extends DomainVo { this.deletedAt = deletedAt; } + public void setAction(ServiceAction action) { this.action = action; } @Override public boolean equals(Object o) { @@ -357,10 +416,12 @@ public class ServiceInfo extends DomainVo { ServiceInfo that = (ServiceInfo) o; return isHidden() == that.isHidden() && isPause() == that.isPause() && + isALaCarte() == that.isALaCarte() && Objects.equals(getDeletedAt(), that.getDeletedAt()) && Objects.equals(getJobId(), that.getJobId()) && Objects.equals(getTemplateId(), that.getTemplateId()) && Objects.equals(getUserId(), that.getUserId()) && + Objects.equals(getMsoRequestId(), that.getMsoRequestId()) && getJobStatus() == that.getJobStatus() && Objects.equals(getStatusModifiedDate(), that.getStatusModifiedDate()) && Objects.equals(getOwningEntityId(), that.getOwningEntityId()) && @@ -374,22 +435,24 @@ public class ServiceInfo extends DomainVo { Objects.equals(getRegionName(), that.getRegionName()) && Objects.equals(getServiceType(), that.getServiceType()) && Objects.equals(getSubscriberName(), that.getSubscriberName()) && + Objects.equals(getSubscriberId(), that.getSubscriberId()) && Objects.equals(getServiceInstanceId(), that.getServiceInstanceId()) && Objects.equals(getServiceInstanceName(), that.getServiceInstanceName()) && Objects.equals(getServiceModelId(), that.getServiceModelId()) && Objects.equals(getServiceModelName(), that.getServiceModelName()) && Objects.equals(getServiceModelVersion(), that.getServiceModelVersion()) && - Objects.equals(getCreatedBulkDate(), that.getCreatedBulkDate()); + Objects.equals(getCreatedBulkDate(), that.getCreatedBulkDate()) && + Objects.equals(getAction(), that.getAction()); } @Override public int hashCode() { - return Objects.hash(getJobId(), getTemplateId(), getUserId(), getJobStatus(), getStatusModifiedDate(), + return Objects.hash(getJobId(), getTemplateId(), getUserId(), getMsoRequestId(), isALaCarte(), getJobStatus(), getStatusModifiedDate(), isHidden(), isPause(), getDeletedAt(), getOwningEntityId(), getOwningEntityName(), getProject(), getAicZoneId(), getAicZoneName(), getTenantId(), getTenantName(), getRegionId(), - getRegionName(), getServiceType(), getSubscriberName(), getServiceInstanceId(), + getRegionName(), getServiceType(), getSubscriberName(), getSubscriberId(), getServiceInstanceId(), getServiceInstanceName(), getServiceModelId(), getServiceModelName(), - getServiceModelVersion(), getCreatedBulkDate()); + getServiceModelVersion(), getCreatedBulkDate(), getAction()); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java b/vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java index 53eb18c64..d82bd55aa 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java @@ -21,14 +21,11 @@ package org.onap.vid.model; import org.apache.commons.collections.MapUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.asdc.beans.tosca.Group; import org.onap.vid.asdc.beans.tosca.ToscaModel; import org.onap.vid.properties.VidProperties; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -40,9 +37,7 @@ public class ServiceModel { /** The Constant LOG. */ private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ServiceModel.class); - - /** The Constant dateFormat. */ - static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + /** The service. */ private Service service; @@ -54,10 +49,12 @@ public class ServiceModel { private Map collectionResource; - /** Port Mirroring Configuration node templates */ private Map configurations; + /** Fabric Configuration node templates */ + private Map fabricConfigurations; + /** Service Proxy Nodes */ private Map serviceProxies; @@ -74,6 +71,10 @@ public class ServiceModel { /** The pnfs. */ private Map pnfs; + + /** Resource groups of VF (VNF) type. */ + private Map vnfGroups; + /** * Instantiates a new service model. */ @@ -135,6 +136,10 @@ public class ServiceModel { return serviceProxies; } + public Map getVnfGroups() { + return vnfGroups; + } + /** * Sets the service. * @@ -221,6 +226,10 @@ public class ServiceModel { */ public void setPnfs(Map pnfs) {this.pnfs = pnfs;} + public void setVnfGroups(Map vnfGroups) { + this.vnfGroups = vnfGroups; + } + public Map getCollectionResource() { return collectionResource; } @@ -229,6 +238,14 @@ public class ServiceModel { this.collectionResource = collectionResource; } + public Map getFabricConfigurations() { + return fabricConfigurations; + } + + public void setFabricConfigurations(Map fabricConfigurations) { + this.fabricConfigurations = fabricConfigurations; + } + /** * Extract service. * @@ -288,7 +305,7 @@ public class ServiceModel { */ public void associateGroups() { String methodName = "associateGroups()"; - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start"); + LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts // with vnf + ".." String vnfCustomizationName = null; @@ -300,7 +317,7 @@ public class ServiceModel { vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName(); normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName); - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + + LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName); // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName @@ -309,7 +326,7 @@ public class ServiceModel { for (Entry vfModuleComponent : getVfModules().entrySet()) { vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName(); - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + + LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " VF Module customizationName=" + vfModuleCustomizationName ); if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) { handleCustomizationName(methodName, vnfCustomizationName, vfModuleCustomizationName, vnfComponent, vfModuleComponent); @@ -328,7 +345,7 @@ public class ServiceModel { tmpVnf = vnfComponent.getValue(); (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue()); - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + + LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName); // now find if this vf module has volume groups, if so, find the volume group with the same customization name and put it under the VNF diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ServiceProxy.java b/vid-app-common/src/main/java/org/onap/vid/model/ServiceProxy.java index 628f56020..362031b60 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/ServiceProxy.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/ServiceProxy.java @@ -1,18 +1,7 @@ package org.onap.vid.model; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; - public class ServiceProxy extends Node { - /** The Constant LOG. */ - private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ServiceProxy.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - private String sourceModelUuid; private String sourceModelInvariant; diff --git a/vid-app-common/src/main/java/org/onap/vid/model/SoftDeleteRequest.java b/vid-app-common/src/main/java/org/onap/vid/model/SoftDeleteRequest.java new file mode 100644 index 000000000..51c246be0 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/SoftDeleteRequest.java @@ -0,0 +1,42 @@ +package org.onap.vid.model; + +public class SoftDeleteRequest { + + private String tenantId; + + private String lcpCloudRegionId; + + private String userId; + + public SoftDeleteRequest() {} + + public SoftDeleteRequest(String tenantId, String lcpCloudRegionId, String userId) { + this.tenantId = tenantId; + this.lcpCloudRegionId = lcpCloudRegionId; + this.userId = userId; + } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getLcpCloudRegionId() { + return lcpCloudRegionId; + } + + public void setLcpCloudRegionId(String lcpCloudRegionId) { + this.lcpCloudRegionId = lcpCloudRegionId; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/Subscriber.java b/vid-app-common/src/main/java/org/onap/vid/model/Subscriber.java index 70711b804..f2a491639 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/Subscriber.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/Subscriber.java @@ -1,7 +1,7 @@ package org.onap.vid.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by Oren on 7/4/17. diff --git a/vid-app-common/src/main/java/org/onap/vid/model/SubscriberList.java b/vid-app-common/src/main/java/org/onap/vid/model/SubscriberList.java index a08b585b5..8df9f81b3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/SubscriberList.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/SubscriberList.java @@ -1,7 +1,5 @@ package org.onap.vid.model; -import org.onap.portalsdk.core.web.support.UserUtils; - import java.util.List; /** diff --git a/vid-app-common/src/main/java/org/onap/vid/model/VNF.java b/vid-app-common/src/main/java/org/onap/vid/model/VNF.java index 9da88870c..76e43d280 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/VNF.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/VNF.java @@ -20,42 +20,27 @@ package org.onap.vid.model; -import java.util.Map; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; +import org.onap.vid.asdc.beans.tosca.NodeTemplate; + import java.util.HashMap; -import java.util.Map.Entry; +import java.util.Map; import java.util.regex.Pattern; -import org.onap.vid.asdc.beans.tosca.NodeTemplate; -import org.onap.vid.controllers.VidController; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.asdc.beans.tosca.Group; -import org.onap.vid.asdc.beans.tosca.Input; - /** * The Class VNF. */ public class VNF extends Node { - - /** The Constant LOG. */ - private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VNF.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - /** The pattern used to normalize VNF names */ - final static Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+"); + static final Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+"); /** The model customization name. */ private String modelCustomizationName; /** The vf modules. */ - private Map vfModules = new HashMap(); + private Map vfModules = new HashMap<>(); /** The volume groups. */ - private Map volumeGroups = new HashMap(); + private Map volumeGroups = new HashMap<>(); private Map vfcInstanceGroups = new HashMap<>(); @@ -160,7 +145,7 @@ public class VNF extends Node { catch (Exception ex ) { return (normalizedName); } - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if ( splitArr != null ) { for (String splitElement : splitArr) { sb.append(splitElement); diff --git a/vid-app-common/src/main/java/org/onap/vid/model/VfModule.java b/vid-app-common/src/main/java/org/onap/vid/model/VfModule.java index ea30571a0..a0ea060f6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/VfModule.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/VfModule.java @@ -20,12 +20,8 @@ package org.onap.vid.model; -import org.onap.vid.asdc.beans.tosca.Group; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; +import org.onap.vid.asdc.beans.tosca.Group; /** * The Class VfModule. @@ -34,9 +30,7 @@ public class VfModule extends org.onap.vid.model.Group { /** The Constant LOG. */ private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VfModule.class); - - /** The Constant dateFormat. */ - static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + public static final String VOLUME_GROUP = "volume_group"; /** The volume group allowed. */ @@ -88,7 +82,7 @@ public class VfModule extends org.onap.vid.model.Group { if (group.getProperties().get(VOLUME_GROUP) != null) { Class c = group.getProperties().get(VOLUME_GROUP).getClass(); - LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " class name=" + + LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " class name=" + c.getName()); if ( c.getName().equalsIgnoreCase(Boolean.class.getName()) ) { @@ -101,7 +95,7 @@ public class VfModule extends org.onap.vid.model.Group { } } catch ( Exception e ) { - LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module from group: e=" + + LOG.error(EELFLoggerDelegate.errorLogger, methodName + " Unable to parse VF Module from group: e=" + e.toString()); } return vfModule; diff --git a/vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt b/vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt new file mode 100644 index 000000000..b49af085d --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/VidNotions.kt @@ -0,0 +1,34 @@ +package org.onap.vid.model + +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.JsonValue +import com.google.common.base.CaseFormat + +class VidNotions(@get:JsonInclude(JsonInclude.Include.NON_NULL) + val instantiationUI: InstantiationUI, val modelCategory: ModelCategory, val viewEditUI: InstantiationUI) { + enum class InstantiationUI { + NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS, + SERVICE_WITH_FABRIC_CONFIGURATION, + LEGACY, + SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de, + ANY_ALACARTE_NEW_UI, + MACRO_SERVICE, + SERVICE_WITH_VNF_GROUPING; + + @JsonValue + fun toLowerCamel(): String { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, this.name) + } + + } + + enum class ModelCategory { + @JsonProperty("5G Provider Network") + IS_5G_PROVIDER_NETWORK_MODEL, + @JsonProperty("5G Fabric Configuration") + IS_5G_FABRIC_CONFIGURATION_MODEL, + @JsonProperty("other") + OTHER + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/AAITreeNode.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/AAITreeNode.java new file mode 100644 index 000000000..e6f822969 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/AAITreeNode.java @@ -0,0 +1,178 @@ +package org.onap.vid.model.aaiTree; + +import org.apache.commons.lang3.StringUtils; + +import java.util.*; + +public class AAITreeNode { + + private String type; + private int uniqueNumber; + private String orchestrationStatus; + private String provStatus; + private Boolean inMaint = null; + private String modelVersionId; + private String modelCustomizationId; + private String modelInvariantId; + private String id; + private String name; + private String modelVersion; + private String modelName; + private String modelCustomizationName; + private final List children = Collections.synchronizedList(new LinkedList<>()); + private Map additionalProperties = new HashMap<>(); + private String keyInModel; + private AAITreeNode parent; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public int getUniqueNumber() { + return uniqueNumber; + } + + public void setUniqueNumber(int uniqueNumber) { + this.uniqueNumber = uniqueNumber; + } + + public String getOrchestrationStatus() { + return orchestrationStatus; + } + + public void setOrchestrationStatus(String orchestrationStatus) { + this.orchestrationStatus = orchestrationStatus; + } + + public String getProvStatus() { + return provStatus; + } + + public void setProvStatus(String provStatus) { + this.provStatus = provStatus; + } + + public Boolean getInMaint() { + return inMaint; + } + + public void setInMaint(Boolean inMaint) { + this.inMaint = inMaint; + } + + public String getModelVersionId() { + return modelVersionId; + } + + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + + public String getModelCustomizationId() { + return modelCustomizationId; + } + + public void setModelCustomizationId(String modelCustomizationId) { + this.modelCustomizationId = modelCustomizationId; + } + + public String getModelInvariantId() { + return modelInvariantId; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getModelVersion() { + return modelVersion; + } + + public void setModelVersion(String modelVersion) { + this.modelVersion = modelVersion; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getModelCustomizationName() { + return modelCustomizationName; + } + + public void setModelCustomizationName(String modelCustomizationName) { + this.modelCustomizationName = modelCustomizationName; + } + + public List getChildren() { + return children; + } + + public Map getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + } + + public String getNodeKey() { + if (this.keyInModel != null) { + return this.keyInModel; + } + + return StringUtils.defaultIfEmpty(this.modelVersionId, "not provided"); + } + + public String getUniqueNodeKey() { + return getNodeKey() + ":" + String.format("%03d", this.uniqueNumber); + } + + public void setKeyInModel(String keyInModel) { + this.keyInModel = keyInModel; + } + + public String getKeyInModel() { + return keyInModel; + } + + public AAITreeNode getParent() { + return parent; + } + + public void setParent(AAITreeNode parent) { + this.parent = parent; + } + + public void addChildren(List children) { + for (AAITreeNode child : children) { + child.setParent(this); + } + + this.getChildren().addAll(children); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/AbstractNode.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/AbstractNode.java new file mode 100644 index 000000000..86669e92f --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/AbstractNode.java @@ -0,0 +1,53 @@ +package org.onap.vid.model.aaiTree; + +import org.onap.vid.model.Action; +import org.onap.vid.mso.model.ModelInfo; + +public abstract class AbstractNode { + + protected final Action action; + protected String instanceName; + protected String instanceId; + protected String orchStatus; + protected String productFamilyId; + protected String lcpCloudRegionId; + protected String tenantId; + protected ModelInfo modelInfo; + + public AbstractNode() { + this.action = Action.None; + } + + public final Action getAction() { + return action; + } + + public final String getInstanceName() { + return instanceName; + } + + public final String getInstanceId() { + return instanceId; + } + + public final String getOrchStatus() { + return orchStatus; + } + + public final String getProductFamilyId() { + return productFamilyId; + } + + public final String getLcpCloudRegionId() { + return lcpCloudRegionId; + } + + public final String getTenantId() { + return tenantId; + } + + public final ModelInfo getModelInfo() { + return modelInfo; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/FailureAAITreeNode.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/FailureAAITreeNode.java new file mode 100644 index 000000000..e6234fca2 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/FailureAAITreeNode.java @@ -0,0 +1,31 @@ +package org.onap.vid.model.aaiTree; + +import org.apache.commons.proxy.Invoker; +import org.apache.commons.proxy.factory.javassist.JavassistProxyFactory; +import org.jetbrains.annotations.NotNull; +import org.onap.vid.exceptions.GenericUncheckedException; + +public class FailureAAITreeNode extends AAITreeNode { + + private static final Class[] classes = {AAITreeNode.class}; + private static final JavassistProxyFactory proxyFactory = new JavassistProxyFactory(); // can proxy a class without an interface + + private FailureAAITreeNode() { + // don't instantiate this class + } + + /* + Returns a new AAITreeNode instance that throws an exception when + invoking any of its methods + */ + public static AAITreeNode of(Exception failureException) { + return (AAITreeNode) proxyFactory.createInvokerProxy(exceptionThrower(failureException), classes); + } + + @NotNull + private static Invoker exceptionThrower(Exception exception) { + return (self, thisMethod, args) -> { + throw new GenericUncheckedException("AAI node fetching failed.", exception); + }; + } +} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Network.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Network.java new file mode 100644 index 000000000..959f741cd --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Network.java @@ -0,0 +1,20 @@ +package org.onap.vid.model.aaiTree; + +import org.onap.vid.aai.util.AAITreeConverter; + +import static org.onap.vid.aai.util.AAITreeConverter.NETWORK_TYPE; + +public class Network extends Node { + + public Network(AAITreeNode node) { + super(node, AAITreeConverter.ModelType.network); + } + + public static Network from(AAITreeNode node) { + Network network = new Network(node); + if (node.getAdditionalProperties().get(NETWORK_TYPE) != null) { + network.setInstanceType(node.getAdditionalProperties().get(NETWORK_TYPE).toString()); + } + return network; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Node.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Node.java new file mode 100644 index 000000000..6f0a4a05b --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Node.java @@ -0,0 +1,139 @@ +package org.onap.vid.model.aaiTree; + +import org.onap.vid.aai.util.AAITreeConverter; +import org.onap.vid.mso.model.ModelInfo; + +public class Node extends AbstractNode { + private String instanceType; + + private String provStatus; + private Boolean inMaint; + + private String uuid; + private String originalName; + + private String legacyRegion; + private String lineOfBusiness; + private String platformName; + + private final String trackById; + + public Node(AAITreeNode aaiNode, AAITreeConverter.ModelType modelType) { + super(); + this.instanceId = aaiNode.getId(); + this.instanceName = aaiNode.getName(); + this.orchStatus = aaiNode.getOrchestrationStatus(); + this.provStatus = aaiNode.getProvStatus(); + this.inMaint = aaiNode.getInMaint(); + this.uuid = aaiNode.getModelVersionId(); + this.originalName = aaiNode.getModelCustomizationName(); + this.trackById = aaiNode.getUniqueNodeKey(); + + ModelInfo nodeModelInfo = new ModelInfo(); + nodeModelInfo.setModelType(modelType.name()); + nodeModelInfo.setModelName(aaiNode.getModelName()); + nodeModelInfo.setModelVersion(aaiNode.getModelVersion()); + nodeModelInfo.setModelVersionId(aaiNode.getModelVersionId()); + nodeModelInfo.setModelInvariantId(aaiNode.getModelInvariantId()); + nodeModelInfo.setModelCustomizationId(aaiNode.getModelCustomizationId()); + nodeModelInfo.setModelCustomizationName(aaiNode.getModelCustomizationName()); + + this.modelInfo = nodeModelInfo; + } + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public String getInstanceType() { + return instanceType; + } + + public void setInstanceType(String instanceType) { + this.instanceType = instanceType; + } + + public void setOrchStatus(String orchStatus) { + this.orchStatus = orchStatus; + } + + public String getProvStatus() { + return provStatus; + } + + public void setProvStatus(String provStatus) { + this.provStatus = provStatus; + } + + public Boolean getInMaint() { + return inMaint; + } + + public void setInMaint(Boolean inMaint) { + this.inMaint = inMaint; + } + + public void setModelInfo(ModelInfo modelInfo) { + this.modelInfo = modelInfo; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getOriginalName() { + return originalName; + } + + public void setOriginalName(String originalName) { + this.originalName = originalName; + } + + public void setProductFamilyId(String productFamilyId) { + this.productFamilyId = productFamilyId; + } + + public void setLcpCloudRegionId(String lcpCloudRegionId) { + this.lcpCloudRegionId = lcpCloudRegionId; + } + + public String getLegacyRegion() { + return legacyRegion; + } + + public void setLegacyRegion(String legacyRegion) { + this.legacyRegion = legacyRegion; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getLineOfBusiness() { + return lineOfBusiness; + } + + public void setLineOfBusiness(String lineOfBusiness) { + this.lineOfBusiness = lineOfBusiness; + } + + public String getPlatformName() { + return platformName; + } + + public void setPlatformName(String platformName) { + this.platformName = platformName; + } + + public String getTrackById() { + return trackById; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/RelatedVnf.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/RelatedVnf.java new file mode 100644 index 000000000..043d2ccd9 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/RelatedVnf.java @@ -0,0 +1,52 @@ +package org.onap.vid.model.aaiTree; + +import org.onap.vid.aai.util.AAITreeConverter; + +import static org.onap.vid.aai.util.AAITreeConverter.VNF_TYPE; + +public class RelatedVnf extends Node { + + private String serviceInstanceId; + private String serviceInstanceName; + private String tenantName; + + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public void setServiceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } + + public String getServiceInstanceName() { + return serviceInstanceName; + } + + public void setServiceInstanceName(String serviceInstanceName) { + this.serviceInstanceName = serviceInstanceName; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public RelatedVnf(AAITreeNode node) { + super(node, AAITreeConverter.ModelType.vnf); + } + + public static RelatedVnf from(AAITreeNode node) { + RelatedVnf vnf = new RelatedVnf(node); + vnf.setServiceInstanceId(node.getParent().getId()); + vnf.setServiceInstanceName(node.getParent().getName()); + + if (node.getAdditionalProperties().get(VNF_TYPE) != null) { + vnf.setInstanceType(node.getAdditionalProperties().get(VNF_TYPE).toString()); + } + + return vnf; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java new file mode 100644 index 000000000..6c6600774 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/ServiceInstance.java @@ -0,0 +1,193 @@ +package org.onap.vid.model.aaiTree; + +import org.onap.vid.mso.model.ModelInfo; + +import java.util.HashMap; +import java.util.Map; + +public class ServiceInstance extends AbstractNode { + + private String globalSubscriberId; + private String subscriptionServiceType; + + private String owningEntityId; + + private String owningEntityName; + private String tenantName; + private String aicZoneId; + private String aicZoneName; + private String projectName; + + private String rollbackOnFailure; + private boolean isALaCarte; + + private Map vnfs = new HashMap<>(); + private Map networks = new HashMap<>(); + + private Map vnfGroups = new HashMap<>(); + + private int validationCounter; + private Map existingVNFCounterMap; + private Map existingNetworksCounterMap; + private Map existingVnfGroupCounterMap; + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + public void setOrchStatus(String orchStatus) { + this.orchStatus = orchStatus; + } + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + public String getOwningEntityId() { + return owningEntityId; + } + + public void setOwningEntityId(String owningEntityId) { + this.owningEntityId = owningEntityId; + } + + public String getOwningEntityName() { + return owningEntityName; + } + + public void setOwningEntityName(String owningEntityName) { + this.owningEntityName = owningEntityName; + } + + public void setProductFamilyId(String productFamilyId) { + this.productFamilyId = productFamilyId; + } + + public void setLcpCloudRegionId(String lcpCloudRegionId) { + this.lcpCloudRegionId = lcpCloudRegionId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public String getAicZoneId() { + return aicZoneId; + } + + public void setAicZoneId(String aicZoneId) { + this.aicZoneId = aicZoneId; + } + + public String getAicZoneName() { + return aicZoneName; + } + + public void setAicZoneName(String aicZoneName) { + this.aicZoneName = aicZoneName; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getRollbackOnFailure() { + return rollbackOnFailure; + } + + public void setRollbackOnFailure(String rollbackOnFailure) { + this.rollbackOnFailure = rollbackOnFailure; + } + + public boolean getIsALaCarte() { + return isALaCarte; + } + + public void setIsALaCarte(boolean isALaCarte) { + this.isALaCarte = isALaCarte; + } + + public void setModelInfo(ModelInfo modelInfo) { + this.modelInfo = modelInfo; + } + + public Map getVnfs() { + return vnfs; + } + + public void setVnfs(Map vnfs) { + this.vnfs = vnfs; + } + + public Map getNetworks() { + return networks; + } + + public void setNetworks(Map networks) { + this.networks = networks; + } + + public Map getVnfGroups() { return vnfGroups; } + + public void setVnfGroups(Map vnfGroups) { this.vnfGroups = vnfGroups; } + + public int getValidationCounter() { + return validationCounter; + } + + public void setValidationCounter(int validationCounter) { + this.validationCounter = validationCounter; + } + + public Map getExistingVNFCounterMap() { + return existingVNFCounterMap; + } + + public void setExistingVNFCounterMap(Map existingVNFCounterMap) { + this.existingVNFCounterMap = existingVNFCounterMap; + } + + public Map getExistingNetworksCounterMap() { + return existingNetworksCounterMap; + } + + public void setExistingNetworksCounterMap(Map existingNetworksCounterMap) { + this.existingNetworksCounterMap = existingNetworksCounterMap; + } + + public Map getExistingVnfGroupCounterMap() { + return existingVnfGroupCounterMap; + } + + public void setExistingVnfGroupCounterMap(Map existingVnfGroupCounterMap) { + this.existingVnfGroupCounterMap = existingVnfGroupCounterMap; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/VfModule.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/VfModule.java new file mode 100644 index 000000000..14a43e797 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/VfModule.java @@ -0,0 +1,41 @@ +package org.onap.vid.model.aaiTree; + +import org.onap.vid.aai.util.AAITreeConverter; + +import static org.onap.vid.aai.util.AAITreeConverter.IS_BASE_VF_MODULE; + +public class VfModule extends Node { + + private boolean isBase; + private String volumeGroupName; + + public VfModule(AAITreeNode node) { + super(node, AAITreeConverter.ModelType.vfModule); + } + + public boolean getIsBase() { + return isBase; + } + + public void setIsBase(boolean isBase) { + this.isBase = isBase; + } + + public String getVolumeGroupName() { + return volumeGroupName; + } + + public void setVolumeGroupName(String volumeGroupName) { + this.volumeGroupName = volumeGroupName; + } + + public static VfModule from(AAITreeNode node) { + VfModule vfModule = new VfModule(node); + + if (node.getAdditionalProperties().get(IS_BASE_VF_MODULE) != null) { + vfModule.setIsBase(Boolean.valueOf(node.getAdditionalProperties().get(IS_BASE_VF_MODULE).toString())); + } + + return vfModule; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Vnf.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Vnf.java new file mode 100644 index 000000000..a3280f4e3 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/Vnf.java @@ -0,0 +1,54 @@ +package org.onap.vid.model.aaiTree; + +import org.onap.vid.aai.util.AAITreeConverter; +import org.onap.vid.services.AAITreeNodeBuilder; + +import java.util.HashMap; +import java.util.Map; + +import static org.onap.vid.aai.util.AAITreeConverter.VNF_TYPE; + +public class Vnf extends Node { + + private Map> vfModules = new HashMap<>(); + private Map networks = new HashMap<>(); + + public Vnf(AAITreeNode node) { + super(node, AAITreeConverter.ModelType.vnf); + } + + public Map> getVfModules() { + return vfModules; + } + + public void setVfModules(Map> vfModules) { + this.vfModules = vfModules; + } + + public Map getNetworks() { + return networks; + } + + public void setNetworks(Map networks) { + this.networks = networks; + } + + public static Vnf from(AAITreeNode node) { + Vnf vnf = new Vnf(node); + if (node.getAdditionalProperties().get(VNF_TYPE) != null) { + vnf.setInstanceType(node.getAdditionalProperties().get(VNF_TYPE).toString()); + } + + node.getChildren().forEach(child -> { + if (child.getType().equals(AAITreeNodeBuilder.VF_MODULE)) { + vnf.getVfModules().putIfAbsent(child.getNodeKey(), new HashMap<>()); + vnf.getVfModules().get(child.getNodeKey()) + .put(child.getUniqueNodeKey(), VfModule.from(child)); + } else if (child.getType().equals(AAITreeNodeBuilder.NETWORK)) { + vnf.getNetworks().put(child.getUniqueNodeKey(), Network.from(child)); + } + }); + + return vnf; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/VnfGroup.java b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/VnfGroup.java new file mode 100644 index 000000000..00e7ed8da --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/aaiTree/VnfGroup.java @@ -0,0 +1,52 @@ +package org.onap.vid.model.aaiTree; + +import org.onap.vid.aai.util.AAITreeConverter; + + +public class VnfGroup extends Node { + + public static final String INSTANCE_GROUP_TYPE = "instance-group-type"; + public static final String INSTANCE_GROUP_ROLE = "instance-group-role"; + public static final String INSTANCE_GROUP_FUNCTION = "instance-group-function"; + + private String instanceGroupRole; + private String instanceGroupFunction; + + + public VnfGroup(AAITreeNode node) { + super(node, AAITreeConverter.ModelType.instanceGroup); + } + + public static VnfGroup from(AAITreeNode node) { + VnfGroup vnfGroup = new VnfGroup(node); + if (node.getAdditionalProperties().get(INSTANCE_GROUP_TYPE) != null) { + vnfGroup.setInstanceType(node.getAdditionalProperties().get(INSTANCE_GROUP_TYPE).toString()); + } + if (node.getAdditionalProperties().get(INSTANCE_GROUP_FUNCTION) != null) { + vnfGroup.setInstanceGroupFunction(node.getAdditionalProperties().get(INSTANCE_GROUP_FUNCTION).toString()); + } + if (node.getAdditionalProperties().get(INSTANCE_GROUP_ROLE) != null) { + vnfGroup.setInstanceGroupRole(node.getAdditionalProperties().get(INSTANCE_GROUP_ROLE).toString()); + } + + return vnfGroup; + } + + public String getInstanceGroupRole() { + return instanceGroupRole; + } + + public void setInstanceGroupRole(String instanceGroupRole) { + this.instanceGroupRole = instanceGroupRole; + } + + public String getInstanceGroupFunction() { + return instanceGroupFunction; + } + + public void setInstanceGroupFunction(String instanceGroupFunction) { + this.instanceGroupFunction = instanceGroupFunction; + } + + +} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/model/probes/ExternalComponentStatus.java b/vid-app-common/src/main/java/org/onap/vid/model/probes/ExternalComponentStatus.java index da8c912e3..5f5a0def0 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/probes/ExternalComponentStatus.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/probes/ExternalComponentStatus.java @@ -1,7 +1,7 @@ package org.onap.vid.model.probes; public class ExternalComponentStatus { - public enum Component {AAI, MSO} + public enum Component {AAI, MSO, SDC, SCHEDULER} private final Component component; private final boolean available; private final StatusMetadata metadata; diff --git a/vid-app-common/src/main/java/org/onap/vid/model/probes/HttpRequestMetadata.java b/vid-app-common/src/main/java/org/onap/vid/model/probes/HttpRequestMetadata.java index e80d563bf..08bed397e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/probes/HttpRequestMetadata.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/probes/HttpRequestMetadata.java @@ -1,12 +1,20 @@ package org.onap.vid.model.probes; +import com.google.common.base.MoreObjects; +import org.apache.commons.lang3.StringUtils; +import org.onap.vid.aai.ExceptionWithRequestInfo; +import org.onap.vid.aai.ResponseWithRequestInfo; +import org.onap.vid.mso.RestObjectWithRequestInfo; +import org.onap.vid.utils.Logging; import org.springframework.http.HttpMethod; +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; + public class HttpRequestMetadata extends StatusMetadata { private final HttpMethod httpMethod; private final int httpCode; private final String url; - private final String rawData; + private String rawData = ""; public HttpRequestMetadata(HttpMethod httpMethod, int httpCode, String url, String rawData, String description, long duration) { super(description, duration); @@ -16,6 +24,43 @@ public class HttpRequestMetadata extends StatusMetadata { this.rawData = rawData; } + public HttpRequestMetadata(ResponseWithRequestInfo response, String description, long duration) { + this(response, description, duration, true); + } + + public HttpRequestMetadata(RestObjectWithRequestInfo response, String description, long duration) { + super(description, duration); + this.httpMethod = response.getHttpMethod(); + this.url = response.getRequestedUrl(); + this.httpCode = response.getHttpCode(); + this.rawData = response.getRawData(); + } + + public HttpRequestMetadata(ResponseWithRequestInfo response, String description, long duration, boolean readRawData) { + super(description, duration); + this.httpMethod = response.getRequestHttpMethod(); + this.url = response.getRequestUrl(); + this.httpCode = response.getResponse().getStatus(); + if (readRawData) { + try { + this.rawData = response.getResponse().readEntity(String.class); + } catch (Exception e) { + //Nothing to do here + } + } + } + + public HttpRequestMetadata(ExceptionWithRequestInfo exception, long duration) { + this(exception.getHttpMethod(), + defaultIfNull(exception.getHttpCode(), 0), + exception.getRequestedUrl(), + exception.getRawData(), + Logging.exceptionToDescription(exception.getCause()), + duration); + } + + + public HttpMethod getHttpMethod() { return httpMethod; } @@ -29,6 +74,18 @@ public class HttpRequestMetadata extends StatusMetadata { } public String getRawData() { - return rawData; + return StringUtils.substring(rawData, 0, 500); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("httpMethod", httpMethod) + .add("httpCode", httpCode) + .add("url", url) + .add("duration", duration) + .add("description", description) + .add("rawData", rawData) + .toString(); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/BaseResource.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/BaseResource.java new file mode 100644 index 000000000..653c73477 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/BaseResource.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.model.serviceInstantiation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang3.StringUtils; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.model.Action; +import org.onap.vid.mso.model.ModelInfo; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public abstract class BaseResource implements JobAdapter.AsyncJobRequest { + + protected final String instanceId; + protected ModelInfo modelInfo; + + protected String instanceName; + + protected final Action action; + + protected String lcpCloudRegionId; + + protected String tenantId; + + protected List> instanceParams; + + protected boolean rollbackOnFailure; + + private static final Map actionStingToEnumMap = ImmutableMap.of( + "Delete", Action.Delete, + "Create", Action.Create, + "None", Action.None, + "Update_Delete", Action.Delete, + "None_Delete", Action.Delete + ); + + + protected BaseResource(@JsonProperty("modelInfo") ModelInfo modelInfo, + @JsonProperty("instanceName") String instanceName, + @JsonProperty("action") String action, + @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId, + @JsonProperty("legacyRegion") String legacyRegion, + @JsonProperty("tenantId") String tenantId, + @JsonProperty("instanceParams") List> instanceParams, + @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure, + @JsonProperty("instanceId") String instanceId) { + this.modelInfo = modelInfo; + this.modelInfo.setModelType(getModelType()); + this.rollbackOnFailure = rollbackOnFailure; + this.instanceName = StringUtils.defaultString(instanceName, "");; + this.action = actionStringToEnum(action); + this.lcpCloudRegionId = StringUtils.isNotEmpty(legacyRegion) ? legacyRegion : lcpCloudRegionId; + this.tenantId = tenantId; + this.instanceParams = instanceParams; + this.instanceId = instanceId; + } + + private Action actionStringToEnum(String actionAsString) { + return actionStingToEnumMap.get(actionAsString); + } + + public ModelInfo getModelInfo() { + return modelInfo; + } + + public String getInstanceName() { + return instanceName; + } + + public Action getAction() { + return action; + } + + public String getLcpCloudRegionId() { + return lcpCloudRegionId; + } + + public String getTenantId() { + return tenantId; + } + + public List> getInstanceParams() { + return instanceParams == null ? Collections.emptyList() : instanceParams; + } + + public boolean isRollbackOnFailure() { return rollbackOnFailure; } + + public String getInstanceId() { + return instanceId; + } + + protected abstract String getModelType(); +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/InstanceGroup.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/InstanceGroup.java new file mode 100644 index 000000000..6155480c7 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/InstanceGroup.java @@ -0,0 +1,22 @@ +package org.onap.vid.model.serviceInstantiation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.mso.model.ModelInfo; + +public class InstanceGroup extends BaseResource implements JobAdapter.AsyncJobRequest { + + public InstanceGroup(@JsonProperty("modelInfo") ModelInfo modelInfo, + @JsonProperty("instanceName") String instanceName, + @JsonProperty("action") String action, + @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure, + @JsonProperty("instanceId") String instanceId) { + + super(modelInfo, instanceName, action, null, null, null, null, rollbackOnFailure, instanceId); + } + + @Override + protected String getModelType() { + return "instanceGroup"; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/Network.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/Network.java new file mode 100644 index 000000000..0e0c7e139 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/Network.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.model.serviceInstantiation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.mso.model.ModelInfo; + +import java.util.List; +import java.util.Map; + +public class Network extends BaseResource implements JobAdapter.AsyncJobRequest { + + private final String productFamilyId; + + private final String platformName; + + private final String lineOfBusiness; + + public Network(@JsonProperty("modelInfo") ModelInfo modelInfo, + @JsonProperty("productFamilyId") String productFamilyId, + @JsonProperty("instanceName") String instanceName, + @JsonProperty("action") String action, + @JsonProperty("platformName") String platformName, + @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId, + @JsonProperty("legacyRegion") String legacyRegion, + @JsonProperty("tenantId") String tenantId, + @JsonProperty("instanceParams") List> instanceParams, + @JsonProperty("lineOfBusinessName") String lineOfBusiness, + @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure, + @JsonProperty("instanceId") String instanceId) { + + super(modelInfo, instanceName, action, lcpCloudRegionId, legacyRegion, tenantId, instanceParams, rollbackOnFailure, instanceId); + this.productFamilyId = productFamilyId; + this.platformName = platformName; + this.lineOfBusiness = lineOfBusiness; + } + + public String getProductFamilyId() { + return productFamilyId; + } + + public String getPlatformName() { + return platformName; + } + + public String getLineOfBusiness() { + return lineOfBusiness; + } + + @Override + protected String getModelType() { + return "network"; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiation.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiation.java index 1d2e69d54..3cb1e9492 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiation.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiation.java @@ -1,16 +1,14 @@ package org.onap.vid.model.serviceInstantiation; import com.fasterxml.jackson.annotation.JsonProperty; -import org.onap.vid.domain.mso.ModelInfo; import org.onap.vid.job.JobAdapter; +import org.onap.vid.mso.model.ModelInfo; import java.util.Collections; import java.util.List; import java.util.Map; -public class ServiceInstantiation implements JobAdapter.AsyncJobRequest { - - private final ModelInfo modelInfo; +public class ServiceInstantiation extends BaseResource implements JobAdapter.AsyncJobRequest { private final String owningEntityId; @@ -24,16 +22,8 @@ public class ServiceInstantiation implements JobAdapter.AsyncJobRequest { private final String productFamilyId; - private final String instanceName; - - private final Boolean isUserProvidedNaming; - private final String subscriptionServiceType; - private final String lcpCloudRegionId; - - private final String tenantId; - private final String tenantName; private final String aicZoneId; @@ -42,13 +32,17 @@ public class ServiceInstantiation implements JobAdapter.AsyncJobRequest { private final Map vnfs; - private final List> instanceParams; + private final Map networks; + + private final Map vnfGroups; private final boolean isPause; private final int bulkSize; - private final boolean rollbackOnFailure; + private final String testApi; + + private final boolean isALaCarte; public ServiceInstantiation(@JsonProperty("modelInfo") ModelInfo modelInfo, @JsonProperty("owningEntityId") String owningEntityId, @@ -58,45 +52,43 @@ public class ServiceInstantiation implements JobAdapter.AsyncJobRequest { @JsonProperty("subscriberName") String subscriberName, @JsonProperty("productFamilyId") String productFamilyId, @JsonProperty("instanceName") String instanceName, - @JsonProperty("isUserProvidedNaming") Boolean isUserProvidedNaming, @JsonProperty("subscriptionServiceType") String subscriptionServiceType, @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId, + @JsonProperty("legacyRegion") String legacyRegion, @JsonProperty("tenantId") String tenantId, @JsonProperty("tenantName") String tenantName, @JsonProperty("aicZoneId") String aicZoneId, @JsonProperty("aicZoneName") String aicZoneName, @JsonProperty("vnfs") Map vnfs, + @JsonProperty("networks") Map networks, + @JsonProperty("vnfGroups") Map vnfGroups, @JsonProperty("instanceParams") List> instanceParams, @JsonProperty("pause") boolean isPause, @JsonProperty("bulkSize") int bulkSize, - @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure + @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure, + @JsonProperty("isALaCarte") boolean isALaCarte, + @JsonProperty("testApi") String testApi, + @JsonProperty("instanceId") String instanceId, + @JsonProperty("action") String action ) { - - this.modelInfo = modelInfo; - this.modelInfo.setModelType("service"); + super(modelInfo, instanceName, action, lcpCloudRegionId, legacyRegion, tenantId, instanceParams, rollbackOnFailure, instanceId); this.owningEntityId = owningEntityId; this.owningEntityName = owningEntityName; this.projectName = projectName; this.globalSubscriberId = globalSubscriberId; this.subscriberName = subscriberName; this.productFamilyId = productFamilyId; - this.instanceName = instanceName; - this.isUserProvidedNaming = isUserProvidedNaming; this.subscriptionServiceType = subscriptionServiceType; - this.lcpCloudRegionId = lcpCloudRegionId; - this.tenantId = tenantId; this.tenantName = tenantName; this.aicZoneId = aicZoneId; this.aicZoneName = aicZoneName; this.vnfs = vnfs; - this.instanceParams = instanceParams; + this.networks = networks; + this.vnfGroups = vnfGroups; this.isPause = isPause; this.bulkSize = bulkSize; - this.rollbackOnFailure = rollbackOnFailure; - } - - public ModelInfo getModelInfo() { - return modelInfo; + this.isALaCarte = isALaCarte; + this.testApi = isALaCarte ? testApi : null; } public String getOwningEntityId() { @@ -123,25 +115,10 @@ public class ServiceInstantiation implements JobAdapter.AsyncJobRequest { return productFamilyId; } - public String getInstanceName() { - return instanceName; - } - - @JsonProperty("isUserProvidedNaming") - public Boolean isUserProvidedNaming() { return isUserProvidedNaming; } - public String getSubscriptionServiceType() { return subscriptionServiceType; } - public String getLcpCloudRegionId() { - return lcpCloudRegionId; - } - - public String getTenantId() { - return tenantId; - } - public String getTenantName() { return tenantName; } @@ -155,11 +132,15 @@ public class ServiceInstantiation implements JobAdapter.AsyncJobRequest { } public Map getVnfs() { - return vnfs; + return vnfs == null ? Collections.emptyMap() : vnfs; + } + + public Map getNetworks() { + return networks == null ? Collections.emptyMap() : networks; } - public List> getInstanceParams() { - return instanceParams == null ? Collections.emptyList() : instanceParams; + public Map getVnfGroups() { + return vnfGroups == null ? Collections.emptyMap() : vnfGroups; } public boolean isPause() { @@ -168,7 +149,18 @@ public class ServiceInstantiation implements JobAdapter.AsyncJobRequest { public int getBulkSize() { return bulkSize; } - public boolean isRollbackOnFailure() { - return rollbackOnFailure; + @Override + protected String getModelType() { + return "service"; + } + + @JsonProperty("isALaCarte") + public boolean isALaCarte() { + return isALaCarte; } + + public String getTestApi() { + return this.testApi; + } + } \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java index f63fb3365..b930ba4db 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java @@ -22,10 +22,9 @@ package org.onap.vid.model.serviceInstantiation; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.StringUtils; -import org.onap.vid.domain.mso.ModelInfo; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.mso.model.ModelInfo; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -34,42 +33,47 @@ import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; /** * The Class VfModule. */ -public class VfModule { +@JsonInclude(NON_NULL) +public class VfModule extends BaseResource implements JobAdapter.AsyncJobRequest { - - - private final ModelInfo modelInfo; - - @JsonInclude(NON_NULL) private final String instanceName; - - private final List> instanceParams; @JsonInclude(NON_NULL) private final String volumeGroupInstanceName; - - public VfModule(@JsonProperty("modelInfo") ModelInfo modelInfo, - @JsonProperty("instanceName") String instanceName, - @JsonProperty(value = "volumeGroupName") String volumeGroupInstanceName, - @JsonProperty("instanceParams") List> instanceParams) { - this.modelInfo = modelInfo; - this.modelInfo.setModelType("vfModule"); - this.instanceName = instanceName; - this.instanceParams = instanceParams; + private boolean usePreload; + private Map supplementaryParams; + + public VfModule( @JsonProperty("modelInfo") ModelInfo modelInfo, + @JsonProperty("instanceName") String instanceName, + @JsonProperty("volumeGroupName") String volumeGroupInstanceName, + @JsonProperty("action") String action, + @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId, + @JsonProperty("legacyRegion") String legacyRegion, + @JsonProperty("tenantId") String tenantId, + @JsonProperty("instanceParams") List> instanceParams, + @JsonProperty("supplementaryFileContent") Map supplementaryParams, + @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure, + @JsonProperty("sdncPreLoad") boolean usePreload, + @JsonProperty("instanceId") String instanceId) { + super(modelInfo, instanceName, action, lcpCloudRegionId, legacyRegion, tenantId, instanceParams, rollbackOnFailure, instanceId); this.volumeGroupInstanceName = volumeGroupInstanceName; + this.usePreload = usePreload; + this.supplementaryParams = supplementaryParams; } - public ModelInfo getModelInfo() { - return modelInfo; + public String getVolumeGroupInstanceName() { + return volumeGroupInstanceName; } - public String getInstanceName() { - return instanceName; + public boolean isUsePreload() { + return usePreload; } - public String getVolumeGroupInstanceName() { - return volumeGroupInstanceName; + public Map getSupplementaryParams() { + return supplementaryParams; } - public List> getInstanceParams() { - return instanceParams == null ? Collections.emptyList() : instanceParams; + @Override + protected String getModelType() { + return "vfModule"; } + } \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/Vnf.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/Vnf.java index 621754d17..3856e8894 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/Vnf.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/Vnf.java @@ -22,99 +22,64 @@ package org.onap.vid.model.serviceInstantiation; import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.StringUtils; -import org.onap.vid.domain.mso.ModelInfo; +import org.onap.vid.job.JobAdapter; +import org.onap.vid.mso.model.ModelInfo; -import java.util.Collections; import java.util.List; import java.util.Map; /** * The Class VNF. */ -public class Vnf { - private final ModelInfo modelInfo; +public class Vnf extends BaseResource implements JobAdapter.AsyncJobRequest { private final String productFamilyId; - private final String instanceName; - private final String platformName; - private final String lcpCloudRegionId; - - private final String tenantId; - - private final Boolean isUserProvidedNaming; - - private final List> instanceParams; - private final String lineOfBusiness; - private final Map> vfModules; public Vnf(@JsonProperty("modelInfo") ModelInfo modelInfo, - @JsonProperty("productFamilyId") String productFamilyId, - @JsonProperty("instanceName") String instanceName, - @JsonProperty("isUserProvidedNaming") Boolean isUserProvidedNaming, - @JsonProperty("platformName") String platformName, - @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId, - @JsonProperty("tenantId") String tenantId, - @JsonProperty("instanceParams") List> instanceParams, - @JsonProperty("lineOfBusinessName") String lineOfBusiness, - @JsonProperty("vfModules") Map> vfModules) { - this.modelInfo = modelInfo; - this.modelInfo.setModelType("vnf"); + @JsonProperty("productFamilyId") String productFamilyId, + @JsonProperty("instanceName") String instanceName, + @JsonProperty("action") String action, + @JsonProperty("platformName") String platformName, + @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId, + @JsonProperty("legacyRegion") String legacyRegion, + @JsonProperty("tenantId") String tenantId, + @JsonProperty("instanceParams") List> instanceParams, + @JsonProperty("lineOfBusinessName") String lineOfBusiness, + @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure, + @JsonProperty("instanceId") String instanceId, + @JsonProperty("vfModules") Map> vfModules) { + + super(modelInfo, instanceName, action, lcpCloudRegionId, legacyRegion, tenantId, instanceParams, rollbackOnFailure, instanceId); this.productFamilyId = productFamilyId; - this.instanceName = instanceName; - this.isUserProvidedNaming = isUserProvidedNaming; this.platformName = platformName; - this.lcpCloudRegionId = lcpCloudRegionId; - this.tenantId = tenantId; - this.instanceParams = instanceParams; - this.vfModules = vfModules; this.lineOfBusiness = lineOfBusiness; - } - - public ModelInfo getModelInfo() { - return modelInfo; + this.vfModules = vfModules; } public String getProductFamilyId() { return productFamilyId; } - public String getInstanceName() { - return instanceName; - } - - @JsonProperty("isUserProvidedNaming") - public Boolean isUserProvidedNaming() { - return isUserProvidedNaming; - } - public String getPlatformName() { return platformName; } - public String getLcpCloudRegionId() { - return lcpCloudRegionId; - } - - public String getTenantId() { - return tenantId; - } - - public List> getInstanceParams() { - return instanceParams == null ? Collections.emptyList() : instanceParams; + public String getLineOfBusiness() { + return lineOfBusiness; } public Map> getVfModules() { return vfModules; } - public String getLineOfBusiness() { - return lineOfBusiness; + @Override + protected String getModelType() { + return "vnf"; } } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogic.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogic.java index 0ecb9257e..ef45d5ce5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogic.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogic.java @@ -1,7 +1,8 @@ package org.onap.vid.mso; import org.onap.vid.changeManagement.RequestDetailsWrapper; -import org.onap.vid.controllers.OperationalEnvironmentController; +import org.onap.vid.controller.OperationalEnvironmentController; +import org.onap.vid.model.SoftDeleteRequest; import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo; import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails; @@ -17,9 +18,9 @@ public interface MsoBusinessLogic { MsoResponseWrapper createSvcInstance(RequestDetails msoRequest); MsoResponseWrapper createE2eSvcInstance(Object msoRequest); - + MsoResponseWrapper deleteE2eSvcInstance(Object requestDetails, String serviceInstanceId); - + MsoResponseWrapper createVnf(RequestDetails requestDetails, String serviceInstanceId); MsoResponseWrapper createNwInstance(RequestDetails requestDetails, String serviceInstanceId); @@ -102,4 +103,15 @@ public interface MsoBusinessLogic { RequestDetailsWrapper generateInPlaceMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails); RequestDetailsWrapper generateConfigMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails); + + String getActivateFabricConfigurationPath(String serviceInstanceId); + + String getDeactivateAndCloudDeletePath(String serviceInstanceId, String vnfInstanceId, String vfModuleInstanceId); + + RequestDetails buildRequestDetailsForSoftDelete(SoftDeleteRequest softDeleteRequest); + + MsoResponseWrapper2 deactivateAndCloudDelete(String serviceInstanceId, String vnfInstanceId, String vfModuleInstanceId, RequestDetails requestDetails); + + MsoResponseWrapper2 activateFabricConfiguration(String serviceInstanceId, RequestDetails requestDetails); + } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java index a6226e00e..7fe79b392 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java @@ -26,24 +26,22 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.changeManagement.ChangeManagementRequest; import org.onap.vid.changeManagement.RequestDetailsWrapper; -import org.onap.vid.controllers.OperationalEnvironmentController; -import org.onap.vid.domain.mso.RequestInfo; +import org.onap.vid.controller.OperationalEnvironmentController; import org.onap.vid.exceptions.GenericUncheckedException; -import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; -import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo; +import org.onap.vid.model.RequestReferencesContainer; +import org.onap.vid.model.SoftDeleteRequest; +import org.onap.vid.mso.model.*; import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails; import org.onap.vid.mso.rest.*; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; import org.togglz.core.manager.FeatureManager; import javax.ws.rs.BadRequestException; import java.io.IOException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -53,7 +51,7 @@ import static java.util.stream.Collectors.collectingAndThen; import static java.util.stream.Collectors.toList; import static org.apache.commons.lang.StringUtils.upperCase; import static org.onap.vid.changeManagement.ChangeManagementRequest.MsoChangeManagementRequest; -import static org.onap.vid.controllers.MsoController.*; +import static org.onap.vid.controller.MsoController.*; import static org.onap.vid.mso.MsoProperties.*; import static org.onap.vid.properties.Features.FLAG_UNASSIGN_SERVICE; import static org.onap.vid.utils.Logging.debugRequestDetails; @@ -68,16 +66,14 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { .map(requestType -> requestType.toString().toUpperCase()) .collect(collectingAndThen(toList(), Collections::unmodifiableList)); private static final String RESOURCE_TYPE = "resourceType"; - /** - * The Constant dateFormat. - */ - private static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); private static final Pattern SOFTWARE_VERSION_PATTERN = Pattern.compile("^[A-Za-z0-9.\\-]+$"); private static final Pattern NUMBER_PATTERN = Pattern.compile("^[0-9]+$"); private static final String ACTIVATE = "/activate"; private static final String DEACTIVATE = "/deactivate"; private static final String ENABLE_PORT = "/enablePort"; private static final String DISABLE_PORT = "/disablePort"; + private static final String ACTIVATE_FABRIC_CONFIGURATION = "/activateFabricConfiguration"; + private static final String DEACTIVATE_AND_CLOUD_DELETE = "/deactivateAndCloudDelete"; private static final String RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT = "operationalEnvironment"; private static final String SOURCE_OPERATIONAL_ENVIRONMENT = "VID"; private static final ObjectMapper objectMapper = new ObjectMapper(); @@ -130,8 +126,8 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE); - String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - return msoClientInterface.createVnf(requestDetails, vnf_endpoint); + String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + return msoClientInterface.createVnf(requestDetails, vnfEndpoint); } @Override @@ -150,10 +146,10 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE); - String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - vnf_endpoint = vnf_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); + String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + vnfEndpoint = vnfEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); - return msoClientInterface.createVolumeGroupInstance(requestDetails, vnf_endpoint); + return msoClientInterface.createVolumeGroupInstance(requestDetails, vnfEndpoint); } @Override @@ -232,10 +228,10 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { logInvocationInDebug("deleteVnf"); String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE); - String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId; + String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + vnfEndpoint = vnfEndpoint + '/' + vnfInstanceId; - return msoClientInterface.deleteVnf(requestDetails, vnf_endpoint); + return msoClientInterface.deleteVnf(requestDetails, vnfEndpoint); } @Override @@ -255,8 +251,8 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE); String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - String vnf_endpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); - String delete_volume_group_endpoint = vnf_endpoint + "/" + volumeGroupId; + String vnfEndpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); + String delete_volume_group_endpoint = vnfEndpoint + "/" + volumeGroupId; return msoClientInterface.deleteVolumeGroupInstance(requestDetails, delete_volume_group_endpoint); } @@ -341,7 +337,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { RestObject restObjStr = new RestObject<>(); String str = new String(); restObjStr.set(str); - MsoResponseWrapper msoResponseWrapper = msoClientInterface.getOrchestrationRequestsForDashboard(str, "", orchestrationReqPath, restObjStr); + MsoResponseWrapper msoResponseWrapper = msoClientInterface.getOrchestrationRequest(str, "", orchestrationReqPath, restObjStr, true); return deserializeOrchestrationRequestsJson(msoResponseWrapper.getEntity()); } @@ -447,9 +443,9 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String endpoint; endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE); - String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId; - return msoClientInterface.updateVnf(requestDetails, vnf_endpoint); + String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + vnfEndpoint = vnfEndpoint + '/' + vnfInstanceId; + return msoClientInterface.updateVnf(requestDetails, vnfEndpoint); } @Override @@ -457,10 +453,10 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { logInvocationInDebug("replaceVnf"); String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE); - String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId); - vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, MsoChangeManagementRequest.REPLACE); - return msoClientInterface.replaceVnf(requestDetails, vnf_endpoint); + String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + vnfEndpoint = vnfEndpoint.replace(VNF_INSTANCE_ID, vnfInstanceId); + vnfEndpoint = vnfEndpoint.replace(REQUEST_TYPE, MsoChangeManagementRequest.REPLACE); + return msoClientInterface.replaceVnf(requestDetails, vnfEndpoint); } public RequestDetailsWrapper generateInPlaceMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails) { @@ -485,28 +481,83 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { return requestDetailsWrapper; } + @Override + public String getActivateFabricConfigurationPath(String serviceInstanceId) { + String path = validateEndpointPath(MsoProperties.MSO_REST_API_SERVICE_INSTANCE_CREATE); + path += "/" + serviceInstanceId + ACTIVATE_FABRIC_CONFIGURATION; + + return path; + } + + @Override + public String getDeactivateAndCloudDeletePath(String serviceInstanceId, String vnfInstanceId, String vfModuleInstanceId) { + String path = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE); + path = path.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); + path += "/" + vfModuleInstanceId + DEACTIVATE_AND_CLOUD_DELETE; + + return path; + } + + @Override + public RequestDetails buildRequestDetailsForSoftDelete(SoftDeleteRequest softDeleteRequest) { + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setSource("VID"); + requestInfo.setRequestorId(softDeleteRequest.getUserId()); + requestDetails.setRequestInfo(requestInfo); + + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setTenantId(softDeleteRequest.getTenantId()); + cloudConfiguration.setLcpCloudRegionId(softDeleteRequest.getLcpCloudRegionId()); + requestDetails.setCloudConfiguration(cloudConfiguration); + + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelType("vfModule"); + requestDetails.setModelInfo(modelInfo); + + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setTestApi("GR_API"); + requestDetails.setRequestParameters(requestParameters); + + return requestDetails; + } + + @Override + public MsoResponseWrapper2 deactivateAndCloudDelete(String serviceInstanceId, String vnfInstanceId, String vfModuleInstanceId, RequestDetails requestDetails) { + String path = getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId); + return new MsoResponseWrapper2<>(msoClientInterface.post(path, new RequestDetailsWrapper<>(requestDetails), RequestReferencesContainer.class)); + } + + @Override + public MsoResponseWrapper2 activateFabricConfiguration(String serviceInstanceId, RequestDetails requestDetails) { + String path = getActivateFabricConfigurationPath(serviceInstanceId); + return new MsoResponseWrapper2<>(msoClientInterface.post(path, new RequestDetailsWrapper<>(requestDetails), RequestReferencesContainer.class)); + } + + @Override public MsoResponseWrapperInterface updateVnfSoftware(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) { logInvocationInDebug("updateVnfSoftware"); - String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.SOFTWARE_UPDATE); //workflow name in mso is different than workflow name in vid UI + String vnfEndpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.SOFTWARE_UPDATE); //workflow name in mso is different than workflow name in vid UI RequestDetailsWrapper finalRequestDetails = generateInPlaceMsoRequest(requestDetails); - return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint); + return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnfEndpoint); } @Override public MsoResponseWrapperInterface updateVnfConfig(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) { logInvocationInDebug("updateVnfConfig"); RequestDetailsWrapper finalRequestDetails = generateConfigMsoRequest(requestDetails); - String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.CONFIG_UPDATE); - return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint); + String vnfEndpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.CONFIG_UPDATE); + return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnfEndpoint); } private String getChangeManagementEndpoint(String serviceInstanceId, String vnfInstanceId, String vnfRequestType) { String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE); - String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId); - vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, vnfRequestType); - return vnf_endpoint; + String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + vnfEndpoint = vnfEndpoint.replace(VNF_INSTANCE_ID, vnfInstanceId); + vnfEndpoint = vnfEndpoint.replace(REQUEST_TYPE, vnfRequestType); + return vnfEndpoint; } private Map getChangeManagementPayload(RequestDetails requestDetails, String message) { @@ -598,8 +649,8 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { return MsoUtil.wrapResponse(restObjStr); } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString()); throw e; } } @@ -632,13 +683,13 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { requestInfo.setRequestorId(details.getUserId()); requestDetails.setRequestInfo(requestInfo); - org.onap.vid.domain.mso.RelatedInstance relatedInstance = new org.onap.vid.domain.mso.RelatedInstance(); + RelatedInstance relatedInstance = new RelatedInstance(); relatedInstance.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT); relatedInstance.setInstanceId(details.getRelatedInstanceId()); relatedInstance.setInstanceName(details.getRelatedInstanceName()); requestDetails.setAdditionalProperty("relatedInstanceList", Collections.singletonList(ImmutableMap.of("relatedInstance", relatedInstance))); - org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters(); + RequestParameters requestParameters = new RequestParameters(); requestParameters.setUserParams(null); requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF"); requestParameters.setAdditionalProperty("workloadContext", details.getWorkloadContext()); @@ -669,7 +720,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { requestInfo.setRequestorId(details.getUserId()); requestDetails.setRequestInfo(requestInfo); - org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters(); + RequestParameters requestParameters = new RequestParameters(); requestParameters.setUserParams(null); requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF"); requestDetails.setRequestParameters(requestParameters); @@ -760,12 +811,12 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } private void logInvocationInDebug(String methodName) { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); } private void logException(String methodName, Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString()); } enum RequestType { @@ -781,6 +832,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { SCALE_OUT("scaleOut"), UNKNOWN("unknown"), NOT_PROVIDED("not provided"); + private final String value; private static final Map CONSTANTS = new HashMap<>(); static { @@ -789,8 +841,6 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } } - private final String value; - RequestType(String value) { this.value = value; } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java index 7c8ab89c1..41400f978 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java @@ -20,15 +20,10 @@ */ package org.onap.vid.mso; -import com.fasterxml.jackson.core.JsonProcessingException; import io.joshworks.restclient.http.HttpResponse; -import io.joshworks.restclient.http.mapper.ObjectMapper; -import org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.mso.rest.RequestDetails; -import java.io.IOException; - /** * Created by pickjonathan on 21/06/2017. */ @@ -43,7 +38,7 @@ public interface MsoInterface { * @throws Exception */ MsoResponseWrapper createSvcInstance(RequestDetails requestDetails, String endpoint); - + //For VoLTE E2E services MsoResponseWrapper createE2eSvcInstance(Object requestDetails, String endpoint); MsoResponseWrapper deleteE2eSvcInstance(Object requestDetails, String endpoint); @@ -90,19 +85,19 @@ public interface MsoInterface { MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String endpoint); - MsoResponseWrapper getOrchestrationRequest(String endpoint); + MsoResponseWrapper getOrchestrationRequest(String t, String sourceId, String endpoint, RestObject restObject, boolean warpException); - MsoResponseWrapper getOrchestrationRequestsForDashboard(String t , String sourceId , String endpoint , RestObject restObject); + MsoResponseWrapper getOrchestrationRequest(String endpoint); MsoResponseWrapper getManualTasksByRequestId(String t , String sourceId , String endpoint , RestObject restObject); MsoResponseWrapper completeManualTask(RequestDetails requestDetails, String t, String sourceId, String endpoint, RestObject restObject); - MsoResponseWrapper updateVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String vnf_endpoint); + MsoResponseWrapper updateVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String vnfEndpoint); - MsoResponseWrapper replaceVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String vnf_endpoint); + MsoResponseWrapper replaceVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String vnfEndpoint); - MsoResponseWrapper deleteConfiguration(org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String pmc_endpoint); + MsoResponseWrapper deleteConfiguration(org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String pmcEndpoint); MsoResponseWrapper setConfigurationActiveStatus(RequestDetails requestDetails, String endpoint); @@ -120,29 +115,5 @@ public interface MsoInterface { HttpResponse post(String path, RequestDetailsWrapper requestDetailsWrapper, Class responseClass); - - static ObjectMapper objectMapper() { - return new ObjectMapper() { - CustomJacksonJaxBJsonProvider mapper = new CustomJacksonJaxBJsonProvider(); - - @Override - public T readValue(String s, Class aClass) { - try { - return mapper.getMapper().readValue(s, aClass); - } catch (IOException e) { - throw new MsoException(e); - } - } - - @Override - public String writeValue(Object o) { - try { - return mapper.getMapper().writeValueAsString(o); - } catch (JsonProcessingException e) { - throw new MsoException(e); - } - } - }; - } } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoProperties.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoProperties.java index 1d71e9c75..1039a29d4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoProperties.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoProperties.java @@ -20,12 +20,8 @@ package org.onap.vid.mso; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; -import java.text.DateFormat; -import java.text.SimpleDateFormat; - /** * The Class MsoProperties. */ @@ -71,7 +67,7 @@ public class MsoProperties extends SystemProperties { /** The Constant MSO_REST_API_SVC_INSTANCE. */ public static final String MSO_REST_API_E2E_SVC_INSTANCE = "mso.restapi.svc.e2einstance"; // /e2eServiceInstances/v3 - + /** The Constant MSO_REST_API_SVC_INSTANCE. */ public static final String MSO_REST_API_SVC_INSTANCE = "mso.restapi.svc.instance"; // /serviceInstances/v2 @@ -79,13 +75,13 @@ public class MsoProperties extends SystemProperties { public static final String MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE = "mso.restapi.svc.instance.deleteAndUnassign"; /** The Constant MSO_REST_API_VNF_INSTANCE. */ - public static final String MSO_REST_API_VNF_INSTANCE = "mso.restapi.vnf.instance"; // /serviceInstances/v2/{service_instance_id}/vnfs + public static final String MSO_REST_API_VNF_INSTANCE = "mso.restapi.vnf.instance"; /** The Constant MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE. */ - public static final String MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE = "mso.restapi.vnf.changemanagement.instance"; // /serviceInstances/v2/{service_instance_id}/vnfs/{request_type} + public static final String MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE = "mso.restapi.vnf.changemanagement.instance"; /** The Constant MSO_REST_API_NETWORK_INSTANCE. */ - public static final String MSO_REST_API_NETWORK_INSTANCE = "mso.restapi.network.instance"; // /serviceInstances/v2/{serviceInstanceId}/networks + public static final String MSO_REST_API_NETWORK_INSTANCE = "mso.restapi.network.instance"; /** The Constant MSO_REST_API_GET_ORC_REQ. */ public static final String MSO_REST_API_GET_ORC_REQ = "mso.restapi.get.orc.req"; @@ -102,11 +98,14 @@ public class MsoProperties extends SystemProperties { public static final String MSO_REST_API_VF_MODULE_SCALE_OUT = "mso.restapi.vf.module.scaleout"; /** The Constant MSO_REST_API_VOLUME_GROUP_INSTANCE. */ - public static final String MSO_REST_API_VOLUME_GROUP_INSTANCE = "mso.restapi.volume.group.instance"; //serviceInstances/v2/{serviceInstanceId}/volumeGroups + public static final String MSO_REST_API_VOLUME_GROUP_INSTANCE = "mso.restapi.volume.group.instance"; + + /** The Constant MSO_REST_API_VOLUME_GROUP_INSTANCE. */ + public static final String MSO_REST_API_INSTANCE_GROUP = "mso.restapi.instance.group"; /** The Constant MSO_REST_API_CONFIGURATION_INSTANCE. */ - public static final String MSO_REST_API_CONFIGURATIONS = "mso.restapi.configurations"; //serviceInstances/v5/{serviceInstanceId}/configurations - public static final String MSO_REST_API_CONFIGURATION_INSTANCE = "mso.restapi.configuration.instance"; //serviceInstances/v5/{serviceInstanceId}/configurations/{configurationId} + public static final String MSO_REST_API_CONFIGURATIONS = "mso.restapi.configurations"; + public static final String MSO_REST_API_CONFIGURATION_INSTANCE = "mso.restapi.configuration.instance"; /** The Constant MSO_REST_API_OPERATIONAL_ENVIRONMENT */ public static final String MSO_REST_API_OPERATIONAL_ENVIRONMENT_ACTIVATE = "mso.restapi.operationalEnvironment.activate"; @@ -118,10 +117,9 @@ public class MsoProperties extends SystemProperties { /** The Constant MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS */ public static final String MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS = "mso.restapi.operationalEnvironment.cloudResourcesRequests.status"; - /** The logger. */ - public EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoProperties.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + /** The Constant MSO_REST_API_SERVICE_INSTANCE_CREATE */ + public static final String MSO_REST_API_SERVICE_INSTANCE_CREATE = "mso.restapi.serviceInstanceCreate"; + /** The Constant MSO_REST_API_SERVICE_INSTANCE_ASSIGN */ + public static final String MSO_REST_API_SERVICE_INSTANCE_ASSIGN = "mso.restapi.serviceInstanceAssign"; } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper.java index b890114b5..5a35e1092 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper.java @@ -20,6 +20,7 @@ package org.onap.vid.mso; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @@ -111,8 +112,7 @@ public class MsoResponseWrapper implements MsoResponseWrapperInterface { * * @return the response */ - @org.codehaus.jackson.annotate.JsonIgnore - @com.fasterxml.jackson.annotation.JsonIgnore + @JsonIgnore public String getResponse () { StringBuilder b = new StringBuilder ("{ \"status\": "); diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java index 2372e7fb7..fff14ebc3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java @@ -20,6 +20,7 @@ */ package org.onap.vid.mso; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.core.JsonProcessingException; @@ -38,7 +39,7 @@ The serialized "entity" field may be either String or nested object. */ public class MsoResponseWrapper2 implements MsoResponseWrapperInterface { - final static ObjectMapper objectMapper = new ObjectMapper(); + static final ObjectMapper objectMapper = new ObjectMapper(); private final int status; private final T entity; @@ -69,8 +70,7 @@ public class MsoResponseWrapper2 implements MsoResponseWrapperInterface { } @Override - @org.codehaus.jackson.annotate.JsonIgnore - @com.fasterxml.jackson.annotation.JsonIgnore + @JsonIgnore public String getResponse() { try { return objectMapper.writeValueAsString(this); diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapperInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapperInterface.java index ad251bdeb..e293398fb 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapperInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapperInterface.java @@ -1,5 +1,6 @@ package org.onap.vid.mso; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; public interface MsoResponseWrapperInterface { @@ -9,7 +10,6 @@ public interface MsoResponseWrapperInterface { @JsonProperty("status") int getStatus(); - @org.codehaus.jackson.annotate.JsonIgnore - @com.fasterxml.jackson.annotation.JsonIgnore + @JsonIgnore String getResponse(); } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java index 722a1c4cd..999188ffc 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java @@ -3,14 +3,13 @@ * VID * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,9 +27,6 @@ import org.apache.commons.lang3.ObjectUtils; import org.glassfish.jersey.client.ClientResponse; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import java.text.DateFormat; -import java.text.SimpleDateFormat; - import static org.onap.vid.utils.Logging.getMethodName; /** @@ -40,10 +36,7 @@ public class MsoUtil { /** The logger. */ private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoUtil.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - + /** * Wrap response. * @@ -67,12 +60,13 @@ public class MsoUtil { * @return the mso response wrapper */ public static MsoResponseWrapper wrapResponse (ClientResponse cres) { - String resp_str = ""; + String respStr = ""; + int statuscode = 0; if ( cres != null ) { - resp_str = cres.readEntity(String.class); + respStr = cres.readEntity(String.class); + statuscode = cres.getStatus(); } - int statuscode = cres.getStatus(); - MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, statuscode ); + MsoResponseWrapper w = MsoUtil.wrapResponse ( respStr, statuscode ); return (w); } @@ -83,16 +77,16 @@ public class MsoUtil { * @return the mso response wrapper */ public static MsoResponseWrapper wrapResponse (RestObject rs) { - String resp_str = null; + String respStr = null; int status = 0; if ( rs != null ) { - resp_str = rs.get() != null ? rs.get() : rs.getRaw(); + respStr = rs.get() != null ? rs.get() : rs.getRaw(); status = rs.getStatusCode(); } - MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, status ); + MsoResponseWrapper w = MsoUtil.wrapResponse ( respStr, status ); return (w); - } - + } + public static MsoResponseWrapper wrapResponse (HttpResponse rs) { MsoResponseWrapper w = new MsoResponseWrapper(); w.setStatus (rs.getStatus()); @@ -111,19 +105,17 @@ public class MsoUtil { * @throws JsonProcessingException the json processing exception */ public static String convertPojoToString ( T t ) { - - String methodName = "convertPojoToString"; ObjectMapper mapper = new ObjectMapper(); - String r_json_str = ""; + String rJsonStr = ""; if ( t != null ) { try { - r_json_str = mapper.writeValueAsString(t); + rJsonStr = mapper.writeValueAsString(t); } catch ( com.fasterxml.jackson.core.JsonProcessingException j ) { logger.debug(EELFLoggerDelegate.debugLogger,getMethodName() + " Unable to parse object of type " + t.getClass().getName() + " as json", j); } } - return (r_json_str); + return (rJsonStr); } /** diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java index 0494facd5..31836f66a 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java @@ -3,15 +3,17 @@ package org.onap.vid.mso; import com.att.eelf.configuration.EELFLogger; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.codec.binary.Base64; +import org.apache.http.HttpException; import org.eclipse.jetty.util.security.Password; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.aai.util.HttpClientMode; import org.onap.vid.aai.util.HttpsAuthClient; import org.onap.vid.client.HttpBasicClient; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.mso.rest.RestInterface; import org.onap.vid.utils.Logging; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; @@ -21,53 +23,44 @@ import javax.ws.rs.client.Invocation; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.Response; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.Collections; -import java.util.Date; -import java.util.UUID; +import java.util.Optional; import static org.onap.vid.utils.Logging.*; /** * Created by pickjonathan on 26/06/2017. */ -public class RestMsoImplementation implements RestInterface { - - public static final String START_LOG = " start"; - public static final String APPLICATION_JSON = "application/json"; - public static final String WITH_STATUS = " with status="; - public static final String URL_LOG = ", url="; - public static final String NO_RESPONSE_ENTITY_LOG = " No response entity, this is probably ok, e="; - public static final String WITH_URL_LOG = " with url="; - public static final String EXCEPTION_LOG = ", Exception: "; - public static final String REST_API_SUCCESSFULL_LOG = " REST api was successfull!"; - public static final String REST_API_POST_WAS_SUCCESSFUL_LOG = " REST api POST was successful!"; +public abstract class RestMsoImplementation implements RestInterface { + /** * The logger. */ - EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMsoImplementation.class); + protected EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMsoImplementation.class); private final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("mso"); - /** - * The Constant dateFormat. - */ - static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - /** The client. */ private Client client = null; @Autowired - HttpsAuthClient httpsAuthClient; - + protected HttpsAuthClient httpsAuthClient; + + private static final String START_LOG = " start"; + private static final String APPLICATION_JSON = "application/json"; + private static final String WITH_STATUS = " with status="; + private static final String URL_LOG = ", url="; + private static final String NO_RESPONSE_ENTITY_LOG = " No response entity, this is probably ok, e="; + private static final String WITH_URL_LOG = " with url="; + private static final String EXCEPTION_LOG = ", Exception: "; + private static final String REST_API_SUCCESSFULL_LOG = " REST api was successfull!"; + private static final String REST_MSG_TEMPLATE = "start {}->{}({}, {}, {})"; /** The common headers. */ /** * Instantiates a new mso rest interface. */ @SuppressWarnings("Duplicates") - @Override - public MultivaluedHashMap initMsoClient() + protected MultivaluedHashMap initMsoClient() { final String methodname = "initRestClient()"; @@ -83,15 +76,11 @@ public class RestMsoImplementation implements RestInterface { MultivaluedHashMap commonHeaders = new MultivaluedHashMap(); commonHeaders.put("Authorization", Collections.singletonList(("Basic " + authStringEnc))); - //Pass calling application identifier to SO - commonHeaders.put("X-FromAppId", Collections.singletonList(SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME))); - try { - commonHeaders.put(REQUEST_ID_HEADER_KEY, Collections.singletonList(Logging.extractOrGenerateRequestId())); - } - catch (IllegalStateException e){ - //in async jobs we don't have any HttpServletRequest - commonHeaders.put(REQUEST_ID_HEADER_KEY, Collections.singletonList(UUID.randomUUID().toString())); - } + commonHeaders.put("X-ONAP-PartnerName", Collections.singletonList("VID")); + + String requestIdValue = Logging.extractOrGenerateRequestId(); + commonHeaders.put(REQUEST_ID_HEADER_KEY, Collections.singletonList(requestIdValue)); + commonHeaders.put(ONAP_REQUEST_ID_HEADER_KEY, Collections.singletonList(requestIdValue)); boolean useSsl = true; @@ -108,54 +97,65 @@ public class RestMsoImplementation implements RestInterface { client = HttpBasicClient.getClient(); } } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodname + " Unable to get the SSL client"); + logger.info(EELFLoggerDelegate.errorLogger,methodname + " Unable to get the SSL client"); } } return commonHeaders; } - public void Get (T t, String sourceId, String path, RestObject restObject ) { + public RestObjectWithRequestInfo Get(T t, String path, RestObject restObject, boolean warpException) { String methodName = "Get"; logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_LOG); - String url=""; - restObject.set(t); + String url = null; + String rawData = null; + Integer status = null; - url = SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path; + try { + restObject.set(t); + url = SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path; - MultivaluedHashMap commonHeaders = initMsoClient(); - Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); - final Response cres = client.target(url) - .request() - .accept(APPLICATION_JSON) - .headers(commonHeaders) - .get(); - Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, cres); - int status = cres.getStatus(); - restObject.setStatusCode (status); + MultivaluedHashMap commonHeaders = initMsoClient(); + Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); + final Response cres = client.target(url) + .request() + .accept(APPLICATION_JSON) + .headers(commonHeaders) + .get(); + Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, cres); - if (status == 200 || status == 202) { - t = (T) cres.readEntity(t.getClass()); - restObject.set(t); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + REST_API_SUCCESSFULL_LOG); + cres.bufferEntity(); + status = cres.getStatus(); + rawData = cres.readEntity(String.class); - } else { - throw new GenericUncheckedException(methodName + WITH_STATUS + status + ", url= " + url ); - } + restObject.setStatusCode(status); - logger.debug(EELFLoggerDelegate.debugLogger,methodName + " received status=" + status ); + if (status == 200 || status == 202) { + t = (T) cres.readEntity(t.getClass()); + restObject.set(t); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + REST_API_SUCCESSFULL_LOG); - return; + } else { + throw new GenericUncheckedException(new HttpException(methodName + WITH_STATUS + status + " (200 or 202 expected), url= " + url)); + } + + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " received status=" + status); + + return new RestObjectWithRequestInfo<>(HttpMethod.GET, url, restObject, status, rawData); + } catch (RuntimeException e) { + throw warpException ? new ExceptionWithRequestInfo(HttpMethod.GET, url, rawData, status, e) : e; + } } - public RestObject GetForObject(String sourceID, String path, Class clazz) { + @Override + public RestObject GetForObject(String path, Class clazz) { final String methodName = getMethodName(); - logger.debug(EELFLoggerDelegate.debugLogger, "start {}->{}({}, {}, {})", getMethodCallerName(), methodName, sourceID, path, clazz); + logger.debug(EELFLoggerDelegate.debugLogger, "start {}->{}({}, {})", getMethodCallerName(), methodName, path, clazz); String url = SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " sending request to url= " + url); + logger.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + " sending request to url= " + url); MultivaluedHashMap commonHeaders = initMsoClient(); Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); @@ -169,9 +169,9 @@ public class RestMsoImplementation implements RestInterface { int status = cres.getStatus(); if (status == 200 || status == 202) { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + REST_API_SUCCESSFULL_LOG); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + REST_API_SUCCESSFULL_LOG); } else { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + WITH_STATUS +status+ URL_LOG +url); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_STATUS +status+ URL_LOG +url); } logger.debug(EELFLoggerDelegate.debugLogger,methodName + " received status=" + status ); @@ -180,13 +180,13 @@ public class RestMsoImplementation implements RestInterface { } @Override - public void Delete(T t, Object r, String sourceID, String path, RestObject restObject) { + public void Delete(T t, Object r, String path, RestObject restObject) { String methodName = "Delete"; String url=""; - Response cres = null; + Response cres; - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + START_LOG); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + START_LOG); try { MultivaluedHashMap commonHeaders = initMsoClient(); @@ -206,16 +206,16 @@ public class RestMsoImplementation implements RestInterface { if (status == 404) { // resource not found String msg = "Resource does not exist...: " + cres.getStatus(); - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + msg); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg); } else if (status == 200 || status == 204){ - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + "Resource " + url + " deleted"); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + "Resource " + url + " deleted"); } else if (status == 202) { - String msg = "Delete in progress: " + status; - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + msg); + String msg = "Delete in progress: " + status; + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg); } else { String msg = "Deleting Resource failed: " + status; - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + msg); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg); } try { @@ -223,37 +223,40 @@ public class RestMsoImplementation implements RestInterface { restObject.set(t); } catch ( Exception e ) { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + NO_RESPONSE_ENTITY_LOG + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + NO_RESPONSE_ENTITY_LOG + e.getMessage()); } } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString()); throw e; } } - public RestObject PostForObject(Object requestDetails, String sourceID, String path, Class clazz) { - logger.debug(EELFLoggerDelegate.debugLogger, "start {}->{}({}, {}, {}, {})", getMethodCallerName(), getMethodName(), requestDetails, sourceID, path, clazz); - RestObject restObject = new RestObject<>(); - Post(clazz, requestDetails, path, restObject); - return restObject; + public RestObject PostForObject(Object requestDetails, String path, Class clazz) { + logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), requestDetails, path, clazz); + return restCall(HttpMethod.POST, clazz, requestDetails, path); + } + + public RestObject DeleteForObject(Object requestDetails, String path, Class clazz) { + logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), requestDetails, path, clazz); + return restCall(HttpMethod.DELETE, clazz, requestDetails, path); } @Override - public void Post(T t, Object r, String sourceID, String path, RestObject restObject) { - logger.debug(EELFLoggerDelegate.debugLogger, "start {}->{}({}, {}, {}, {})", getMethodCallerName(), getMethodName(), t.getClass(), r, sourceID, path); - Post(t.getClass(), r, path, restObject); + public void Post(String t, Object r, String path, RestObject restObject) { + logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), t.getClass(), r, path); + restObject.copyFrom(restCall(HttpMethod.POST, String.class, r, path)); } public Invocation.Builder prepareClient(String path, String methodName) { MultivaluedHashMap commonHeaders = initMsoClient(); String url = SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path; - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " sending request to url= " + url); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + " sending request to url= " + url); // Change the content length return client.target(url) .request() @@ -261,49 +264,44 @@ public class RestMsoImplementation implements RestInterface { .headers(commonHeaders); } + public RestObject restCall(HttpMethod httpMethod, Class tClass, Object payload, String path) { + return restCall(httpMethod, tClass, payload, path, Optional.empty()); + } - public void Post(Class tClass, Object requestDetails, String path, RestObject restObject) { - String methodName = "Post"; + /* + user id is needed to be pass as X-RequestorID in new MSO flows like Delete instanceGroup + */ + public RestObject restCall(HttpMethod httpMethod, Class tClass, Object payload, String path, Optional userId) { + String methodName = httpMethod.name(); String url=""; try { MultivaluedHashMap commonHeaders = initMsoClient(); + userId.ifPresent(id->commonHeaders.put("X-RequestorID", Collections.singletonList(id))); url = SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path; - Logging.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, requestDetails); + Logging.logRequest(outgoingRequestsLogger, httpMethod, url, payload); // Change the content length - final Response cres = client.target(url) + final Invocation.Builder restBuilder = client.target(url) .request() .accept(APPLICATION_JSON) - .headers(commonHeaders) - .post(Entity.entity(requestDetails, MediaType.APPLICATION_JSON)); - Logging.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, cres); - final RestObject cresToRestObject = cresToRestObject(cres, tClass); - restObject.set(cresToRestObject.get()); - restObject.setStatusCode(cresToRestObject.getStatusCode()); - restObject.setRaw(cresToRestObject.getRaw()); - - int status = cres.getStatus(); - restObject.setStatusCode (status); + .headers(commonHeaders); - if ( status >= 200 && status <= 299 ) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + REST_API_POST_WAS_SUCCESSFUL_LOG); - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + REST_API_POST_WAS_SUCCESSFUL_LOG); - - } else { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + WITH_STATUS +status+ URL_LOG +url); - } + Invocation restInvocation = payload==null ? + restBuilder.build(httpMethod.name()) : + restBuilder.build(httpMethod.name(), Entity.entity(payload, MediaType.APPLICATION_JSON)); + final Response cres = restInvocation.invoke(); - } catch (Exception e) - { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString()); + Logging.logResponse(outgoingRequestsLogger, httpMethod, url, cres); + return cresToRestObject(cres, tClass); + } + catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString()); throw e; - } - logger.debug(EELFLoggerDelegate.debugLogger, "end {}() => ({}){}", getMethodName(), tClass, restObject); } private RestObject cresToRestObject(Response cres, Class tClass) { @@ -319,10 +317,10 @@ public class RestMsoImplementation implements RestInterface { } catch ( Exception e ) { try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + getMethodCallerName() + " Error reading response entity as " + tClass + ": , e=" + logger.debug(EELFLoggerDelegate.debugLogger, "<== " + getMethodCallerName() + " Error reading response entity as " + tClass + ": , e=" + e.getMessage() + ", Entity=" + rawEntity); } catch (Exception e2) { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + getMethodCallerName() + NO_RESPONSE_ENTITY_LOG + logger.debug(EELFLoggerDelegate.debugLogger, "<== " + getMethodCallerName() + NO_RESPONSE_ENTITY_LOG + e.getMessage()); } } @@ -335,12 +333,12 @@ public class RestMsoImplementation implements RestInterface { } @Override - public void Put(T t, org.onap.vid.changeManagement.RequestDetailsWrapper r, String sourceID, String path, RestObject restObject) { + public void Put(T t, org.onap.vid.changeManagement.RequestDetailsWrapper r, String path, RestObject restObject) { String methodName = "Put"; String url=""; - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + START_LOG); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + START_LOG); try { @@ -354,7 +352,6 @@ public class RestMsoImplementation implements RestInterface { .accept(APPLICATION_JSON) .headers(commonHeaders) //.header("content-length", 201) - //.header("X-FromAppId", sourceID) .put(Entity.entity(r, MediaType.APPLICATION_JSON)); Logging.logResponse(outgoingRequestsLogger, HttpMethod.PUT, url, cres); @@ -364,7 +361,7 @@ public class RestMsoImplementation implements RestInterface { restObject.set(t); } catch ( Exception e ) { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + NO_RESPONSE_ENTITY_LOG + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + NO_RESPONSE_ENTITY_LOG + e.getMessage()); } @@ -372,16 +369,16 @@ public class RestMsoImplementation implements RestInterface { restObject.setStatusCode (status); if ( status >= 200 && status <= 299 ) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + REST_API_POST_WAS_SUCCESSFUL_LOG); - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + REST_API_POST_WAS_SUCCESSFUL_LOG); + logger.info(EELFLoggerDelegate.errorLogger, "<== " + methodName + REST_API_SUCCESSFULL_LOG); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + REST_API_SUCCESSFULL_LOG); } else { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + WITH_STATUS +status+ URL_LOG +url); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_STATUS +status+ URL_LOG +url); } } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString()); throw e; } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestObject.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestObject.java index e5024518b..7ebecba57 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/RestObject.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestObject.java @@ -25,9 +25,6 @@ import com.google.common.base.MoreObjects; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import javax.ws.rs.core.Response; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import static org.onap.vid.utils.Logging.getMethodCallerName; @@ -38,9 +35,7 @@ import static org.onap.vid.utils.Logging.getMethodCallerName; */ public class RestObject { - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - final static ObjectMapper objectMapper = new ObjectMapper(); + static final ObjectMapper objectMapper = new ObjectMapper(); /** * Generic version of the RestObject class. @@ -58,6 +53,12 @@ public class RestObject { public RestObject() { } + public void copyFrom(RestObject src) { + set(src.get()); + setRaw(src.getRaw()); + setStatusCode(src.getStatusCode()); + } + public RestObject(Response cres, Class tClass, EELFLoggerDelegate logger) { String rawEntity = null; @@ -70,10 +71,10 @@ public class RestObject { catch ( Exception e ) { try { this.setRaw(rawEntity); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + getMethodCallerName() + " Error reading response entity as " + tClass + ": , e=" + logger.debug(EELFLoggerDelegate.debugLogger, "<== " + getMethodCallerName() + " Error reading response entity as " + tClass + ": , e=" + e.getMessage() + ", Entity=" + rawEntity); } catch (Exception e2) { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + getMethodCallerName() + " No response entity, this is probably ok, e=" + logger.debug(EELFLoggerDelegate.debugLogger, "<== " + getMethodCallerName() + " No response entity, this is probably ok, e=" + e.getMessage()); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestObjectWithRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestObjectWithRequestInfo.java new file mode 100644 index 000000000..98cc808cd --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestObjectWithRequestInfo.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.mso; + +import org.springframework.http.HttpMethod; + +public class RestObjectWithRequestInfo { + + private final RestObject restObject; + private final String requestedUrl; + private final int httpCode; + private final String rawData; + private final HttpMethod httpMethod; + + public RestObjectWithRequestInfo(HttpMethod httpMethod, String requestedUrl, RestObject restObject, int httpCode, String rawData) { + this.restObject = restObject; + this.requestedUrl = requestedUrl; + this.httpCode = httpCode; + this.rawData = rawData; + this.httpMethod = httpMethod; + } + + public RestObject getRestObject() { + return restObject; + } + + public String getRequestedUrl() { + return requestedUrl; + } + + public int getHttpCode() { + return httpCode; + } + + public String getRawData() { + return rawData; + } + + public HttpMethod getHttpMethod() { + return httpMethod; + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/BaseResourceInstantiationRequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/BaseResourceInstantiationRequestDetails.java new file mode 100644 index 000000000..9ade2abc4 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/BaseResourceInstantiationRequestDetails.java @@ -0,0 +1,142 @@ +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +import java.util.List; + +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; + +@JsonInclude(NON_NULL) +public class BaseResourceInstantiationRequestDetails { + + @JsonProperty("modelInfo") + protected ModelInfo modelInfo; + + @JsonProperty("cloudConfiguration") + protected CloudConfiguration cloudConfiguration; + + @JsonProperty("requestInfo") + protected RequestInfo requestInfo; + + @JsonProperty("platform") + protected Platform platform; + + @JsonProperty("lineOfBusiness") + protected LineOfBusiness lineOfBusiness; + + @JsonProperty("relatedInstanceList") + protected List relatedInstanceList; + + @JsonProperty("requestParameters") + protected RequestParameters requestParameters; + + public BaseResourceInstantiationRequestDetails(@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty(value = "cloudConfiguration", required = true) CloudConfiguration cloudConfiguration, + @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo, + @JsonProperty(value = "platform", required = true) Platform platform, + @JsonProperty(value = "lineOfBusiness", required = true) LineOfBusiness lineOfBusiness, + @JsonProperty(value = "relatedInstanceList", required = true) List relatedInstanceList, + @JsonProperty(value = "requestParameters", required = true) RequestParameters requestParameters) + { + this.modelInfo = modelInfo; + this.cloudConfiguration = cloudConfiguration; + this.requestInfo = requestInfo; + this.platform = platform; + this.lineOfBusiness = lineOfBusiness; + this.relatedInstanceList = relatedInstanceList; + this.requestParameters = requestParameters; + } + + public BaseResourceInstantiationRequestDetails(@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty(value = "cloudConfiguration", required = true) CloudConfiguration cloudConfiguration, + @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo, + @JsonProperty(value = "relatedInstanceList", required = true) List relatedInstanceList, + @JsonProperty(value = "requestParameters", required = true) RequestParameters requestParameters) + { + this.modelInfo = modelInfo; + this.cloudConfiguration = cloudConfiguration; + this.requestInfo = requestInfo; + this.relatedInstanceList = relatedInstanceList; + this.requestParameters = requestParameters; + } + + public static class RequestInfo { + + @JsonInclude(NON_NULL) public final String instanceName; + @JsonInclude(NON_NULL) public final String productFamilyId; + public final String source; + public final boolean suppressRollback; + public final String requestorId; + + public RequestInfo(String instanceName, String productFamilyId, String source, boolean rollbackOnFailure, String requestorId) { + this.instanceName = instanceName; + this.productFamilyId = productFamilyId; + this.source = source; + this.requestorId = requestorId; + // in the FE we are asking for "RollbackOnFailure" but to MSO we are passing the negative value "suppressRollback" + this.suppressRollback = !rollbackOnFailure; + } + } + + public static class Project{ + public final String projectName; + + public Project(String projectName) { + this.projectName = projectName; + } + } + + public static class Platform{ + public final String platformName; + + public Platform(String platformName) { + this.platformName = platformName; + } + } + + public static class LineOfBusiness{ + public final String lineOfBusinessName; + + public LineOfBusiness(String lineOfBusiness) { + this.lineOfBusinessName = lineOfBusiness; + } + } + + @JsonTypeName("relatedInstance") + @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) + public static class RelatedInstance{ + public ModelInfo modelInfo; + @JsonInclude(NON_NULL) public String instanceId; //TODO ask Eylon - is this needed, and if yes, for other fields as well? + @JsonInclude(NON_NULL) public String instanceName; + + public RelatedInstance (@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty (value = "instanceId", required = true) String instanceId){ + this.modelInfo = modelInfo; + this.instanceId = instanceId; + } + + public RelatedInstance (@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty (value = "instanceId", required = true) String instanceId, + @JsonProperty (value = "instanceName", required = true) String instanceName){ + this.modelInfo = modelInfo; + this.instanceId = instanceId; + this.instanceName = instanceName; + } + } + + public static class RequestParameters { + public final List userParams; + + public RequestParameters(List userParams) { + this.userParams = userParams; + } + + public List getUserParams() { + return userParams; + } + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/CloudConfiguration.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/CloudConfiguration.java new file mode 100644 index 000000000..8286ec2b0 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/CloudConfiguration.java @@ -0,0 +1,173 @@ + +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.*; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.HashMap; +import java.util.Map; + + +/** + * fields communicating the cloud configuration in a standard way + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "nodeLocation", + "lcpCloudRegionId", + "tenantId", + "cloudOwner" +}) +public class CloudConfiguration { + + /** + * Location identifier for the node + * + */ + @JsonProperty("nodeLocation") + private String nodeLocation; + /** + * LCP Node Location identifier + * + */ + @JsonProperty("lcpCloudRegionId") + private String lcpCloudRegionId; + /** + * Openstack tenant id + * + */ + @JsonProperty("tenantId") + private String tenantId; + /** + * the cloud owner + * + */ + @JsonProperty("cloudOwner") + private String cloudOwner; + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /** + * Location identifier for the node + * + * @return + * The nodeLocation + */ + @JsonProperty("nodeLocation") + public String getNodeLocation() { + return nodeLocation; + } + + /** + * Location identifier for the node + * + * @param nodeLocation + * The nodeLocation + */ + @JsonProperty("nodeLocation") + public void setNodeLocation(String nodeLocation) { + this.nodeLocation = nodeLocation; + } + + /** + * LCP Node Location identifier + * + * @return + * The lcpCloudRegionId + */ + @JsonProperty("lcpCloudRegionId") + public String getLcpCloudRegionId() { + return lcpCloudRegionId; + } + + /** + * LCP Node Location identifier + * + * @param lcpCloudRegionId + * The lcpCloudRegionId + */ + @JsonProperty("lcpCloudRegionId") + public void setLcpCloudRegionId(String lcpCloudRegionId) { + this.lcpCloudRegionId = lcpCloudRegionId; + } + + /** + * Openstack tenant id + * + * @return + * The tenantId + */ + @JsonProperty("tenantId") + public String getTenantId() { + return tenantId; + } + + /** + * Openstack tenant id + * + * @param tenantId + * The tenantId + */ + @JsonProperty("tenantId") + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + /** + * the cloud owner + * + * @return + * The cloudOwner + */ + @JsonProperty("cloudOwner") + public String getCloudOwner() { + return cloudOwner; + } + + /** + * the cloud owner + * + * @param cloudOwner + * The cloudOwner + */ + @JsonProperty("cloudOwner") + public void setCloudOwner(String cloudOwner) { + this.cloudOwner = cloudOwner; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(nodeLocation).append(lcpCloudRegionId).append(tenantId).append(cloudOwner).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof CloudConfiguration)) { + return false; + } + CloudConfiguration rhs = ((CloudConfiguration) other); + return new EqualsBuilder().append(nodeLocation, rhs.nodeLocation).append(lcpCloudRegionId, rhs.lcpCloudRegionId).append(tenantId, rhs.tenantId).append(cloudOwner, rhs.cloudOwner).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/InstanceGroupInstantiationRequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/InstanceGroupInstantiationRequestDetails.java new file mode 100644 index 000000000..26013412b --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/InstanceGroupInstantiationRequestDetails.java @@ -0,0 +1,48 @@ +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/* Based on this model: + +//{ +// "requestDetails": { +// "modelInfo": { +// "modelType": "instanceGroup", +// "modelVersionId": "ddcbbf3d-f2c1-4ca0-8852-76a807285efc" +// }, +// "requestInfo": { +// "source": "VID", +// "requestorId": "az2016" +// }, +// "relatedInstanceList": [ +// { +// "relatedInstance": { +// "instanceId": "{the relate-to/parent serviceInstanceId}", +// "modelInfo": { +// "modelType": "service", +// "modelVersionId": "b3b7e7d3-ecb9-4a91-8f6d-e60d236e8e77", +// } +// } +// } +// ], +// "requestParameters": { +// "userParams": [] +// } +// } +//} + + */ + +public class InstanceGroupInstantiationRequestDetails extends BaseResourceInstantiationRequestDetails { + + public InstanceGroupInstantiationRequestDetails(@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo, + @JsonProperty(value = "relatedInstanceList", required = true) List relatedInstanceList, + @JsonProperty(value = "requestParameters", required = true) RequestParameters requestParameters) + { + super(modelInfo, null, requestInfo, null, null, relatedInstanceList, requestParameters); + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/ModelInfo.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/ModelInfo.java new file mode 100644 index 000000000..091a241df --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/ModelInfo.java @@ -0,0 +1,279 @@ + +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + + +/** + * fields describing the SDC entity being operated on by the request + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "modelCustomizationName", + "modelCustomizationId", + "modelInvariantId", + "modelVersionId", + "modelName", + "modelNameVersionId", + "modelType", + "modelVersion" +}) +public class ModelInfo { + + /** + * reference to the customized set of parameters associated with a model in a given service context + * + */ + @JsonProperty("modelCustomizationName") + private String modelCustomizationName; + /** + * reference to the customized set of parameters associated with a model in a given service context + * + */ + @JsonProperty("modelCustomizationId") + private String modelCustomizationId; + /** + * Invariant UUID for the model name, irrespective of the version, as defined in SDC--authoritative + * + */ + @JsonProperty("modelInvariantId") + private String modelInvariantId; + /** + * Version id for version + * + */ + @JsonProperty("modelVersionId") + private String modelVersionId; + /** + * name of the model as defined in SDC--not authoritative + * + */ + @JsonProperty("modelName") + private String modelName; + /** + * UUID for the model name and version combination as defined in SDC--authoritative + * + */ + @JsonProperty("modelNameVersionId") + private String modelNameVersionId; + /** + * short description of the entity being operated on + * (Required) + * + */ + @JsonProperty("modelType") + private String modelType; + /** + * the version of the model as defined in SDC--not authoritative + * + */ + @JsonProperty("modelVersion") + private String modelVersion; + + /** + * reference to the customized set of parameters associated with a model in a given service context + * + * @return + * The modelCustomizationName + */ + @JsonProperty("modelCustomizationName") + public String getModelCustomizationName() { + return modelCustomizationName; + } + + /** + * reference to the customized set of parameters associated with a model in a given service context + * + * @param modelCustomizationName + * The modelCustomizationName + */ + @JsonProperty("modelCustomizationName") + public void setModelCustomizationName(String modelCustomizationName) { + this.modelCustomizationName = modelCustomizationName; + } + + /** + * reference to the customized set of parameters associated with a model in a given service context + * + * @return + * The modelCustomizationId + */ + @JsonProperty("modelCustomizationId") + public String getModelCustomizationId() { + return modelCustomizationId; + } + + /** + * reference to the customized set of parameters associated with a model in a given service context + * + * @param modelCustomizationId + * The modelCustomizationId + */ + @JsonProperty("modelCustomizationId") + public void setModelCustomizationId(String modelCustomizationId) { + this.modelCustomizationId = modelCustomizationId; + } + + /** + * Invariant UUID for the model name, irrespective of the version, as defined in SDC--authoritative + * + * @return + * The modelInvariantId + */ + @JsonProperty("modelInvariantId") + public String getModelInvariantId() { + return modelInvariantId; + } + + /** + * Invariant UUID for the model name, irrespective of the version, as defined in SDC--authoritative + * + * @param modelInvariantId + * The modelInvariantId + */ + @JsonProperty("modelInvariantId") + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + /** + * Version id for version + * + * @return + * The modelVersionId + */ + @JsonProperty("modelVersionId") + public String getModelVersionId() { + return modelVersionId; + } + + /** + * Version id for version + * + * @param modelVersionId + * The modelVersionId + */ + @JsonProperty("modelVersionId") + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + + /** + * name of the model as defined in SDC--not authoritative + * + * @return + * The modelName + */ + @JsonProperty("modelName") + public String getModelName() { + return modelName; + } + + /** + * name of the model as defined in SDC--not authoritative + * + * @param modelName + * The modelName + */ + @JsonProperty("modelName") + public void setModelName(String modelName) { + this.modelName = modelName; + } + + /** + * UUID for the model name and version combination as defined in SDC--authoritative + * + * @return + * The modelNameVersionId + */ + @JsonProperty("modelNameVersionId") + public String getModelNameVersionId() { + return modelNameVersionId; + } + + /** + * UUID for the model name and version combination as defined in SDC--authoritative + * + * @param modelNameVersionId + * The modelNameVersionId + */ + @JsonProperty("modelNameVersionId") + public void setModelNameVersionId(String modelNameVersionId) { + this.modelNameVersionId = modelNameVersionId; + } + + /** + * short description of the entity being operated on + * (Required) + * + * @return + * The modelType + */ + @JsonProperty("modelType") + public String getModelType() { + return modelType; + } + + /** + * short description of the entity being operated on + * (Required) + * + * @param modelType + * The modelType + */ + @JsonProperty("modelType") + public void setModelType(String modelType) { + this.modelType = modelType; + } + + /** + * the version of the model as defined in SDC--not authoritative + * + * @return + * The modelVersion + */ + @JsonProperty("modelVersion") + public String getModelVersion() { + return modelVersion; + } + + /** + * the version of the model as defined in SDC--not authoritative + * + * @param modelVersion + * The modelVersion + */ + @JsonProperty("modelVersion") + public void setModelVersion(String modelVersion) { + this.modelVersion = modelVersion; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(modelCustomizationName).append(modelCustomizationId).append(modelInvariantId).append(modelVersionId).append(modelName).append(modelNameVersionId).append(modelType).append(modelVersion).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof ModelInfo)) { + return false; + } + ModelInfo rhs = ((ModelInfo) other); + return new EqualsBuilder().append(modelCustomizationName, rhs.modelCustomizationName).append(modelCustomizationId, rhs.modelCustomizationId).append(modelInvariantId, rhs.modelInvariantId).append(modelVersionId, rhs.modelVersionId).append(modelName, rhs.modelName).append(modelNameVersionId, rhs.modelNameVersionId).append(modelType, rhs.modelType).append(modelVersion, rhs.modelVersion).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/NetworkInstantiationRequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/NetworkInstantiationRequestDetails.java new file mode 100644 index 000000000..d8539f6a9 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/NetworkInstantiationRequestDetails.java @@ -0,0 +1,86 @@ +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/* Based on this model: + + +// { +// "requestDetails": { +// "modelInfo": { +// “modelType”: “network”, +// “modelInvariantId”: “ff5256d1-5a33-55df-13ab-12abad84e7ff”, +// “modelVersionId”: “fe042c22-ba82-43c6-b2f6-8f1fc4164091”, +// “modelName”: “vSAMP12”, +// "modelVersion": "1.0", +// “modelCustomizationName”: “vSAMP12 1”, +// “modelCustomizationId”: “a7f1d08e-b02d-11e6-80f5-76304dec7eb7” +// }, +// “cloudConfiguration”: { +// “lcpCloudRegionId”: “mdt1”, +// “tenantId”: “88a6ca3ee0394ade9403f075db23167e” +// }, +// "requestInfo": { +// “instanceName”: “MSOTEST103a”, +// “productFamilyId”: “a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb”, +// “source”: “VID”, +// “suppressRollback”: false, +// “requestorId”: “az2016” +// }, +// "platform": { +// "platformName": "{some platformName}" +// }, +// "lineOfBusiness": { +// "lineOfBusinessName": "{some string}" +// }, +// "relatedInstanceList": [ +// { +// “relatedInstance”: { +// “instanceId”: “{serviceInstanceId}”, +// “modelInfo”: { +// “modelType”: “service”, +// “modelInvariantId”: “ff3514e3-5a33-55df-13ab-12abad84e7ff”, +// “modelVersionId”: “fe6985cd-ea33-3346-ac12-ab121484a3fe”, +// “modelName”: “{parent service model name}”, +// "modelVersion": "1.0" +// } +// } +// }, +// { +// “relatedInstance”: { +// “instanceId”: “{instanceGroupId}”, +// “modelInfo”: { +// “modelType”: “networkCollection”, +// “modelInvariantId”: “9ea660dc-155f-44d3-b45c-cc7648b4f31c”, +// “modelVersionId”: “bb07aad1-ce2d-40c1-85cb-5392f76bb1ef”, +// “modelName”: “{network collection model name}”, +// "modelVersion": "1.0" +// } +// } +// } + +// ], +// “requestParameters”: { +// “userParams”: [] +// } +// } +// } + + */ + +public class NetworkInstantiationRequestDetails extends BaseResourceInstantiationRequestDetails { + + public NetworkInstantiationRequestDetails(@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty(value = "cloudConfiguration", required = true) CloudConfiguration cloudConfiguration, + @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo, + @JsonProperty(value = "platform", required = true) Platform platform, + @JsonProperty(value = "lineOfBusiness", required = true) LineOfBusiness lineOfBusiness, + @JsonProperty(value = "relatedInstanceList", required = true) List relatedInstanceList, + @JsonProperty(value = "requestParameters", required = true) RequestParameters requestParameters) + { + super(modelInfo, cloudConfiguration, requestInfo, platform, lineOfBusiness, relatedInstanceList, requestParameters); + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfo.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfo.java index a5a10a774..bca643a6d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfo.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/OperationalEnvironmentActivateInfo.java @@ -1,8 +1,7 @@ package org.onap.vid.mso.model; -import org.onap.vid.controllers.OperationalEnvironmentController; - import com.google.common.base.MoreObjects; +import org.onap.vid.controller.OperationalEnvironmentController; public class OperationalEnvironmentActivateInfo extends OperationalEnvironmentController.OperationalEnvironmentActivateBody { private final String userId; diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestInfo.java new file mode 100644 index 000000000..1290361a1 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestInfo.java @@ -0,0 +1,376 @@ + +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.*; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.HashMap; +import java.util.Map; + + +/** + * fields providing general context information for the request + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "billingAccountNumber", + "callbackUrl", + "correlator", + "instanceName", + "orderNumber", + "orderVersion", + "productFamilyId", + "source", + "suppressRollback", + "responseValue", + "requestorId" +}) +public class RequestInfo { + + /** + * billing account associated with the model being operated on + * + */ + @JsonProperty("billingAccountNumber") + private String billingAccountNumber; + /** + * client URL to use for asynchronous responses + * + */ + @JsonProperty("callbackUrl") + private String callbackUrl; + /** + * Optional correlationId for async callback requests + * + */ + @JsonProperty("correlator") + private String correlator; + /** + * Client provided name for the instance being operated on by the operation (note: not guaranteed to be unique) + * + */ + @JsonProperty("instanceName") + private String instanceName; + /** + * reference to an order + * + */ + @JsonProperty("orderNumber") + private String orderNumber; + /** + * order version number + * + */ + @JsonProperty("orderVersion") + private Double orderVersion; + /** + * UUID for the product family associated with the model being operated on + * + */ + @JsonProperty("productFamilyId") + private String productFamilyId; + /** + * source of the request--not authoritative--actual source revealed via authentication + * + */ + @JsonProperty("source") + private String source; + /** + * true or false boolean indicating whether rollbacks should be suppressed on failures + * + */ + @JsonProperty("suppressRollback") + private Boolean suppressRollback; + /** + * Is the user selected value based on the validResponses list provided to complete the manual task + * + */ + @JsonProperty("responseValue") + private String responseValue; + /** + * The id of the person who initiated the completion request + * + */ + @JsonProperty("requestorId") + private String requestorId; + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /** + * billing account associated with the model being operated on + * + * @return + * The billingAccountNumber + */ + @JsonProperty("billingAccountNumber") + public String getBillingAccountNumber() { + return billingAccountNumber; + } + + /** + * billing account associated with the model being operated on + * + * @param billingAccountNumber + * The billingAccountNumber + */ + @JsonProperty("billingAccountNumber") + public void setBillingAccountNumber(String billingAccountNumber) { + this.billingAccountNumber = billingAccountNumber; + } + + /** + * client URL to use for asynchronous responses + * + * @return + * The callbackUrl + */ + @JsonProperty("callbackUrl") + public String getCallbackUrl() { + return callbackUrl; + } + + /** + * client URL to use for asynchronous responses + * + * @param callbackUrl + * The callbackUrl + */ + @JsonProperty("callbackUrl") + public void setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + } + + /** + * Optional correlationId for async callback requests + * + * @return + * The correlator + */ + @JsonProperty("correlator") + public String getCorrelator() { + return correlator; + } + + /** + * Optional correlationId for async callback requests + * + * @param correlator + * The correlator + */ + @JsonProperty("correlator") + public void setCorrelator(String correlator) { + this.correlator = correlator; + } + + /** + * Client provided name for the instance being operated on by the operation (note: not guaranteed to be unique) + * + * @return + * The instanceName + */ + @JsonProperty("instanceName") + public String getInstanceName() { + return instanceName; + } + + /** + * Client provided name for the instance being operated on by the operation (note: not guaranteed to be unique) + * + * @param instanceName + * The instanceName + */ + @JsonProperty("instanceName") + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + /** + * reference to an order + * + * @return + * The orderNumber + */ + @JsonProperty("orderNumber") + public String getOrderNumber() { + return orderNumber; + } + + /** + * reference to an order + * + * @param orderNumber + * The orderNumber + */ + @JsonProperty("orderNumber") + public void setOrderNumber(String orderNumber) { + this.orderNumber = orderNumber; + } + + /** + * order version number + * + * @return + * The orderVersion + */ + @JsonProperty("orderVersion") + public Double getOrderVersion() { + return orderVersion; + } + + /** + * order version number + * + * @param orderVersion + * The orderVersion + */ + @JsonProperty("orderVersion") + public void setOrderVersion(Double orderVersion) { + this.orderVersion = orderVersion; + } + + /** + * UUID for the product family associated with the model being operated on + * + * @return + * The productFamilyId + */ + @JsonProperty("productFamilyId") + public String getProductFamilyId() { + return productFamilyId; + } + + /** + * UUID for the product family associated with the model being operated on + * + * @param productFamilyId + * The productFamilyId + */ + @JsonProperty("productFamilyId") + public void setProductFamilyId(String productFamilyId) { + this.productFamilyId = productFamilyId; + } + + /** + * source of the request--not authoritative--actual source revealed via authentication + * + * @return + * The source + */ + @JsonProperty("source") + public String getSource() { + return source; + } + + /** + * source of the request--not authoritative--actual source revealed via authentication + * + * @param source + * The source + */ + @JsonProperty("source") + public void setSource(String source) { + this.source = source; + } + + /** + * true or false boolean indicating whether rollbacks should be suppressed on failures + * + * @return + * The suppressRollback + */ + @JsonProperty("suppressRollback") + public Boolean getSuppressRollback() { + return suppressRollback; + } + + /** + * true or false boolean indicating whether rollbacks should be suppressed on failures + * + * @param suppressRollback + * The suppressRollback + */ + @JsonProperty("suppressRollback") + public void setSuppressRollback(Boolean suppressRollback) { + this.suppressRollback = suppressRollback; + } + + /** + * Is the user selected value based on the validResponses list provided to complete the manual task + * + * @return + * The responseValue + */ + @JsonProperty("responseValue") + public String getResponseValue() { + return responseValue; + } + + /** + * Is the user selected value based on the validResponses list provided to complete the manual task + * + * @param responseValue + * The responseValue + */ + @JsonProperty("responseValue") + public void setResponseValue(String responseValue) { + this.responseValue = responseValue; + } + + /** + * The id of the person who initiated the completion request + * + * @return + * The requestorId + */ + @JsonProperty("requestorId") + public String getRequestorId() { + return requestorId; + } + + /** + * The id of the person who initiated the completion request + * + * @param requestorId + * The requestorId + */ + @JsonProperty("requestorId") + public void setRequestorId(String requestorId) { + this.requestorId = requestorId; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(billingAccountNumber).append(callbackUrl).append(correlator).append(instanceName).append(orderNumber).append(orderVersion).append(productFamilyId).append(source).append(suppressRollback).append(responseValue).append(requestorId).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof RequestInfo)) { + return false; + } + RequestInfo rhs = ((RequestInfo) other); + return new EqualsBuilder().append(billingAccountNumber, rhs.billingAccountNumber).append(callbackUrl, rhs.callbackUrl).append(correlator, rhs.correlator).append(instanceName, rhs.instanceName).append(orderNumber, rhs.orderNumber).append(orderVersion, rhs.orderVersion).append(productFamilyId, rhs.productFamilyId).append(source, rhs.source).append(suppressRollback, rhs.suppressRollback).append(responseValue, rhs.responseValue).append(requestorId, rhs.requestorId).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestParameters.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestParameters.java new file mode 100644 index 000000000..65e351258 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestParameters.java @@ -0,0 +1,123 @@ + +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.*; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "subscriptionServiceType", + "testApi", + "userParams" +}) +public class RequestParameters { + + @JsonProperty("subscriptionServiceType") + private String subscriptionServiceType; + @JsonProperty("testApi") + private String testApi; + @JsonProperty("userParams") + private List userParams = new ArrayList<>(); + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /** + * + * @return + * The subscriptionServiceType + */ + @JsonProperty("subscriptionServiceType") + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + /** + * + * @param subscriptionServiceType + * The subscriptionServiceType + */ + @JsonProperty("subscriptionServiceType") + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + /** + * + * @return + * The testApi + */ + @JsonProperty("testApi") + public String getTestApi() { + return testApi; + } + + /** + * + * @param testApi + * The testApi + */ + @JsonProperty("testApi") + public void setTestApi(String testApi) { + this.testApi = testApi; + } + + /** + * + * @return + * The userParams + */ + @JsonProperty("userParams") + public List getUserParams() { + return userParams; + } + + /** + * + * @param userParams + * The userParams + */ + @JsonProperty("userParams") + public void setUserParams(List userParams) { + this.userParams = userParams; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(subscriptionServiceType).append(testApi).append(userParams).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof RequestParameters)) { + return false; + } + RequestParameters rhs = ((RequestParameters) other); + return new EqualsBuilder().append(subscriptionServiceType, rhs.subscriptionServiceType).append(testApi, rhs.testApi).append(userParams, rhs.userParams).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestReferences.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestReferences.java new file mode 100644 index 000000000..9c044e113 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/RequestReferences.java @@ -0,0 +1,121 @@ + +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.*; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.HashMap; +import java.util.Map; + + +/** + * provides the instanceId and requestId associated with the request + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "instanceId", + "requestId" +}) +public class RequestReferences { + + /** + * UUID for the service instance + * (Required) + * + */ + @JsonProperty("instanceId") + private String instanceId; + /** + * UUID for the request + * (Required) + * + */ + @JsonProperty("requestId") + private String requestId; + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /** + * UUID for the service instance + * (Required) + * + * @return + * The instanceId + */ + @JsonProperty("instanceId") + public String getInstanceId() { + return instanceId; + } + + /** + * UUID for the service instance + * (Required) + * + * @param instanceId + * The instanceId + */ + @JsonProperty("instanceId") + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + + /** + * UUID for the request + * (Required) + * + * @return + * The requestId + */ + @JsonProperty("requestId") + public String getRequestId() { + return requestId; + } + + /** + * UUID for the request + * (Required) + * + * @param requestId + * The requestId + */ + @JsonProperty("requestId") + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(instanceId).append(requestId).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof RequestReferences)) { + return false; + } + RequestReferences rhs = ((RequestReferences) other); + return new EqualsBuilder().append(instanceId, rhs.instanceId).append(requestId, rhs.requestId).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceDeletionRequestDetails.kt b/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceDeletionRequestDetails.kt new file mode 100644 index 000000000..c41db0861 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceDeletionRequestDetails.kt @@ -0,0 +1,15 @@ +package org.onap.vid.mso.model + +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL +import com.fasterxml.jackson.annotation.JsonProperty + +class ServiceDeletionRequestDetails(val modelInfo: ModelInfo, + val requestInfo: RequestInfo, + val requestParameters: RequestParameters) { + + class RequestInfo(val source: String, val requestorId: String) + + class RequestParameters(@JsonInclude(NON_NULL) @get:JsonProperty("aLaCarte") val aLaCarte: Boolean?, + @JsonInclude(NON_NULL) val testApi: String?) +} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java index 1a54b74cb..c6d89e31f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java @@ -2,12 +2,7 @@ package org.onap.vid.mso.model; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonTypeName; -import org.onap.vid.domain.mso.CloudConfiguration; -import org.onap.vid.domain.mso.ModelInfo; -import org.onap.vid.domain.mso.SubscriberInfo; -import org.onap.vid.model.serviceInstantiation.VfModule; +import org.onap.vid.mso.rest.SubscriberInfo; import java.util.List; import java.util.Map; @@ -62,7 +57,7 @@ public class ServiceInstantiationRequestDetails { public static class RequestInfo { @JsonInclude(NON_NULL) public final String instanceName; - public final String productFamilyId; + @JsonInclude(NON_NULL) public final String productFamilyId; public final String source; public final boolean suppressRollback; public final String requestorId; @@ -86,33 +81,68 @@ public class ServiceInstantiationRequestDetails { } public static class RequestParameters { - + @JsonInclude(NON_NULL) public final String testApi; public final String subscriptionServiceType; public final boolean aLaCarte; - public final List userParams; + public final List userParams; - public RequestParameters(String subscriptionServiceType, boolean aLaCarte, List userParams) { + public RequestParameters(String subscriptionServiceType, boolean aLaCarte, List userParams) { + this(subscriptionServiceType, aLaCarte, userParams, null); + } + + public RequestParameters(String subscriptionServiceType, boolean aLaCarte, List userParams, String testApi) { this.subscriptionServiceType = subscriptionServiceType; this.aLaCarte = aLaCarte; this.userParams = userParams; + this.testApi = testApi; } } - @JsonTypeName("service") - @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) - public static class ServiceInstantiationService{ - public ModelInfo modelInfo = new ModelInfo(); - @JsonInclude(NON_NULL) public String instanceName; - public List> instanceParams; - public ServiceInstantiationVnfList resources; - - public ServiceInstantiationService (ModelInfo modelInfo, String instanceName, List> instanceParams, ServiceInstantiationVnfList vnfs){ - this.modelInfo.setModelType(modelInfo.getModelType()); - this.modelInfo.setModelName(modelInfo.getModelName()); - this.modelInfo.setModelVersionId(modelInfo.getModelVersionId()); - this.instanceName = instanceName; - this.instanceParams = instanceParams; - this.resources = vnfs; + public static class UserParamNameAndValue implements UserParamTypes { + private final String name; + private final String value; + + public UserParamNameAndValue(String name, String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + } + + public static class ServiceInstantiationService implements UserParamTypes { + private final ServiceInstantiationServiceInner serviceInstantiationServiceInner; + + public ServiceInstantiationService(ModelInfo modelInfo, String instanceName, List> instanceParams, ServiceInstantiationVnfList vnfs) { + serviceInstantiationServiceInner = new ServiceInstantiationServiceInner(modelInfo, instanceName, instanceParams, vnfs); + } + + @JsonProperty("service") + public ServiceInstantiationServiceInner getServiceInstantiationServiceInner() { + return serviceInstantiationServiceInner; + } + + private static class ServiceInstantiationServiceInner implements UserParamTypes { + public ModelInfo modelInfo = new ModelInfo(); + @JsonInclude(NON_NULL) + public String instanceName; + public List> instanceParams; + public ServiceInstantiationVnfList resources; + + public ServiceInstantiationServiceInner(ModelInfo modelInfo, String instanceName, List> instanceParams, ServiceInstantiationVnfList vnfs) { + this.modelInfo.setModelType(modelInfo.getModelType()); + this.modelInfo.setModelName(modelInfo.getModelName()); + this.modelInfo.setModelVersionId(modelInfo.getModelVersionId()); + this.instanceName = instanceName; + this.instanceParams = instanceParams; + this.resources = vnfs; + } } } @@ -131,10 +161,10 @@ public class ServiceInstantiationRequestDetails { public final LineOfBusiness lineOfBusiness; public final String productFamilyId; public final List> instanceParams; - @JsonInclude(NON_EMPTY) public final List vfModules; + @JsonInclude(NON_EMPTY) public final List vfModules; @JsonInclude(NON_NULL) public final String instanceName; - public ServiceInstantiationVnf(ModelInfo modelInfo, CloudConfiguration cloudConfiguration, String platform, String lineOfBusiness, String productFamilyId, List> instanceParams, List vfModules, String instanceName) { + public ServiceInstantiationVnf(ModelInfo modelInfo, CloudConfiguration cloudConfiguration, String platform, String lineOfBusiness, String productFamilyId, List> instanceParams, List vfModules, String instanceName) { this.modelInfo = modelInfo; this.cloudConfiguration = cloudConfiguration; this.platform = new Platform(platform); diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/UserParam.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/UserParam.java new file mode 100644 index 000000000..b6c9131ed --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/UserParam.java @@ -0,0 +1,98 @@ + +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.*; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.HashMap; +import java.util.Map; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "name", + "value" +}) +public class UserParam { + + @JsonProperty("name") + private String name; + @JsonProperty("value") + private String value; + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /** + * + * @return + * The name + */ + @JsonProperty("name") + public String getName() { + return name; + } + + /** + * + * @param name + * The name + */ + @JsonProperty("name") + public void setName(String name) { + this.name = name; + } + + /** + * + * @return + * The value + */ + @JsonProperty("value") + public String getValue() { + return value; + } + + /** + * + * @param value + * The value + */ + @JsonProperty("value") + public void setValue(String value) { + this.value = value; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(name).append(value).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof UserParam)) { + return false; + } + UserParam rhs = ((UserParam) other); + return new EqualsBuilder().append(name, rhs.name).append(value, rhs.value).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/UserParamTypes.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/UserParamTypes.java new file mode 100644 index 000000000..8e5a88d28 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/UserParamTypes.java @@ -0,0 +1,4 @@ +package org.onap.vid.mso.model; + +public interface UserParamTypes { +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/VfModuleInstantiationRequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/VfModuleInstantiationRequestDetails.java new file mode 100644 index 000000000..9a3a0c853 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/VfModuleInstantiationRequestDetails.java @@ -0,0 +1,111 @@ +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/* Based on this model: + +{ + "requestDetails": { + "modelInfo": { + “modelType”: “vfModule”, + “modelInvariantId”: “ff5256d2-5a33-55df-13ab-12abad84e7ff”, + “modelVersionId”: “fe6478e5-ea33-3346-ac12-ab121484a3fe”, + “modelCustomizationId”: “856f9806-b01a-11e6-80f5-76304dec7eb7”, + “modelName”: “vSAMP12..base..module-0”, + "modelVersion": "1" + }, + “cloudConfiguration”: { + “lcpCloudRegionId”: “mdt1”, + “tenantId”: “88a6ca3ee0394ade9403f075db23167e” + }, + "requestInfo": { + “instanceName”: “MSOTEST103a-vSAMP12_base_module-0”, + “source”: “VID”, + “suppressRollback”: true, + “requestorId”: “az2016” + }, + "relatedInstanceList": [ + { + // This related instance captures the volumeGroup to attach + “relatedInstance”: { + “instanceId”: “17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c”, + “instanceName”: “MSOTESTVOL103a-vSAMP12_base_module-0_vol”, + “modelInfo”: { + “modelType”: “volumeGroup” + } + } + }, + { + “relatedInstance”: { + “instanceId”: “{serviceInstanceId}”, + “modelInfo”: { + “modelType”: “service”, + “modelInvariantId”: “ff3514e3-5a33-55df-13ab-12abad84e7ff”, + “modelVersionId”: “fe6985cd-ea33-3346-ac12-ab121484a3fe”, + “modelName”: “{parent service model name}”, + "modelVersion": "1.0" + } + } + }, + { + “relatedInstance”: { + “instanceId”: “{vnfInstanceId}”, + "modelInfo": { + “modelType”: “vnf”, + “modelInvariantId”: “ff5256d1-5a33-55df-13ab-12abad84e7ff”, + “modelVersionId”: “fe6478e4-ea33-3346-ac12-ab121484a3fe”, + “modelName”: “vSAMP12”, + "modelVersion": "1.0", + “modelCustomizationName”: “vSAMP12 1”, + “modelCustomizationId”: “a7f1d08e-b02d-11e6-80f5-76304dec7eb7” + } + } + } + ], + “requestParameters”: { + “usePreload”: true, + “userParams”: [] + } + } +} + + + */ + +public class VfModuleInstantiationRequestDetails extends BaseResourceInstantiationRequestDetails { + + public VfModuleInstantiationRequestDetails( + @JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty(value = "cloudConfiguration", required = true) CloudConfiguration cloudConfiguration, + @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo, + @JsonProperty(value = "relatedInstanceList", required = true) List relatedInstanceList, + @JsonProperty(value = "requestParameters", required = true) RequestParametersVfModule requestParameters) + { + super(modelInfo, cloudConfiguration, requestInfo, relatedInstanceList, requestParameters); + } + + public static class RequestParametersVfModule extends BaseResourceInstantiationRequestDetails.RequestParameters { + private final boolean usePreload; + + public RequestParametersVfModule(List userParams, boolean usePreload) { + super(userParams); + this.usePreload = usePreload; + } + + public boolean isUsePreload() { + return usePreload; + } + } + + public static class UserParamMap extends HashMap implements UserParamTypes, Map { + + public UserParamMap() { + super(); + } + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/VfModuleMacro.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/VfModuleMacro.java new file mode 100644 index 000000000..1bb8a37c6 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/VfModuleMacro.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * 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.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; + +public class VfModuleMacro { + + private final ModelInfo modelInfo; + + @JsonInclude(NON_NULL) + private final String instanceName; + + private final List> instanceParams; + + @JsonInclude(NON_NULL) + private final String volumeGroupInstanceName; + + public VfModuleMacro(@JsonProperty("modelInfo") ModelInfo modelInfo, + @JsonProperty("instanceName") String instanceName, + @JsonProperty("volumeGroupName") String volumeGroupInstanceName, + @JsonProperty("instanceParams") List> instanceParams) { + this.modelInfo = modelInfo; + this.modelInfo.setModelType("vfModule"); + this.instanceName = instanceName; + this.instanceParams = instanceParams; + this.volumeGroupInstanceName = volumeGroupInstanceName; + } + + public ModelInfo getModelInfo() { + return modelInfo; + } + + public String getInstanceName() { + return instanceName; + } + + public String getVolumeGroupInstanceName() { + return volumeGroupInstanceName; + } + + public List> getInstanceParams() { + return instanceParams == null ? Collections.emptyList() : instanceParams; + } +} + + diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/VnfInstantiationRequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/VnfInstantiationRequestDetails.java new file mode 100644 index 000000000..4a60c1a51 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/VnfInstantiationRequestDetails.java @@ -0,0 +1,87 @@ +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/* Based on this model: + + +// { +// "requestDetails": { +// "modelInfo": { +// “modelType”: “vnf”, +// “modelInvariantId”: “ff5256d1-5a33-55df-13ab-12abad84e7ff”, +// “modelVersionId”: “fe042c22-ba82-43c6-b2f6-8f1fc4164091”, +// “modelName”: “vSAMP12”, +// "modelVersion": "1.0", +// “modelCustomizationName”: “vSAMP12 1”, +// “modelCustomizationId”: “a7f1d08e-b02d-11e6-80f5-76304dec7eb7” +// }, +// “cloudConfiguration”: { +// “lcpCloudRegionId”: “mdt1”, +// “tenantId”: “88a6ca3ee0394ade9403f075db23167e” +// }, +// "requestInfo": { +// “instanceName”: “MSOTEST103a”, +// “productFamilyId”: “a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb”, +// “source”: “VID”, +// “suppressRollback”: false, +// “requestorId”: “az2016” +// }, +// "platform": { +// "platformName": "{some platformName}" +// }, +// "lineOfBusiness": { +// "lineOfBusinessName": "{some string}" +// }, +// "relatedInstanceList": [ +// { +// “relatedInstance”: { +// “instanceId”: “{serviceInstanceId}”, +// “modelInfo”: { +// “modelType”: “service”, +// “modelInvariantId”: “ff3514e3-5a33-55df-13ab-12abad84e7ff”, +// “modelVersionId”: “fe6985cd-ea33-3346-ac12-ab121484a3fe”, +// “modelName”: “{parent service model name}”, +// "modelVersion": "1.0" +// } +// } +// }, +// { +// “relatedInstance”: { +// “instanceId”: “{instanceGroupId}”, +// “modelInfo”: { +// “modelType”: “networkCollection”, +// “modelInvariantId”: “9ea660dc-155f-44d3-b45c-cc7648b4f31c”, +// “modelVersionId”: “bb07aad1-ce2d-40c1-85cb-5392f76bb1ef”, +// “modelName”: “{network collection model name}”, +// "modelVersion": "1.0" +// } +// } +// } + +// ], +// “requestParameters”: { +// “userParams”: [] +// } +// } +// } + + */ + +public class VnfInstantiationRequestDetails extends BaseResourceInstantiationRequestDetails { + + public VnfInstantiationRequestDetails( + @JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty(value = "cloudConfiguration", required = true) CloudConfiguration cloudConfiguration, + @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo, + @JsonProperty(value = "platform", required = true) Platform platform, + @JsonProperty(value = "lineOfBusiness", required = true) LineOfBusiness lineOfBusiness, + @JsonProperty(value = "relatedInstanceList", required = true) List relatedInstanceList, + @JsonProperty(value = "requestParameters", required = true) RequestParameters requestParameters) + { + super(modelInfo, cloudConfiguration, requestInfo, platform, lineOfBusiness, relatedInstanceList, requestParameters); + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/VolumeGroupRequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/VolumeGroupRequestDetails.java new file mode 100644 index 000000000..d60c9975b --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/VolumeGroupRequestDetails.java @@ -0,0 +1,18 @@ +package org.onap.vid.mso.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class VolumeGroupRequestDetails extends BaseResourceInstantiationRequestDetails { + + public VolumeGroupRequestDetails( + @JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo, + @JsonProperty(value = "cloudConfiguration", required = true) CloudConfiguration cloudConfiguration, + @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo, + @JsonProperty(value = "relatedInstanceList", required = true) List relatedInstanceList, + @JsonProperty(value = "requestParameters", required = true) VfModuleInstantiationRequestDetails.RequestParametersVfModule requestParameters) + { + super(modelInfo, cloudConfiguration, requestInfo, relatedInstanceList, requestParameters); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/AsyncRequestStatus.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/AsyncRequestStatus.java index 4c3dca26f..7d844feed 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/AsyncRequestStatus.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/AsyncRequestStatus.java @@ -23,7 +23,6 @@ package org.onap.vid.mso.rest; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import org.onap.vid.domain.mso.RequestStatus; /** * Represent response for: GET orchestrationRequests @@ -53,16 +52,29 @@ public class AsyncRequestStatus { } public String requestId; + public String requestScope; /** * The instance ids. */ public InstanceReferences instanceReferences; + + /** + * The request details. + */ + public RequestDetails requestDetails; + /** * The request status. */ public RequestStatus requestStatus; + + /** + * The time of start. + */ + public String startTime; + } @JsonIgnoreProperties(ignoreUnknown = true) @@ -71,5 +83,18 @@ public class AsyncRequestStatus { public String serviceInstanceId; } + @JsonIgnoreProperties(ignoreUnknown = true) + public static class RequestDetails { + + public RequestInfo requestInfo; + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class RequestInfo { + + public String instanceName; + } + + } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/AsyncRequestStatusList.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/AsyncRequestStatusList.java new file mode 100644 index 000000000..04ced39fb --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/AsyncRequestStatusList.java @@ -0,0 +1,17 @@ +package org.onap.vid.mso.rest; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class AsyncRequestStatusList { + AsyncRequestStatusList(@JsonProperty("requestList") List requestList) { + this.requestList = requestList; + } + + public List getRequestList() { + return requestList; + } + + private final List requestList; +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/InstanceIds.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/InstanceIds.java new file mode 100644 index 000000000..5e1c5ce88 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/InstanceIds.java @@ -0,0 +1,202 @@ + +package org.onap.vid.mso.rest; + +import com.fasterxml.jackson.annotation.*; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.HashMap; +import java.util.Map; + + +/** + * instanceIds that may be associated with a particular request + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "networkInstanceId", + "serviceInstanceId", + "vfModuleInstanceId", + "vnfInstanceId", + "volumeGroupInstanceId" +}) +public class InstanceIds { + + /** + * UUID for the network instance (if any) + * + */ + @JsonProperty("networkInstanceId") + private String networkInstanceId; + /** + * UUID for the service instance + * + */ + @JsonProperty("serviceInstanceId") + private String serviceInstanceId; + /** + * UUID for the vfModule instance (if any) + * + */ + @JsonProperty("vfModuleInstanceId") + private String vfModuleInstanceId; + /** + * UUID for the vnf instance (if any) + * + */ + @JsonProperty("vnfInstanceId") + private String vnfInstanceId; + /** + * UUID for the volume group instance (if any) + * + */ + @JsonProperty("volumeGroupInstanceId") + private String volumeGroupInstanceId; + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /** + * UUID for the network instance (if any) + * + * @return + * The networkInstanceId + */ + @JsonProperty("networkInstanceId") + public String getNetworkInstanceId() { + return networkInstanceId; + } + + /** + * UUID for the network instance (if any) + * + * @param networkInstanceId + * The networkInstanceId + */ + @JsonProperty("networkInstanceId") + public void setNetworkInstanceId(String networkInstanceId) { + this.networkInstanceId = networkInstanceId; + } + + /** + * UUID for the service instance + * + * @return + * The serviceInstanceId + */ + @JsonProperty("serviceInstanceId") + public String getServiceInstanceId() { + return serviceInstanceId; + } + + /** + * UUID for the service instance + * + * @param serviceInstanceId + * The serviceInstanceId + */ + @JsonProperty("serviceInstanceId") + public void setServiceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } + + /** + * UUID for the vfModule instance (if any) + * + * @return + * The vfModuleInstanceId + */ + @JsonProperty("vfModuleInstanceId") + public String getVfModuleInstanceId() { + return vfModuleInstanceId; + } + + /** + * UUID for the vfModule instance (if any) + * + * @param vfModuleInstanceId + * The vfModuleInstanceId + */ + @JsonProperty("vfModuleInstanceId") + public void setVfModuleInstanceId(String vfModuleInstanceId) { + this.vfModuleInstanceId = vfModuleInstanceId; + } + + /** + * UUID for the vnf instance (if any) + * + * @return + * The vnfInstanceId + */ + @JsonProperty("vnfInstanceId") + public String getVnfInstanceId() { + return vnfInstanceId; + } + + /** + * UUID for the vnf instance (if any) + * + * @param vnfInstanceId + * The vnfInstanceId + */ + @JsonProperty("vnfInstanceId") + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + /** + * UUID for the volume group instance (if any) + * + * @return + * The volumeGroupInstanceId + */ + @JsonProperty("volumeGroupInstanceId") + public String getVolumeGroupInstanceId() { + return volumeGroupInstanceId; + } + + /** + * UUID for the volume group instance (if any) + * + * @param volumeGroupInstanceId + * The volumeGroupInstanceId + */ + @JsonProperty("volumeGroupInstanceId") + public void setVolumeGroupInstanceId(String volumeGroupInstanceId) { + this.volumeGroupInstanceId = volumeGroupInstanceId; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(networkInstanceId).append(serviceInstanceId).append(vfModuleInstanceId).append(vnfInstanceId).append(volumeGroupInstanceId).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof InstanceIds)) { + return false; + } + InstanceIds rhs = ((InstanceIds) other); + return new EqualsBuilder().append(networkInstanceId, rhs.networkInstanceId).append(serviceInstanceId, rhs.serviceInstanceId).append(vfModuleInstanceId, rhs.vfModuleInstanceId).append(vnfInstanceId, rhs.vnfInstanceId).append(volumeGroupInstanceId, rhs.volumeGroupInstanceId).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java index 37600f7b9..2ff337653 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java @@ -22,10 +22,6 @@ package org.onap.vid.mso.rest; import com.google.common.collect.ImmutableMap; import io.joshworks.restclient.http.HttpResponse; -import java.util.HashMap; -import java.util.Map; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; import org.apache.commons.codec.binary.Base64; import org.eclipse.jetty.util.security.Password; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; @@ -35,17 +31,21 @@ import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.client.SyncRestClient; import org.onap.vid.model.RequestReferencesContainer; import org.onap.vid.mso.*; +import org.onap.vid.utils.Logging; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -import org.onap.vid.utils.Logging; +import java.util.HashMap; +import java.util.Map; /** * Created by pickjonathan on 21/06/2017. */ -public class MsoRestClientNew implements MsoInterface { +public class MsoRestClientNew extends RestMsoImplementation implements MsoInterface { /** * The Constant dateFormat. @@ -70,7 +70,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper createSvcInstance(RequestDetails requestDetails, String endpoint) { String methodName = "createSvcInstance "; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return createInstance(requestDetails, path); @@ -79,7 +79,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper createE2eSvcInstance(Object requestDetails, String endpoint) { String methodName = "createE2eSvcInstance "; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return createInstance(requestDetails, path); @@ -89,7 +89,7 @@ public class MsoRestClientNew implements MsoInterface { public MsoResponseWrapper createVnf(RequestDetails requestDetails, String endpoint) { String methodName = "createVnf"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return createInstance(requestDetails, path); @@ -99,7 +99,7 @@ public class MsoRestClientNew implements MsoInterface { public MsoResponseWrapper createNwInstance(RequestDetails requestDetails, String endpoint) { String methodName = "createNwInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return createInstance(requestDetails, path); @@ -108,7 +108,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper createVolumeGroupInstance(RequestDetails requestDetails, String endpoint) { String methodName = "createVolumeGroupInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return createInstance(requestDetails, path); @@ -117,7 +117,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper createVfModuleInstance(RequestDetails requestDetails, String endpoint) { String methodName = "createVfModuleInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return createInstance(requestDetails, path); @@ -126,7 +126,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper scaleOutVFModuleInstance(RequestDetailsWrapper requestDetailsWrapper, String endpoint) { String methodName = "scaleOutVFModuleInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return createInstance(requestDetailsWrapper, path); } @@ -134,7 +134,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper createConfigurationInstance(org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String endpoint) { String methodName = "createConfigurationInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return createInstance(requestDetailsWrapper, path); @@ -143,7 +143,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper deleteE2eSvcInstance(Object requestDetails, String endpoint) { String methodName = "deleteE2eSvcInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return deleteInstance(requestDetails, path); } @@ -151,7 +151,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper deleteSvcInstance(RequestDetails requestDetails, String endpoint) { String methodName = "deleteSvcInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return deleteInstance(requestDetails, path); } @@ -159,15 +159,17 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper unassignSvcInstance(RequestDetails requestDetails, String endpoint) { String methodName = "unassignSvcInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); - HttpResponse response = client.post(endpoint, commonHeaders, requestDetails, String.class); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); + String path = baseUrl + endpoint; + + HttpResponse response = client.post(path, commonHeaders, requestDetails, String.class); return MsoUtil.wrapResponse(response); } @Override public MsoResponseWrapper deleteVnf(RequestDetails requestDetails, String endpoint) { String methodName = "deleteVnf"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return deleteInstance(requestDetails, path); @@ -176,7 +178,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper deleteVfModule(RequestDetails requestDetails, String endpoint) { String methodName = "deleteVfModule"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return deleteInstance(requestDetails, path); @@ -185,7 +187,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper deleteVolumeGroupInstance(RequestDetails requestDetails, String endpoint) { String methodName = "deleteVolumeGroupInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return deleteInstance(requestDetails, path); @@ -194,59 +196,50 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String endpoint) { String methodName = "deleteNwInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return deleteInstance(requestDetails, path); } @Override - public MsoResponseWrapper getOrchestrationRequest(String endpoint) { + public MsoResponseWrapper getOrchestrationRequest(String t, String sourceId, String endpoint, RestObject restObject, boolean warpException) { String path = baseUrl + endpoint; HttpResponse response = client.get(path, commonHeaders, new HashMap<>(), String.class); return MsoUtil.wrapResponse(response); } - public MsoResponseWrapper getManualTasks(String endpoint) { + @Override + public MsoResponseWrapper getOrchestrationRequest(String endpoint) { String path = baseUrl + endpoint; HttpResponse response = client.get(path, commonHeaders, new HashMap<>(), String.class); return MsoUtil.wrapResponse(response); } - public MsoResponseWrapper getOrchestrationRequestsForDashboard(String t, String sourceId, String path, RestObject restObject) { - String methodName = "getOrchestrationRequestsForDashboard"; - logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START); - - try { - MsoResponseWrapper w = getOrchestrationRequest(path); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); - - return w; + public MsoResponseWrapper getManualTasks(String endpoint) { + String path = baseUrl + endpoint; - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - throw e; - } + HttpResponse response = client.get(path, commonHeaders, new HashMap<>(), String.class); + return MsoUtil.wrapResponse(response); } public MsoResponseWrapper getManualTasksByRequestId(String t, String sourceId, String endpoint, RestObject restObject) { String methodName = "getManualTasksByRequestId"; - logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(methodName + START); try { String path = baseUrl + endpoint; MsoResponseWrapper w =getManualTasks(path); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " w=" + w.getResponse()); return w; } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } } @@ -254,19 +247,19 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper completeManualTask(RequestDetails requestDetails, String t, String sourceId, String endpoint, RestObject restObject) { String methodName = "completeManualTask"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Complete "); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " calling Complete "); try { String path = baseUrl + endpoint; HttpResponse response = client.post(path, commonHeaders, requestDetails, String.class); MsoResponseWrapper w = MsoUtil.wrapResponse(response); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " w=" + w.getResponse()); return w; } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } } @@ -274,7 +267,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper replaceVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String endpoint) { String methodName = "replaceVnf"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; return replaceInstance(requestDetails, path); } @@ -283,7 +276,7 @@ public class MsoRestClientNew implements MsoInterface { public MsoResponseWrapper deleteConfiguration(org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String pmc_endpoint) { String methodName = "deleteConfiguration"; logger.debug(EELFLoggerDelegate.debugLogger, - dateFormat.format(new Date()) + "<== " + methodName + START); + methodName + START); String path = baseUrl + pmc_endpoint; return deleteInstance(requestDetailsWrapper, path); @@ -292,7 +285,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper setConfigurationActiveStatus(RequestDetails request, String endpoint) { String methodName = "setConfigurationActiveStatus"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); try { String path = baseUrl + endpoint; @@ -302,8 +295,8 @@ public class MsoRestClientNew implements MsoInterface { HttpResponse response = client.post(path, commonHeaders, request, String.class); return MsoUtil.wrapResponse(response); } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.info(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } } @@ -311,7 +304,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper setPortOnConfigurationStatus(RequestDetails request, String endpoint) { String methodName = "setPortOnConfigurationStatus"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); try { String path = baseUrl + endpoint; @@ -320,8 +313,8 @@ public class MsoRestClientNew implements MsoInterface { HttpResponse response = client.post(path, commonHeaders, request, String.class); return MsoUtil.wrapResponse(response); } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.info(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } } @@ -335,28 +328,29 @@ public class MsoRestClientNew implements MsoInterface { public MsoResponseWrapper replaceInstance(org.onap.vid.changeManagement.RequestDetails request, String path) { String methodName = "replaceInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Replace VNF, path =[" + path + "]"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " calling Replace VNF, path =[" + path + "]"); + RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); + requestDetailsWrapper.requestDetails = new MsoRequestDetails(request); - HttpResponse response = client.post(path, commonHeaders, request, String.class); + HttpResponse response = client.post(path, commonHeaders, requestDetailsWrapper, String.class); MsoResponseWrapper msoResponseWrapperObject = MsoUtil.wrapResponse(response); int status = msoResponseWrapperObject.getStatus(); if (status == 202) { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + + logger.debug(EELFLoggerDelegate.debugLogger, methodName + ",post succeeded, msoResponseWrapperObject response:" + msoResponseWrapperObject.getResponse()); } else { - logger.error(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + + logger.error(EELFLoggerDelegate.debugLogger, methodName + ": post failed, msoResponseWrapperObject status" + status + ", response:" + msoResponseWrapperObject.getResponse()); - // TODO } return msoResponseWrapperObject; } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.info(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } @@ -365,7 +359,7 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper updateVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String endpoint) { String methodName = "updateVnf"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); String path = baseUrl + endpoint; RequestDetailsWrapper wrapper = new RequestDetailsWrapper(); @@ -375,20 +369,22 @@ public class MsoRestClientNew implements MsoInterface { public MsoResponseWrapper updateInstance(org.onap.vid.changeManagement.RequestDetails request, String path) { String methodName = "updateInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " calling Delete, path =[" + path + "]"); - HttpResponse response = client.post(path, commonHeaders, request, String.class); + RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); + requestDetailsWrapper.requestDetails = new MsoRequestDetails(request); + HttpResponse response = client.put(path, commonHeaders, requestDetailsWrapper, String.class); MsoResponseWrapper w = MsoUtil.wrapResponse(response); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " w=" + w.getResponse()); return w; } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.info(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } @@ -396,16 +392,16 @@ public class MsoRestClientNew implements MsoInterface { public void setServiceInstanceStatus(RequestDetails requestDetails, String t, String sourceId, String endpoint, RestObject restObject) { String methodName = "activateServiceInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start "); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start "); try { String path = baseUrl + endpoint; HttpResponse response = client.post(path, commonHeaders, requestDetails, String.class); MsoResponseWrapper w = MsoUtil.wrapResponse(response); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w =" + w.getResponse()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " w =" + w.getResponse()); } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } } @@ -413,16 +409,16 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper removeRelationshipFromServiceInstance(RequestDetails requestDetails, String endpoint) { String methodName = "removeRelationshipFromServiceInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Remove relationship from service instance, path =[" + endpoint + "]"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " calling Remove relationship from service instance, path =[" + endpoint + "]"); String path = baseUrl + endpoint; HttpResponse response = client.post(path, commonHeaders, requestDetails, String.class); return MsoUtil.wrapResponse(response); } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.info(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } } @@ -430,43 +426,45 @@ public class MsoRestClientNew implements MsoInterface { @Override public MsoResponseWrapper addRelationshipToServiceInstance(RequestDetails requestDetails, String addRelationshipsPath) { String methodName = "addRelationshipToServiceInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Add relationship to service instance, path =[" + addRelationshipsPath + "]"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " calling Add relationship to service instance, path =[" + addRelationshipsPath + "]"); String path = baseUrl + addRelationshipsPath; HttpResponse response = client.post(path, commonHeaders, requestDetails, String.class); return MsoUtil.wrapResponse(response); } catch (Exception e) { - logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.info(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } } @Override - public HttpResponse get(String path, Class responseClass) { + public HttpResponse get(String endpoint, Class responseClass) { + String path = baseUrl + endpoint; return client.get(path, commonHeaders, new HashMap<>(), responseClass); } @Override - public HttpResponse post(String path, RequestDetailsWrapper requestDetailsWrapper, - Class responseClass) { + public HttpResponse post(String endpoint, RequestDetailsWrapper requestDetailsWrapper, Class responseClass) { + String path = baseUrl + endpoint; + return client.post(path, commonHeaders, requestDetailsWrapper, responseClass); } - private MsoResponseWrapper createInstance(Object request, String endpoint) { + private MsoResponseWrapper createInstance(Object request, String path) { String methodName = "createInstance"; - logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(methodName + START); try { - HttpResponse response = client.post(endpoint, commonHeaders, request, String.class); + HttpResponse response = client.post(path, commonHeaders, request, String.class); return MsoUtil.wrapResponse(response); } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } } @@ -481,20 +479,20 @@ public class MsoRestClientNew implements MsoInterface { */ private MsoResponseWrapper deleteInstance(Object request, String path) { String methodName = "deleteInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + START); try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " calling Delete, path =[" + path + "]"); HttpResponse response = client.delete(path, commonHeaders, request, String.class); MsoResponseWrapper w = MsoUtil.wrapResponse(response); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " w=" + w.getResponse()); return w; } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "." + methodName + e.toString()); throw e; } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RelatedInstance.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RelatedInstance.java index 3fd4cd4d1..2f64e3a56 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RelatedInstance.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RelatedInstance.java @@ -20,40 +20,92 @@ package org.onap.vid.mso.rest; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Generated; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.*; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; +import org.onap.vid.mso.model.ModelInfo; + +import java.util.HashMap; +import java.util.Map; /** * modelInfo and optional instanceId and instanceName for a model related to the modelInfo being operated on. */ @JsonInclude(JsonInclude.Include.NON_NULL) -@Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "instanceName", "instanceId", "modelInfo" }) -public class RelatedInstance extends org.onap.vid.domain.mso.RelatedInstance{ +public class RelatedInstance { + + /** + * optional name for the instance Id of the related model + * + */ + @JsonProperty("instanceName") + private String instanceName; + /** + * instance Id for the related model + * + */ + @JsonProperty("instanceId") + private String instanceId; /** The model info. */ @JsonProperty("modelInfo") - private org.onap.vid.domain.mso.ModelInfo modelInfo; + private ModelInfo modelInfo; /** The additional properties. */ @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); + + /** + * optional name for the instance Id of the related model + * + * @return + * The instanceName + */ + @JsonProperty("instanceName") + public String getInstanceName() { + return instanceName; + } + + /** + * optional name for the instance Id of the related model + * + * @param instanceName + * The instanceName + */ + @JsonProperty("instanceName") + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } + + /** + * instance Id for the related model + * + * @return + * The instanceId + */ + @JsonProperty("instanceId") + public String getInstanceId() { + return instanceId; + } + + /** + * instance Id for the related model + * + * @param instanceId + * The instanceId + */ + @JsonProperty("instanceId") + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } /** * (Required). @@ -61,7 +113,7 @@ public class RelatedInstance extends org.onap.vid.domain.mso.RelatedInstance{ * @return The modelInfo */ @JsonProperty("modelInfo") - public org.onap.vid.domain.mso.ModelInfo getModelInfo() { + public ModelInfo getModelInfo() { return modelInfo; } @@ -71,7 +123,7 @@ public class RelatedInstance extends org.onap.vid.domain.mso.RelatedInstance{ * @param modelInfo The modelInfo */ @JsonProperty("modelInfo") - public void setModelInfo(org.onap.vid.domain.mso.ModelInfo modelInfo) { + public void setModelInfo(ModelInfo modelInfo) { this.modelInfo = modelInfo; } @@ -115,7 +167,7 @@ public class RelatedInstance extends org.onap.vid.domain.mso.RelatedInstance{ if (other == this) { return true; } - if ((other instanceof RelatedInstance) == false) { + if (!(other instanceof RelatedInstance)) { return false; } RelatedInstance rhs = ((RelatedInstance) other); diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RelatedModel.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RelatedModel.java deleted file mode 100644 index 36487c596..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RelatedModel.java +++ /dev/null @@ -1,125 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.mso.rest; - -import java.util.HashMap; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; - - -/** - * modelInfo and optional instance id for a model related to the modelInfo being operated on. - */ -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "instanceId", - "modelInfo" -}) -public class RelatedModel extends org.onap.vid.domain.mso.RelatedModel { - - /** (Required). */ - @JsonProperty("modelInfo") - private org.onap.vid.domain.mso.ModelInfo modelInfo; - -// /** The related model object instance list. */ -// @JsonProperty("instanceId") -// private org.onap.vid.domain.mso.InstanceIds instanceId; - - /** The additional properties. */ - @JsonIgnore - private Map additionalProperties = new HashMap(); - - /** - * (Required). - * - * @return The modelInfo - */ - @JsonProperty("modelInfo") - public org.onap.vid.domain.mso.ModelInfo getModelInfo() { - return modelInfo; - } - - /** - * (Required). - * - * @param modelInfo The modelInfo - */ - @JsonProperty("modelInfo") - public void setModelInfo(org.onap.vid.domain.mso.ModelInfo modelInfo) { - this.modelInfo = modelInfo; - } - - /* (non-Javadoc) - * @see org.onap.vid.domain.mso.RelatedModel#toString() - */ - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } - - /* (non-Javadoc) - * @see org.onap.vid.domain.mso.RelatedModel#getAdditionalProperties() - */ - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - /* (non-Javadoc) - * @see org.onap.vid.domain.mso.RelatedModel#setAdditionalProperty(java.lang.String, java.lang.Object) - */ - @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } - - /* (non-Javadoc) - * @see org.onap.vid.domain.mso.RelatedModel#hashCode() - */ - @Override - public int hashCode() { - return new HashCodeBuilder().append(getInstanceId()).append(modelInfo).append(additionalProperties).toHashCode(); - } - - /* (non-Javadoc) - * @see org.onap.vid.domain.mso.RelatedModel#equals(java.lang.Object) - */ - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - if ((other instanceof RelatedModel) == false) { - return false; - } - RelatedModel rhs = ((RelatedModel) other); - return new EqualsBuilder().append(getInstanceId(), rhs.getInstanceId()).append(modelInfo, rhs.modelInfo).append(additionalProperties, rhs.additionalProperties).isEquals(); - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/Request.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/Request.java index ee1652e75..91739937a 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/Request.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/Request.java @@ -20,44 +20,89 @@ package org.onap.vid.mso.rest; -//import java.util.HashMap; -//import java.util.Map; -//import javax.annotation.Generated; - -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.onap.vid.domain.mso.InstanceIds; -import org.onap.vid.domain.mso.RequestStatus; -//import com.fasterxml.jackson.annotation.JsonAnyGetter; -//import com.fasterxml.jackson.annotation.JsonAnySetter; -//import com.fasterxml.jackson.annotation.JsonCreator; -//import com.fasterxml.jackson.annotation.JsonIgnore; -//import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -//import com.fasterxml.jackson.annotation.JsonPropertyOrder; -//import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.annotation.*; import org.apache.commons.lang.builder.EqualsBuilder; -//import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import java.util.HashMap; +import java.util.Map; /** * request structure. */ -public class Request extends org.onap.vid.domain.mso.Request { +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "finishTime", + "instanceIds", + "requestDetails", + "requestId", + "requestScope", + "requestStatus", + "requestType", + "startTime" +}) +public class Request { /** The instance ids. */ + @JsonProperty("instanceIds") private InstanceIds instanceIds; /** The request details. */ + @JsonProperty("requestDetails") private RequestDetails requestDetails; /** The request status. */ + @JsonProperty("requestStatus") private RequestStatus requestStatus; - - + + /** + * Date and time the request was finished in GMT with the following sample format: Wed, 15 Oct 2014 13:01:52 GMT + * + */ + @JsonProperty("finishTime") + private String finishTime; + + /** + * UUID for the request generated by the instantiation service + * (Required) + * + */ + @JsonProperty("requestId") + private String requestId; + + /** + * short description of the entity being operated on + * (Required) + * + */ + @JsonProperty("requestScope") + private String requestScope; + + /** + * short description of the action being performed on the requestScope + * (Required) + * + */ + @JsonProperty("requestType") + private String requestType; + + /** + * Date and time the request was created in GMT with the following sample format: Wed, 15 Oct 2014 13:01:52 GMT + * (Required) + * + */ + @JsonProperty("startTime") + private String startTime; + + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /* (non-Javadoc) - * @see org.onap.vid.domain.mso.Request#getInstanceIds() + * @see org.openecomp.vid.domain.mso.Request#getInstanceIds() */ @JsonProperty("instanceIds") public InstanceIds getInstanceIds() { @@ -115,32 +160,154 @@ public class Request extends org.onap.vid.domain.mso.Request { this.requestStatus = requestStatus; } - - /* (non-Javadoc) - * @see org.onap.vid.domain.mso.Request#toString() + /** + * Date and time the request was finished in GMT with the following sample format: Wed, 15 Oct 2014 13:01:52 GMT + * + * @return + * The finishTime + */ + @JsonProperty("finishTime") + public String getFinishTime() { + return finishTime; + } + + /** + * Date and time the request was finished in GMT with the following sample format: Wed, 15 Oct 2014 13:01:52 GMT + * + * @param finishTime + * The finishTime + */ + @JsonProperty("finishTime") + public void setFinishTime(String finishTime) { + this.finishTime = finishTime; + } + + /** + * UUID for the request generated by the instantiation service + * (Required) + * + * @return + * The requestId + */ + @JsonProperty("requestId") + public String getRequestId() { + return requestId; + } + + /** + * UUID for the request generated by the instantiation service + * (Required) + * + * @param requestId + * The requestId */ + @JsonProperty("requestId") + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + /** + * short description of the entity being operated on + * (Required) + * + * @return + * The requestScope + */ + @JsonProperty("requestScope") + public String getRequestScope() { + return requestScope; + } + + /** + * short description of the entity being operated on + * (Required) + * + * @param requestScope + * The requestScope + */ + @JsonProperty("requestScope") + public void setRequestScope(String requestScope) { + this.requestScope = requestScope; + } + + /** + * short description of the action being performed on the requestScope + * (Required) + * + * @return + * The requestType + */ + @JsonProperty("requestType") + public String getRequestType() { + return requestType; + } + + /** + * short description of the action being performed on the requestScope + * (Required) + * + * @param requestType + * The requestType + */ + @JsonProperty("requestType") + public void setRequestType(String requestType) { + this.requestType = requestType; + } + + /** + * Date and time the request was created in GMT with the following sample format: Wed, 15 Oct 2014 13:01:52 GMT + * (Required) + * + * @return + * The startTime + */ + @JsonProperty("startTime") + public String getStartTime() { + return startTime; + } + + /** + * Date and time the request was created in GMT with the following sample format: Wed, 15 Oct 2014 13:01:52 GMT + * (Required) + * + * @param startTime + * The startTime + */ + @JsonProperty("startTime") + public void setStartTime(String startTime) { + this.startTime = startTime; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); } - - /* (non-Javadoc) - * @see org.onap.vid.domain.mso.Request#equals(java.lang.Object) - */ + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37).append(getFinishTime()).append(getInstanceIds()).append(getRequestDetails()).append(getRequestId()).append(getRequestScope()).append(getRequestStatus()).append(getRequestType()).append(getStartTime()).append(getAdditionalProperties()).toHashCode(); + } + @Override public boolean equals(Object other) { if (other == this) { return true; } - if ((other instanceof Request) == false) { + if (!(other instanceof Request)) { return false; } Request rhs = ((Request) other); return new EqualsBuilder().append(getFinishTime(), rhs.getFinishTime()).append(getInstanceIds(), rhs.getInstanceIds()).append(getRequestDetails(), rhs.getRequestDetails()).append(getRequestId(), rhs.getRequestId()).append(getRequestScope(), rhs.getRequestScope()).append(getRequestStatus(), rhs.getRequestStatus()).append(getRequestType(), rhs.getRequestType()).append(getStartTime(), rhs.getStartTime()).append(getAdditionalProperties(), rhs.getAdditionalProperties()).isEquals(); } - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37).append(getFinishTime()).append(getInstanceIds()).append(getRequestDetails()).append(getRequestId()).append(getRequestScope()).append(getRequestStatus()).append(getRequestType()).append(getStartTime()).append(getAdditionalProperties()).toHashCode(); - } } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestDetails.java index 2b159f812..da6d46da5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestDetails.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestDetails.java @@ -20,20 +20,15 @@ package org.onap.vid.mso.rest; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.*; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.onap.vid.domain.mso.CloudConfiguration; -import org.onap.vid.domain.mso.ModelInfo; -import org.onap.vid.domain.mso.RequestInfo; -import org.onap.vid.domain.mso.RequestParameters; -import org.onap.vid.domain.mso.SubscriberInfo; +import org.onap.vid.exceptions.NotFoundException; +import org.onap.vid.mso.model.CloudConfiguration; +import org.onap.vid.mso.model.ModelInfo; +import org.onap.vid.mso.model.RequestInfo; +import org.onap.vid.mso.model.RequestParameters; import java.util.HashMap; import java.util.List; @@ -86,7 +81,7 @@ public class RequestDetails{ /** The additional properties. */ @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); /** * Gets the cloud configuration. @@ -269,4 +264,26 @@ public class RequestDetails{ public void setRequestParameters(RequestParameters requestParameters) { this.requestParameters = requestParameters; } + + public T extractValueByPathUsingAdditionalProperties (List keys, Class clazz) { + Object result = getAdditionalProperties(); + for (String key : keys) { + if (result instanceof Map) { + result = ((Map) result).get(key); + } + + else { + throw new NotFoundException("failed to find key: "+key+" in path: "+String.join("\\", keys)); + } + } + if (clazz.isInstance(result)) { + return clazz.cast(result); + } + + throw new NotFoundException( + String.format("failed to extract value from path:%s because %s is not of type %s", + String.join("\\", keys), String.valueOf(result) , clazz)); + } + + } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestList.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestList.java index 8f8272c07..00289da65 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestList.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestList.java @@ -20,30 +20,19 @@ package org.onap.vid.mso.rest; -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Generated; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -//import com.fasterxml.jackson.annotation.JsonInclude; -//import com.fasterxml.jackson.annotation.JsonProperty; -//import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.*; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * List of relatedModel structures that are related to a modelInfo being operated on. */ @JsonInclude(JsonInclude.Include.NON_NULL) -@Generated("org.jsonschema2pojo") @JsonPropertyOrder({ "finishTime", "instanceIds", @@ -62,7 +51,7 @@ public class RequestList { /** The additional properties. */ @JsonIgnore - private Map additionalProperties = new HashMap(); + private Map additionalProperties = new HashMap<>(); /** * (Required). @@ -127,7 +116,7 @@ public class RequestList { if (other == this) { return true; } - if ((other instanceof RequestList) == false) { + if (!(other instanceof RequestList)) { return false; } RequestList rhs = ((RequestList) other); diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestStatus.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestStatus.java new file mode 100644 index 000000000..f9c890454 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RequestStatus.java @@ -0,0 +1,208 @@ + +package org.onap.vid.mso.rest; + +import com.fasterxml.jackson.annotation.*; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.HashMap; +import java.util.Map; + + +/** + * fields describing the status of a request + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "percentProgress", + "requestState", + "statusMessage", + "timestamp", + "wasRolledBack" +}) +public class RequestStatus { + + /** + * percentage complete estimate from 0 to 100 + * + */ + @JsonProperty("percentProgress") + private Double percentProgress; + /** + * short description of the instantiation state + * (Required) + * + */ + @JsonProperty("requestState") + private String requestState; + /** + * additional descriptive information about the status + * + */ + @JsonProperty("statusMessage") + private String statusMessage; + /** + * GMT Datetime the requestStatus was created e.g.: Wed, 15 Oct 2014 13:01:52 GMT + * (Required) + * + */ + @JsonProperty("timestamp") + private String timestamp; + /** + * true or false boolean indicating whether the request was rolled back + * + */ + @JsonProperty("wasRolledBack") + private Boolean wasRolledBack; + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /** + * percentage complete estimate from 0 to 100 + * + * @return + * The percentProgress + */ + @JsonProperty("percentProgress") + public Double getPercentProgress() { + return percentProgress; + } + + /** + * percentage complete estimate from 0 to 100 + * + * @param percentProgress + * The percentProgress + */ + @JsonProperty("percentProgress") + public void setPercentProgress(Double percentProgress) { + this.percentProgress = percentProgress; + } + + /** + * short description of the instantiation state + * (Required) + * + * @return + * The requestState + */ + @JsonProperty("requestState") + public String getRequestState() { + return requestState; + } + + /** + * short description of the instantiation state + * (Required) + * + * @param requestState + * The requestState + */ + @JsonProperty("requestState") + public void setRequestState(String requestState) { + this.requestState = requestState; + } + + /** + * additional descriptive information about the status + * + * @return + * The statusMessage + */ + @JsonProperty("statusMessage") + public String getStatusMessage() { + return statusMessage; + } + + /** + * additional descriptive information about the status + * + * @param statusMessage + * The statusMessage + */ + @JsonProperty("statusMessage") + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } + + /** + * GMT Datetime the requestStatus was created e.g.: Wed, 15 Oct 2014 13:01:52 GMT + * (Required) + * + * @return + * The timestamp + */ + @JsonProperty("timestamp") + public String getTimestamp() { + return timestamp; + } + + /** + * GMT Datetime the requestStatus was created e.g.: Wed, 15 Oct 2014 13:01:52 GMT + * (Required) + * + * @param timestamp + * The timestamp + */ + @JsonProperty("timestamp") + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + /** + * true or false boolean indicating whether the request was rolled back + * + * @return + * The wasRolledBack + */ + @JsonProperty("wasRolledBack") + public Boolean getWasRolledBack() { + return wasRolledBack; + } + + /** + * true or false boolean indicating whether the request was rolled back + * + * @param wasRolledBack + * The wasRolledBack + */ + @JsonProperty("wasRolledBack") + public void setWasRolledBack(Boolean wasRolledBack) { + this.wasRolledBack = wasRolledBack; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(percentProgress).append(requestState).append(statusMessage).append(timestamp).append(wasRolledBack).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof RequestStatus)) { + return false; + } + RequestStatus rhs = ((RequestStatus) other); + return new EqualsBuilder().append(percentProgress, rhs.percentProgress).append(requestState, rhs.requestState).append(statusMessage, rhs.statusMessage).append(timestamp, rhs.timestamp).append(wasRolledBack, rhs.wasRolledBack).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java index feb3f3c1e..ec117cf04 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java @@ -1,30 +1,25 @@ package org.onap.vid.mso.rest; +import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.mso.RestObject; - -import javax.ws.rs.core.MultivaluedHashMap; +import org.onap.vid.mso.RestObjectWithRequestInfo; /** * Created by pickjonathan on 26/06/2017. */ public interface RestInterface { - /** - * Inits the rest client. - */ - MultivaluedHashMap initMsoClient(); - /** * Gets the. * * @param the generic type * @param t the t - * @param sourceId the source id * @param path the path * @param restObject the rest object + * @param warpException * @throws Exception the exception */ - void Get (T t, String sourceId, String path, RestObject restObject ); + RestObjectWithRequestInfo Get(T t, String path, RestObject restObject, boolean warpException); /** * Delete. @@ -32,25 +27,22 @@ public interface RestInterface { * @param the generic type * @param t the t * @param r the r - * @param sourceID the source ID * @param path the path * @param restObject the rest object * @throws Exception the exception */ - void Delete(T t, Object r, String sourceID, String path, RestObject restObject); + void Delete(T t, Object r, String path, RestObject restObject); /** * Post. * - * @param the generic type * @param t the t * @param r the r - * @param sourceID the source ID * @param path the path * @param restObject the rest object * @throws Exception the exception */ - void Post(T t, Object r, String sourceID, String path, RestObject restObject); + void Post(String t, Object r, String path, RestObject restObject); /** * Put. @@ -58,11 +50,12 @@ public interface RestInterface { * @param the generic type * @param t the t * @param r the r - * @param sourceID the source ID * @param path the path * @param restObject the rest object * @throws Exception the exception */ - void Put(T t, org.onap.vid.changeManagement.RequestDetailsWrapper r, String sourceID, String path, RestObject restObject); + void Put(T t, RequestDetailsWrapper r, String path, RestObject restObject); + + RestObject GetForObject(String path, Class clazz); } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/SubscriberInfo.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/SubscriberInfo.java new file mode 100644 index 000000000..0c8d7c2a1 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/SubscriberInfo.java @@ -0,0 +1,144 @@ + +package org.onap.vid.mso.rest; + +import com.fasterxml.jackson.annotation.*; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.HashMap; +import java.util.Map; + + +/** + * fields providing information about the subscriber associated with the request + * + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "globalSubscriberId", + "subscriberCommonSiteId", + "subscriberName" +}) +public class SubscriberInfo { + + /** + * global Customer Id understood by A&AI + * + */ + @JsonProperty("globalSubscriberId") + private String globalSubscriberId; + /** + * id representing the location of the subscriber + * + */ + @JsonProperty("subscriberCommonSiteId") + private String subscriberCommonSiteId; + /** + * name of the customer or subscriber + * + */ + @JsonProperty("subscriberName") + private String subscriberName; + @JsonIgnore + private Map additionalProperties = new HashMap<>(); + + /** + * global Customer Id understood by A&AI + * + * @return + * The globalSubscriberId + */ + @JsonProperty("globalSubscriberId") + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + /** + * global Customer Id understood by A&AI + * + * @param globalSubscriberId + * The globalSubscriberId + */ + @JsonProperty("globalSubscriberId") + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + /** + * id representing the location of the subscriber + * + * @return + * The subscriberCommonSiteId + */ + @JsonProperty("subscriberCommonSiteId") + public String getSubscriberCommonSiteId() { + return subscriberCommonSiteId; + } + + /** + * id representing the location of the subscriber + * + * @param subscriberCommonSiteId + * The subscriberCommonSiteId + */ + @JsonProperty("subscriberCommonSiteId") + public void setSubscriberCommonSiteId(String subscriberCommonSiteId) { + this.subscriberCommonSiteId = subscriberCommonSiteId; + } + + /** + * name of the customer or subscriber + * + * @return + * The subscriberName + */ + @JsonProperty("subscriberName") + public String getSubscriberName() { + return subscriberName; + } + + /** + * name of the customer or subscriber + * + * @param subscriberName + * The subscriberName + */ + @JsonProperty("subscriberName") + public void setSubscriberName(String subscriberName) { + this.subscriberName = subscriberName; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(globalSubscriberId).append(subscriberCommonSiteId).append(subscriberName).append(additionalProperties).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof SubscriberInfo)) { + return false; + } + SubscriberInfo rhs = ((SubscriberInfo) other); + return new EqualsBuilder().append(globalSubscriberId, rhs.globalSubscriberId).append(subscriberCommonSiteId, rhs.subscriberCommonSiteId).append(subscriberName, rhs.subscriberName).append(additionalProperties, rhs.additionalProperties).isEquals(); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyProperties.java b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyProperties.java deleted file mode 100644 index 940adddb3..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyProperties.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.onap.vid.policy; - -import org.onap.portalsdk.core.util.SystemProperties; - - -public class PolicyProperties extends SystemProperties { - - public static final String POLICY_CLIENTAUTH_VAL = "policy.ClientAuth"; - - public static final String POLICY_CLIENT_MECHID_VAL = "policy.client.mechId"; - - public static final String POLICY_CLIENT_PASSWORD_VAL = "policy.client.password"; - - public static final String POLICY_USERNAME_VAL = "policy.username"; - - public static final String POLICY_PASSWORD_VAL = "policy.password"; - - public static final String POLICY_AUTHORIZATION_VAL = "policy.Authorization"; - - public static final String POLICY_SERVER_URL_VAL = "policy.server.url"; - - public static final String POLICY_ENVIRONMENT_VAL = "policy.environment"; - - public static final String POLICY_GET_CONFIG_VAL = "policy.get.config"; - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyResponseWrapper.java b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyResponseWrapper.java deleted file mode 100644 index d5a4d124c..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyResponseWrapper.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.onap.vid.policy; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.apache.commons.lang.builder.ToStringBuilder; - -/** - * This wrapper encapsulates the Policy response - */ -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "status", - "entity" -}) - -public class PolicyResponseWrapper { - - @JsonProperty("status") - private int status; - - @JsonProperty("entity") - private String entity; - - @JsonProperty("entity") - public String getEntity() { - return entity; - } - - @JsonProperty("status") - public int getStatus() { - return status; - } - - @JsonProperty("status") - public void setStatus(int v) { - this.status = v; - } - - @JsonProperty("entity") - public void setEntity(String v) { - this.entity = v; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } - - public String getResponse () { - - StringBuilder b = new StringBuilder ("{ \"status\": "); - b.append(getStatus()).append(", \"entity\": " ).append(this.getEntity()).append("}"); - return (b.toString()); - } -} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInt.java b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInt.java deleted file mode 100644 index 65dcb8180..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInt.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.policy; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.policy.rest.RequestDetails; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class PolicyRestInt { - - /** The logger. */ - private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PolicyRestInt.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - /** The request date format. */ - public DateFormat requestDateFormat = new SimpleDateFormat("EEE, dd MMM YYYY HH:mm:ss z"); - - public PolicyRestInt() { - requestDateFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT")); - } - - /** - * Log request. - * - * @param r the r - */ - public void logRequest ( RequestDetails r ) { - String methodName = "logRequest"; - ObjectMapper mapper = new ObjectMapper(); - String r_json_str = ""; - if ( r != null ) { - r_json_str = r.toString(); - try { - r_json_str = mapper.writeValueAsString(r); - } - catch ( com.fasterxml.jackson.core.JsonProcessingException j ) { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " Unable to parse request as json"); - } - } - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " Request=(" + r_json_str + ")"); - } -} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterface.java deleted file mode 100644 index e550f0262..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterface.java +++ /dev/null @@ -1,230 +0,0 @@ -package org.onap.vid.policy; - -import org.apache.commons.codec.binary.Base64; -import org.eclipse.jetty.util.security.Password; -import org.json.simple.JSONObject; -import org.onap.vid.client.HttpBasicClient; -import org.onap.vid.exceptions.GenericUncheckedException; -import org.onap.vid.policy.rest.RequestDetails; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.util.SystemProperties; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.Response; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; - -public class PolicyRestInterface extends PolicyRestInt implements PolicyRestInterfaceIfc { - - /** The logger. */ - private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PolicyRestInterface.class); - - public static final String APPLICATION_JSON = "application/json"; - - /** The client. */ - private static Client client = null; - - /** The common headers. */ - private MultivaluedHashMap commonHeaders; - public PolicyRestInterface() { - super(); - } - - /** The Constant dateFormat. */ - static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - public void initRestClient() - { - final String methodname = "initRestClient()"; - - final String mechId = SystemProperties.getProperty(PolicyProperties.POLICY_CLIENT_MECHID_VAL); - final String clientPassword = SystemProperties.getProperty(PolicyProperties.POLICY_CLIENT_PASSWORD_VAL); - final String username = SystemProperties.getProperty(PolicyProperties.POLICY_USERNAME_VAL); - final String password = SystemProperties.getProperty(PolicyProperties.POLICY_PASSWORD_VAL); - final String environment = SystemProperties.getProperty(PolicyProperties.POLICY_ENVIRONMENT_VAL); - - final String decrypted_client_password = Password.deobfuscate(clientPassword); - String mechAuthString = mechId + ":" + decrypted_client_password; - byte[] mechAuthEncBytes = Base64.encodeBase64(mechAuthString.getBytes()); - String clientAuth = new String(mechAuthEncBytes); - - final String decrypted_password = Password.deobfuscate(password); - String authString = username + ":" + decrypted_password; - byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); - String authorization = new String(authEncBytes); - - commonHeaders = new MultivaluedHashMap<> (); - commonHeaders.put("ClientAuth", Collections.singletonList((Object) ("Basic " + clientAuth))); - commonHeaders.put("Authorization", Collections.singletonList((Object) ("Basic " + authorization))); - commonHeaders.put("Environment", Collections.singletonList((Object) (environment))); - - if (client == null) { - - try { - client = HttpBasicClient.getClient(); - } catch (Exception e) { - System.out.println( methodname + " Unable to get the SSL client"); - } - } - } - - @SuppressWarnings("unchecked") - public void Get (T t, String sourceId, String path, RestObject restObject ) { - String methodName = "Get"; - - logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); - - String url=""; - restObject.set(t); - - url = SystemProperties.getProperty(PolicyProperties.POLICY_SERVER_URL_VAL) + path; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " sending request to url= " + url); - - initRestClient(); - - final Response cres = client.target(url) - .request() - .accept(APPLICATION_JSON) - .headers(commonHeaders) - .get(); - - int status = cres.getStatus(); - restObject.setStatusCode (status); - - if (status == 200) { - t = (T) cres.readEntity(t.getClass()); - restObject.set(t); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " REST api was successfull!"); - - } else { - throw new GenericUncheckedException(methodName + " with status="+ status + ", url= " + url ); - } - - logger.debug(EELFLoggerDelegate.debugLogger,methodName + " received status=" + status ); - - return; - } - - @SuppressWarnings("unchecked") - public void Delete(T t, RequestDetails r, String sourceID, String path, RestObject restObject) { - - String methodName = "Delete"; - String url=""; - Response cres = null; - - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " start"); - logRequest (r); - - try { - initRestClient(); - - url = SystemProperties.getProperty(PolicyProperties.POLICY_SERVER_URL_VAL) + path; - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + " methodName sending request to: " + url); - - cres = client.target(url) - .request() - .accept(APPLICATION_JSON) - .headers(commonHeaders) - //.entity(r) - .build("DELETE", Entity.entity(r, MediaType.APPLICATION_JSON)).invoke(); - - int status = cres.getStatus(); - restObject.setStatusCode (status); - - if (status == 404) { // resource not found - String msg = "Resource does not exist...: " + cres.getStatus(); - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + msg); - } else if (status == 200 || status == 204){ - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + "Resource " + url + " deleted"); - } else if (status == 202) { - String msg = "Delete in progress: " + status; - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + msg); - } - else { - String msg = "Deleting Resource failed: " + status; - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + msg); - } - - try { - t = (T) cres.readEntity(t.getClass()); - restObject.set(t); - } - catch ( Exception e ) { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " No response entity, this is probably ok, e=" - + e.getMessage()); - } - - } - catch (Exception e) - { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " with url="+url+ ", Exception: " + e.toString()); - throw e; - - } - } - - @SuppressWarnings("unchecked") - public void Post(T t, JSONObject requestDetails, String uuid, String path, RestObject restObject) { - - String methodName = "Post"; - String url=""; - - System.out.println( "POST policy rest interface"); - - try { - - initRestClient(); - - url = SystemProperties.getProperty(PolicyProperties.POLICY_SERVER_URL_VAL) + path; - System.out.println( "<== " + methodName + " sending request to url= " + url); - // Change the content length - final Response cres = client.target(url) - .request() - .accept(APPLICATION_JSON) - .headers(commonHeaders) - //.header("content-length", 201) - //.header("X-FromAppId", sourceID) - .post(Entity.entity(requestDetails, MediaType.APPLICATION_JSON)); - - try { - t = (T) cres.readEntity(t.getClass()); - restObject.set(t); - } - catch ( Exception e ) { - - System.out.println("<== " + methodName + " No response entity, this is probably ok, e=" + e.getMessage()); - } - - int status = cres.getStatus(); - restObject.setStatusCode (status); - - if ( status >= 200 && status <= 299 ) { - System.out.println( "<== " + methodName + " REST api POST was successful!"); - - } else { - System.out.println( "<== " + methodName + " with status="+status+", url="+url); - } - - } catch (Exception e) - { - System.out.println( "<== " + methodName + " with url="+url+ ", Exception: " + e.toString()); - throw e; - - } - } - - public T getInstance(Class clazz) throws IllegalAccessException, InstantiationException - { - return clazz.newInstance(); - } - - @Override - public void logRequest(RequestDetails r) { - // TODO Auto-generated method stub - } -} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterfaceFactory.java b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterfaceFactory.java deleted file mode 100644 index 40cb854bf..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterfaceFactory.java +++ /dev/null @@ -1,14 +0,0 @@ - -package org.onap.vid.policy; - -public class PolicyRestInterfaceFactory { - - - public static PolicyRestInterfaceIfc getInstance () { - PolicyRestInterfaceIfc obj = null; - - obj = new PolicyRestInterface(); - - return ( obj ); - } -} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterfaceIfc.java b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterfaceIfc.java deleted file mode 100644 index 61108fc53..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyRestInterfaceIfc.java +++ /dev/null @@ -1,58 +0,0 @@ - -package org.onap.vid.policy; - -import org.json.simple.JSONObject; -import org.onap.vid.policy.rest.RequestDetails; - -public interface PolicyRestInterfaceIfc { - /** - * Inits the rest client. - */ - public void initRestClient(); - - /** - * Gets the. - * - * @param the generic type - * @param t the t - * @param sourceId the source id - * @param path the path - * @param restObject the rest object - * @throws Exception the exception - */ - public void Get (T t, String sourceId, String path, RestObject restObject ); - - /** - * Delete. - * - * @param the generic type - * @param t the t - * @param r the r - * @param sourceID the source ID - * @param path the path - * @param restObject the rest object - * @throws Exception the exception - */ - public void Delete(T t, RequestDetails r, String sourceID, String path, RestObject restObject); - - /** - * Post. - * - * @param the generic type - * @param t the t - * @param r the r - * @param sourceID the source ID - * @param path the path - * @param restObject the rest object - * @throws Exception the exception - */ - public void Post(T t, JSONObject r, String sourceID, String path, RestObject restObject); - - /*** - * Log request. - * - * @param r the r - */ - public void logRequest ( RequestDetails r ); - -} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java deleted file mode 100644 index 740569754..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.onap.vid.policy; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.glassfish.jersey.client.ClientResponse; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.vid.policy.PolicyResponseWrapper; -import org.onap.vid.policy.PolicyUtil; -import org.onap.vid.policy.RestObject; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class PolicyUtil { - - private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PolicyUtil.class); - - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); - - public static PolicyResponseWrapper wrapResponse ( String body, int statusCode ) { - - PolicyResponseWrapper w = new PolicyResponseWrapper(); - w.setStatus (statusCode); - w.setEntity(body); - - return w; - } - - public static PolicyResponseWrapper wrapResponse (ClientResponse cres) { - String resp_str = ""; - if ( cres != null ) { - resp_str = cres.readEntity(String.class); - } - int statuscode = cres.getStatus(); - PolicyResponseWrapper w = PolicyUtil.wrapResponse ( resp_str, statuscode ); - return (w); - } - - public static PolicyResponseWrapper wrapResponse (RestObject rs) { - String resp_str = ""; - int status = 0; - if ( rs != null ) { - resp_str = rs.get(); - status = rs.getStatusCode(); - } - PolicyResponseWrapper w = PolicyUtil.wrapResponse ( resp_str, status ); - return (w); - } - - public static String convertPojoToString ( T t ) throws com.fasterxml.jackson.core.JsonProcessingException { - - String methodName = "convertPojoToString"; - ObjectMapper mapper = new ObjectMapper(); - String r_json_str = ""; - if ( t != null ) { - try { - r_json_str = mapper.writeValueAsString(t); - } - catch ( com.fasterxml.jackson.core.JsonProcessingException j ) { - logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " Unable to parse object as json"); - } - } - return (r_json_str); - } - - - public static void main(String[] args) { - // TODO Auto-generated method stub - } -} diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/RestObject.java b/vid-app-common/src/main/java/org/onap/vid/policy/RestObject.java deleted file mode 100644 index 81b354eb0..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/RestObject.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.policy; - -/** - * The Class RestObject. - * - * @param the generic type - */ -public class RestObject { - - /** - * Generic version of the RestObject class. - * - */ - // T stands for "Type" - private T t; - - /** The status code. */ - private int statusCode= 0; - - /** - * Sets the. - * - * @param t the t - */ - public void set(T t) { this.t = t; } - - /** - * Gets the. - * - * @return the t - */ - public T get() { return t; } - - /** - * Sets the status code. - * - * @param v the new status code - */ - public void setStatusCode(int v) { this.statusCode = v; } - - /** - * Gets the status code. - * - * @return the status code - */ - public int getStatusCode() { return this.statusCode; } - -} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/rest/RequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/policy/rest/RequestDetails.java deleted file mode 100644 index 81e2f2d8b..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/policy/rest/RequestDetails.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.policy.rest; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; - -/* - [ - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"TimeLimitAndVerticalTopology\",\"policyName\":\"SNIRO_CM_1707.Demo_TimeLimitAndVerticalTopology_zone_localTime\",\"description\":\"dev instance\",\"templateVersion\":\"1702.03\",\"version\":\"1707\",\"priority\":\"4\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"serviceType\":\"networkOnDemand\",\"identity\":\"vnf_upgrade_policy\",\"policyScope\":{\"serviceType\":[\"networkOnDemand\"],\"aicZone\":[\" \"],\"entityType\":[\"vnf\"]},\"timeSchedule\":{\"allowedPeriodicTime\":[{\"day\":\"weekday\",\"timeRange\":[{\"start_time\":\"04:00:00\",\"end_time\":\"13:00:00\"}]}]},\"nodeType\":[\"vnf\"],\"type\":\"timeLimitAndVerticalTopology\",\"conflictScope\":\"vnf_zone\"}}", - "policyName": "SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_zone_localTime.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ConfigName": "", - "service": "TimeLimitAndVerticalTopology", - "uuid": "", - "Location": "" - }, - "responseAttributes": {}, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"TimeLimitAndVerticalTopology\",\"policyName\":\"SNIRO_CM_1707.Demo_TimeLimitAndVerticalTopology_pserver_localTime\",\"description\":\"dev instance\",\"templateVersion\":\"1702.03\",\"version\":\"1707\",\"priority\":\"4\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"serviceType\":\"networkOnDemand\",\"identity\":\"vnf_upgrade_policy\",\"policyScope\":{\"serviceType\":[\"networkOnDemand\"],\"aicZone\":[\" \"],\"entityType\":[\"vnf\"]},\"timeSchedule\":{\"allowedPeriodicTime\":[{\"day\":\"weekday\",\"timeRange\":[{\"start_time\":\"04:00:00\",\"end_time\":\"13:00:00\"}]}]},\"nodeType\":[\"vnf\"],\"type\":\"timeLimitAndVerticalTopology\",\"conflictScope\":\"vnf_pserver\"}}", - "policyName": "SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_pserver_localTime.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ConfigName": "", - "service": "TimeLimitAndVerticalTopology", - "uuid": "", - "Location": "" - }, - "responseAttributes": {}, - "property": null - }, - { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - "config": "{\"service\":\"TimeLimitAndVerticalTopology\",\"policyName\":\"SNIRO_CM_1707.Demo_TimeLimitAndVerticalTopology_vnf_localTime\",\"description\":\"dev instance\",\"templateVersion\":\"1702.03\",\"version\":\"1707\",\"priority\":\"4\",\"riskType\":\"test\",\"riskLevel\":\"3\",\"guard\":\"False\",\"content\":{\"serviceType\":\"networkOnDemand\",\"identity\":\"vnf_upgrade_policy\",\"policyScope\":{\"serviceType\":[\"networkOnDemand\"],\"aicZone\":[\" \"],\"entityType\":[\"vnf\"]},\"timeSchedule\":{\"allowedPeriodicTime\":[{\"day\":\"weekday\",\"timeRange\":[{\"start_time\":\"04:00:00\",\"end_time\":\"13:00:00\"}]}]},\"nodeType\":[\"vnf\"],\"type\":\"timeLimitAndVerticalTopology\",\"conflictScope\":\"vnf\"}}", - "policyName": "SNIRO_CM_1707.Config_MS_Demo_TimeLimitAndVerticalTopology_vnf_localTime.1.xml", - "policyVersion": "1", - "matchingConditions": { - "ECOMPName": "SNIRO-Placement", - "ConfigName": "", - "service": "TimeLimitAndVerticalTopology", - "uuid": "", - "Location": "" - }, - "responseAttributes": {}, - "property": null - } - ] -*/ -@JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({ - "policyConfigMessage", - "policyConfigStatus", - "type", - "config", - "policyName", - "policyVersion", - "matchingConditions" -}) -public class RequestDetails { - - @JsonProperty("policyName") - private String policyName; - - @JsonProperty("policyName") - public String getPolicyName() { - return policyName; - } - - @JsonProperty("policyName") - public void setPolicyName(String policyName) { - this.policyName = policyName; - } - -} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java index cc623d44f..6c521107f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java +++ b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java @@ -10,10 +10,8 @@ public enum Features implements Feature { */ FLAG_ASYNC_JOBS, - FLAG_REGION_ID_FROM_REMOTE, CREATE_INSTANCE_TEST, EMPTY_DRAWING_BOARD_TEST, - FLAG_ADVANCED_PORTS_FILTER, FLAG_ADD_MSO_TESTAPI_FIELD, FLAG_ASYNC_INSTANTIATION, FLAG_SERVICE_MODEL_CACHE, @@ -21,9 +19,30 @@ public enum Features implements Feature { FLAG_NETWORK_TO_ASYNC_INSTANTIATION, FLAG_COLLECTION_RESOURCE_SUPPORT, FLAG_SHOW_ASSIGNMENTS, - FLAG_SHOW_VERIFY_SERVICE, + FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS, + FLAG_SHOW_VERIFY_SERVICE, // AKA POMBA + FLAG_DUPLICATE_VNF, + FLAG_DEFAULT_VNF, FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD, - FLAG_PNP_INSTANTIATION; + FLAG_PNP_INSTANTIATION, + FLAG_RESTRICTED_SELECT, + FLAG_5G_IN_NEW_INSTANTIATION_UI, + FLAG_ASYNC_ALACARTE_VNF, + FLAG_A_LA_CARTE_AUDIT_INFO, + FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS, + FLAG_ASYNC_ALACARTE_VFMODULE, + FLAG_SUPPLEMENTARY_FILE, + FLAG_SHIFT_VFMODULE_PARAMS_TO_VNF, + FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI, + FLAG_1810_CR_LET_SELECTING_COLLECTOR_TYPE_UNCONDITIONALLY, + FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST, + FLAG_1810_CR_SOFT_DELETE_ALACARTE_VF_MODULE, + FLAG_1810_AAI_LOCAL_CACHE, + FLAG_1810_IDENTIFY_SERVICE_FOR_NEW_UI, + FLAG_1902_NEW_VIEW_EDIT, + FLAG_EXP_USE_DEFAULT_HOST_NAME_VERIFIER, + FLAG_1902_VNF_GROUPING, + ; public boolean isActive() { return FeatureContext.getFeatureManager().isActive(this); diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/FeaturesTogglingConfiguration.java b/vid-app-common/src/main/java/org/onap/vid/properties/FeaturesTogglingConfiguration.java index ef28ea400..88bcce871 100644 --- a/vid-app-common/src/main/java/org/onap/vid/properties/FeaturesTogglingConfiguration.java +++ b/vid-app-common/src/main/java/org/onap/vid/properties/FeaturesTogglingConfiguration.java @@ -24,16 +24,18 @@ public class FeaturesTogglingConfiguration { public FeatureManager featureManager(ServletContext servletContext, Environment environment) { final String defaultFilename = "features.properties"; - String filename = environment.getProperty("featureFlags.filename"); + String filename = environment.getProperty("features.set.filename"); if (StringUtils.isBlank(filename)) { filename = defaultFilename; } + filename = StringUtils.trimToNull(filename); + return new FeatureManagerBuilder() .featureEnum(Features.class) .stateRepository(new FileBasedStateRepository( - new File(servletContext.getRealPath("/WEB-INF/conf/" + filename)) + new File(filename.startsWith("/")? filename : servletContext.getRealPath("/WEB-INF/conf/" + filename)) )) .build(); } diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/VidProperties.java b/vid-app-common/src/main/java/org/onap/vid/properties/VidProperties.java index d670e9783..0a7d8d1a7 100644 --- a/vid-app-common/src/main/java/org/onap/vid/properties/VidProperties.java +++ b/vid-app-common/src/main/java/org/onap/vid/properties/VidProperties.java @@ -20,13 +20,10 @@ package org.onap.vid.properties; +import org.apache.commons.lang3.StringUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.model.ModelConstants; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; /** * The Class VidProperties. */ @@ -37,6 +34,7 @@ public class VidProperties extends SystemProperties { public static final String MSO_DEFAULT_TEST_API="mso.defaultTestAPI"; public static final String MSO_MAX_OPENED_INSTANTIATION_REQUESTS="mso.maxOpenedInstantiationRequests"; public static final String MSO_ASYNC_POLLING_INTERVAL_SECONDS="mso.asyncPollingIntervalSeconds"; + public static final String PROBE_SDC_MODEL_UUID="probe.sdc.model.uuid"; /** The Constant VID_TRUSTSTORE_FILENAME. */ public static final String VID_TRUSTSTORE_FILENAME = "vid.truststore.filename"; @@ -49,9 +47,9 @@ public class VidProperties extends SystemProperties { /** The Constant LOG. */ private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidProperties.class); - - /** The Constant dateFormat. */ - final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + + public static final String VID_JOB_MAX_HOURS_IN_PROGRESS = "vid.asyncJob.maxHoursInProgress"; + /** * Gets the asdc model namespace prefix property * @@ -67,7 +65,7 @@ public class VidProperties extends SystemProperties { } } catch ( Exception e ) { - LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default " + LOG.error (EELFLoggerDelegate.errorLogger, methodName + "unable to find the value, using the default " + ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE); asdcModelNamespace = ModelConstants.DEFAULT_ASDC_MODEL_NAMESPACE; } @@ -88,10 +86,28 @@ public class VidProperties extends SystemProperties { } } catch ( Exception e ) { - LOG.error (EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + "unable to find the value, using the default " + LOG.error (EELFLoggerDelegate.errorLogger, methodName + "unable to find the value, using the default " + defaultValue); propValue = defaultValue; } return (propValue); } + + public static long getLongProperty(String key) { + return getLongProperty(key, 0); + } + + public static long getLongProperty(String key, long defaultValue) { + if (!containsProperty(key)) { + LOG.debug(EELFLoggerDelegate.debugLogger, "No such property: {}. {} value is used", key, defaultValue); + return defaultValue; + } + String configValue = getProperty(key); + if (StringUtils.isNumeric(configValue)) { + return Long.parseLong(configValue); + } else { + LOG.debug(EELFLoggerDelegate.debugLogger, "{} property value is not valid: {}. {} value is used", key, configValue, defaultValue); + return defaultValue; + } + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java index b83f751fe..d4256f893 100644 --- a/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java +++ b/vid-app-common/src/main/java/org/onap/vid/roles/RoleProvider.java @@ -26,7 +26,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.joshworks.restclient.http.HttpResponse; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.web.support.UserUtils; -import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.exceptions.RoleParsingException; import org.onap.vid.model.ModelConstants; import org.onap.vid.model.Subscriber; @@ -37,6 +36,8 @@ import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; import java.util.*; +import java.util.stream.Collectors; + /** * Created by Oren on 7/1/17. @@ -46,46 +47,32 @@ import java.util.*; public class RoleProvider { private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(RoleProvider.class); - final String readPermissionString = "read"; - SubscriberList subscribers; - ObjectMapper om = new ObjectMapper(); + static final String READ_PERMISSION_STRING = "read"; + private final ObjectMapper om = new ObjectMapper(); + @Autowired private AaiService aaiService; - public static List extractRoleFromSession(HttpServletRequest request) { - - return new ArrayList(); - - } - - public void init() { - LOG.debug(EELFLoggerDelegate.debugLogger, "Role provider => init method started"); - HttpResponse subscribersResponse = aaiService.getFullSubscriberList(); - subscribers = subscribersResponse.getBody(); - LOG.debug(EELFLoggerDelegate.debugLogger, "Role provider => init method finished"); - } - public List getUserRoles(HttpServletRequest request) { String logPrefix = "Role Provider (" + UserUtils.getUserId(request) + ") ==>"; LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "Entering to get user role for user " + UserUtils.getUserId(request)); List roleList = new ArrayList<>(); - Map roles = UserUtils.getRoles(request); for (Object role : roles.keySet()) { org.onap.portalsdk.core.domain.Role sdkRol = (org.onap.portalsdk.core.domain.Role) roles.get(role); LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "Role " + sdkRol.getName() + " is being proccessed"); try { - if (sdkRol.getName().contains(readPermissionString)) { - LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + " Role " + sdkRol.getName() + " contain " + readPermissionString); + if (sdkRol.getName().contains(READ_PERMISSION_STRING)) { + LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + " Role " + sdkRol.getName() + " contain " + READ_PERMISSION_STRING); continue; } String[] roleParts = splitRole((sdkRol.getName()), logPrefix); roleList.add(createRoleFromStringArr(roleParts, logPrefix)); - String msg = String.format(logPrefix + " User %s got permissions %s", UserUtils.getUserId(request), Arrays.toString(roleParts)); + String msg = String.format("%s User %s got permissions %s", logPrefix, UserUtils.getUserId(request), Arrays.toString(roleParts)); LOG.debug(EELFLoggerDelegate.debugLogger, msg); } catch (Exception e) { LOG.error(logPrefix + " Failed to parse permission"); @@ -102,29 +89,30 @@ public class RoleProvider { } public boolean userPermissionIsReadOnly(List roles) { - - return (!(roles.size() > 0)); + return roles.isEmpty(); } public boolean userPermissionIsReadLogs(List roles){ for(Role role: roles){ - if(role.getServiceType().equals("LOGS")){ - if(role.getTenant().equals("PERMITTED")){ - return true; - } + if ( role.getServiceType().equals("LOGS") && role.getTenant().equals("PERMITTED") ) { + return true; } } return false; } - private String replaceSubscriberNameToGlobalCustomerID(String subscriberName, String logPrefix) throws JsonProcessingException { - if (subscribers == null) { - LOG.debug(EELFLoggerDelegate.debugLogger, "replaceSubscriberNameToGlobalCustomerID calling init method"); - init(); - } - LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "subscribers list size is " + subscribers.customer.size() + " with the values " + om.writeValueAsString(subscribers.customer)); - LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "subscribers list size is " + subscribers.customer.size() + " with the values " + om.writeValueAsString(subscribers.customer)); + private String replaceSubscriberNameToGlobalCustomerID(String subscriberName, String logPrefix) { + // SubscriberList should be cached by cacheProvider so by calling getFullSubscriberList() method we just gat it from cache + HttpResponse subscribersResponse = aaiService.getFullSubscriberList(); + SubscriberList subscribers = subscribersResponse.getBody(); + try { + LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "subscribers list size is " + subscribers.customer.size() + " with the values " + om.writeValueAsString(subscribers.customer)); + } catch (JsonProcessingException e) { + // log subscriberNames without object mapper + LOG.debug(EELFLoggerDelegate.debugLogger, logPrefix + "subscribers list size is " + subscribers.customer.size() + + " with the values " + subscribers.customer.stream().map(subscriber -> subscriber.subscriberName).collect(Collectors.joining(","))); + } Optional s = subscribers.customer.stream().filter(x -> x.subscriberName.equals(subscriberName)).findFirst(); //Fixing bug of logging "optional get" before isPresent @@ -133,7 +121,7 @@ public class RoleProvider { return replacement; } - public Role createRoleFromStringArr(String[] roleParts, String rolePrefix) throws JsonProcessingException, RoleParsingException { + public Role createRoleFromStringArr(String[] roleParts, String rolePrefix) throws RoleParsingException { String globalCustomerID = replaceSubscriberNameToGlobalCustomerID(roleParts[0], rolePrefix); try { if (roleParts.length > 2) { @@ -153,5 +141,8 @@ public class RoleProvider { } + public RoleValidator getUserRolesValidator(HttpServletRequest request) { + return new RoleValidator(getUserRoles(request)); + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java deleted file mode 100644 index 4accb55da..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObject.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.scheduler; - - -public class RestObject { - - private T t; - - private int statusCode= 0; - - public String uuid; - - public void set(T t) { this.t = t; } - - public T get() { return t; } - - public void setStatusCode(int v) { this.statusCode = v; } - - public int getStatusCode() { return this.statusCode; } - - public void setUUID(String uuid) { this.uuid = uuid; } - - public String getUUID() { return this.uuid; } -} - diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java deleted file mode 100644 index ff1ffb4c5..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/RestObjects/RestObject.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * 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.onap.vid.scheduler.RestObjects; - - -public class RestObject { - - private T t; - - private int statusCode= 0; - - public void set(T t) { this.t = t; } - - public T get() { return t; } - - public void setStatusCode(int v) { this.statusCode = v; } - - public int getStatusCode() { return this.statusCode; } - -} - diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java index a4c5b00a8..c986f2256 100644 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java @@ -4,12 +4,16 @@ import com.att.eelf.configuration.EELFLogger; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import io.joshworks.restclient.http.HttpResponse; +import org.apache.http.HttpException; import org.eclipse.jetty.util.security.Password; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.client.SyncRestClient; import org.onap.vid.client.SyncRestClientInterface; import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.RestObjectWithRequestInfo; import org.onap.vid.utils.Logging; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; @@ -24,8 +28,9 @@ import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY; @Service public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { - final private static EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("scheduler"); + private static final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("scheduler"); private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SchedulerRestInterface.class); + private static final String SUCCESSFUL_API_MESSAGE=" REST api GET was successful!"; private SyncRestClientInterface syncRestClient; private Function propertyGetter; private Map commonHeaders; @@ -50,30 +55,43 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc { logger.info("\t<== Client Initialized \n"); } - public void Get(T t, String sourceId, String path, org.onap.vid.scheduler.RestObject restObject) { - initRestClient(); - String methodName = "Get"; - String url = String.format("%s%s", propertyGetter.apply(SchedulerProperties.SCHEDULER_SERVER_URL_VAL), path); - Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); - Map requestHeaders = ImmutableMap.builder() - .putAll(commonHeaders) - .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()).build(); - final HttpResponse response = ((HttpResponse) syncRestClient.get(url, requestHeaders, - Collections.emptyMap(), t.getClass())); - Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response); - int status = response.getStatus(); - restObject.setStatusCode(status); - - if (status == 200) { - t = response.getBody(); - restObject.set(t); - - } else { - throw new GenericUncheckedException(String.format("%s with status=%d, url=%s", methodName, status, url)); + public RestObjectWithRequestInfo Get(T t, String path, RestObject restObject) { + + String url = null; + String rawData = null; + Integer status = null; + + try { + String methodName = "Get"; + url = String.format("%s%s", propertyGetter.apply(SchedulerProperties.SCHEDULER_SERVER_URL_VAL), path); + initRestClient(); + Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); + Map requestHeaders = ImmutableMap.builder() + .putAll(commonHeaders) + .put(REQUEST_ID_HEADER_KEY, Logging.extractOrGenerateRequestId()) + .build(); + final HttpResponse response = ((HttpResponse) syncRestClient.get(url, requestHeaders, + Collections.emptyMap(), t.getClass())); + Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response); + status = response.getStatus(); + restObject.setStatusCode(status); + + if (status == 200) { + t = response.getBody(); + restObject.set(t); + logger.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE); + logger.info(EELFLoggerDelegate.errorLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE); + } else { + throw new GenericUncheckedException(new HttpException(String.format("%s with status=%d, url=%s", methodName, status, url))); + } + return new RestObjectWithRequestInfo<>(HttpMethod.GET, url, restObject, status, rawData); + } + catch (RuntimeException e) { + throw new ExceptionWithRequestInfo(HttpMethod.GET, url, rawData, status, e); } } - public void Delete(T t, String sourceID, String path, org.onap.vid.scheduler.RestObject restObject) { + public void Delete(T t, String sourceID, String path, RestObject restObject) { initRestClient(); String url = String.format("%s%s", propertyGetter.apply(SchedulerProperties.SCHEDULER_SERVER_URL_VAL), path); Logging.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url); diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java index d39e938b4..ca5c02651 100644 --- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterfaceIfc.java @@ -1,6 +1,8 @@ package org.onap.vid.scheduler; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.RestObjectWithRequestInfo; import org.springframework.stereotype.Service; @Service @@ -8,10 +10,9 @@ public interface SchedulerRestInterfaceIfc { void initRestClient(); - void Get(T t, String sourceId, String path, org.onap.vid.scheduler.RestObject restObject); + RestObjectWithRequestInfo Get(T t, String path, RestObject restObject); - void Delete(T t, String sourceID, String path, org.onap.vid.scheduler.RestObject restObject) - throws Exception; + void Delete(T t, String sourceID, String path, RestObject restObject); } diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java new file mode 100644 index 000000000..b4246d5c0 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerService.java @@ -0,0 +1,7 @@ +package org.onap.vid.scheduler; + +import org.onap.vid.model.probes.ExternalComponentStatus; + +public interface SchedulerService { + ExternalComponentStatus probeGetSchedulerChangeManagements(); +} diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java new file mode 100644 index 000000000..99754fcde --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerServiceImpl.java @@ -0,0 +1,43 @@ +package org.onap.vid.scheduler; + +import org.onap.vid.aai.ExceptionWithRequestInfo; +import org.onap.vid.model.probes.ErrorMetadata; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.model.probes.HttpRequestMetadata; +import org.onap.vid.mso.RestObjectWithRequestInfo; +import org.onap.vid.services.ChangeManagementService; +import org.onap.vid.utils.Logging; +import org.springframework.beans.factory.annotation.Autowired; + +public class SchedulerServiceImpl implements SchedulerService{ + + private final ChangeManagementService changeManagementService; + + + @Autowired + public SchedulerServiceImpl(ChangeManagementService changeManagementService) { + this.changeManagementService = changeManagementService; + } + + @Override + public ExternalComponentStatus probeGetSchedulerChangeManagements() { + long startTime = System.currentTimeMillis(); + try { + RestObjectWithRequestInfo response = this.changeManagementService.getSchedulerChangeManagementsWithRequestInfo(); + return new ExternalComponentStatus( + ExternalComponentStatus.Component.SCHEDULER, + true, + new HttpRequestMetadata(response, "OK", startTime) + ); + } catch (ExceptionWithRequestInfo e) { + long duration = System.currentTimeMillis() - startTime; + return new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER, + false, + new HttpRequestMetadata(e, duration)); + } catch (Exception e) { + long duration = System.currentTimeMillis() - startTime; + return new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER, false, + new ErrorMetadata(Logging.exceptionToDescription(e), duration)); + } + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AAIServiceTree.java b/vid-app-common/src/main/java/org/onap/vid/services/AAIServiceTree.java new file mode 100644 index 000000000..432ab6401 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/AAIServiceTree.java @@ -0,0 +1,247 @@ +package org.onap.vid.services; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.aai.util.AAITreeConverter; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.asdc.parser.ServiceModelInflator; +import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.aaiTree.AAITreeNode; +import org.onap.vid.model.aaiTree.ServiceInstance; +import org.onap.vid.utils.Tree; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import javax.ws.rs.core.Response; +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; + +import static java.lang.Thread.sleep; +import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.toSet; +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; +import static org.onap.vid.services.AAITreeNodeBuilder.*; + +@Component +public class AAIServiceTree { + + private final AAITreeNodeBuilder aaiTreeNodeBuilder; + + private final AAITreeConverter aaiTreeConverter; + + private final AaiClientInterface aaiClient; + + private final VidService sdcService; + + private final ServiceModelInflator serviceModelInflator; + + private final ObjectMapper mapper = new ObjectMapper(); + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AAIServiceTree.class); + + public static final Tree AAI_TREE_PATHS = + new Tree<>(new AaiRelationship(SERVICE_INSTANCE)); + + static { + AAI_TREE_PATHS.addPath(toAaiRelationshipList(GENERIC_VNF, VG)); + AAI_TREE_PATHS.addPath(toAaiRelationshipList(NETWORK)); + AAI_TREE_PATHS.addPath(toAaiRelationshipList(GENERIC_VNF, NETWORK)); + AAI_TREE_PATHS.addPath(toAaiRelationshipList(INSTANCE_GROUP)); + } + + @Inject + public AAIServiceTree(AaiClientInterface aaiClient, AAITreeNodeBuilder aaiTreeNodeBuilder, + AAITreeConverter aaiTreeConverter, VidService sdcService, + ServiceModelInflator serviceModelInflator) { + this.aaiClient = aaiClient; + this.aaiTreeNodeBuilder = aaiTreeNodeBuilder; + this.aaiTreeConverter = aaiTreeConverter; + this.sdcService = sdcService; + this.serviceModelInflator = serviceModelInflator; + } + + public List buildAAITree(String getUrl, Tree pathsToSearch) { + + ConcurrentSkipListSet nodesAccumulator = createNodesAccumulator(); + + List aaiTreeNodes = fetchAAITree(getUrl, pathsToSearch, nodesAccumulator, true); + + enrichNodesWithModelVersionAndModelName(nodesAccumulator); + + return aaiTreeNodes; + } + + public ServiceInstance getServiceInstanceTopology(String globalCustomerId, String serviceType, String serviceInstanceId) { + + String getURL = "business/customers/customer/" + + globalCustomerId + "/service-subscriptions/service-subscription/" + + serviceType + "/service-instances/service-instance/" + serviceInstanceId; + + //Used later to get the nodes UUID + ConcurrentSkipListSet nodesAccumulator = createNodesAccumulator(); + + AAITreeNode aaiTree = fetchAAITree(getURL, AAI_TREE_PATHS, nodesAccumulator, false).get(0); + + //Populate nodes with model-name & model-version (from aai) + enrichNodesWithModelVersionAndModelName(nodesAccumulator); + + final ServiceModel serviceModel = getServiceModel(aaiTree.getModelVersionId()); + + //Populate nodes with model-customization-name (from sdc model) + enrichNodesWithModelCustomizationName(nodesAccumulator, serviceModel); + + return aaiTreeConverter.convertTreeToUIModel(aaiTree, globalCustomerId, serviceType, getInstantiationType(serviceModel)); + } + + private List fetchAAITree(String getUrl, Tree pathsToSearch, + ConcurrentSkipListSet nodesAccumulator, boolean partialTreeOnTimeout) { + ThreadPoolExecutor threadPool = getThreadPool(); + + List aaiTree = aaiTreeNodeBuilder.buildNode(SERVICE_INSTANCE, + getUrl, defaultIfNull(nodesAccumulator, createNodesAccumulator()), + threadPool, new ConcurrentLinkedQueue<>(), + new AtomicInteger(0), pathsToSearch); + + boolean timeoutOccurred = waitForTreeFetch(threadPool); + + if (timeoutOccurred) { + if (!partialTreeOnTimeout) { + throw new GenericUncheckedException("Timeout on fetchAAITree. Fetched " + nodesAccumulator.size() + " nodes for url: " + getUrl); + } + LOGGER.warn(EELFLoggerDelegate.errorLogger, "Timeout on fetchAAITree for url: " + getUrl); + } + + return aaiTree; + } + + private ConcurrentSkipListSet createNodesAccumulator() { + return new ConcurrentSkipListSet<>(comparing(AAITreeNode::getUniqueNodeKey)); + } + + private String getInstantiationType(ServiceModel serviceModel) { + if (serviceModel.getService() != null && serviceModel.getService().getInstantiationType() != null) { + return serviceModel.getService().getInstantiationType(); + } else { + return null; + } + } + + private ServiceModel getServiceModel(String modelVersionId) { + try { + final ServiceModel serviceModel = sdcService.getService(modelVersionId); + if (serviceModel == null) { + throw new GenericUncheckedException("Model version '" + modelVersionId + "' not found"); + } + return serviceModel; + } catch (AsdcCatalogException e) { + throw new GenericUncheckedException("Exception while loading model version '" + modelVersionId + "'", e); + } + + } + + void enrichNodesWithModelCustomizationName(Collection nodes, ServiceModel serviceModel) { + final Map customizationNameByVersionId = serviceModelInflator.toNamesByVersionId(serviceModel); + + nodes.forEach(node -> { + final ServiceModelInflator.Names names = customizationNameByVersionId.get(node.getModelVersionId()); + if (names != null) { + node.setKeyInModel(names.getModelKey()); + node.setModelCustomizationName(names.getModelCustomizationName()); + } + }); + } + + + private void enrichNodesWithModelVersionAndModelName(Collection nodes) { + + Collection invariantIDs = getModelInvariantIds(nodes); + + Map modelVersionByModelVersionId = new HashMap<>(); + Map modelNameByModelVersionId = new HashMap<>(); + + JsonNode models = getModels(aaiClient, invariantIDs); + for (JsonNode model: models) { + JsonNode modelVersions = model.get("model-vers").get("model-ver"); + for (JsonNode modelVersion: modelVersions) { + final String modelVersionId = modelVersion.get("model-version-id").asText(); + modelVersionByModelVersionId.put(modelVersionId, modelVersion.get("model-version").asText()); + modelNameByModelVersionId.put(modelVersionId, modelVersion.get("model-name").asText()); + } + } + + nodes.forEach(node -> { + node.setModelVersion(modelVersionByModelVersionId.get(node.getModelVersionId())); + node.setModelName(modelNameByModelVersionId.get(node.getModelVersionId())); + }); + + } + + private JsonNode getModels(AaiClientInterface aaiClient, Collection invariantIDs) { + Response response = aaiClient.getVersionByInvariantId(ImmutableList.copyOf(invariantIDs)); + try { + JsonNode responseJson = mapper.readTree(response.readEntity(String.class)); + return responseJson.get("model"); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to getVersionByInvariantId from A&AI", e); + } + return mapper.createObjectNode(); + } + + private Set getModelInvariantIds(Collection nodes) { + return nodes.stream() + .map(AAITreeNode::getModelInvariantId) + .filter(Objects::nonNull) + .collect(toSet()); + } + + private boolean waitForTreeFetch(ThreadPoolExecutor threadPool) { + int timer = 60; + try { + //Stop fetching information if it takes more than 1 minute + while (threadPool.getActiveCount() != 0 && + timer > 0) { + sleep(1000); + timer--; + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new GenericUncheckedException(e); + } + threadPool.shutdown(); + return (timer == 0); + } + + private ThreadPoolExecutor getThreadPool() { + //Use at least one thread, and never more than 75% of the available thread. + int cores = Math.max((int)(Runtime.getRuntime().availableProcessors() * 0.75), 1); + BlockingQueue queue = new LinkedBlockingQueue<>(); + return new ThreadPoolExecutor(1, cores, 10, TimeUnit.SECONDS, queue); + } + + public static class AaiRelationship { + + public final String type; + + public AaiRelationship(String type) { + this.type = type; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof AaiRelationship)) return false; + AaiRelationship that = (AaiRelationship) o; + return Objects.equals(type, that.type); + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java new file mode 100644 index 000000000..41f0144c9 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/AAITreeNodeBuilder.java @@ -0,0 +1,281 @@ +package org.onap.vid.services; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.aai.ExceptionWithRequestInfo; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList; +import org.onap.vid.model.aaiTree.AAITreeNode; +import org.onap.vid.model.aaiTree.FailureAAITreeNode; +import org.onap.vid.utils.Streams; +import org.onap.vid.utils.Tree; +import org.onap.vid.utils.Unchecked; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.*; +import static org.onap.vid.utils.Streams.not; + + +@Component +public class AAITreeNodeBuilder { + + private AaiClientInterface aaiClient; + + private final ObjectMapper mapper = new ObjectMapper(); + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AAITreeNodeBuilder.class); + + //List of all the node types the tree should include + public static final String SERVICE_INSTANCE = "service-instance"; + public static final String GENERIC_VNF = "generic-vnf"; + public static final String NETWORK = "l3-network"; + public static final String FAILURE = "failure_node"; + public static final String COLLECTION_RESOURCE = "collection"; + public static final String CONFIGURATION = "configuration"; + public static final String PNF = "pnf"; + public static final String VF_MODULE = "vf-module"; + public static final String INSTANCE_GROUP = "instance-group"; + public static final String PORT = "l-interface"; + public static final String VG = "volume-group"; + public static final String VLAN_TAG = "vlan-tag"; + + //Hashmap that defines the node-type and the tag that should be used to find it's ID key in the JSON. + private static HashMap nodeTypeToIdKeyMap = generateTypeToIdKeyMap(); + + //Hashmap that defines the node-type and the tag that should be used to find it's NAMR key in the JSON. + private static HashMap nodeTypeToNameKeyMap = generateTypeToNameKeyMap(); + + public enum AAIBaseProperties { + ORCHESTRATION_STATUS("orchestration-status"), + PROV_STATUS("prov-status"), + IN_MAINT("in-maint"), + MODEL_VERSION_ID("model-version-id"), + MODEL_CUSTOMIZATION_ID("model-customization-id"), + MODEL_INVARIANT_ID("model-invariant-id"), + RELATIONSHIP_LIST("relationship-list"); + + private final String aaiKey; + + AAIBaseProperties(String aaiKey) { + this.aaiKey = aaiKey; + } + + public String getAaiKey() { + return aaiKey; + } + } + + public static List toAaiRelationshipList(String... types) { + return Stream.of(types).map(AAIServiceTree.AaiRelationship::new).collect(Collectors.toList()); + } + + @Inject + public AAITreeNodeBuilder(AaiClientInterface aaiClient) { + this.aaiClient = aaiClient; + } + + public List buildNode(String nodeType, + String requestURL, + ConcurrentSkipListSet nodesAccumulator, ExecutorService threadPool, + ConcurrentLinkedQueue visitedNodes, + AtomicInteger nodesCounter, + Tree pathsTree) { + + JsonNode topLevelJson = aaiClient.typedAaiGet(Unchecked.toURI(requestURL), JsonNode.class); + + if (topLevelJson.has(nodeType) && topLevelJson.get(nodeType).isArray()) { + return Streams.fromIterable(topLevelJson.get(nodeType)) + .map(item -> parseNodeAndGetChildren(nodeType, requestURL, item, + nodesAccumulator, threadPool, visitedNodes, nodesCounter, pathsTree)) + .collect(toList()); + } else { + return ImmutableList.of(parseNodeAndGetChildren(nodeType, requestURL, topLevelJson, + nodesAccumulator, threadPool, visitedNodes, nodesCounter, pathsTree)); + } + } + + private AAITreeNode parseNodeAndGetChildren(String nodeType, + String requestURL, + JsonNode topLevelJson, + ConcurrentSkipListSet nodesAccumulator, ExecutorService threadPool, + ConcurrentLinkedQueue visitedNodes, + AtomicInteger nodesCounter, + Tree pathsTree) { + AAITreeNode node = jsonToAaiNode(nodeType, topLevelJson, nodesAccumulator, nodesCounter); + + RelationshipList relationships = mapper.convertValue(topLevelJson.get(AAIBaseProperties.RELATIONSHIP_LIST.getAaiKey()), RelationshipList.class); + if (relationships != null) { + getChildren(threadPool, nodesAccumulator, relationships.getRelationship(), visitedNodes, node, nodesCounter, pathsTree); + } + if (StringUtils.equals(node.getType(), GENERIC_VNF)) { + getRelatedVfModules(threadPool, nodesAccumulator, requestURL, node, nodesCounter); + } + return node; + } + + private AAITreeNode jsonToAaiNode(String nodeType, JsonNode topLevelJson, ConcurrentSkipListSet nodesAccumulator, AtomicInteger nodesCounter) { + AAITreeNode node = fillNodeMetaData(nodeType, topLevelJson, nodesCounter); + + nodesAccumulator.add(node); + + return node; + } + + private void getRelatedVfModules(ExecutorService threadPool, ConcurrentSkipListSet nodesAccumulator, String parentURL, AAITreeNode parentNode, AtomicInteger nodesCounter) { + /* + VNFs do not report their direct related-to vf-modules, so try + directly fetching a resource URI. + */ + + threadPool.execute(() -> { + // the response is an array of vf-modules + final JsonNode topLevelJson; + try { + topLevelJson = aaiClient.typedAaiGet(Unchecked.toURI(parentURL + "/vf-modules"), JsonNode.class); + } catch (ExceptionWithRequestInfo e) { + if (e.getHttpCode().equals(404)) { + // it's ok, as we're just optimistically fetching + // the /vf-modules uri; 404 says this time it was + // a bad guess + return; + } else { + throw e; + } + } + + if (topLevelJson != null) { + parentNode.getChildren().addAll( + Streams.fromIterable(topLevelJson.get(VF_MODULE)) + .map(vfModuleNode -> jsonToAaiNode(VF_MODULE, vfModuleNode, nodesAccumulator, nodesCounter)) + .collect(toList()) + ); + } else { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to get vf-modules for vnf " + parentNode.getId()); + } + }); + } + + private void getChildren(ExecutorService threadPool, ConcurrentSkipListSet nodesAccumulator, + List relationships, ConcurrentLinkedQueue visitedNodes, AAITreeNode parent, AtomicInteger nodesCounter, Tree pathsTree) { + for (Relationship relationship : relationships) { + createChildNode(threadPool, nodesAccumulator, relationship, visitedNodes, parent, nodesCounter, pathsTree); + } + } + + private void createChildNode(ExecutorService threadPool, ConcurrentSkipListSet nodesAccumulator, + Relationship relationship, ConcurrentLinkedQueue visitedNodes, AAITreeNode parent, AtomicInteger nodesCounter, Tree pathsTree) { + String newNodeType = relationship.getRelatedTo(); + Tree subTree = pathsTree.getSubTree(new AAIServiceTree.AaiRelationship(newNodeType)); + if (subTree!=null) { + String newNodeUrl = relationship.getRelatedLink(); + if (!visitedNodes.contains(newNodeUrl)) { + visitedNodes.add(newNodeUrl); + threadPool.execute(() -> { + try { + parent.addChildren(buildNode(newNodeType, newNodeUrl, nodesAccumulator, threadPool, visitedNodes, nodesCounter, subTree)); + } catch (Exception e) { + parent.getChildren().add(createFailureNode(e)); + } + } + ); + } + } + } + + private AAITreeNode fillNodeMetaData(String nodeType, JsonNode model, @NotNull AtomicInteger nodesCounter) { + AAITreeNode node = new AAITreeNode(); + node.setType(nodeType); + node.setUniqueNumber(nodesCounter.getAndIncrement()); + node.setOrchestrationStatus(getStringDataFromJsonIfExists(model, AAIBaseProperties.ORCHESTRATION_STATUS.getAaiKey())); + node.setProvStatus(getStringDataFromJsonIfExists(model, AAIBaseProperties.PROV_STATUS.getAaiKey())); + node.setInMaint(getBooleanDataFromJsonIfExists(model, AAIBaseProperties.IN_MAINT.getAaiKey())); + node.setModelVersionId(getStringDataFromJsonIfExists(model, AAIBaseProperties.MODEL_VERSION_ID.getAaiKey())); + node.setModelCustomizationId(getStringDataFromJsonIfExists(model, AAIBaseProperties.MODEL_CUSTOMIZATION_ID.getAaiKey())); + node.setModelInvariantId(getStringDataFromJsonIfExists(model, AAIBaseProperties.MODEL_INVARIANT_ID.getAaiKey())); + node.setId(getStringDataFromJsonIfExists(model, nodeTypeToIdKeyMap.get(nodeType))); + node.setName(getStringDataFromJsonIfExists(model, nodeTypeToNameKeyMap.get(nodeType))); + node.setAdditionalProperties(aggregateAllOtherProperties(model, nodeType)); + + return node; + } + + private AAITreeNode createFailureNode(Exception exception) { + return FailureAAITreeNode.of(exception); + } + + private String getStringDataFromJsonIfExists(JsonNode model, String key) { + if (model.has(key)) { + return model.get(key).asText(); + } + return null; + } + + private Boolean getBooleanDataFromJsonIfExists(JsonNode model, String key) { + if (model.has(key)) { + return model.get(key).asBoolean(); + } + return false; + } + + private Map aggregateAllOtherProperties(JsonNode model, String nodeType) { + Set ignoreProperties = Stream.of(AAIBaseProperties.values()) + .map(AAIBaseProperties::getAaiKey).collect(toSet()); + + return Streams.fromIterator(model.fields()) + .filter(not(field -> StringUtils.equals(field.getKey(), nodeTypeToIdKeyMap.get(nodeType)))) + .filter(not(field -> StringUtils.equals(field.getKey(), nodeTypeToNameKeyMap.get(nodeType)))) + .filter(not(field -> ignoreProperties.contains(field.getKey()))) + .collect(toMap(Map.Entry::getKey, v -> v.getValue().asText())); + } + + private static HashMap generateTypeToIdKeyMap() { + HashMap result = new HashMap<>(); + result.put(SERVICE_INSTANCE, "service-instance-id"); + result.put(GENERIC_VNF, "vnf-id"); + result.put(NETWORK, "network-id"); + result.put(COLLECTION_RESOURCE, "collection-id"); + result.put(CONFIGURATION, "configuration-id"); + result.put(PNF, "pnf-id"); + result.put(VF_MODULE, "vf-module-id"); + result.put(INSTANCE_GROUP, "id"); + result.put(PORT, "l-interface-id"); + result.put(VG, "volume-group-id"); + result.put(VLAN_TAG, "vlan-id"); + + return result; + } + + private static HashMap generateTypeToNameKeyMap() { + HashMap result = new HashMap<>(); + result.put(SERVICE_INSTANCE, "service-instance-name"); + result.put(GENERIC_VNF, "vnf-name"); + result.put(NETWORK, "network-name"); + result.put(COLLECTION_RESOURCE, "collection-name"); + result.put(CONFIGURATION, "configuration-name"); + result.put(PNF, "pnf-name"); + result.put(VF_MODULE, "vf-module-name"); + result.put(INSTANCE_GROUP, "instance-group-name"); + result.put(PORT, "l-interface-name"); + result.put(VG, "volume-group-name"); + result.put(VLAN_TAG, "vlan-name"); + + return result; + } +} \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java index d2ee32cbc..bd751c5c2 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java @@ -22,6 +22,7 @@ package org.onap.vid.services; import io.joshworks.restclient.http.HttpResponse; +import org.onap.vid.aai.AaiGetVnfResponse; import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.AaiResponseTranslator; import org.onap.vid.aai.SubscriberFilteredResults; @@ -32,6 +33,7 @@ import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; import org.onap.vid.aai.model.PortDetailsTranslator; import org.onap.vid.asdc.beans.Service; import org.onap.vid.model.SubscriberList; +import org.onap.vid.model.aaiTree.RelatedVnf; import org.onap.vid.roles.RoleValidator; import javax.ws.rs.core.Response; @@ -64,7 +66,7 @@ public interface AaiService { AaiResponse getAicZoneForPnf(String globalCustomerId , String serviceType , String serviceId); - Response getVNFData(String globalSubscriberId, String serviceType); + AaiResponse getVNFData(String globalSubscriberId, String serviceType); AaiResponse getTenants(String globalCustomerId, String serviceType, RoleValidator roleValidator); @@ -87,4 +89,10 @@ public interface AaiService { List getPortMirroringSourcePorts(String configurationId); AaiResponse getInstanceGroupsByVnfInstanceId(String vnfInstanceId); + + String getAAIServiceTree(String globalCustomerId, String serviceType, String serviceInstanceId); + + GetTenantsResponse getHomingDataByVfModule(String vnfInstanceId, String vfModuleId); + + List searchGroupMembers(String globalCustomerId, String serviceType, String invariantId, String groupType, String groupRole); } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index acdf0afb5..fe4a66185 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -21,38 +21,35 @@ package org.onap.vid.services; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import io.joshworks.restclient.http.HttpResponse; import org.apache.http.HttpStatus; -import org.codehaus.jackson.JsonNode; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.aai.*; -import org.onap.vid.aai.ServiceInstance; -import org.onap.vid.aai.ServiceSubscription; -import org.onap.vid.aai.Services; -import org.onap.vid.aai.model.AaiGetAicZone.AicZones; -import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.AaiGetNetworkCollectionDetails; +import org.onap.vid.aai.model.*; import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.AaiGetRelatedInstanceGroupsByVnfId; import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; import org.onap.vid.aai.model.AaiGetPnfs.Pnf; import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone; +import org.onap.vid.aai.model.Properties; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; -import org.onap.vid.aai.model.*; import org.onap.vid.asdc.beans.Service; +import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.ServiceInstanceSearchResult; import org.onap.vid.model.SubscriberList; +import org.onap.vid.model.aaiTree.AAITreeNode; +import org.onap.vid.model.aaiTree.RelatedVnf; import org.onap.vid.roles.RoleValidator; import org.onap.vid.utils.Intersection; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.utils.Tree; import org.springframework.beans.factory.annotation.Autowired; import javax.ws.rs.core.Response; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; -import org.springframework.beans.factory.annotation.Qualifier; /** * Created by Oren on 7/4/17. @@ -62,18 +59,25 @@ public class AaiServiceImpl implements AaiService { private static final String SERVICE_TYPE = "service-subscription.service-type"; private static final String CUSTOMER_ID = "customer.global-customer-id"; private static final String SERVICE_INSTANCE_NAME = "service-instance.service-instance-name"; + private static final String TENANT_NODE_TYPE = "tenant"; + private static final String CLOUD_REGION_NODE_TYPE = "cloud-region"; private int indexOfSubscriberName = 6; @Autowired private AaiClientInterface aaiClient; @Autowired - @Qualifier("aaiClientForCodehausMapping") private AaiOverTLSClientInterface aaiOverTLSClient; @Autowired private AaiResponseTranslator aaiResponseTranslator; + @Autowired + private AAITreeNodeBuilder aaiTreeNode; + + @Autowired + private AAIServiceTree aaiServiceTree; + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiServiceImpl.class); private List convertModelToService(Model model) { @@ -277,9 +281,7 @@ public class AaiServiceImpl implements AaiService { new ServiceInstanceSearchResult(serviceInstance.serviceInstanceId, subscriberId, serviceType, serviceInstance.serviceInstanceName, subscriberName, serviceInstance.modelInvariantId, serviceInstance.modelVersionId, serviceSubscription.isPermitted); - if (instanceIdentifier == null) { - results.add(serviceInstanceSearchResult); - } else if (serviceInstanceMatchesIdentifier(instanceIdentifier, serviceInstance)) { + if ((instanceIdentifier == null) || (serviceInstanceMatchesIdentifier(instanceIdentifier, serviceInstance))){ results.add(serviceInstanceSearchResult); } } @@ -345,13 +347,31 @@ public class AaiServiceImpl implements AaiService { } @Override - public Response getVNFData(String globalSubscriberId, String serviceType) { - return aaiClient.getVNFData(globalSubscriberId, serviceType); + public AaiResponse getVNFData(String globalSubscriberId, String serviceType) { + AaiResponse response = aaiClient.getVNFData(globalSubscriberId, serviceType); + return filterChangeManagementVNFCandidatesResponse(response); + } + + private AaiResponse filterChangeManagementVNFCandidatesResponse(AaiResponse response) { + + + if (response != null && response.getT() != null) { + response.getT().results = + response.getT().results.stream() + .filter(result -> ( + result.nodeType.equalsIgnoreCase("generic-vnf") || + result.nodeType.equalsIgnoreCase("service-instance"))) + .collect(Collectors.toList()); + + return response; + } + + return new AaiResponse(); } @Override public AaiResponse getAaiZones() { - return (AaiResponse) aaiClient.getAllAicZones(); + return aaiClient.getAllAicZones(); } @Override @@ -386,14 +406,12 @@ public class AaiServiceImpl implements AaiService { @Override public AaiResponse getNetworkCollectionDetails(String serviceInstanceId){ - AaiResponse getNetworkCollectionDetailsAaiResponse = aaiClient.getNetworkCollectionDetails(serviceInstanceId); - return getNetworkCollectionDetailsAaiResponse; + return aaiClient.getNetworkCollectionDetails(serviceInstanceId); } @Override public AaiResponse getInstanceGroupsByCloudRegion(String cloudOwner, String cloudRegionId, String networkFunction){ - AaiResponse getInstanceGroupsByCloudRegionResponse = aaiClient.getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction); - return getInstanceGroupsByCloudRegionResponse; + return aaiClient.getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction); } @Override @@ -452,6 +470,66 @@ public class AaiServiceImpl implements AaiService { return aaiClient.getInstanceGroupsByVnfInstanceId(vnfInstanceId); } + @Override + public GetTenantsResponse getHomingDataByVfModule(String vnfInstanceId, String vfModuleId) { + return aaiClient.getHomingDataByVfModule(vnfInstanceId,vfModuleId); + } + + @Override + public List searchGroupMembers(String globalCustomerId, String serviceType, String invariantId, String groupType, String groupRole) { + String getURL = "business/customers/customer/" + + globalCustomerId + "/service-subscriptions/service-subscription/" + + serviceType + "/service-instances?model-invariant-id=" + invariantId; + + Tree pathsToSearch = new Tree<>(new AAIServiceTree.AaiRelationship(AAITreeNodeBuilder.SERVICE_INSTANCE)); + pathsToSearch.addPath(AAITreeNodeBuilder.toAaiRelationshipList(AAITreeNodeBuilder.GENERIC_VNF, AAITreeNodeBuilder.INSTANCE_GROUP)); + + //get all vnfs related to service-instances from the model-invariant-id + List aaiTree = aaiServiceTree.buildAAITree(getURL, pathsToSearch); + + //filter by instance-group-role & instance-group-type properties (from getAdditionalProperties) + //only vnfs has related instance-group with the same groupType & groupRole - are filtered out. + List filteredVnfs = filterByInstanceGroupRoleAndType(aaiTree, groupRole, groupType); + + //convert vnfs to expected result + return filteredVnfs.stream() + .map(RelatedVnf::from) + .map(this::enrichRelatedVnfWithCloudRegionAndTenant) + .collect(Collectors.toList()); + } + + private List filterByInstanceGroupRoleAndType(List aaiTree, String groupRole, String groupType) { + + return aaiTree.stream() + .map(AAITreeNode::getChildren) + .flatMap(Collection::stream) + .filter(vnf -> isInstanceGroupsNotMatchRoleAndType(vnf.getChildren(), groupRole, groupType)) + .collect(Collectors.toList()); + } + + public boolean isInstanceGroupsNotMatchRoleAndType(List instanceGroups, String groupRole, String groupType) { + return instanceGroups.stream() + .map(AAITreeNode::getAdditionalProperties) + .allMatch(props -> + (!(groupRole.equals(props.get("instance-group-role")) && + groupType.equals(props.get("instance-group-type")))) + ); + } + + public RelatedVnf enrichRelatedVnfWithCloudRegionAndTenant(RelatedVnf vnf) { + Map cloudRegionAndTenant = aaiClient.getCloudRegionAndTenantByVnfId(vnf.getInstanceId()); + + if (cloudRegionAndTenant.containsKey(TENANT_NODE_TYPE)) { + vnf.setTenantId(cloudRegionAndTenant.get(TENANT_NODE_TYPE).getTenantId()); + vnf.setTenantName(cloudRegionAndTenant.get(TENANT_NODE_TYPE).getTenantName()); + } + + if (cloudRegionAndTenant.containsKey(CLOUD_REGION_NODE_TYPE)) { + vnf.setLcpCloudRegionId(cloudRegionAndTenant.get(CLOUD_REGION_NODE_TYPE).getCloudRegionId()); + } + + return vnf; + } private List convertGetInstanceGroupsResponseToSimpleResponse(AaiGetRelatedInstanceGroupsByVnfId response) { List instanceGroupInfoList = new ArrayList<>(); for(org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship relationship: response.getRelationshipList().getRelationship()){ @@ -524,4 +602,16 @@ public class AaiServiceImpl implements AaiService { return relationshipValues; } + + public String getAAIServiceTree(String globalCustomerId, String serviceType, String serviceInstanceId) { + ObjectMapper om = new ObjectMapper(); + String result; + try { + org.onap.vid.model.aaiTree.ServiceInstance tree = aaiServiceTree.getServiceInstanceTopology(globalCustomerId, serviceType, serviceInstanceId); + result = om.writeValueAsString(tree); + } catch (Exception e) { + throw new GenericUncheckedException(e); + } + return result; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java index 90eb0d2b8..07bf46157 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogic.java @@ -5,12 +5,13 @@ import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.job.Job; import org.onap.vid.model.JobAuditStatus; import org.onap.vid.model.ServiceInfo; -import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; -import org.onap.vid.mso.model.ServiceInstantiationRequestDetails; +import org.onap.vid.model.serviceInstantiation.*; +import org.onap.vid.mso.model.*; import org.onap.vid.mso.rest.AsyncRequestStatus; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.function.Consumer; @@ -22,10 +23,40 @@ public interface AsyncInstantiationBusinessLogic { List pushBulkJob(ServiceInstantiation request, String userId); - RequestDetailsWrapper generateServiceInstantiationRequest(UUID uuid, ServiceInstantiation details, String userId); + RequestDetailsWrapper generateMacroServiceInstantiationRequest(UUID uuid, ServiceInstantiation details, String optimisticUniqueServiceInstanceName, String userId); + + RequestDetailsWrapper generateALaCarteServiceInstantiationRequest(UUID uuid, ServiceInstantiation details, String optimisticUniqueServiceInstanceName, String userId); + + RequestDetailsWrapper generateALaCarteServiceDeletionRequest(UUID uuid, ServiceInstantiation details, String userId); + + RequestDetailsWrapper generateVnfInstantiationRequest(Vnf vnfDetails, ModelInfo serviceModelInfo, String serviceInstanceId, String userId); + + RequestDetailsWrapper generateVfModuleInstantiationRequest(VfModule vfModuleDetails, ModelInfo serviceModelInfo, String serviceInstanceId, ModelInfo vnfModelInfo, String vnfInstanceId, String vgInstanceId, String userId); + + RequestDetailsWrapper generateVolumeGroupInstantiationRequest(VfModule vfModuleDetails, ModelInfo serviceModelInfo, String serviceInstanceId, ModelInfo vnfModelInfo, String vnfInstanceId, String userId); + + RequestDetailsWrapper generateNetworkInstantiationRequest(Network networkDetails, ModelInfo serviceModelInfo, String serviceInstanceId, String userId); + + RequestDetailsWrapper generateInstanceGroupInstantiationRequest(InstanceGroup request, ModelInfo serviceModelInfo, String serviceInstanceId, String userId); + + List> buildVnfInstanceParams(List> currentVnfInstanceParams, List vfModules); String getServiceInstantiationPath(ServiceInstantiation serviceInstantiationRequest); + String getServiceDeletionPath(String serviceInstanceId); + + String getVnfInstantiationPath(String serviceInstanceId); + + String getNetworkInstantiationPath(String serviceInstanceId); + + String getVfmoduleInstantiationPath(String serviceInstanceId, String vnfInstanceId); + + String getVolumeGroupInstantiationPath(String serviceInstanceId, String vnfInstanceId); + + String getInstanceGroupInstantiationPath(); + + String getInstanceGroupDeletePath(String instanceGroupId); + String getOrchestrationRequestsPath(); ServiceInfo getServiceInfoByJobId(UUID jobUUID); @@ -57,4 +88,6 @@ public interface AsyncInstantiationBusinessLogic { void setMaxRetriesGettingFreeNameFromAai(int maxRetriesGettingFreeNameFromAai); String getUniqueName(String name, ResourceType resourceType); + + } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java index df8e92d66..c4264c6b5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java @@ -1,42 +1,17 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - package org.onap.vid.services; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import io.joshworks.restclient.http.HttpResponse; -import java.io.IOException; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.hibernate.SessionFactory; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.service.DataAccessService; import org.onap.vid.aai.AaiClientInterface; -import org.onap.vid.aai.AaiOverTLSClientInterface; -import org.onap.vid.aai.AaiResponse; -import org.onap.vid.aai.exceptions.InvalidAAIResponseException; -import org.onap.vid.aai.model.AaiNodeQueryResponse; +import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.changeManagement.RequestDetailsWrapper; -import org.onap.vid.domain.mso.CloudConfiguration; -import org.onap.vid.domain.mso.SubscriberInfo; import org.onap.vid.exceptions.DbFailureUncheckedException; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.exceptions.MaxRetriesException; @@ -46,22 +21,25 @@ import org.onap.vid.job.Job.JobStatus; import org.onap.vid.job.JobAdapter; import org.onap.vid.job.JobType; import org.onap.vid.job.JobsBrokerService; +import org.onap.vid.model.Action; import org.onap.vid.model.JobAuditStatus; import org.onap.vid.model.NameCounter; import org.onap.vid.model.ServiceInfo; -import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; -import org.onap.vid.model.serviceInstantiation.VfModule; -import org.onap.vid.model.serviceInstantiation.Vnf; +import org.onap.vid.model.serviceInstantiation.*; import org.onap.vid.mso.MsoBusinessLogicImpl; import org.onap.vid.mso.MsoProperties; -import org.onap.vid.mso.model.ServiceInstantiationRequestDetails; +import org.onap.vid.mso.model.*; +import org.onap.vid.mso.model.ServiceInstantiationRequestDetails.RequestParameters; +import org.onap.vid.mso.model.ServiceInstantiationRequestDetails.*; +import org.onap.vid.mso.model.VfModuleInstantiationRequestDetails.RequestParametersVfModule; +import org.onap.vid.mso.model.VfModuleInstantiationRequestDetails.UserParamMap; import org.onap.vid.mso.rest.AsyncRequestStatus; +import org.onap.vid.mso.rest.SubscriberInfo; +import org.onap.vid.properties.Features; import org.onap.vid.utils.DaoUtils; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.service.DataAccessService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; +import org.togglz.core.manager.FeatureManager; import java.sql.Timestamp; import java.time.LocalDateTime; @@ -69,14 +47,19 @@ import java.util.*; import java.util.function.Consumer; import java.util.stream.Collectors; +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; +import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID; +import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID; import static org.onap.vid.utils.Logging.debugRequestDetails; @Service -public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBusinessLogic { +public class AsyncInstantiationBusinessLogicImpl implements + AsyncInstantiationBusinessLogic { private static final int MAX_RETRIES_GETTING_COUNTER = 100; private static final int MAX_RETRIES_GETTING_FREE_NAME_FROM_AAI = 10000; - private static final String NAME_FOR_CHECK_AAI_STATUS = "NAME_FOR_CHECK_AAI_STATUS"; + public static final String NAME_FOR_CHECK_AAI_STATUS = "NAME_FOR_CHECK_AAI_STATUS"; + private static final String VID_SOURCE = "VID"; private final DataAccessService dataAccessService; @@ -84,64 +67,86 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu private final JobsBrokerService jobService; + private final CloudOwnerService cloudOwnerService; + private SessionFactory sessionFactory; - private AaiOverTLSClientInterface aaiOverTLSClient; + private AaiClientInterface aaiClient; + + private FeatureManager featureManager; private int maxRetriesGettingFreeNameFromAai = MAX_RETRIES_GETTING_FREE_NAME_FROM_AAI; - private static final EELFLoggerDelegate logger = EELFLoggerDelegate - .getLogger(AsyncInstantiationBusinessLogicImpl.class); + private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AsyncInstantiationBusinessLogicImpl.class); private Map msoStateToJobStatusMap = ImmutableMap.builder() - .put("inprogress", JobStatus.IN_PROGRESS) - .put("failed", JobStatus.FAILED) - .put("pause", JobStatus.PAUSE) - .put("paused", JobStatus.PAUSE) - .put("complete", JobStatus.COMPLETED) - .put("pending", JobStatus.IN_PROGRESS) - .put("pendingmanualtask", JobStatus.PAUSE) - .put("unlocked", JobStatus.IN_PROGRESS) - .build(); + .put("inprogress", JobStatus.IN_PROGRESS) + .put("failed", JobStatus.FAILED) + .put("pause", JobStatus.PAUSE) + .put("paused", JobStatus.PAUSE) + .put("complete", JobStatus.COMPLETED) + .put("pending", JobStatus.IN_PROGRESS) + .put("pendingmanualtask", JobStatus.PAUSE) + .put("unlocked", JobStatus.IN_PROGRESS) + .build(); @Autowired public AsyncInstantiationBusinessLogicImpl(DataAccessService dataAccessService, - JobAdapter jobAdapter, - JobsBrokerService jobService, - SessionFactory sessionFactory, - @Qualifier("aaiClientForFasterXmlMapping") AaiOverTLSClientInterface aaiOverTLSClient) { + JobAdapter jobAdapter, + JobsBrokerService jobService, + SessionFactory sessionFactory, + AaiClientInterface aaiClient, + FeatureManager featureManager, + CloudOwnerService cloudOwnerService) { this.dataAccessService = dataAccessService; this.jobAdapter = jobAdapter; this.jobService = jobService; this.sessionFactory = sessionFactory; - this.aaiOverTLSClient = aaiOverTLSClient; + this.aaiClient = aaiClient; + this.featureManager = featureManager; + this.cloudOwnerService = cloudOwnerService; } @Override public List getAllServicesInfo() { - return dataAccessService - .getList(ServiceInfo.class, filterByCreationDateAndNotDeleted(), orderByCreatedDateAndStatus(), null); + return dataAccessService.getList(ServiceInfo.class, filterByCreationDateAndNotDeleted(), orderByCreatedDateAndStatus(), null); } private String filterByCreationDateAndNotDeleted() { LocalDateTime minus3Months = LocalDateTime.now().minusMonths(3); Timestamp filterDate = Timestamp.valueOf(minus3Months); return " where" + - " hidden = false" + - " and deleted_at is null" + // don't fetch deleted - " and created >= '" + filterDate + "' "; + " hidden = false" + + " and deleted_at is null" + // don't fetch deleted + " and created >= '" + filterDate + "' "; } private String orderByCreatedDateAndStatus() { return " createdBulkDate DESC ,\n" + - " (CASE jobStatus\n" + - " WHEN 'COMPLETED' THEN 0\n" + - " WHEN 'FAILED' THEN 0\n" + - " WHEN 'IN_PROGRESS' THEN 1\n" + - " WHEN 'PAUSE' THEN 2\n" + - " WHEN 'PENDING' THEN 3\n" + - " WHEN 'STOPPED' THEN 3 END),\n" + - " statusModifiedDate "; + " (CASE jobStatus\n" + + " WHEN 'COMPLETED' THEN 0\n" + + " WHEN 'FAILED' THEN 0\n" + + " WHEN 'COMPLETED_WITH_ERRORS' THEN 0\n" + + " WHEN 'IN_PROGRESS' THEN 1\n" + + " WHEN 'PAUSE' THEN 2\n" + + " WHEN 'PENDING' THEN 3\n" + + " WHEN 'STOPPED' THEN 3 END),\n" + + " statusModifiedDate "; + } + + JobType getJobType(ServiceInstantiation request) { + if (request.isALaCarte()) { + switch (defaultIfNull(request.getAction(), Action.Create)) { + case Delete: + return JobType.ALaCarteService; + case None: + return JobType.ALaCarteService; + default: + return JobType.ALaCarteServiceInstantiation; + } + } else { + return JobType.MacroServiceInstantiation; + } } @Override @@ -151,173 +156,460 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu int bulkSize = request.getBulkSize(); UUID templateId = UUID.randomUUID(); for (int i = 0; i < bulkSize; i++) { - Job job = jobAdapter.createJob(JobType.ServiceInstantiation, request, templateId, userId, i); + ServiceInfo.ServiceAction serviceAction = getAction(request); + JobType jobType = getJobType(request); + final String optimisticUniqueServiceInstanceName = getOptimisticUniqueServiceInstanceName(request); + Job job = jobAdapter.createServiceInstantiationJob(jobType, request, templateId, userId, optimisticUniqueServiceInstanceName, i); UUID jobId = jobService.add(job); + dataAccessService.saveDomainObject(createServiceInfo(userId, request, jobId, templateId, createdBulkDate, optimisticUniqueServiceInstanceName, serviceAction), DaoUtils.getPropsMap()); auditVidStatus(jobId, job.getStatus()); uuids.add(jobId); - dataAccessService.saveDomainObject(createServiceInfo(userId, request, jobId, templateId, createdBulkDate), - DaoUtils.getPropsMap()); } return uuids; } - private ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId, - UUID templateId, Date createdBulkDate) { + private ServiceInfo.ServiceAction getAction(ServiceInstantiation request) { + if (request.getAction() == null) { + //throw new GenericUncheckedException("Required 'action' field not provided at service level"); + return Action.Create.getServiceAction(); + } + return request.getAction().getServiceAction(); + } + + + private String getOptimisticUniqueServiceInstanceName(ServiceInstantiation request) { + return StringUtils.isNotEmpty(request.getInstanceName()) ? getUniqueNameFromDbOnly(request.getInstanceName()) : request.getInstanceName(); + } + + protected ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId, UUID templateId, Date createdBulkDate, String optimisticUniqueServiceInstanceName, ServiceInfo.ServiceAction serviceAction) { return new ServiceInfo( - userId, Job.JobStatus.PENDING, serviceInstantiation.isPause(), jobId, templateId, - serviceInstantiation.getOwningEntityId(), - serviceInstantiation.getOwningEntityName(), - serviceInstantiation.getProjectName(), - serviceInstantiation.getAicZoneId(), - serviceInstantiation.getAicZoneName(), - serviceInstantiation.getTenantId(), - serviceInstantiation.getTenantName(), - serviceInstantiation.getLcpCloudRegionId(), - null, - serviceInstantiation.getSubscriptionServiceType(), - serviceInstantiation.getSubscriberName(), - null, - serviceInstantiation.getInstanceName(), - serviceInstantiation.getModelInfo().getModelInvariantId(), - serviceInstantiation.getModelInfo().getModelName(), - serviceInstantiation.getModelInfo().getModelVersion(), - createdBulkDate + userId, + serviceInstantiation.isALaCarte(), + Job.JobStatus.PENDING, serviceInstantiation.isPause(), jobId, templateId, + serviceInstantiation.getOwningEntityId(), + serviceInstantiation.getOwningEntityName(), + serviceInstantiation.getProjectName(), + serviceInstantiation.getAicZoneId(), + serviceInstantiation.getAicZoneName(), + serviceInstantiation.getTenantId(), + serviceInstantiation.getTenantName(), + serviceInstantiation.getLcpCloudRegionId(), + null, + serviceInstantiation.getSubscriptionServiceType(), + serviceInstantiation.getSubscriberName(), + serviceInstantiation.getGlobalSubscriberId(), + serviceInstantiation.getInstanceId(), + optimisticUniqueServiceInstanceName, + serviceInstantiation.getModelInfo().getModelVersionId(), + serviceInstantiation.getModelInfo().getModelName(), + serviceInstantiation.getModelInfo().getModelVersion(), + createdBulkDate, + serviceAction ); } @Override - public RequestDetailsWrapper generateServiceInstantiationRequest(UUID jobId, - ServiceInstantiation payload, String userId) { + public RequestDetailsWrapper generateMacroServiceInstantiationRequest(UUID jobId, ServiceInstantiation payload, String optimisticUniqueServiceInstanceName, String userId) { + String serviceInstanceName = generateServiceName(jobId, payload, optimisticUniqueServiceInstanceName); + + List serviceInstantiationServiceList = generateServiceInstantiationServicesList(payload, serviceInstanceName, createServiceInstantiationVnfList(payload)); + + RequestParameters requestParameters = new RequestParameters(payload.getSubscriptionServiceType(), false, serviceInstantiationServiceList); + + ServiceInstantiationRequestDetails requestDetails = generateServiceInstantiationRequestDetails(payload,requestParameters,serviceInstanceName, userId); + + RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails); + debugRequestDetails(requestDetailsWrapper, logger); + + return requestDetailsWrapper; + } + + @Override + public RequestDetailsWrapper generateALaCarteServiceInstantiationRequest(UUID jobId, ServiceInstantiation payload, String optimisticUniqueServiceInstanceName, String userId) { + String serviceInstanceName = generateServiceName(jobId, payload, optimisticUniqueServiceInstanceName); + + List userParams = generateUserParamList(); + + RequestParameters requestParameters = new RequestParameters(payload.getSubscriptionServiceType(), true, userParams, payload.getTestApi()); + + ServiceInstantiationRequestDetails requestDetails = generateServiceInstantiationRequestDetails(payload,requestParameters,serviceInstanceName, userId); + + RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails); + debugRequestDetails(requestDetailsWrapper, logger); + return requestDetailsWrapper; + } + + + @Override + public RequestDetailsWrapper generateALaCarteServiceDeletionRequest(UUID jobId, ServiceInstantiation payload, String userId){ + + ServiceDeletionRequestDetails.RequestParameters requestParameters = new ServiceDeletionRequestDetails.RequestParameters( true, payload.getTestApi()); + + ServiceDeletionRequestDetails.RequestInfo requestInfo = new ServiceDeletionRequestDetails.RequestInfo( + VID_SOURCE, + userId); + + ServiceDeletionRequestDetails requestDetails = new ServiceDeletionRequestDetails(payload.getModelInfo(), requestInfo, requestParameters); + + RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails); + debugRequestDetails(requestDetailsWrapper, logger); + return requestDetailsWrapper; + } + + @Override + public RequestDetailsWrapper generateVnfInstantiationRequest(Vnf vnfDetails, ModelInfo serviceModelInfo, String serviceInstanceId, String userId) { + + VnfInstantiationRequestDetails.RequestInfo requestInfo = new VnfInstantiationRequestDetails.RequestInfo( + getUniqueNameIfNeeded(vnfDetails.getInstanceName(), ResourceType.GENERIC_VNF), + vnfDetails.getProductFamilyId(), + VID_SOURCE, + vnfDetails.isRollbackOnFailure(), + userId); + CloudConfiguration cloudConfiguration = generateCloudConfiguration(vnfDetails.getLcpCloudRegionId(), vnfDetails.getTenantId()); + VnfInstantiationRequestDetails.Platform platform = new VnfInstantiationRequestDetails.Platform(vnfDetails.getPlatformName()); + VnfInstantiationRequestDetails.LineOfBusiness lineOfBusiness = new VnfInstantiationRequestDetails.LineOfBusiness(vnfDetails.getLineOfBusiness()); + VnfInstantiationRequestDetails.RequestParameters requestParameters = new VnfInstantiationRequestDetails.RequestParameters(generateUserParamList()); + VnfInstantiationRequestDetails.RelatedInstance serviceInstance = new VnfInstantiationRequestDetails.RelatedInstance(serviceModelInfo, serviceInstanceId); + List relatedInstanceList = new ArrayList<>(); + relatedInstanceList.add(serviceInstance); + return new RequestDetailsWrapper<>(new VnfInstantiationRequestDetails(vnfDetails.getModelInfo(), cloudConfiguration, requestInfo, platform, lineOfBusiness, relatedInstanceList, requestParameters)); + } + + @Override + public RequestDetailsWrapper generateVfModuleInstantiationRequest(VfModule vfModuleDetails, ModelInfo serviceModelInfo, String serviceInstanceId, ModelInfo vnfModelInfo, String vnfInstanceId, String vgInstanceId, String userId) { + + VfModuleInstantiationRequestDetails.RequestInfo requestInfo = new VfModuleInstantiationRequestDetails.RequestInfo( + getUniqueNameIfNeeded(vfModuleDetails.getInstanceName(), ResourceType.VF_MODULE), + null, + VID_SOURCE, + vfModuleDetails.isRollbackOnFailure(), + userId); + + //cloud configuration + CloudConfiguration cloudConfiguration = generateCloudConfiguration(vfModuleDetails.getLcpCloudRegionId(), vfModuleDetails.getTenantId()); + + //request parameters + List> userParams = aggregateAllInstanceParams(extractActualInstanceParams(vfModuleDetails.getInstanceParams()), vfModuleDetails.getSupplementaryParams()); + RequestParametersVfModule requestParameters = new RequestParametersVfModule(userParams, vfModuleDetails.isUsePreload()); + + //related instance list + VfModuleInstantiationRequestDetails.RelatedInstance serviceInstance = new VfModuleInstantiationRequestDetails.RelatedInstance(serviceModelInfo, serviceInstanceId); + VfModuleInstantiationRequestDetails.RelatedInstance vnfInstance = new VfModuleInstantiationRequestDetails.RelatedInstance(vnfModelInfo, vnfInstanceId); + List relatedInstanceList = new ArrayList<>(); + relatedInstanceList.add(serviceInstance); + relatedInstanceList.add(vnfInstance); + if (vgInstanceId != null) { + ModelInfo volumeGroupModel = new ModelInfo(); + volumeGroupModel.setModelType("volumeGroup"); + VfModuleInstantiationRequestDetails.RelatedInstance volumeGroupInstance = new VfModuleInstantiationRequestDetails.RelatedInstance(volumeGroupModel, vgInstanceId, vfModuleDetails.getVolumeGroupInstanceName()); + relatedInstanceList.add(volumeGroupInstance); + } + + return new RequestDetailsWrapper<>(new VfModuleInstantiationRequestDetails(vfModuleDetails.getModelInfo(), cloudConfiguration, requestInfo, relatedInstanceList, requestParameters)); + } + + protected CloudConfiguration generateCloudConfiguration(String lcpCloudRegionId, String tenantId) { + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setLcpCloudRegionId(lcpCloudRegionId); + cloudConfiguration.setTenantId(tenantId); + cloudOwnerService.enrichCloudConfigurationWithCloudOwner(cloudConfiguration, lcpCloudRegionId); + return cloudConfiguration; + } + + @Override + public RequestDetailsWrapper generateVolumeGroupInstantiationRequest(VfModule vfModuleDetails, ModelInfo serviceModelInfo, String serviceInstanceId, ModelInfo vnfModelInfo, String vnfInstanceId, String userId) { + VolumeGroupRequestDetails.RequestInfo requestInfo = new VolumeGroupRequestDetails.RequestInfo( + getUniqueNameIfNeeded(vfModuleDetails.getVolumeGroupInstanceName(), ResourceType.VOLUME_GROUP), + null, + VID_SOURCE, + vfModuleDetails.isRollbackOnFailure(), + userId); + CloudConfiguration cloudConfiguration = generateCloudConfiguration(vfModuleDetails.getLcpCloudRegionId(), vfModuleDetails.getTenantId()); + + List> userParams = aggregateAllInstanceParams(extractActualInstanceParams(vfModuleDetails.getInstanceParams()), vfModuleDetails.getSupplementaryParams()); + RequestParametersVfModule requestParameters = new RequestParametersVfModule(userParams, vfModuleDetails.isUsePreload()); + + VfModuleInstantiationRequestDetails.RelatedInstance serviceInstance = new VfModuleInstantiationRequestDetails.RelatedInstance(serviceModelInfo, serviceInstanceId); + VfModuleInstantiationRequestDetails.RelatedInstance vnfInstance = new VfModuleInstantiationRequestDetails.RelatedInstance(vnfModelInfo, vnfInstanceId); + List relatedInstancs = ImmutableList.of(serviceInstance, vnfInstance); + + ModelInfo modelInfo = vfModuleDetails.getModelInfo(); + modelInfo.setModelType("volumeGroup"); + return new RequestDetailsWrapper<>(new VolumeGroupRequestDetails(modelInfo, cloudConfiguration, requestInfo, relatedInstancs, requestParameters)); + } + + protected List> aggregateAllInstanceParams(Map instanceParams, Map supplementaryParams) { + Map instanceParamsFinal = defaultIfNull(instanceParams, new HashMap<>()); + Map supplementaryParamsFinal = defaultIfNull(supplementaryParams, new HashMap<>()); + + if (!(instanceParamsFinal.isEmpty() && supplementaryParamsFinal.isEmpty())) { + //remove duplicate keys from instanceParams if exist in supplementaryParams + instanceParamsFinal = instanceParams.entrySet().stream().filter(m-> + !supplementaryParamsFinal.containsKey(m.getKey()) + ).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + //aggregate the 2 collections and format them as UserParamMap + UserParamMap aggregatedParams = new UserParamMap<>(); + aggregatedParams.putAll(instanceParamsFinal); + aggregatedParams.putAll(supplementaryParamsFinal); + + return ImmutableList.of(aggregatedParams); + } - ServiceInstantiationRequestDetails.ServiceInstantiationOwningEntity owningEntity = new ServiceInstantiationRequestDetails.ServiceInstantiationOwningEntity( - payload.getOwningEntityId(), payload.getOwningEntityName()); + return Collections.emptyList(); + } + + @Override + public RequestDetailsWrapper generateNetworkInstantiationRequest(Network networkDetails, ModelInfo serviceModelInfo, String serviceInstanceId, String userId) { + + NetworkInstantiationRequestDetails.RequestInfo requestInfo = new NetworkInstantiationRequestDetails.RequestInfo( + getUniqueNameIfNeeded(networkDetails.getInstanceName(), ResourceType.L3_NETWORK), + networkDetails.getProductFamilyId(), + VID_SOURCE, + networkDetails.isRollbackOnFailure(), + userId); + CloudConfiguration cloudConfiguration = generateCloudConfiguration(networkDetails.getLcpCloudRegionId(), networkDetails.getTenantId()); + NetworkInstantiationRequestDetails.Platform platform = new NetworkInstantiationRequestDetails.Platform(networkDetails.getPlatformName()); + NetworkInstantiationRequestDetails.LineOfBusiness lineOfBusiness = new NetworkInstantiationRequestDetails.LineOfBusiness(networkDetails.getLineOfBusiness()); + NetworkInstantiationRequestDetails.RequestParameters requestParameters = new NetworkInstantiationRequestDetails.RequestParameters(generateUserParamList()); + NetworkInstantiationRequestDetails.RelatedInstance serviceInstance = new NetworkInstantiationRequestDetails.RelatedInstance(serviceModelInfo, serviceInstanceId); + List relatedInstanceList = new ArrayList<>(); + relatedInstanceList.add(serviceInstance); + return new RequestDetailsWrapper<>(new NetworkInstantiationRequestDetails(networkDetails.getModelInfo(), cloudConfiguration, requestInfo, platform, lineOfBusiness, relatedInstanceList, requestParameters)); + } + @Override + public RequestDetailsWrapper generateInstanceGroupInstantiationRequest(InstanceGroup instanceGroupDetails, ModelInfo serviceModelInfo, String serviceInstanceId, String userId) { + InstanceGroupInstantiationRequestDetails.RequestInfo requestInfo = new InstanceGroupInstantiationRequestDetails.RequestInfo( + getUniqueNameIfNeeded(instanceGroupDetails.getInstanceName(), ResourceType.INSTANCE_GROUP), + null, + "VID", + instanceGroupDetails.isRollbackOnFailure(), + userId); + InstanceGroupInstantiationRequestDetails.RequestParameters requestParameters = new InstanceGroupInstantiationRequestDetails.RequestParameters(generateUserParamList()); + InstanceGroupInstantiationRequestDetails.RelatedInstance serviceInstance = new InstanceGroupInstantiationRequestDetails.RelatedInstance(serviceModelInfo, serviceInstanceId); + List relatedInstanceList = ImmutableList.of(serviceInstance); + return new RequestDetailsWrapper<>(new InstanceGroupInstantiationRequestDetails(instanceGroupDetails.getModelInfo(), requestInfo, relatedInstanceList, requestParameters)); + } + + // TODO + private List generateUserParamList() { + return Collections.emptyList(); + } + + protected List generateServiceInstantiationServicesList(ServiceInstantiation payload, String serviceInstanceName, ServiceInstantiationVnfList vnfList) { + List serviceInstantiationServiceList = new LinkedList<>(); + List> unFilteredInstanceParams = defaultIfNull(payload.getInstanceParams(), Collections.emptyList()); + List> filteredInstanceParams = removeUnNeededParams(unFilteredInstanceParams); + ServiceInstantiationService serviceInstantiationService = new ServiceInstantiationService( + payload.getModelInfo(), + serviceInstanceName, + filteredInstanceParams, + vnfList + ); + serviceInstantiationServiceList.add(serviceInstantiationService); + return serviceInstantiationServiceList; + } + + private ServiceInstantiationRequestDetails generateServiceInstantiationRequestDetails(ServiceInstantiation payload, RequestParameters requestParameters, String serviceInstanceName, String userId) { + ServiceInstantiationRequestDetails.RequestInfo requestInfo = new ServiceInstantiationRequestDetails.RequestInfo(serviceInstanceName, + payload.getProductFamilyId(), + VID_SOURCE, + payload.isRollbackOnFailure(), + userId); + ServiceInstantiationOwningEntity owningEntity = new ServiceInstantiationOwningEntity(payload.getOwningEntityId(), payload.getOwningEntityName()); + SubscriberInfo subscriberInfo = generateSubscriberInfo(payload); + Project project = payload.getProjectName() != null ? new Project(payload.getProjectName()) : null; + return new ServiceInstantiationRequestDetails(payload.getModelInfo(), owningEntity, subscriberInfo, project, requestInfo, requestParameters); + } + + + protected SubscriberInfo generateSubscriberInfo(ServiceInstantiation payload) { SubscriberInfo subscriberInfo = new SubscriberInfo(); subscriberInfo.setGlobalSubscriberId(payload.getGlobalSubscriberId()); + return subscriberInfo; + } + protected String generateServiceName(UUID jobId, ServiceInstantiation payload, String optimisticUniqueServiceInstanceName) { String serviceInstanceName = null; - if (payload.isUserProvidedNaming()) { + if(StringUtils.isNotEmpty(optimisticUniqueServiceInstanceName)) { + serviceInstanceName = peekServiceName(jobId, payload, optimisticUniqueServiceInstanceName); + } + return serviceInstanceName; + } + + protected String peekServiceName(UUID jobId, ServiceInstantiation payload, String optimisticUniqueServiceInstanceName) { + String serviceInstanceName; + // unique name already exist in service info. If it's free in AAI we use it + if (isNameFreeInAai(optimisticUniqueServiceInstanceName, ResourceType.SERVICE_INSTANCE)) { + serviceInstanceName = optimisticUniqueServiceInstanceName; + } + //otherwise we used the original service instance name (from payload) to get a new unique name from DB and AAI + else { serviceInstanceName = getUniqueName(payload.getInstanceName(), ResourceType.SERVICE_INSTANCE); - String finalServiceInstanceName = serviceInstanceName; - updateServiceInfo(jobId, x -> x.setServiceInstanceName(finalServiceInstanceName)); } - ServiceInstantiationRequestDetails.RequestInfo requestInfo = new ServiceInstantiationRequestDetails.RequestInfo( - serviceInstanceName, - payload.getProductFamilyId(), - "VID", - payload.isRollbackOnFailure(), - userId); - - List serviceInstantiationService = new LinkedList<>(); - List> unFilteredInstanceParams = - payload.getInstanceParams() != null ? payload.getInstanceParams() : new LinkedList<>(); - List> filteredInstanceParams = removeUnNeededParams(unFilteredInstanceParams); - ServiceInstantiationRequestDetails.ServiceInstantiationService serviceInstantiationService1 = new ServiceInstantiationRequestDetails.ServiceInstantiationService( - payload.getModelInfo(), - serviceInstanceName, - filteredInstanceParams, - createServiceInstantiationVnfList(payload) - ); - serviceInstantiationService.add(serviceInstantiationService1); - ServiceInstantiationRequestDetails.RequestParameters requestParameters = new ServiceInstantiationRequestDetails.RequestParameters( - payload.getSubscriptionServiceType(), false, serviceInstantiationService); + //update serviceInfo with new name if needed + try { + updateServiceInfo(jobId, x -> x.setServiceInstanceName(serviceInstanceName)); + } catch (Exception e) { + logger.error("Failed updating service name {} in serviceInfo", serviceInstanceName, e); + } - ServiceInstantiationRequestDetails.Project project = - payload.getProjectName() != null ? new ServiceInstantiationRequestDetails.Project(payload.getProjectName()) - : null; + return serviceInstanceName; + } - ServiceInstantiationRequestDetails requestDetails = new ServiceInstantiationRequestDetails( - payload.getModelInfo(), owningEntity, subscriberInfo, - project, requestInfo, requestParameters); + @Override + public List> buildVnfInstanceParams(List> currentVnfInstanceParams, List vfModules){ + List> filteredVnfInstanceParams = removeUnNeededParams(currentVnfInstanceParams); - RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper( - requestDetails); - debugRequestDetails(requestDetailsWrapper, logger); - return requestDetailsWrapper; + if (!featureManager.isActive(Features.FLAG_SHIFT_VFMODULE_PARAMS_TO_VNF)) { + return filteredVnfInstanceParams; + } + + Map vnfInstanceParams = extractActualInstanceParams(filteredVnfInstanceParams); + vfModules.stream() + .map(x->extractActualInstanceParams(x.getInstanceParams())) + .forEach(vnfInstanceParams::putAll); + return vnfInstanceParams.isEmpty() ? Collections.emptyList() : ImmutableList.of(vnfInstanceParams); + } + + //Make sure we always get a one Map from InstanceParams + private Map extractActualInstanceParams(List> originalInstanceParams) { + if (originalInstanceParams==null || originalInstanceParams.isEmpty() || originalInstanceParams.get(0)==null) { + return new HashMap<>(); + } + return originalInstanceParams.get(0); } private List> removeUnNeededParams(List> instanceParams) { List keysToRemove = new ArrayList<>(); - if (instanceParams != null && !instanceParams.isEmpty()) { - for (String key : instanceParams.get(0).keySet()) { - for (String paramToIgnore : PARAMS_TO_IGNORE) { - if ((key.equalsIgnoreCase(paramToIgnore))) { - keysToRemove.add(key); - } + if (instanceParams == null || instanceParams.isEmpty()) { + return Collections.emptyList(); + } + + for (String key : instanceParams.get(0).keySet()) { + for (String paramToIgnore : PARAMS_TO_IGNORE) + if ((key.equalsIgnoreCase(paramToIgnore))) { + keysToRemove.add(key); } - } - for (String key : keysToRemove) { - instanceParams.get(0).remove(key); - } - //TODO will be removed on once we stop using List> - if (instanceParams.get(0).isEmpty()) { - return Collections.emptyList(); - } } - return instanceParams; + + Map result = instanceParams.get(0).entrySet().stream() + .filter(entry->!keysToRemove.contains(entry.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + return result.isEmpty() ? Collections.emptyList() : Collections.singletonList(result); } - private ServiceInstantiationRequestDetails.ServiceInstantiationVnfList createServiceInstantiationVnfList( - ServiceInstantiation payload) { - CloudConfiguration cloudConfiguration = new CloudConfiguration(); - cloudConfiguration.setTenantId(payload.getTenantId()); - cloudConfiguration.setLcpCloudRegionId(payload.getLcpCloudRegionId()); + private ServiceInstantiationVnfList createServiceInstantiationVnfList(ServiceInstantiation payload) { + CloudConfiguration cloudConfiguration = generateCloudConfiguration(payload.getLcpCloudRegionId(), payload.getTenantId()); Map vnfs = payload.getVnfs(); - List vnfList = new ArrayList<>(); + List vnfList = new ArrayList<>(); for (Vnf vnf : vnfs.values()) { Map> vfModules = vnf.getVfModules(); - List convertedUnFilteredVfModules = convertVfModuleMapToList(vfModules); - List filteredVfModules = filterInstanceParamsFromVfModuleAndUniqueNames( - convertedUnFilteredVfModules, vnf.isUserProvidedNaming()); - ServiceInstantiationRequestDetails.ServiceInstantiationVnf serviceInstantiationVnf = new ServiceInstantiationRequestDetails.ServiceInstantiationVnf( - vnf.getModelInfo(), - cloudConfiguration, - vnf.getPlatformName(), - vnf.getLineOfBusiness(), - payload.getProductFamilyId(), - removeUnNeededParams(vnf.getInstanceParams()), - filteredVfModules, - vnf.isUserProvidedNaming() ? getUniqueName(vnf.getInstanceName(), ResourceType.GENERIC_VNF) : null + List convertedUnFilteredVfModules = convertVfModuleMapToList(vfModules); + List filteredVfModules = filterInstanceParamsFromVfModuleAndUniqueNames(convertedUnFilteredVfModules); + ServiceInstantiationVnf serviceInstantiationVnf = new ServiceInstantiationVnf( + vnf.getModelInfo(), + cloudConfiguration, + vnf.getPlatformName(), + vnf.getLineOfBusiness(), + payload.getProductFamilyId(), + buildVnfInstanceParams(vnf.getInstanceParams(), filteredVfModules), + filteredVfModules, + getUniqueNameIfNeeded(vnf.getInstanceName(), ResourceType.GENERIC_VNF) ); vnfList.add(serviceInstantiationVnf); } - return new ServiceInstantiationRequestDetails.ServiceInstantiationVnfList(vnfList); + return new ServiceInstantiationVnfList(vnfList); } - private List convertVfModuleMapToList(Map> vfModules) { - return vfModules.values().stream().flatMap(vfModule -> vfModule.values().stream()).collect(Collectors.toList()); + private List convertVfModuleMapToList(Map> vfModules) { + ObjectMapper mapper = new ObjectMapper(); + return vfModules.values().stream().flatMap(vfModule -> + vfModule.values().stream().map(item -> { + List> aggregatedParams = aggregateAllInstanceParams(extractActualInstanceParams(item.getInstanceParams()), item.getSupplementaryParams()); + List> aggregatedParamsConverted = mapper.convertValue(aggregatedParams, new TypeReference>(){}); + + return new VfModuleMacro( + item.getModelInfo(), + item.getInstanceName(), + item.getVolumeGroupInstanceName(), + aggregatedParamsConverted); + } + ) + ).collect(Collectors.toList()); } - private List filterInstanceParamsFromVfModuleAndUniqueNames(List unFilteredVfModules, - boolean isUserProvidedNaming) { + private List filterInstanceParamsFromVfModuleAndUniqueNames(List unFilteredVfModules) { return unFilteredVfModules.stream().map(vfModule -> - new VfModule( - vfModule.getModelInfo(), - getUniqueNameIfNeeded(isUserProvidedNaming, vfModule.getInstanceName(), ResourceType.VF_MODULE), - getUniqueNameIfNeeded(isUserProvidedNaming, vfModule.getVolumeGroupInstanceName(), - ResourceType.VOLUME_GROUP), - removeUnNeededParams(vfModule.getInstanceParams()))) - .collect(Collectors.toList()); + new VfModuleMacro( + vfModule.getModelInfo(), + getUniqueNameIfNeeded(vfModule.getInstanceName(), ResourceType.VF_MODULE), + getUniqueNameIfNeeded(vfModule.getVolumeGroupInstanceName(), ResourceType.VOLUME_GROUP), + removeUnNeededParams(vfModule.getInstanceParams()))) + .collect(Collectors.toList()); } - private String getUniqueNameIfNeeded(boolean isUserProvidedNaming, String name, ResourceType resourceType) { - return isUserProvidedNaming && !StringUtils.isEmpty(name) ? - getUniqueName(name, resourceType) : null; + private String getUniqueNameIfNeeded(String name, ResourceType resourceType) { + return StringUtils.isNotEmpty(name) ? getUniqueName(name, resourceType) : null; } @Override public String getServiceInstantiationPath(ServiceInstantiation serviceInstantiationRequest) { //in case pause flag is true - use assign , else - use create. return MsoBusinessLogicImpl.validateEndpointPath( - serviceInstantiationRequest.isPause() ? - "mso.restapi.serviceInstanceAssign" : "mso.restapi.serviceInstanceCreate" + serviceInstantiationRequest.isPause() ? + MsoProperties.MSO_REST_API_SERVICE_INSTANCE_ASSIGN : MsoProperties.MSO_REST_API_SERVICE_INSTANCE_CREATE ); } + @Override + public String getServiceDeletionPath(String serviceInstanceId) { + return MsoBusinessLogicImpl.validateEndpointPath( MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE) + "/" + serviceInstanceId; + } + + @Override + public String getVnfInstantiationPath(String serviceInstanceId) { + return MsoBusinessLogicImpl.validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE). + replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + } + + @Override + public String getNetworkInstantiationPath(String serviceInstanceId) { + return MsoBusinessLogicImpl.validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE). + replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + } + + @Override + public String getVfmoduleInstantiationPath(String serviceInstanceId, String vnfInstanceId) { + return MsoBusinessLogicImpl.validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE) + .replaceFirst(SVC_INSTANCE_ID, serviceInstanceId) + .replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); + } + + @Override + public String getVolumeGroupInstantiationPath(String serviceInstanceId, String vnfInstanceId) { + return MsoBusinessLogicImpl.validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE) + .replaceFirst(SVC_INSTANCE_ID, serviceInstanceId) + .replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); + } + + @Override + public String getInstanceGroupInstantiationPath() { + return MsoBusinessLogicImpl.validateEndpointPath(MsoProperties.MSO_REST_API_INSTANCE_GROUP); + } + + @Override + public String getInstanceGroupDeletePath(String instanceGroupId) { + return MsoBusinessLogicImpl.validateEndpointPath(MsoProperties.MSO_REST_API_INSTANCE_GROUP) + + '/' + instanceGroupId; + } + @Override public String getOrchestrationRequestsPath() { return MsoBusinessLogicImpl.validateEndpointPath(MsoProperties.MSO_REST_API_GET_ORC_REQ); @@ -333,7 +625,7 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu @Override public ServiceInfo updateServiceInfoAndAuditStatus(UUID jobUuid, JobStatus jobStatus) { - auditVidStatus(jobUuid, jobStatus); + auditVidStatus(jobUuid,jobStatus); return updateServiceInfo(jobUuid, x -> setServiceInfoStatus(x, jobStatus)); } @@ -343,12 +635,9 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu } public ServiceInfo getServiceInfoByJobId(UUID jobUUID) { - List serviceInfoList = dataAccessService - .getList(ServiceInfo.class, String.format(" where jobId = '%s' ", jobUUID), null, null); + List serviceInfoList = dataAccessService.getList(ServiceInfo.class, String.format(" where jobId = '%s' ", jobUUID), null, null); if (serviceInfoList.size() != 1) { - throw new GenericUncheckedException( - "Failed to retrieve job with uuid " + jobUUID + " from ServiceInfo table. Instances found: " - + serviceInfoList.size()); + throw new GenericUncheckedException("Failed to retrieve job with uuid " + jobUUID + " from ServiceInfo table. Instances found: " + serviceInfoList.size()); } return serviceInfoList.get(0); } @@ -356,46 +645,43 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu public List getAuditStatuses(UUID jobUUID, JobAuditStatus.SourceStatus source) { return dataAccessService.getList( JobAuditStatus.class, - String.format(" where SOURCE = '%s' and JOB_ID = '%s'", source, jobUUID), + String.format(" where SOURCE = '%s' and JOB_ID = '%s'",source, jobUUID), " CREATED_DATE ", null); } - private JobAuditStatus getLatestAuditStatus(UUID jobUUID, JobAuditStatus.SourceStatus source) { - List list = getAuditStatuses(jobUUID, source); - return !list.isEmpty() ? list.get(list.size() - 1) : null; + private JobAuditStatus getLatestAuditStatus(UUID jobUUID, JobAuditStatus.SourceStatus source){ + List list = getAuditStatuses(jobUUID,source); + return !list.isEmpty() ? list.get(list.size()-1) : null; } @Override - public void auditVidStatus(UUID jobUUID, JobStatus jobStatus) { + public void auditVidStatus(UUID jobUUID, JobStatus jobStatus){ JobAuditStatus vidStatus = new JobAuditStatus(jobUUID, jobStatus.toString(), JobAuditStatus.SourceStatus.VID); auditStatus(vidStatus); } @Override - public void auditMsoStatus(UUID jobUUID, AsyncRequestStatus.Request msoRequestStatus) { - auditMsoStatus(jobUUID, msoRequestStatus.requestStatus.getRequestState(), msoRequestStatus.requestId, - msoRequestStatus.requestStatus.getStatusMessage()); + public void auditMsoStatus(UUID jobUUID, AsyncRequestStatus.Request msoRequestStatus){ + auditMsoStatus(jobUUID, msoRequestStatus.requestStatus.getRequestState(), msoRequestStatus.requestId, msoRequestStatus.requestStatus.getStatusMessage()); } @Override - public void auditMsoStatus(UUID jobUUID, String jobStatus, String requestId, String additionalInfo) { + public void auditMsoStatus(UUID jobUUID, String jobStatus, String requestId, String additionalInfo){ JobAuditStatus msoStatus = new JobAuditStatus(jobUUID, jobStatus, JobAuditStatus.SourceStatus.MSO, - requestId != null ? UUID.fromString(requestId) : null, - additionalInfo); + requestId != null ? UUID.fromString(requestId) : null, + additionalInfo); auditStatus(msoStatus); } - private void auditStatus(JobAuditStatus jobAuditStatus) { + private void auditStatus(JobAuditStatus jobAuditStatus){ JobAuditStatus latestStatus = getLatestAuditStatus(jobAuditStatus.getJobId(), jobAuditStatus.getSource()); - if (latestStatus == null || !latestStatus.equals(jobAuditStatus)) { + if (latestStatus == null || !latestStatus.equals(jobAuditStatus)) dataAccessService.saveDomainObject(jobAuditStatus, DaoUtils.getPropsMap()); - } } public Job.JobStatus calcStatus(AsyncRequestStatus asyncRequestStatus) { - String msoRequestState = asyncRequestStatus.request.requestStatus.getRequestState().toLowerCase() - .replaceAll("[^a-z]+", ""); + String msoRequestState = asyncRequestStatus.request.requestStatus.getRequestState().toLowerCase().replaceAll("[^a-z]+", ""); JobStatus jobStatus = msoStateToJobStatusMap.get(msoRequestState); return (jobStatus != null ? jobStatus : JobStatus.IN_PROGRESS); } @@ -404,11 +690,11 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu public void handleFailedInstantiation(UUID jobUUID) { ServiceInfo serviceInfo = updateServiceInfoAndAuditStatus(jobUUID, JobStatus.FAILED); List serviceInfoList = dataAccessService.getList( - ServiceInfo.class, - String.format(" where templateId = '%s' and jobStatus = '%s'", - serviceInfo.getTemplateId(), - JobStatus.PENDING), - null, null); + ServiceInfo.class, + String.format(" where templateId = '%s' and jobStatus = '%s'", + serviceInfo.getTemplateId(), + JobStatus.PENDING), + null, null); serviceInfoList.forEach(si -> updateServiceInfoAndAuditStatus(si.getJobId(), JobStatus.STOPPED)); } @@ -423,9 +709,9 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu public void hideServiceInfo(UUID jobUUID) { ServiceInfo serviceInfo = getServiceInfoByJobId(jobUUID); if (!serviceInfo.getJobStatus().isFinal()) { - String message = String.format("jobId %s: Service status does not allow hide service, status = %s", - serviceInfo.getJobId(), - serviceInfo.getJobStatus()); + String message = String.format( "jobId %s: Service status does not allow hide service, status = %s", + serviceInfo.getJobId(), + serviceInfo.getJobStatus()); logger.error(EELFLoggerDelegate.errorLogger, message); throw new OperationNotAllowedException(message); } @@ -434,31 +720,30 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu } @Override - public int - - getCounterForName(String name) { + public int getCounterForName(String name) { String hqlSelectNC = "from NameCounter where name = :name"; String hqlUpdateCounter = "update NameCounter set counter = :newCounter " + - "where name= :name " + - "and counter= :prevCounter"; + "where name= :name " + + "and counter= :prevCounter"; Integer counter = null; GenericUncheckedException lastException = null; - for (int i = 0; i < MAX_RETRIES_GETTING_COUNTER && counter == null; i++) { + for (int i = 0; i< MAX_RETRIES_GETTING_COUNTER && counter==null; i++) { try { counter = calcCounter(name, hqlSelectNC, hqlUpdateCounter); - } catch (GenericUncheckedException exception) { + } + catch (GenericUncheckedException exception) { lastException = exception; //do nothing, we will try again in the loop } } - if (counter != null) { + if (counter!=null) { return counter; } - throw lastException != null ? new DbFailureUncheckedException(lastException) : - new DbFailureUncheckedException("Failed to get counter for " + name + " due to unknown error"); + throw lastException!=null ? new DbFailureUncheckedException(lastException) : + new DbFailureUncheckedException("Failed to get counter for "+name+" due to unknown error"); } @@ -466,14 +751,14 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu Integer counter; counter = DaoUtils.tryWithSessionAndTransaction(sessionFactory, session -> { NameCounter nameCounter = (NameCounter) session.createQuery(hqlSelectNC) - .setText("name", name) - .uniqueResult(); + .setText("name", name) + .uniqueResult(); if (nameCounter != null) { int updatedRows = session.createQuery(hqlUpdateCounter) - .setText("name", nameCounter.getName()) - .setInteger("prevCounter", nameCounter.getCounter()) - .setInteger("newCounter", nameCounter.getCounter() + 1) - .executeUpdate(); + .setText("name", nameCounter.getName()) + .setInteger("prevCounter", nameCounter.getCounter()) + .setInteger("newCounter", nameCounter.getCounter() + 1) + .executeUpdate(); if (updatedRows == 1) { return nameCounter.getCounter() + 1; } @@ -481,7 +766,7 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu Object nameAsId = session.save(new NameCounter(name)); //if save success if (nameAsId != null) { - return 1; + return 0; } } //in case of failure return null, in order to continue the loop @@ -506,34 +791,28 @@ public class AsyncInstantiationBusinessLogicImpl implements AsyncInstantiationBu //Prevents unnecessary increasing of the counter while AAI doesn't response isNameFreeInAai(NAME_FOR_CHECK_AAI_STATUS, resourceType); - for (int i = 0; i < getMaxRetriesGettingFreeNameFromAai(); i++) { - int counter = getCounterForName(name); - String newName = formatNameAndCounter(name, counter); + for (int i=0; i aaiResponse = aaiOverTLSClient - .searchNodeTypeByName(name, resourceType); - if (aaiResponse.getStatus() > 399 || aaiResponse.getBody() == null) { - try { - String message = IOUtils.toString(aaiResponse.getRawBody(), "UTF-8"); - throw new InvalidAAIResponseException(aaiResponse.getStatus(), message); - } catch (IOException e) { - throw new InvalidAAIResponseException(aaiResponse.getStatus(), aaiResponse.getStatusText()); - } - } - return CollectionUtils.isEmpty(aaiResponse.getBody().resultData); + private boolean isNameFreeInAai(String name, ResourceType resourceType) throws ExceptionWithRequestInfo { + return !aaiClient.isNodeTypeExistsByName(name, resourceType); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AuditService.java b/vid-app-common/src/main/java/org/onap/vid/services/AuditService.java index 19569a7fb..01443deab 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AuditService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AuditService.java @@ -1,11 +1,18 @@ package org.onap.vid.services; -import org.onap.vid.model.RequestReferencesContainer; -import org.onap.vid.mso.RestObject; +import org.onap.vid.model.JobAuditStatus; +import java.util.List; import java.util.UUID; public interface AuditService { void setFailedAuditStatusFromMso(UUID jobUuid, String requestId, int statusCode, String msoResponse); + + + List getAuditStatusFromMsoByRequestId(UUID jobId, UUID requestId); + + List getAuditStatusFromMsoByServiceInstanceId(UUID jobId, UUID serviceInstanceId); + + List getAuditStatusFromMsoByJobId(UUID jobId); } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AuditServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AuditServiceImpl.java index b4806f1ce..339a9edd7 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AuditServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AuditServiceImpl.java @@ -1,47 +1,42 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2018 Nokia. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ package org.onap.vid.services; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.StringUtils; import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.model.JobAuditStatus; +import org.onap.vid.mso.MsoBusinessLogicImpl; +import org.onap.vid.mso.MsoProperties; +import org.onap.vid.mso.RestMsoImplementation; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.rest.AsyncRequestStatus; +import org.onap.vid.mso.rest.AsyncRequestStatusList; import org.springframework.stereotype.Service; import javax.inject.Inject; import java.io.IOException; +import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; @Service public class AuditServiceImpl implements AuditService{ + private final AsyncInstantiationBusinessLogic asyncInstantiationBL; + private final RestMsoImplementation restMso; + @Inject - private AsyncInstantiationBusinessLogic asyncInstantiationBL; - public static final String FAILED_MSO_REQUEST_STATUS = "FAILED"; + public AuditServiceImpl(AsyncInstantiationBusinessLogic asyncInstantiationBL, RestMsoImplementation restMso) { + this.asyncInstantiationBL = asyncInstantiationBL; + this.restMso = restMso; + } @Override public void setFailedAuditStatusFromMso(UUID jobUuid, String requestId, int statusCode, String msoResponse){ + final String failedMsoRequestStatus = "FAILED"; String additionalInfo = formatExceptionAdditionalInfo(statusCode, msoResponse); - asyncInstantiationBL.auditMsoStatus(jobUuid, FAILED_MSO_REQUEST_STATUS, requestId, additionalInfo); + asyncInstantiationBL.auditMsoStatus(jobUuid, failedMsoRequestStatus, requestId, additionalInfo); } private String formatExceptionAdditionalInfo(int statusCode, String msoResponse) { @@ -64,4 +59,90 @@ public class AuditServiceImpl implements AuditService{ } return errorMsg; } + + @Override + public List getAuditStatusFromMsoByRequestId(UUID jobId, UUID requestId) { + String filter = "requestId:EQUALS:" + requestId; + return getAuditStatusFromMso(jobId, filter, null); + } + + @Override + public List getAuditStatusFromMsoByServiceInstanceId(UUID jobId, UUID serviceInstanceId) { + String filter = "serviceInstanceId:EQUALS:" + serviceInstanceId; + return getAuditStatusFromMso(jobId, filter, serviceInstanceId); + } + + @Override + public List getAuditStatusFromMsoByJobId(UUID jobId) { + List auditStatuses = asyncInstantiationBL.getAuditStatuses(jobId, JobAuditStatus.SourceStatus.MSO); + String instanceName = getInstanceNameFromServiceInfo(jobId); + auditStatuses.stream().forEach(status -> + status.setInstanceName(instanceName) + ); + return auditStatuses; + } + + + + private List getAuditStatusFromMso(UUID jobId, String filter, UUID serviceInstanceId) { + + String path = MsoBusinessLogicImpl.validateEndpointPath(MsoProperties.MSO_REST_API_GET_ORC_REQS) + "filter=" + filter; + RestObject msoResponse = restMso.GetForObject(path , AsyncRequestStatusList.class); + if (msoResponse.getStatusCode() >= 400 || msoResponse.get() == null) { + throw new BadResponseFromMso(msoResponse); + } + + //add service name from service info for each audit status (in case that serviceInstanceId is null all statuses belong to service) + String userInstanceName = serviceInstanceId == null ? getInstanceNameFromServiceInfo(jobId): null; + return convertMsoResponseStatusToJobAuditStatus(msoResponse.get().getRequestList(), userInstanceName); + } + + private String getInstanceNameFromServiceInfo(UUID jobId) { + return asyncInstantiationBL.getServiceInfoByJobId(jobId).getServiceInstanceName(); + } + + protected List convertMsoResponseStatusToJobAuditStatus(List msoStatuses, String defaultName){ + return msoStatuses.stream().map(status -> { + UUID requestId = null; + String instanceName = defaultName; + String jobStatus = null; + String additionalInfo = null; + String created = null; + String instanceType = null; + + AsyncRequestStatus.Request request = status.request; + if(request != null) { + requestId = UUID.fromString(request.requestId); + instanceName = extractInstanceName(instanceName, request); + instanceType = request.requestScope; + if(request.requestStatus != null) { + jobStatus = request.requestStatus.getRequestState(); + additionalInfo = request.requestStatus.getStatusMessage(); + if(!request.requestStatus.getAdditionalProperties().isEmpty()) { + created = request.requestStatus.getAdditionalProperties().get("finishTime") != null? request.requestStatus.getAdditionalProperties().get("finishTime").toString() : request.requestStatus.getTimestamp(); + } + } + } + return new JobAuditStatus(instanceName, jobStatus, requestId, additionalInfo, created, instanceType); + }).collect(Collectors.toList()); + } + + private String extractInstanceName(String instanceName, AsyncRequestStatus.Request request) { + if(request.requestDetails != null && request.requestDetails.requestInfo != null && request.requestDetails.requestInfo.instanceName != null) { + instanceName = request.requestDetails.requestInfo.instanceName; + } + return instanceName; + } + + public static class BadResponseFromMso extends RuntimeException { + private final RestObject msoResponse; + + public BadResponseFromMso(RestObject msoResponse) { + this.msoResponse = msoResponse; + } + + public RestObject getMsoResponse() { + return msoResponse; + } + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/BulkInstantiationService.java b/vid-app-common/src/main/java/org/onap/vid/services/BulkInstantiationService.java index 387edc12d..645a6122d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/BulkInstantiationService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/BulkInstantiationService.java @@ -1,15 +1,11 @@ package org.onap.vid.services; -import org.onap.vid.model.JobBulk; import org.onap.vid.model.JobModel; -import java.util.Map; import java.util.UUID; public interface BulkInstantiationService { - JobBulk saveBulk(Map bulkRequest); - JobModel getJob(UUID uuid); } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/BulkInstantiationServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/BulkInstantiationServiceImpl.java index 2a868f138..20f719a74 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/BulkInstantiationServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/BulkInstantiationServiceImpl.java @@ -3,14 +3,11 @@ package org.onap.vid.services; import org.onap.vid.job.Job; import org.onap.vid.job.JobAdapter; import org.onap.vid.job.JobsBrokerService; -import org.onap.vid.model.JobBulk; import org.onap.vid.model.JobModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.ws.rs.NotFoundException; -import java.util.List; -import java.util.Map; import java.util.UUID; @Service @@ -25,13 +22,6 @@ public class BulkInstantiationServiceImpl implements BulkInstantiationService { this.jobAdapter = jobAdapter; } - @Override - public JobBulk saveBulk(Map bulkRequest) { - List jobList = jobAdapter.createBulkOfJobs(bulkRequest); - jobList.forEach(jobsBrokerService::add); - return jobAdapter.toModelBulk(jobList); - } - @Override public JobModel getJob(UUID uuid) { Job job = jobsBrokerService.peek(uuid); diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementService.java b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementService.java index ab6239fd6..c83e1937f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementService.java @@ -1,8 +1,9 @@ package org.onap.vid.services; +import com.fasterxml.jackson.databind.node.ArrayNode; import org.apache.commons.lang3.tuple.Pair; -import org.json.simple.JSONArray; import org.onap.vid.changeManagement.*; +import org.onap.vid.mso.RestObjectWithRequestInfo; import org.onap.vid.mso.rest.Request; import org.springframework.http.ResponseEntity; import org.springframework.web.multipart.MultipartFile; @@ -13,7 +14,8 @@ import java.util.List; public interface ChangeManagementService { Collection getMSOChangeManagements(); ResponseEntity doChangeManagement(ChangeManagementRequest request, String vnfName); - JSONArray getSchedulerChangeManagements(); + ArrayNode getSchedulerChangeManagements(); + RestObjectWithRequestInfo getSchedulerChangeManagementsWithRequestInfo(); /** * Deleting a scheduled flow. diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java index e4a6b3990..13525f842 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java @@ -1,20 +1,23 @@ package org.onap.vid.services; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.hibernate.NonUniqueObjectException; import org.json.JSONObject; -import org.json.simple.JSONArray; -import org.json.simple.parser.JSONParser; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.changeManagement.*; +import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.exceptions.NotFoundException; import org.onap.vid.model.VNFDao; import org.onap.vid.model.VidWorkflow; import org.onap.vid.mso.MsoBusinessLogic; import org.onap.vid.mso.MsoResponseWrapperInterface; +import org.onap.vid.mso.RestObject; +import org.onap.vid.mso.RestObjectWithRequestInfo; import org.onap.vid.mso.rest.Request; import org.onap.vid.scheduler.SchedulerProperties; import org.onap.vid.scheduler.SchedulerRestInterfaceIfc; @@ -34,26 +37,27 @@ import java.util.stream.Collectors; @Service public class ChangeManagementServiceImpl implements ChangeManagementService { - private final static String PRIMARY_KEY = "payload"; - private final static Set REQUIRED_KEYS = new HashSet<>(Arrays.asList("request-parameters", "configuration-parameters")); + private static final String PRIMARY_KEY = "payload"; + private static final Set REQUIRED_KEYS = new HashSet<>(Arrays.asList("request-parameters", "configuration-parameters")); private final DataAccessService dataAccessService; private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ChangeManagementServiceImpl.class); private MsoBusinessLogic msoBusinessLogic; private final SchedulerRestInterfaceIfc restClient; + private final CloudOwnerService cloudOwnerService; @Autowired private CsvService csvService; @Autowired - public ChangeManagementServiceImpl(DataAccessService dataAccessService, MsoBusinessLogic msoBusinessLogic, SchedulerRestInterfaceIfc schedulerRestInterface) { + public ChangeManagementServiceImpl(DataAccessService dataAccessService, MsoBusinessLogic msoBusinessLogic, SchedulerRestInterfaceIfc schedulerRestInterface, CloudOwnerService cloudOwnerService) { this.dataAccessService = dataAccessService; this.msoBusinessLogic = msoBusinessLogic; this.restClient = schedulerRestInterface; + this.cloudOwnerService = cloudOwnerService; } @Override public Collection getMSOChangeManagements() { - Collection result = null; return msoBusinessLogic.getOrchestrationRequestsForDashboard(); } @@ -86,14 +90,17 @@ public class ChangeManagementServiceImpl implements ChangeManagementService { try { switch (requestType.toLowerCase()) { case ChangeManagementRequest.UPDATE: { + cloudOwnerService.enrichRequestWithCloudOwner(currentRequestDetails); msoResponseWrapperObject = msoBusinessLogic.updateVnf(currentRequestDetails, serviceInstanceId, vnfInstanceId); break; } case ChangeManagementRequest.REPLACE: { + cloudOwnerService.enrichRequestWithCloudOwner(currentRequestDetails); msoResponseWrapperObject = msoBusinessLogic.replaceVnf(currentRequestDetails, serviceInstanceId, vnfInstanceId); break; } case ChangeManagementRequest.VNF_IN_PLACE_SOFTWARE_UPDATE: { + cloudOwnerService.enrichRequestWithCloudOwner(currentRequestDetails); msoResponseWrapperObject = msoBusinessLogic.updateVnfSoftware(currentRequestDetails, serviceInstanceId, vnfInstanceId); break; } @@ -105,10 +112,10 @@ public class ChangeManagementServiceImpl implements ChangeManagementService { msoResponseWrapperObject = msoBusinessLogic.scaleOutVfModuleInstance(currentRequestDetails, serviceInstanceId, vnfInstanceId); break; } - default: - logger.error("Failure during doChangeManagement with request " + request.toString()); + default: + throw new GenericUncheckedException("Failure during doChangeManagement with request " + request.toString()); } - response = new ResponseEntity(msoResponseWrapperObject.getResponse(), HttpStatus.OK); + response = new ResponseEntity<>(msoResponseWrapperObject.getResponse(), HttpStatus.OK); return response; } catch (Exception e) { logger.error("Failure during doChangeManagement with request " + request.toString(), e); @@ -141,32 +148,26 @@ public class ChangeManagementServiceImpl implements ChangeManagementService { } @Override - public JSONArray getSchedulerChangeManagements() { - JSONArray result = null; - try { - String path = SystemProperties.getProperty(SchedulerProperties.SCHEDULER_GET_SCHEDULES); - org.onap.vid.scheduler.RestObject restObject = new org.onap.vid.scheduler.RestObject<>(); - - String str = new String(); - restObject.set(str); - restClient.Get(str, "", path, restObject); - String restCallResult = restObject.get(); - JSONParser parser = new JSONParser(); - Object parserResult = parser.parse(restCallResult); - result = (JSONArray) parserResult; - } catch (Exception e) { - e.printStackTrace(); - } + public RestObjectWithRequestInfo getSchedulerChangeManagementsWithRequestInfo() { + String path = SystemProperties.getProperty(SchedulerProperties.SCHEDULER_GET_SCHEDULES); + RestObject restObject = new RestObject<>(); + ArrayNode jsonArray = new ArrayNode(new JsonNodeFactory(true)); + restObject.set(jsonArray); + return restClient.Get(jsonArray, path, restObject); + } - return result; + @Override + public ArrayNode getSchedulerChangeManagements() { + RestObjectWithRequestInfo responseWithRequestInfo = getSchedulerChangeManagementsWithRequestInfo(); + return responseWithRequestInfo.getRestObject().get(); } @Override public Pair deleteSchedule(String scheduleId) { try { String path = String.format(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_DELETE_SCHEDULE), scheduleId); - org.onap.vid.scheduler.RestObject restObject = new org.onap.vid.scheduler.RestObject<>(); - String str = new String(); + RestObject restObject = new RestObject<>(); + String str = ""; restObject.set(str); restClient.Delete(str, "", path, restObject); String restCallResult = restObject.get(); @@ -187,11 +188,11 @@ public class ChangeManagementServiceImpl implements ChangeManagementService { continue; } @SuppressWarnings("unchecked") List vnfList = dataAccessService.getList(VNFDao.class, getVnfQueryString(workflowsDetail.getVnfDetails().getUUID(), workflowsDetail.getVnfDetails().getInvariantUUID()), null, null); - if (vnfList.size() == 0) { + if (vnfList.isEmpty()) { vnfList.add(saveNewVnf(workflowsDetail)); } @SuppressWarnings("unchecked") List workflowList = dataAccessService.getList(VidWorkflow.class, String.format(" where wokflowName = '%s'", workflowsDetail.getWorkflowName()), null, null); - if (workflowList.size() == 0) { + if (workflowList.isEmpty()) { vnfWorkflowRelationResponse.getErrors().add("Not Found instance of workflow " + workflowsDetail.getWorkflowName() + " for vnf with UUID " + workflowsDetail.getVnfDetails().getUUID() + " and with invariantUUID " + workflowsDetail.getVnfDetails().getInvariantUUID()); continue; } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CloudOwnerService.java b/vid-app-common/src/main/java/org/onap/vid/services/CloudOwnerService.java new file mode 100644 index 000000000..1d453819f --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/CloudOwnerService.java @@ -0,0 +1,12 @@ +package org.onap.vid.services; + +import org.onap.vid.mso.model.CloudConfiguration; +import org.onap.vid.mso.rest.RequestDetails; + +public interface CloudOwnerService { + + void enrichRequestWithCloudOwner(RequestDetails msoRequest); + + void enrichCloudConfigurationWithCloudOwner(CloudConfiguration cloudConfiguration, String lcpCloudRegionId); + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CloudOwnerServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/CloudOwnerServiceImpl.java new file mode 100644 index 000000000..3acab9ff9 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/CloudOwnerServiceImpl.java @@ -0,0 +1,76 @@ +package org.onap.vid.services; + + +import com.google.common.collect.ImmutableList; +import org.apache.commons.lang3.StringUtils; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.exceptions.NotFoundException; +import org.onap.vid.mso.model.CloudConfiguration; +import org.onap.vid.mso.rest.RequestDetails; +import org.onap.vid.properties.Features; +import org.springframework.beans.factory.annotation.Autowired; +import org.togglz.core.manager.FeatureManager; + +import java.util.List; +import java.util.Map; + +public class CloudOwnerServiceImpl implements CloudOwnerService { + + private static final List CLOUD_CONFIGURATION_PATH = ImmutableList.of("requestDetails", "cloudConfiguration"); + private static final List LCP_CLOUD_REGION_ID_PATH = ImmutableList.of("requestDetails", "cloudConfiguration", "lcpCloudRegionId"); + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(CloudOwnerService.class); + + private final AaiClientInterface aaiClient; + private final FeatureManager featureManager; + + @Autowired + public CloudOwnerServiceImpl(AaiClientInterface aaiClient, FeatureManager featureManager) { + this.aaiClient = aaiClient; + this.featureManager = featureManager; + } + + @Override + public void enrichRequestWithCloudOwner(RequestDetails msoRequest) { + if (!featureManager.isActive(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)) { + return; + } + try { + + //if cloudConfiguration field contains lcpRegion (e.g. in changeManagement scenarios) + if (msoRequest.getCloudConfiguration()!=null && StringUtils.isNotEmpty(msoRequest.getCloudConfiguration().getLcpCloudRegionId())) { + enrichCloudConfigurationWithCloudOwner(msoRequest.getCloudConfiguration(), msoRequest.getCloudConfiguration().getLcpCloudRegionId()); + } + //otherwise the cloudConfiguration is in the additionalProperties field of RequestDetails (e.g. in ng1 view/edit scenario) + else { + enrichRequestWithCloudOwnerByAdditionalProperties(msoRequest); + } + } + catch (Exception e) { + throw new GenericUncheckedException("Failed to enrich requestDetails with cloudOwner", e); + } + } + + protected void enrichRequestWithCloudOwnerByAdditionalProperties(RequestDetails msoRequest) { + String lcpCloudRegionId = null; + try { + lcpCloudRegionId = msoRequest.extractValueByPathUsingAdditionalProperties(LCP_CLOUD_REGION_ID_PATH, String.class); + } + catch (NotFoundException exception) { + LOGGER.debug("Can't find lcp region in RequestDetails. Assume no cloudOwner enrichment is needed. Reason: "+exception.getMessage()); + return; + } + String cloudOwner = aaiClient.getCloudOwnerByCloudRegionId(lcpCloudRegionId); + msoRequest.extractValueByPathUsingAdditionalProperties(CLOUD_CONFIGURATION_PATH, Map.class).put("cloudOwner", cloudOwner); + } + + @Override + public void enrichCloudConfigurationWithCloudOwner(CloudConfiguration cloudConfiguration, String lcpCloudRegionId) { + if (featureManager.isActive(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)) { + String cloudOwner = aaiClient.getCloudOwnerByCloudRegionId(lcpCloudRegionId); + cloudConfiguration.setCloudOwner(cloudOwner); + } + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CsvService.java b/vid-app-common/src/main/java/org/onap/vid/services/CsvService.java index 248068fba..6e4a06657 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/CsvService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/CsvService.java @@ -3,7 +3,6 @@ package org.onap.vid.services; import org.json.JSONObject; import org.springframework.web.multipart.MultipartFile; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java index c34bf4e65..6ba152228 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java @@ -165,7 +165,7 @@ public class CsvServiceImpl implements CsvService{ * @throws IllegalAccessException * @throws InstantiationException */ - private T putJson(T json, String key, E values) throws IllegalAccessException, InstantiationException { + private T putJson(T json, String key, E values) { if (json instanceof JSONArray){ JSONArray currentJson= ((JSONArray)json); if (values == null) //array of strings (for last item) @@ -176,11 +176,8 @@ public class CsvServiceImpl implements CsvService{ if (keyExistsOrFirstElement(currentJson, key)) { currentJson.put(new JSONObject().put(key, values)); } else { - JSONObject lastItem = lastItemInArray(currentJson); - if(lastItem != null){ - lastItem.put(key, values); - } - + JSONObject lastItem = lastItemInArray(currentJson); + lastItem.put(key, values); } } } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java index 500f5ac7f..3ff8db0e5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java @@ -23,16 +23,11 @@ package org.onap.vid.services; import io.joshworks.restclient.http.HttpResponse; import jline.internal.Log; -import org.onap.vid.aai.AaiClientInterface; -import org.onap.vid.aai.AaiOverTLSClientInterface; -import org.onap.vid.aai.AaiResponse; -import org.onap.vid.aai.ServiceSubscription; -import org.onap.vid.aai.Services; +import org.onap.vid.aai.*; import org.onap.vid.model.ModelConstants; import org.onap.vid.model.Subscriber; import org.onap.vid.model.SubscriberList; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -46,7 +41,6 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService { AaiClientInterface client; @Autowired - @Qualifier("aaiClientForCodehausMapping") AaiOverTLSClientInterface aaiOverTLSClient; public static final String DB_NAME = "vid_portal"; @@ -73,8 +67,9 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService { } private String addAvailableRolesCombination(Boolean firstRun, SubscriberList subscribers) { - String query, availableRoles=""; - HashMap servicesNames = new HashMap(); + String query; + String availableRoles=""; + HashMap servicesNames = new HashMap<>(); for (Subscriber subscriber: subscribers.customer) { AaiResponse subscriberResponse = client.getSubscriberData(subscriber.globalCustomerId); for(ServiceSubscription service: subscriberResponse.getT().serviceSubscriptions.serviceSubscription) { @@ -146,13 +141,12 @@ public class RoleGenaratorServiceImpl implements RoleGeneratorService { } private String insertAvailableRolesToFnRole(){ - String query="INSERT INTO fn_role (ROLE_NAME, ACTIVE_YN, PRIORITY)\r\n" + + return "INSERT INTO fn_role (ROLE_NAME, ACTIVE_YN, PRIORITY)\r\n" + "SELECT RNAME, 'Y', 5\r\n" + "FROM available_roles\r\n" + "WHERE NOT EXISTS (SELECT ROLE_NAME\r\n" + "FROM fn_role \r\n" + "where RNAME = ROLE_NAME);\r\n"; - return query; } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java index 1890a5b37..aedd1b950 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java @@ -52,9 +52,7 @@ public class VidServiceImpl implements VidService { * The Constant LOG. */ private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidServiceImpl.class); - /** - * The Constant dateFormat. - */ + protected final AsdcClient asdcClient; private final FeatureManager featureManager; @@ -126,7 +124,7 @@ public class VidServiceImpl implements VidService { final Service asdcServiceMetadata = asdcClient.getService(UUID.fromString(uuid)); return getServiceModel(uuid, serviceCsar, tosca, asdcServiceMetadata); } catch (Exception e) { - LOG.error("Failed to download and proccess service from SDC", e); + LOG.error("Failed to download and process service from SDC", e); } return serviceModel; } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/WorkflowService.java b/vid-app-common/src/main/java/org/onap/vid/services/WorkflowService.java index ea139080f..775b6a9d1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/WorkflowService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/WorkflowService.java @@ -1,6 +1,5 @@ package org.onap.vid.services; -import org.onap.vid.model.Workflow; import java.util.Collection; public interface WorkflowService { diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt b/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt new file mode 100644 index 000000000..7ccdd1bc4 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/utils/KotlinUtils.kt @@ -0,0 +1,10 @@ +package org.onap.vid.utils + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper + +inline fun > getEnumFromMapOfStrings(map: Map, key:String, defaultValue:E): E { + return java.lang.Enum.valueOf(E::class.java, (map.getOrDefault(key, defaultValue.name) as String)) +} + +val JACKSON_OBJECT_MAPPER: ObjectMapper = jacksonObjectMapper() \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java index 3ac905884..f02497b05 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java @@ -28,12 +28,14 @@ import static org.onap.vid.utils.Streams.not; public class Logging { - Logging() { + private Logging() { } public static final String HTTP_REQUESTS_OUTGOING = "http.requests.outgoing."; public static final String REQUEST_ID_HEADER_KEY = SystemProperties.ECOMP_REQUEST_ID; + public static final String ONAP_REQUEST_ID_HEADER_KEY = "X-ONAP-RequestID"; + private static ObjectMapper objectMapper = new ObjectMapper(); diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Multival.java b/vid-app-common/src/main/java/org/onap/vid/utils/Multival.java new file mode 100644 index 000000000..3a9b518d1 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Multival.java @@ -0,0 +1,54 @@ +package org.onap.vid.utils; + +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import java.util.Collection; +import java.util.function.Function; + +import static java.util.stream.Collectors.toSet; + +@JsonPropertyOrder({"keyType", "valuesType"}) +public class Multival { + private final String keyType; + private final String valuesType; + private final K key; + private final Collection values; + + private Multival(String keyType, K key, String valuesType, Collection values) { + this.keyType = keyType; + this.key = key; + this.valuesType = valuesType; + this.values = values; + } + + public static Multival of(String keyType, K key, String valuesType, Collection values) { + return new Multival<>(keyType, key, valuesType, values); + } + + public String getKeyType() { + return keyType; + } + + public String getValuesType() { + return valuesType; + } + + public K getKey() { + return key; + } + + public Collection getValues() { + return values; + } + + public Multival mapEachVal(Function mapper) { + return Multival.of( + this.getKeyType(), + this.getKey(), + this.getValuesType(), + this.getValues().stream() + .map(mapper) + .collect(toSet()) + ); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Streams.java b/vid-app-common/src/main/java/org/onap/vid/utils/Streams.java index 7f81b225a..9c836912d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Streams.java +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Streams.java @@ -9,13 +9,22 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; public class Streams { + + private Streams() { + // hide the implicit public constructor + } + public static Predicate not(Predicate predicate) { return predicate.negate(); } public static Stream fromIterator(final Iterator iterator) { Iterable iterable = () -> iterator; - return StreamSupport.stream(iterable.spliterator(), false); + return StreamSupport.stream(iterable.spliterator(), false); + } + + public static Stream fromIterable(final Iterable iterable) { + return StreamSupport.stream(iterable.spliterator(), false); } diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java b/vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java new file mode 100644 index 000000000..7d281454e --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/utils/TimeUtils.java @@ -0,0 +1,21 @@ +package org.onap.vid.utils; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class TimeUtils { + private static DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME; + + private TimeUtils() { + // explicit private constructor, to hide the implicit public constructor + } + + public static ZonedDateTime parseZonedDateTime(String time) { + + return ZonedDateTime.from(formatter.parse(time)); + } + + public static String zonedDateTimeToString(ZonedDateTime time) { + return formatter.format(time); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt b/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt new file mode 100644 index 000000000..28f989bb3 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt @@ -0,0 +1,44 @@ +package org.onap.vid.utils + +data class Node(val value:T, val children:MutableMap> = hashMapOf()) + +data class Tree(private val root:Node) { + + constructor(value: T) : this(Node(value)) + + fun getRootValue():T { + return root.value; + } + + fun addPath(vararg path: T) { + addPath(path.asList()) + } + + fun addPath(path:Collection) { + var currentNode = root + path.forEach { + currentNode = currentNode.children.getOrPut(it) {Node(it)} + } + } + + fun getSubTree(vararg path: T): Tree? { + return getSubTree(path.asList()) + } + + fun getSubTree(path:Collection): Tree? { + var currentNode:Node = root + path.forEach { + currentNode = currentNode.children[it] ?: return null + } + return Tree(currentNode) + } + + fun isPathExist(vararg path: T): Boolean { + return isPathExist(path.asList()) + } + + fun isPathExist(path:Collection): Boolean { + return getSubTree(path)!=null + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java b/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java new file mode 100644 index 000000000..25bf0efd2 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Unchecked.java @@ -0,0 +1,23 @@ +package org.onap.vid.utils; + +import org.onap.vid.exceptions.GenericUncheckedException; + +import java.net.URI; +import java.net.URISyntaxException; + +public class Unchecked { + private Unchecked() { + // explicit private constructor, to hide the implicit public constructor + } + + public static URI toURI(String uri) { + try { + // Indulge spaces in the URI by the replcement + return new URI(uri.replace(" ", "%20")); + } catch (URISyntaxException e) { + throw new GenericUncheckedException(e); + } + } + + +} -- cgit 1.2.3-korg