diff options
Diffstat (limited to 'plans')
31 files changed, 1159 insertions, 170 deletions
diff --git a/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/tenant.json b/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/tenant.json new file mode 100644 index 00000000..746131a6 --- /dev/null +++ b/plans/so/integration-etsi-testing/config/aai-simulator-populate-data/tenant.json @@ -0,0 +1,4 @@ +{ + "tenant-id": "693c7729b2364a26a3ca602e6f66187d", + "tenant-name": "admin" +} diff --git a/plans/so/integration-etsi-testing/config/override-files/bpmn-infra/onapheat/override.yaml b/plans/so/integration-etsi-testing/config/override-files/bpmn-infra/onapheat/override.yaml new file mode 100644 index 00000000..d38888d5 --- /dev/null +++ b/plans/so/integration-etsi-testing/config/override-files/bpmn-infra/onapheat/override.yaml @@ -0,0 +1,322 @@ +aai: + auth: 221187EFA3AD4E33600DE0488F287099934CE65C3D0697BCECC00BB58E784E07CD74A24581DC31DBC086FF63DF116378776E9BE3D1325885 + dme2: + timeout: '30000' + endpoint: https://aai-simulator:9993 + workflowAaiDistributionDelay: PT30S + pnfEntryNotificationTimeout: P14D +camunda: + bpm: + admin-user: + id: admin + password: so_Admin123 + history-level: full + job-execution: + max-pool-size: 30 + core-pool-size: 3 +cds: + endpoint: blueprints-processor + port: 9111 + auth: Basic Y2NzZGthcHBzOmNjc2RrYXBwcw== + timeout: 60 +entitymanager: + packagesToScan: com +pnf: + dmaap: + host: message-router + port: 3904 + protocol: http + uriPathPrefix: events + topicName: pnfReady + consumerGroup: consumerGroup + consumerId: consumerId + topicListenerDelayInSeconds: 5 +mso: + msoKey: 07a7159d3bf51a0e53be7a8f89699be7 + config: + path: /var/csar/ + correlation: + timeout: 60 + logPath: logs + async: + core-pool-size: 50 + max-pool-size: 50 + queue-capacity: 500 + aai: + endpoint: https://aai-simulator:9993 + adapters: + completemsoprocess: + endpoint: http://bpmn-infra:8081/CompleteMsoProcess + requestDb: + endpoint: http://request-db-adapter:8083 + auth: Basic YnBlbDpwYXNzd29yZDEk + db: + auth: 33293332AEC4930F655D8E2E8BB08937 + password: wLg4sjrAFUS8rfVfdvTXeQ== + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8083/services/RequestsDbAdapter + spring: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8083 + network: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8087/services/NetworkAdapter + rest: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8087/services/rest/v1/networks + openecomp: + db: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8083/services/RequestsDbAdapter + po: + auth: 33293332AEC4930F655D8E2E8BB08937 + password: B8EBDE0311F0AF355CF3F2FD505A8CAD + sdnc: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8086/adapters/SDNCAdapter + rest: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8086/adapters/rest/v1/sdnc + timeout: PT60M + tenant: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8087/services/TenantAdapter + vnf: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8087/services/VnfAdapter + rest: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8087/services/rest/v1/vnfs + volume-groups: + rest: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8087/services/rest/v1/volume-groups + vnf-async: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8087/services/VnfAdapterAsync + bpmn: + process: + historyTimeToLive: '30' + callbackRetryAttempts: '5' + catalog: + db: + endpoint: http://catalog-db-adapter:8082/ecomp/mso/catalog + spring: + endpoint: http://catalog-db-adapter:8082 + db: + auth: Basic YnBlbDpwYXNzd29yZDEk + default: + adapter: + namespace: http://org.onap.mso + healthcheck: + log: + debug: 'false' + infra: + customer: + id: testCustIdInfra + po: + timeout: PT60M + request: + db: + endpoint: http://c1.vm1.mso.simpledemo.onap.org:8083/ + rollback: 'true' + sdnc: + password: 3141634BF7E070AA289CF2892C986C0B + service: + agnostic: + sniro: + endpoint: /sniro/api/v2/placement + host: http://c1.vm1.mso.simpledemo.onap.org:30253 + site-name: CamundaEngine + sniro: + auth: test:testpwd + callback: http://c1.vm1.mso.simpledemo.onap.org:8086/adapters/rest/SDNCNotify + endpoint: http://replaceme:28090/optimizationInstance/V1/create + timeout: PT30M + oof: + auth: test:testpwd + callbackEndpoint: http://bpmn-infra:8081/mso/WorkflowMessage + endpoint: http://oof.api.simpledemo.openecomp.org:8698/api/oof/v1/placement + timeout: PT30M + workflow: + CreateGenericVNFV1: + aai: + volume-group: + uri: /aai/v6/cloud-infrastructure/volume-groups/volume-group + default: + aai: + version: '14' + cloud-region: + version: '14' + generic-vnf: + version: '14' + v14: + customer: + uri: /aai/v14/business/customers/customer + generic-query: + uri: /aai/v14/search/generic-query + generic-vnf: + uri: /aai/v14/network/generic-vnfs/generic-vnf + l3-network: + uri: /aai/v14/network/l3-networks/l3-network + network-policy: + uri: /aai/v14/network/network-policies/network-policy + nodes-query: + uri: /aai/v14/search/nodes-query + route-table-reference: + uri: /aai/v14/network/route-table-references/route-table-reference + tenant: + uri: /aai/v14/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant + vce: + uri: /aai/v14/network/vces/vce + vpn-binding: + uri: /aai/v14/network/vpn-bindings/vpn-binding + sp-partner: + uri: /aai/v14/business/sp-partners/sp-partner + device: + uri: /aai/v14/network/devices/device + v11: + customer: + uri: /aai/v11/business/customers/customer + generic-query: + uri: /aai/v11/search/generic-query + generic-vnf: + uri: /aai/v11/network/generic-vnfs/generic-vnf + l3-network: + uri: /aai/v11/network/l3-networks/l3-network + network-policy: + uri: /aai/v11/network/network-policies/network-policy + nodes-query: + uri: /aai/v11/search/nodes-query + route-table-reference: + uri: /aai/v11/network/route-table-references/route-table-reference + tenant: + uri: /aai/v11/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant + vce: + uri: /aai/v11/network/vces/vce + vpn-binding: + uri: /aai/v11/network/vpn-bindings/vpn-binding + v8: + configuration: + uri: /aai/v11/network/configurations/configuration + customer: + uri: /aai/v8/business/customers/customer + generic-query: + uri: /aai/v8/search/generic-query + l3-network: + uri: /aai/v8/network/l3-networks/l3-network + network-policy: + uri: /aai/v8/network/network-policies/network-policy + nodes-query: + uri: /aai/v8/search/nodes-query + route-table-reference: + uri: /aai/v8/network/route-table-references/route-table-reference + tenant: + uri: /aai/v8/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/RegionOne/tenants/tenant + vce: + uri: /aai/v8/network/vces/vce + vpn-binding: + uri: /aai/v8/network/vpn-bindings/vpn-binding + v9: + cloud-region: + uri: /aai/v9/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner + generic-vnf: + uri: /aai/v9/network/generic-vnfs/generic-vnf + retry: + attempts: '1' + deleteCinderVolumeV1: + aai: + volume-group: + uri: /aai/v6/cloud-infrastructure/volume-groups/volume-group + global: + default: + aai: + namespace: http://org.onap.aai.inventory/ + version: 14 + message: + endpoint: http://bpmn-infra:8081/mso/WorkflowMessage + notification: + name: GenericNotificationServiceATT + sdncadapter: + callback: http://bpmn-infra:8081/mso/SDNCAdapterCallbackService + vnfadapter: + create: + callback: http://c1.vm1.mso.simpledemo.onap.org:8087/mso/vnfAdapterNotify + delete: + callback: http://c1.vm1.mso.simpledemo.onap.org:8087/mso/vnfAdapterNotify + query: + callback: http://c1.vm1.mso.simpledemo.onap.org:8087/mso/vnfAdapterNotify + rollback: + callback: http://c1.vm1.mso.simpledemo.onap.org:8087/mso/vnfAdapterNotify + global: + dmaap: + username: testuser + password: alRyMzJ3NUNeakxl + host: http://10.42.111.36:904 + auth: A4DE725B8B0D1A745049409B16762C16BC9B48555DC157272741D616323104442B3AAC052ED17E74EECA136B89C8C6615C8CC269ED5834EC47C6BE6A75DF39C6C07B07DF064CE268BE6510F472 + publisher: + topic: replaceme +policy: + auth: Basic dGVzdHBkcDphbHBoYTEyMw== + client: + auth: Basic bTAzNzQzOnBvbGljeVIwY2sk + endpoint: https://localhost:8081/pdp/api/ + environment: TEST +sdnc: + auth: Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ== + host: http://sdnc-simulator:9994 + path: /restconf/operations/GENERIC-RESOURCE-API + si: + svc: + types: PORT-MIRROR,PPROBE + +appc: + client: + topic: + read: + name: APPC-LCM-WRITE + timeout: 360000 + write: APPC-LCM-READ + sdnc: + read: + name: SDNC-LCM-WRITE + write: SDNC-LCM-READ + response: + timeout: 360000 + key: VIlbtVl6YLhNUrtU + secret: 64AG2hF4pYeG2pq7CT6XwUOT + service: ueb + poolMembers: ueb1.simpledemo.onap.org:3904,ueb2.simpledemo.onap.org:3904 +server: + port: 8081 + tomcat: + max-threads: 50 +spring: + datasource: + driver-class-name: org.mariadb.jdbc.Driver + url: jdbc:mariadb://mariadb:3306/camundabpmn + username: camundauser + password: camunda123 + dbcp2: + initial-size: 5 + max-total: 20 + validation-query: select 1 + test-on-borrow: true + security: + usercredentials: + - + username: apihBpmn + password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' + role: BPMN-Client + - + username: sdncaBpmn + password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' + role: BPMN-Client + - + username: poBpmn + password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' + role: BPMN-Client + - + username: wmaBpmn + password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' + role: BPMN-Client + - + username: sniro + password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' + role: SNIRO-Client + - + username: mso_admin + password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' + role: ACTUATOR +org: + onap: + so: + cloud-owner: CloudOwner diff --git a/plans/so/integration-etsi-testing/config/populate-aai-simulator.sh b/plans/so/integration-etsi-testing/config/populate-aai-simulator.sh index d96301cf..87062ed3 100755 --- a/plans/so/integration-etsi-testing/config/populate-aai-simulator.sh +++ b/plans/so/integration-etsi-testing/config/populate-aai-simulator.sh @@ -57,6 +57,7 @@ populate_aai_simulator() LINE_OF_BUSINESS_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/line-of-business.json PLATFORM_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/platform.json CLOUD_REGION_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/cloud-region.json + TENANT_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/tenant.json STATUS_CODE_ACCEPTED="202" echo "$SCRIPT_NAME $(current_timestamp): checking health of AAI Simulator" @@ -119,6 +120,14 @@ populate_aai_simulator() exit 1 fi + echo "$SCRIPT_NAME $(current_timestamp): Adding Tenant" + status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/EtsiCloudRegion/tenants/tenant/693c7729b2364a26a3ca602e6f66187d -X PUT -d @$"$TENANT_JSON_FILE") + + if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then + echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put Tenant data in AAI Simulator. Status code received: $status_code" + exit 1 + fi + echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator Populated Successfully" } diff --git a/plans/so/integration-etsi-testing/docker-compose.yml b/plans/so/integration-etsi-testing/docker-compose.yml index e5e56d6c..2c7261c2 100644 --- a/plans/so/integration-etsi-testing/docker-compose.yml +++ b/plans/so/integration-etsi-testing/docker-compose.yml @@ -162,7 +162,8 @@ services: - "8081:8081" volumes: - ${TEST_LAB_DIR}/volumes/so/ca-certificates/onapheat:/app/ca-certificates - - ${TEST_LAB_DIR}/volumes/so/config/bpmn-infra/onapheat:/app/config + - ${CONFIG_DIR_PATH}/override-files/bpmn-infra/onapheat:/app/config + - ${CONFIG_DIR_PATH}/certificates/aai-certificate/aai.crt:/app/ca-certificates/aai.crt environment: - APP=bpmn-infra - JVM_ARGS=-Xms64m -Xmx512m diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java index 22767b29..347743bd 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java @@ -19,28 +19,22 @@ */ package org.onap.so.aaisimulator.controller; -import static org.onap.so.aaisimulator.utils.Constants.COMPOSED_OF; -import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_GLOBAL_CUSTOMER_ID; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_TYPE; import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_URL; import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF; import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_ID; -import static org.onap.so.aaisimulator.utils.Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID; -import static org.onap.so.aaisimulator.utils.Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_NAME; import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; import static org.onap.so.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION; -import static org.onap.so.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE; import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion; -import java.util.List; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; import org.onap.aai.domain.yang.Customer; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.ServiceInstance; @@ -50,7 +44,6 @@ import org.onap.so.aaisimulator.models.NodeServiceInstance; import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider; import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider; -import org.onap.so.aaisimulator.utils.RequestErrorResponseUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -302,9 +295,9 @@ public class BusinessController { return getRequestErrorResponseEntity(request, GENERIC_VNF); } - @PutMapping( - value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/relationship-list/relationship", + value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}" + + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> putSericeInstanceRelationShip( @@ -316,25 +309,12 @@ public class BusinessController { LOGGER.info( "Will add {} relationship for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...", relationship.getRelatedTo(), globalCustomerId, serviceType, serviceInstanceId); - final Optional<ServiceInstance> optional = - cacheServiceProvider.addRelationShip(globalCustomerId, serviceType, serviceInstanceId, relationship); + final Optional<Relationship> optional = cacheServiceProvider.addRelationShip(globalCustomerId, serviceType, + serviceInstanceId, relationship, request.getRequestURI()); if (optional.isPresent()) { - final ServiceInstance serviceInstance = optional.get(); - final Relationship resultantRelationship = new Relationship(); - resultantRelationship.setRelatedTo(GENERIC_VNF); - resultantRelationship.setRelationshipLabel(COMPOSED_OF); - resultantRelationship.setRelatedLink(request.getRequestURI()); - - final List<RelationshipData> relationshipDataList = resultantRelationship.getRelationshipData(); - relationshipDataList.add(getRelationshipData(CUSTOMER_GLOBAL_CUSTOMER_ID, globalCustomerId)); - relationshipDataList.add(getRelationshipData(SERVICE_SUBSCRIPTION_SERVICE_TYPE, serviceType)); - relationshipDataList.add(getRelationshipData(SERVICE_INSTANCE_SERVICE_INSTANCE_ID, serviceInstanceId)); - - final List<RelatedToProperty> relatedToProperty = resultantRelationship.getRelatedToProperty(); - relatedToProperty.add(getRelatedToProperty(SERVICE_INSTANCE_SERVICE_INSTANCE_NAME, - serviceInstance.getServiceInstanceName())); - + final Relationship resultantRelationship = optional.get(); + LOGGER.info("Relationship add, sending resultant relationship: {} in response ...", resultantRelationship); return ResponseEntity.accepted().body(resultantRelationship); } @@ -342,22 +322,6 @@ public class BusinessController { "Couldn't add {} relationship for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...", relationship.getRelatedTo(), globalCustomerId, serviceType, serviceInstanceId); - return RequestErrorResponseUtils.getRequestErrorResponseEntity(request); - } - - private RelatedToProperty getRelatedToProperty(final String key, final String value) { - final RelatedToProperty relatedToProperty = new RelatedToProperty(); - relatedToProperty.setPropertyKey(key); - relatedToProperty.setPropertyValue(value); - return relatedToProperty; - } - - private RelationshipData getRelationshipData(final String key, final String value) { - final RelationshipData relationshipData = new RelationshipData(); - relationshipData.setRelationshipKey(key); - relationshipData.setRelationshipValue(value); - return relationshipData; + return getRequestErrorResponseEntity(request); } - - } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java index 2b45499a..2df11c1f 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java @@ -21,6 +21,8 @@ package org.onap.so.aaisimulator.controller; import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION; import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGIONS; +import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getHeaders; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion; import java.util.Optional; @@ -28,11 +30,14 @@ import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.Tenant; import org.onap.so.aaisimulator.models.CloudRegionKey; import org.onap.so.aaisimulator.service.providers.CloudRegionCacheServiceProvider; +import org.onap.so.aaisimulator.utils.HttpServiceUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @@ -99,7 +104,7 @@ public class CloudRegionsController { return getRequestErrorResponseEntity(request, CLOUD_REGION); } - @PutMapping(value = "{cloud-owner}/{cloud-region-id}/relationship-list/relationship", + @PutMapping(value = "{cloud-owner}/{cloud-region-id}" + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> putRelationShip(@PathVariable("cloud-owner") final String cloudOwner, @@ -119,10 +124,76 @@ public class CloudRegionsController { } LOGGER.error("Couldn't add {} relationship for 'key': {} ...", relationship.getRelatedTo(), key); + return getRequestErrorResponseEntity(request, CLOUD_REGION); + + } + @PutMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> putTenant(@RequestBody final Tenant tenant, + @PathVariable("cloud-owner") final String cloudOwner, + @PathVariable("cloud-region-id") final String cloudRegionId, + @PathVariable("tenant-id") final String tenantId, final HttpServletRequest request) { + + final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId); + + if (key.isValid()) { + LOGGER.info("Will add Tenant to cache with key 'key': {} ....", key); + if (tenant.getResourceVersion() == null || tenant.getResourceVersion().isEmpty()) { + tenant.setResourceVersion(getResourceVersion()); + } + if (cacheServiceProvider.putTenant(key, tenant)) { + return ResponseEntity.accepted().build(); + } + } + + LOGGER.error("Unable to add Tenant in cache using key {}", key); return getRequestErrorResponseEntity(request, CLOUD_REGION); + } + @GetMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> getTenant(@PathVariable("cloud-owner") final String cloudOwner, + @PathVariable("cloud-region-id") final String cloudRegionId, + @PathVariable("tenant-id") final String tenantId, final HttpServletRequest request) { + final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId); + LOGGER.info("Retrieving Tenant using key : {} and tenant-id:{} ...", key, tenantId); + if (key.isValid()) { + final Optional<Tenant> optional = cacheServiceProvider.getTenant(key, tenantId); + if (optional.isPresent()) { + final Tenant tenant = optional.get(); + LOGGER.info("found Tenant {} in cache", tenant); + return ResponseEntity.ok(tenant); + } + } + LOGGER.error("Unable to find Tenant in cache key : {} and tenant-id:{} ...", key, tenantId); + return getRequestErrorResponseEntity(request, CLOUD_REGION); } + @PutMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/relationship-list/relationship", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> putRelationShip(@RequestBody final Relationship relationship, + @PathVariable("cloud-owner") final String cloudOwner, + @PathVariable("cloud-region-id") final String cloudRegionId, + @PathVariable("tenant-id") final String tenantId, final HttpServletRequest request) { + + final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId); + LOGGER.info("Will put RelationShip for key : {} and tenant-id:{} ...", key, tenantId); + + if (relationship.getRelatedLink() != null) { + final String targetBaseUrl = HttpServiceUtils.getBaseUrl(request).toString(); + final HttpHeaders incomingHeader = getHeaders(request); + boolean result = cacheServiceProvider.addRelationShip(incomingHeader, targetBaseUrl, + request.getRequestURI(), key, tenantId, relationship); + if (result) { + LOGGER.info("added created bi directional relationship with {}", relationship.getRelatedLink()); + return ResponseEntity.accepted().build(); + } + } + LOGGER.error("Unable to add relationship for related link: {}", relationship.getRelatedLink()); + return getRequestErrorResponseEntity(request, CLOUD_REGION); + } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java index 2eb84f05..e71cd505 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java @@ -19,13 +19,10 @@ */ package org.onap.so.aaisimulator.controller; -import static org.onap.so.aaisimulator.utils.Constants.COMPOSED_OF; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF; import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNFS_URL; -import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_ID; -import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_NAME; -import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; -import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getBaseUrl; +import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getHeaders; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion; @@ -33,24 +30,25 @@ import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider; -import org.onap.so.aaisimulator.service.providers.HttpRestServiceProvider; +import org.onap.so.aaisimulator.utils.HttpServiceUtils; import org.onap.so.aaisimulator.utils.RequestErrorResponseUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.util.UriComponentsBuilder; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -64,13 +62,10 @@ public class GenericVnfsController { private final GenericVnfCacheServiceProvider cacheServiceProvider; - private final HttpRestServiceProvider httpRestServiceProvider; @Autowired - public GenericVnfsController(final GenericVnfCacheServiceProvider cacheServiceProvider, - final HttpRestServiceProvider httpRestServiceProvider) { + public GenericVnfsController(final GenericVnfCacheServiceProvider cacheServiceProvider) { this.cacheServiceProvider = cacheServiceProvider; - this.httpRestServiceProvider = httpRestServiceProvider; } @PutMapping(value = "/generic-vnf/{vnf-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, @@ -90,8 +85,13 @@ public class GenericVnfsController { @GetMapping(value = "/generic-vnf/{vnf-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> getGenericVnf(@PathVariable("vnf-id") final String vnfId, - @RequestParam(name = "depth", required = false) final Integer depth, final HttpServletRequest request) { - LOGGER.info("Will get GenericVnf for 'vnf-id': {} with depth: {}...", vnfId, depth); + @RequestParam(name = "depth", required = false) final Integer depth, + @RequestParam(name = "resultIndex", required = false) final Integer resultIndex, + @RequestParam(name = "resultSize", required = false) final Integer resultSize, + @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { + LOGGER.info( + "Will get GenericVnf for 'vnf-id': {} with depth: {}, resultIndex: {}, resultSize:{}, format: {} ...", + vnfId, depth, resultIndex, resultSize, format); final Optional<GenericVnf> optional = cacheServiceProvider.getGenericVnf(vnfId); @@ -101,7 +101,9 @@ public class GenericVnfsController { return ResponseEntity.ok(genericVnf); } - LOGGER.error("Unable to find GenericVnf in cache for 'vnf-id': {} with depth: {} ...", vnfId, depth); + LOGGER.error( + "Unable to find GenericVnf in cache for 'vnf-id': {} with depth: {}, resultIndex: {}, resultSize:{}, format:{} ...", + vnfId, depth, resultIndex, resultSize, format); return getRequestErrorResponseEntity(request, GENERIC_VNF); } @@ -113,59 +115,60 @@ public class GenericVnfsController { @PathVariable("vnf-id") final String vnfId, final HttpServletRequest request) { LOGGER.info("Will put RelationShip for 'vnf-id': {} ...", vnfId); - try { - if (relationship.getRelatedLink() != null) { - final Optional<GenericVnf> optional = cacheServiceProvider.getGenericVnf(vnfId); - - if (optional.isPresent()) { - final GenericVnf genericVnf = optional.get(); - final String url = getRelationShipUrl(request, relationship.getRelatedLink()); - - final Relationship serviceRelationship = getRelationship(request.getRequestURI(), genericVnf); - final Optional<Relationship> optionalRelationship = httpRestServiceProvider.put(getHeaders(request), - serviceRelationship, url, Relationship.class); - - if (optionalRelationship.isPresent()) { - final Relationship resultantRelationship = optionalRelationship.get(); - final boolean result = cacheServiceProvider.addRelationShip(vnfId, resultantRelationship); - if (result) { - LOGGER.info("added relationship {} in cache successfully", relationship); - return ResponseEntity.accepted().build(); - } - LOGGER.error("Unable to add relationship {} in cache", relationship); - } - } + if (relationship.getRelatedLink() != null) { + final String targetBaseUrl = HttpServiceUtils.getBaseUrl(request).toString(); + final HttpHeaders incomingHeader = getHeaders(request); + final boolean result = cacheServiceProvider.addRelationShip(incomingHeader, targetBaseUrl, + request.getRequestURI(), vnfId, relationship); + if (result) { + LOGGER.info("added created bi directional relationship with {}", relationship.getRelatedLink()); + return ResponseEntity.accepted().build(); } - } catch (final Exception exception) { - LOGGER.error("Unable to add two-way relationship ", exception); } - LOGGER.error("Unable to add relationship for related link: {}", relationship.getRelatedLink()); return RequestErrorResponseUtils.getRequestErrorResponseEntity(request, GENERIC_VNF); - } - private Relationship getRelationship(final String relatedLink, final GenericVnf genericVnf) { - final Relationship relationShip = new Relationship(); - relationShip.setRelatedTo(GENERIC_VNF); - relationShip.setRelationshipLabel(COMPOSED_OF); - relationShip.setRelatedLink(relatedLink); - - final RelationshipData relationshipData = new RelationshipData(); - relationshipData.setRelationshipKey(GENERIC_VNF_VNF_ID); - relationshipData.setRelationshipValue(genericVnf.getVnfId()); - relationShip.getRelationshipData().add(relationshipData); - - final RelatedToProperty relatedToProperty = new RelatedToProperty(); - relatedToProperty.setPropertyKey(GENERIC_VNF_VNF_NAME); - relatedToProperty.setPropertyValue(genericVnf.getVnfName()); - relationShip.getRelatedToProperty().add(relatedToProperty); - return relationShip; + @PutMapping(value = "/generic-vnf/{vnf-id}" + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL, + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> putBiDirectionalRelationShip(@RequestBody final Relationship relationship, + @PathVariable("vnf-id") final String vnfId, final HttpServletRequest request) { + LOGGER.info("Will put RelationShip for 'vnf-id': {} ...", vnfId); + + final Optional<Relationship> optional = + cacheServiceProvider.addRelationShip(vnfId, relationship, request.getRequestURI()); + + if (optional.isPresent()) { + final Relationship resultantRelationship = optional.get(); + LOGGER.info("Relationship add, sending resultant relationship: {} in response ...", resultantRelationship); + return ResponseEntity.accepted().body(resultantRelationship); + } + + LOGGER.error("Unable to add relationship for related link: {}", relationship.getRelatedLink()); + return RequestErrorResponseUtils.getRequestErrorResponseEntity(request, GENERIC_VNF); } - private String getRelationShipUrl(final HttpServletRequest request, final String relatedLink) { - return UriComponentsBuilder.fromUri(getBaseUrl(request)).path(relatedLink) - .path(RELATIONSHIP_LIST_RELATIONSHIP_URL).toUriString(); + @PostMapping(value = "/generic-vnf/{vnf-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> patchGenericVnf(@RequestBody final GenericVnf genericVnf, + @PathVariable("vnf-id") final String vnfId, + @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String xHttpHeaderOverride, + final HttpServletRequest request) { + + LOGGER.info("Will post GenericVnf to cache with 'vnf-id': {} and '{}': {} ...", vnfId, X_HTTP_METHOD_OVERRIDE, + xHttpHeaderOverride); + + if (HttpMethod.PATCH.toString().equalsIgnoreCase(xHttpHeaderOverride)) { + if (cacheServiceProvider.patchGenericVnf(vnfId, genericVnf)) { + return ResponseEntity.accepted().build(); + } + LOGGER.error("Unable to apply patch to GenericVnf using 'vnf-id': {} ... ", vnfId); + return getRequestErrorResponseEntity(request, GENERIC_VNF); + } + LOGGER.error("{} not supported ... ", xHttpHeaderOverride); + + return getRequestErrorResponseEntity(request, GENERIC_VNF); } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java index ac1ad8c5..b3438d27 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java @@ -19,15 +19,20 @@ */ package org.onap.so.aaisimulator.controller; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.Constants.LINES_OF_BUSINESS_URL; import static org.onap.so.aaisimulator.utils.Constants.LINE_OF_BUSINESS; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; import org.onap.aai.domain.yang.LineOfBusiness; import org.onap.aai.domain.yang.Relationship; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; import org.onap.so.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +44,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -75,19 +81,38 @@ public class LinesOfBusinessController { @GetMapping(value = "{line-of-business-name}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> getLineOfBusiness(@PathVariable("line-of-business-name") final String lineOfBusinessName, - final HttpServletRequest request) { - LOGGER.info("retrieving Platform for 'platform-name': {} ...", lineOfBusinessName); + @RequestParam(name = "depth", required = false) final Integer depth, + @RequestParam(name = "resultIndex", required = false) final Integer resultIndex, + @RequestParam(name = "resultSize", required = false) final Integer resultSize, + @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { + + LOGGER.info( + "retrieving Platform for 'platform-name': {} with depth: {}, resultIndex: {}, resultSize:{}, format: {} ...", + lineOfBusinessName, depth, resultIndex, resultSize, format); + final Optional<LineOfBusiness> optional = cacheServiceProvider.getLineOfBusiness(lineOfBusinessName); if (optional.isPresent()) { - final LineOfBusiness platform = optional.get(); - LOGGER.info("found LineOfBusiness {} in cache", platform); - return ResponseEntity.ok(platform); + + final Format value = Format.forValue(format); + switch (value) { + case RAW: + final LineOfBusiness platform = optional.get(); + LOGGER.info("found LineOfBusiness {} in cache", platform); + return ResponseEntity.ok(platform); + case COUNT: + final Map<String, Object> map = new HashMap<>(); + map.put(LINE_OF_BUSINESS, 1); + return ResponseEntity.ok(new Results(map)); + default: + break; + } + LOGGER.error("invalid format type :{}", format); } LOGGER.error("Unable to find LineOfBusiness in cache using {}", lineOfBusinessName); return getRequestErrorResponseEntity(request, LINE_OF_BUSINESS); } - @PutMapping(value = "/{line-of-business-name}/relationship-list/relationship", + @PutMapping(value = "/{line-of-business-name}" + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> putRelationShip(@PathVariable("line-of-business-name") final String lineOfBusinessName, diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java index d0019727..39e35947 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java @@ -19,15 +19,20 @@ */ package org.onap.so.aaisimulator.controller; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.Constants.PLATFORM; import static org.onap.so.aaisimulator.utils.Constants.PLATFORMS_URL; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity; import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; import org.onap.aai.domain.yang.Platform; import org.onap.aai.domain.yang.Relationship; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +44,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -72,19 +78,38 @@ public class PlatformController { @GetMapping(value = "/{platform-name}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> getPlatform(@PathVariable("platform-name") final String platformName, - final HttpServletRequest request) { - LOGGER.info("retrieving Platform for 'platform-name': {} ...", platformName); + @RequestParam(name = "depth", required = false) final Integer depth, + @RequestParam(name = "resultIndex", required = false) final Integer resultIndex, + @RequestParam(name = "resultSize", required = false) final Integer resultSize, + @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { + + LOGGER.info( + "retrieving Platform for 'platform-name': {} with depth: {}, resultIndex: {}, resultSize:{}, format: {} ...", + platformName, depth, resultIndex, resultSize, format); final Optional<Platform> optional = cacheServiceProvider.getPlatform(platformName); if (optional.isPresent()) { - final Platform platform = optional.get(); - LOGGER.info("found Platform {} in cache", platform); - return ResponseEntity.ok(platform); + + final Format value = Format.forValue(format); + switch (value) { + case RAW: + final Platform platform = optional.get(); + LOGGER.info("found Platform {} in cache", platform); + return ResponseEntity.ok(platform); + case COUNT: + final Map<String, Object> map = new HashMap<>(); + map.put(PLATFORM, 1); + return ResponseEntity.ok(new Results(map)); + default: + break; + } + LOGGER.error("invalid format type :{}", format); + } LOGGER.error("Unable to find Platform in cahce using {}", platformName); return getRequestErrorResponseEntity(request, PLATFORM); } - @PutMapping(value = "/{platform-name}/relationship-list/relationship", + @PutMapping(value = "/{platform-name}" + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> putRelationShip(@PathVariable("platform-name") final String platformName, diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java index a10a8ac4..a53da3f5 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java @@ -22,7 +22,9 @@ package org.onap.so.aaisimulator.service.providers; import java.util.Optional; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.Tenant; import org.onap.so.aaisimulator.models.CloudRegionKey; +import org.springframework.http.HttpHeaders; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -36,4 +38,11 @@ public interface CloudRegionCacheServiceProvider extends Clearable { Optional<Relationship> addRelationShip(final CloudRegionKey key, final Relationship relationship, final String requestUri); + + boolean putTenant(final CloudRegionKey key, Tenant tenant); + + Optional<Tenant> getTenant(final CloudRegionKey key, final String tenantId); + + boolean addRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, final String requestURI, final CloudRegionKey key, + final String tenantId, final Relationship relationship); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java index 41422c40..c18fc8f0 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java @@ -20,11 +20,16 @@ package org.onap.so.aaisimulator.service.providers; import static org.onap.so.aaisimulator.utils.CacheName.CLOUD_REGION_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.BELONGS_TO; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION; import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_CLOUD_OWNER; import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_CLOUD_REGION_ID; import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_OWNER_DEFINED_TYPE; import static org.onap.so.aaisimulator.utils.Constants.LOCATED_IN; +import static org.onap.so.aaisimulator.utils.Constants.TENANT; +import static org.onap.so.aaisimulator.utils.Constants.TENANT_TENANT_ID; +import static org.onap.so.aaisimulator.utils.Constants.TENANT_TENANT_NAME; import java.util.List; import java.util.Optional; import org.onap.aai.domain.yang.CloudRegion; @@ -32,6 +37,8 @@ import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.RelationshipList; +import org.onap.aai.domain.yang.Tenant; +import org.onap.aai.domain.yang.Tenants; import org.onap.so.aaisimulator.models.CloudRegionKey; import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; @@ -39,7 +46,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; +import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Service; +import org.springframework.web.util.UriComponentsBuilder; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -51,10 +60,13 @@ public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServicePro private static final Logger LOGGER = LoggerFactory.getLogger(CloudRegionCacheServiceProviderImpl.class); + private final HttpRestServiceProvider httpRestServiceProvider; @Autowired - public CloudRegionCacheServiceProviderImpl(final CacheManager cacheManager) { + public CloudRegionCacheServiceProviderImpl(final CacheManager cacheManager, + final HttpRestServiceProvider httpRestServiceProvider) { super(cacheManager); + this.httpRestServiceProvider = httpRestServiceProvider; } @Override @@ -116,6 +128,109 @@ public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServicePro return Optional.empty(); } + @Override + public boolean putTenant(final CloudRegionKey key, final Tenant tenant) { + final Optional<CloudRegion> optional = getCloudRegion(key); + if (optional.isPresent()) { + final CloudRegion cloudRegion = optional.get(); + Tenants tenants = cloudRegion.getTenants(); + if (tenants == null) { + tenants = new Tenants(); + cloudRegion.setTenants(tenants); + } + + final Optional<Tenant> existingTenantOptional = tenants.getTenant().stream() + .filter(existing -> existing.getTenantId().equals(tenant.getTenantId())).findFirst(); + + if (!existingTenantOptional.isPresent()) { + return tenants.getTenant().add(tenant); + } + LOGGER.warn("Tenant already exists ..."); + return false; + } + LOGGER.error("Unable to add Tenant using key: {} ...", key); + return false; + } + + @Override + public Optional<Tenant> getTenant(final CloudRegionKey key, final String tenantId) { + final Optional<CloudRegion> optional = getCloudRegion(key); + if (optional.isPresent()) { + final CloudRegion cloudRegion = optional.get(); + final Tenants tenants = cloudRegion.getTenants(); + if (tenants != null) { + return tenants.getTenant().stream().filter(existing -> existing.getTenantId().equals(tenantId)) + .findFirst(); + } + } + + LOGGER.error("Unable to find Tenant using key: {} and tenantId: {} ...", key, tenantId); + return Optional.empty(); + } + + @Override + public boolean addRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, + final String requestUriString, final CloudRegionKey key, final String tenantId, + final Relationship relationship) { + try { + final Optional<Tenant> optional = getTenant(key, tenantId); + if (optional.isPresent()) { + final Tenant tenant = optional.get(); + final String targetUrl = getTargetUrl(targetBaseUrl, relationship.getRelatedLink()); + + final Relationship outGoingRelationShip = getRelationship(requestUriString, key, tenant); + final Optional<Relationship> optionalRelationship = httpRestServiceProvider.put(incomingHeader, + outGoingRelationShip, targetUrl, Relationship.class); + + if (optionalRelationship.isPresent()) { + final Relationship resultantRelationship = optionalRelationship.get(); + RelationshipList relationshipList = tenant.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + tenant.setRelationshipList(relationshipList); + } + + if (relationshipList.getRelationship().add(resultantRelationship)) { + LOGGER.info("added relationship {} in cache successfully", resultantRelationship); + return true; + } + } + + + } + } catch (final Exception exception) { + LOGGER.error("Unable to add two-way relationship for CloudRegion: {} and tenant: {}", key, tenantId, + exception); + } + LOGGER.error("Unable to add relationship in cache for CloudRegion: {} and tenant: {}", key, tenantId); + return false; + } + + private Relationship getRelationship(final String relatedLink, final CloudRegionKey cloudRegionKey, final Tenant tenant) { + final Relationship relationShip = new Relationship(); + relationShip.setRelatedTo(TENANT); + relationShip.setRelationshipLabel(BELONGS_TO); + relationShip.setRelatedLink(relatedLink); + + + final List<RelationshipData> relationshipDataList = relationShip.getRelationshipData(); + relationshipDataList.add(getRelationshipData(CLOUD_REGION_CLOUD_OWNER, cloudRegionKey.getCloudOwner())); + relationshipDataList.add(getRelationshipData(CLOUD_REGION_CLOUD_REGION_ID, cloudRegionKey.getCloudRegionId())); + relationshipDataList.add(getRelationshipData(TENANT_TENANT_ID, tenant.getTenantId())); + + + final RelatedToProperty relatedToProperty = new RelatedToProperty(); + relatedToProperty.setPropertyKey(TENANT_TENANT_NAME); + relatedToProperty.setPropertyValue(tenant.getTenantName()); + relationShip.getRelatedToProperty().add(relatedToProperty); + return relationShip; + } + + private String getTargetUrl(final String targetBaseUrl, final String relatedLink) { + return UriComponentsBuilder.fromUriString(targetBaseUrl).path(relatedLink) + .path(BI_DIRECTIONAL_RELATIONSHIP_LIST_URL).toUriString(); + } + private RelationshipData getRelationshipData(final String key, final String value) { final RelationshipData relationshipData = new RelationshipData(); relationshipData.setRelationshipKey(key); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java index bf30013a..268a6bc3 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java @@ -56,7 +56,7 @@ public interface CustomerCacheServiceProvider extends Clearable { Optional<Relationship> getRelationship(final String globalCustomerId, final String serviceType, final String serviceInstanceId, final String vnfName); - Optional<ServiceInstance> addRelationShip(final String globalCustomerId, final String serviceType, - final String serviceInstanceId, final Relationship relationship); + Optional<Relationship> addRelationShip(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final Relationship relationship, final String requestUri); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java index 695bfc0f..16b34be1 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java @@ -20,12 +20,20 @@ package org.onap.so.aaisimulator.service.providers; import static org.onap.so.aaisimulator.utils.CacheName.CUSTOMER_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.COMPOSED_OF; +import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_GLOBAL_CUSTOMER_ID; +import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF; import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_NAME; +import static org.onap.so.aaisimulator.utils.Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID; +import static org.onap.so.aaisimulator.utils.Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_NAME; +import static org.onap.so.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.onap.aai.domain.yang.Customer; +import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.RelationshipList; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.ServiceInstances; @@ -259,8 +267,8 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid } @Override - public Optional<ServiceInstance> addRelationShip(final String globalCustomerId, final String serviceType, - final String serviceInstanceId, final Relationship relationship) { + public Optional<Relationship> addRelationShip(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final Relationship relationship, final String requestUri) { final Optional<ServiceInstance> optional = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId); if (optional.isPresent()) { final ServiceInstance serviceInstance = optional.get(); @@ -270,12 +278,28 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid serviceInstance.setRelationshipList(relationshipList); } relationshipList.getRelationship().add(relationship); - return Optional.of(serviceInstance); + + LOGGER.info("Successfully added relation to ServiceInstance"); + + final Relationship resultantRelationship = new Relationship(); + resultantRelationship.setRelatedTo(GENERIC_VNF); + resultantRelationship.setRelationshipLabel(COMPOSED_OF); + resultantRelationship.setRelatedLink(requestUri); + + final List<RelationshipData> relationshipDataList = resultantRelationship.getRelationshipData(); + relationshipDataList.add(getRelationshipData(CUSTOMER_GLOBAL_CUSTOMER_ID, globalCustomerId)); + relationshipDataList.add(getRelationshipData(SERVICE_SUBSCRIPTION_SERVICE_TYPE, serviceType)); + relationshipDataList.add(getRelationshipData(SERVICE_INSTANCE_SERVICE_INSTANCE_ID, serviceInstanceId)); + + final List<RelatedToProperty> relatedToProperty = resultantRelationship.getRelatedToProperty(); + relatedToProperty.add(getRelatedToProperty(SERVICE_INSTANCE_SERVICE_INSTANCE_NAME, + serviceInstance.getServiceInstanceName())); + + return Optional.of(resultantRelationship); } LOGGER.error("Unable to find ServiceInstance ..."); return Optional.empty(); - } @Override @@ -283,4 +307,20 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid clearCahce(CUSTOMER_CACHE.getName()); } + private RelatedToProperty getRelatedToProperty(final String key, final String value) { + final RelatedToProperty relatedToProperty = new RelatedToProperty(); + relatedToProperty.setPropertyKey(key); + relatedToProperty.setPropertyValue(value); + return relatedToProperty; + } + + private RelationshipData getRelationshipData(final String key, final String value) { + final RelationshipData relationshipData = new RelationshipData(); + relationshipData.setRelationshipKey(key); + relationshipData.setRelationshipValue(value); + return relationshipData; + } + + + } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java index 213ecf69..20c0f223 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java @@ -22,6 +22,7 @@ package org.onap.so.aaisimulator.service.providers; import java.util.Optional; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Relationship; +import org.springframework.http.HttpHeaders; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -33,8 +34,15 @@ public interface GenericVnfCacheServiceProvider extends Clearable { Optional<GenericVnf> getGenericVnf(final String vnfId); - boolean addRelationShip(final String vnfId, final Relationship relationship); + Optional<Relationship> addRelationShip(final String vnfId, final Relationship relationship, + final String requestURI); + + boolean addRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, final String requestUriString, + final String vnfId, final Relationship relationship); Optional<String> getGenericVnfId(final String vnfName); + boolean patchGenericVnf(final String vnfId, final GenericVnf genericVnf); + + } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java index 7ff012f6..fed79d8e 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java @@ -20,10 +20,17 @@ package org.onap.so.aaisimulator.service.providers; import static org.onap.so.aaisimulator.utils.CacheName.GENERIC_VNF_CACHE; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.so.aaisimulator.utils.Constants.COMPOSED_OF; +import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF; +import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_ID; +import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_NAME; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.RelationshipList; import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; @@ -31,7 +38,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; +import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Service; +import org.springframework.web.util.UriComponentsBuilder; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -43,9 +52,13 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv private static final Logger LOGGER = LoggerFactory.getLogger(GenericVnfCacheServiceProviderImpl.class); + private final HttpRestServiceProvider httpRestServiceProvider; + @Autowired - public GenericVnfCacheServiceProviderImpl(final CacheManager cacheManager) { + public GenericVnfCacheServiceProviderImpl(final CacheManager cacheManager, + final HttpRestServiceProvider httpRestServiceProvider) { super(cacheManager); + this.httpRestServiceProvider = httpRestServiceProvider; } @Override @@ -68,22 +81,6 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv } @Override - public boolean addRelationShip(final String vnfId, final Relationship relationship) { - final Optional<GenericVnf> optional = getGenericVnf(vnfId); - if (optional.isPresent()) { - final GenericVnf genericVnf = optional.get(); - RelationshipList relationshipList = genericVnf.getRelationshipList(); - if (relationshipList == null) { - relationshipList = new RelationshipList(); - genericVnf.setRelationshipList(relationshipList); - } - return relationshipList.getRelationship().add(relationship); - } - LOGGER.error("Unable to find GenericVnf ..."); - return false; - } - - @Override public Optional<String> getGenericVnfId(final String vnfName) { final Cache cache = getCache(GENERIC_VNF_CACHE.getName()); if (cache != null) { @@ -108,6 +105,95 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv } @Override + public boolean addRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, + final String requestUriString, final String vnfId, final Relationship relationship) { + try { + final Optional<GenericVnf> optional = getGenericVnf(vnfId); + if (optional.isPresent()) { + final GenericVnf genericVnf = optional.get(); + final String targetUrl = getTargetUrl(targetBaseUrl, relationship.getRelatedLink()); + final Relationship outGoingRelationShip = getRelationship(requestUriString, genericVnf); + final Optional<Relationship> optionalRelationship = httpRestServiceProvider.put(incomingHeader, + outGoingRelationShip, targetUrl, Relationship.class); + if (optionalRelationship.isPresent()) { + final Relationship resultantRelationship = optionalRelationship.get(); + + RelationshipList relationshipList = genericVnf.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + genericVnf.setRelationshipList(relationshipList); + } + if (relationshipList.getRelationship().add(resultantRelationship)) { + LOGGER.info("added relationship {} in cache successfully", resultantRelationship); + return true; + } + } + } + } catch (final Exception exception) { + LOGGER.error("Unable to add two-way relationship for vnfId: {}", vnfId, exception); + } + LOGGER.error("Unable to add relationship in cache for vnfId: {}", vnfId); + return false; + } + + @Override + public Optional<Relationship> addRelationShip(final String vnfId, final Relationship relationship, + final String requestURI) { + final Optional<GenericVnf> optional = getGenericVnf(vnfId); + if (optional.isPresent()) { + final GenericVnf genericVnf = optional.get(); + RelationshipList relationshipList = genericVnf.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + genericVnf.setRelationshipList(relationshipList); + } + relationshipList.getRelationship().add(relationship); + LOGGER.info("Successfully added relation to GenericVnf for vnfId: {}", vnfId); + + final Relationship resultantRelationship = getRelationship(requestURI, genericVnf); + return Optional.of(resultantRelationship); + } + return Optional.empty(); + } + + @Override + public boolean patchGenericVnf(final String vnfId, final GenericVnf genericVnf) { + final Optional<GenericVnf> optional = getGenericVnf(vnfId); + if (optional.isPresent()) { + final GenericVnf cachedGenericVnf = optional.get(); + LOGGER.info("Changing OrchestrationStatus from {} to {} ", cachedGenericVnf.getOrchestrationStatus(), + genericVnf.getOrchestrationStatus()); + cachedGenericVnf.setOrchestrationStatus(genericVnf.getOrchestrationStatus()); + return true; + } + LOGGER.error("Unable to find GenericVnf ..."); + return false; + } + + private String getTargetUrl(final String targetBaseUrl, final String relatedLink) { + return UriComponentsBuilder.fromUriString(targetBaseUrl).path(relatedLink) + .path(BI_DIRECTIONAL_RELATIONSHIP_LIST_URL).toUriString(); + } + + private Relationship getRelationship(final String relatedLink, final GenericVnf genericVnf) { + final Relationship relationShip = new Relationship(); + relationShip.setRelatedTo(GENERIC_VNF); + relationShip.setRelationshipLabel(COMPOSED_OF); + relationShip.setRelatedLink(relatedLink); + + final RelationshipData relationshipData = new RelationshipData(); + relationshipData.setRelationshipKey(GENERIC_VNF_VNF_ID); + relationshipData.setRelationshipValue(genericVnf.getVnfId()); + relationShip.getRelationshipData().add(relationshipData); + + final RelatedToProperty relatedToProperty = new RelatedToProperty(); + relatedToProperty.setPropertyKey(GENERIC_VNF_VNF_NAME); + relatedToProperty.setPropertyValue(genericVnf.getVnfName()); + relationShip.getRelatedToProperty().add(relatedToProperty); + return relationShip; + } + + @Override public void clearAll() { clearCahce(GENERIC_VNF_CACHE.getName()); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProvider.java index 38d23d78..bbcc435b 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProvider.java @@ -20,6 +20,7 @@ package org.onap.so.aaisimulator.service.providers; import java.util.Optional; +import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; @@ -29,8 +30,7 @@ import org.springframework.http.ResponseEntity; */ public interface HttpRestServiceProvider { - <T> ResponseEntity<T> invokeHttpPut(final HttpHeaders headers, final Object object, final String url, - final Class<T> clazz); + <T> ResponseEntity<T> invokeHttpPut(final HttpEntity<Object> httpEntity, final String url, final Class<T> clazz); <T> Optional<T> put(final HttpHeaders headers, final Object object, final String url, final Class<T> clazz); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProviderImpl.java index b9f92c87..b96920f0 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProviderImpl.java @@ -51,13 +51,13 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider { } @Override - public <T> ResponseEntity<T> invokeHttpPut(final HttpHeaders headers, final Object object, final String url, + public <T> ResponseEntity<T> invokeHttpPut(final HttpEntity<Object> httpEntity, final String url, final Class<T> clazz) { final HttpMethod httpMethod = HttpMethod.PUT; LOGGER.trace("Will invoke HTTP {} using URL: {}", httpMethod, url); try { - return restTemplate.exchange(url, httpMethod, new HttpEntity<>(object, headers), clazz); + return restTemplate.exchange(url, httpMethod, httpEntity, clazz); } catch (final HttpClientErrorException httpClientErrorException) { final String message = "Unable to invoke HTTP " + httpMethod + " using url: " + url + ", Response: " @@ -78,7 +78,8 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider { @Override public <T> Optional<T> put(final HttpHeaders headers, final Object object, final String url, final Class<T> clazz) { - final ResponseEntity<T> response = invokeHttpPut(headers, object, url, clazz); + final HttpEntity<Object> httpEntity = new HttpEntity<Object>(object, headers); + final ResponseEntity<T> response = invokeHttpPut(httpEntity, url, clazz); if (!response.getStatusCode().equals(HttpStatus.OK) && !response.getStatusCode().equals(HttpStatus.CREATED) && !response.getStatusCode().equals(HttpStatus.ACCEPTED)) { diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java index 979da6b9..83ae57a1 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java @@ -49,6 +49,9 @@ public class Constants { public static final String RELATIONSHIP_LIST_RELATIONSHIP_URL = "/relationship-list/relationship"; + public static final String BI_DIRECTIONAL_RELATIONSHIP_LIST_URL = + RELATIONSHIP_LIST_RELATIONSHIP_URL + "/bi-directional"; + public static final String LINES_OF_BUSINESS_URL = BUSINESS_URL + "/lines-of-business/line-of-business/"; public static final String HEALTHY = "healthy"; @@ -105,6 +108,13 @@ public class Constants { public static final String CLOUD_REGION = "cloud-region"; + public static final String TENANT_TENANT_NAME = "tenant.tenant-name"; + + public static final String TENANT_TENANT_ID = "tenant.tenant-id"; + + public static final String BELONGS_TO = "org.onap.relationships.inventory.BelongsTo"; + + public static final String TENANT = "tenant"; private Constants() {} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java index fd3191d6..8c57db58 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java @@ -23,13 +23,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; import static org.onap.so.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; import static org.onap.so.aaisimulator.utils.TestConstants.RELATED_TO_URL; -import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL; import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCES_URL; import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; @@ -336,7 +336,7 @@ public class BusinessControllerTest extends AbstractSpringBootTest { invokeServiceInstanceEndPointAndAssertResponse(); final String relationShipUrl = - getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL, RELATIONSHIP_URL); + getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); final ResponseEntity<Relationship> responseEntity2 = testRestTemplateService.invokeHttpPut(relationShipUrl, TestUtils.getRelationShipJsonObject(), Relationship.class); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java index 2118b6d8..a7bacb29 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java @@ -23,20 +23,34 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_OWNER_NAME; import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_REGION_NAME; -import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.TENANTS_TENANT; +import static org.onap.so.aaisimulator.utils.TestConstants.TENANT_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID; import java.io.IOException; import java.util.List; import java.util.Optional; import org.junit.After; import org.junit.Test; import org.onap.aai.domain.yang.CloudRegion; +import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; +import org.onap.aai.domain.yang.RelationshipList; +import org.onap.aai.domain.yang.Tenant; import org.onap.so.aaisimulator.models.CloudRegionKey; import org.onap.so.aaisimulator.service.providers.CloudRegionCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider; import org.onap.so.aaisimulator.utils.Constants; import org.onap.so.aaisimulator.utils.TestConstants; import org.onap.so.aaisimulator.utils.TestUtils; @@ -55,9 +69,17 @@ public class CloudRegionsControllerTest extends AbstractSpringBootTest { @Autowired private CloudRegionCacheServiceProvider cloudRegionCacheServiceProvider; + @Autowired + private CustomerCacheServiceProvider customerCacheServiceProvider; + + @Autowired + private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider; + @After public void after() { cloudRegionCacheServiceProvider.clearAll(); + customerCacheServiceProvider.clearAll(); + genericVnfCacheServiceProvider.clearAll(); } @Test @@ -106,8 +128,8 @@ public class CloudRegionsControllerTest extends AbstractSpringBootTest { invokeCloudRegionHttpPutEndPointAndAssertResponse(url); - final String relationShipUrl = - getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, RELATIONSHIP_URL); + final String relationShipUrl = getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, TestUtils.getGenericVnfRelationShip(), Relationship.class); @@ -136,6 +158,122 @@ public class CloudRegionsControllerTest extends AbstractSpringBootTest { } + @Test + public void test_putTenant_successfullyAddedToCache() throws Exception { + final String cloudRegionUrl = getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(cloudRegionUrl); + + final String tenantUrl = + getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME + TENANTS_TENANT + TENANT_ID); + addTenantAndAssertResponse(tenantUrl); + + final ResponseEntity<Tenant> response = testRestTemplateService.invokeHttpGet(tenantUrl, Tenant.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Tenant tenant = response.getBody(); + assertEquals(TENANT_ID, tenant.getTenantId()); + assertEquals("admin", tenant.getTenantName()); + + assertNotNull("ResourceVersion should not be null", tenant.getResourceVersion()); + + } + + @Test + public void test_putTenantRelationToGenericVnf_successfullyAddedToCache() throws Exception { + + addCustomerServiceAndGenericVnf(); + + final String cloudRegionUrl = getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + invokeCloudRegionHttpPutEndPointAndAssertResponse(cloudRegionUrl); + + final String tenantUrl = + getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, TENANTS_TENANT + TENANT_ID); + addTenantAndAssertResponse(tenantUrl); + + final String tenantRelationShipUrl = getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, + TENANTS_TENANT + TENANT_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); + + final ResponseEntity<Void> tenantRelationShipResponse = testRestTemplateService + .invokeHttpPut(tenantRelationShipUrl, TestUtils.getGenericVnfRelatedLink(), Void.class); + assertEquals(HttpStatus.ACCEPTED, tenantRelationShipResponse.getStatusCode()); + + final Optional<Tenant> optional = cloudRegionCacheServiceProvider.getTenant(CLOUD_REGION_KEY, TENANT_ID); + + assertTrue(optional.isPresent()); + final Tenant actualTenant = optional.get(); + final RelationshipList relationshipList = actualTenant.getRelationshipList(); + assertNotNull(relationshipList); + assertFalse(relationshipList.getRelationship().isEmpty()); + + final Relationship relationship = relationshipList.getRelationship().get(0); + + assertEquals(Constants.COMPOSED_OF, relationship.getRelationshipLabel()); + assertFalse(relationship.getRelationshipData().isEmpty()); + assertEquals(1, relationship.getRelationshipData().size()); + + final List<RelationshipData> relationshipDataList = relationship.getRelationshipData(); + + final RelationshipData relationshipData = + getRelationshipData(relationshipDataList, Constants.GENERIC_VNF_VNF_ID); + assertNotNull(relationshipData); + assertEquals(VNF_ID, relationshipData.getRelationshipValue()); + + final List<RelatedToProperty> relatedToPropertyList = relationship.getRelatedToProperty(); + + final RelatedToProperty property = getRelatedToProperty(relatedToPropertyList, Constants.GENERIC_VNF_VNF_NAME); + assertNotNull(property); + assertEquals(GENERIC_VNF_NAME, property.getPropertyValue()); + + final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(genericVnfOptional.isPresent()); + final GenericVnf actualGenericVnf = genericVnfOptional.get(); + final RelationshipList relationshipListGenericVnf = actualGenericVnf.getRelationshipList(); + assertNotNull(relationshipListGenericVnf); + assertFalse(relationshipListGenericVnf.getRelationship().isEmpty()); + + final Relationship relationshipGenericVnf = relationshipListGenericVnf.getRelationship().get(0); + + assertEquals(Constants.BELONGS_TO, relationshipGenericVnf.getRelationshipLabel()); + assertFalse(relationshipGenericVnf.getRelationshipData().isEmpty()); + assertEquals(3, relationshipGenericVnf.getRelationshipData().size()); + + } + + private void addTenantAndAssertResponse(final String tenantUrl) throws IOException { + final ResponseEntity<Void> responseEntity = + testRestTemplateService.invokeHttpPut(tenantUrl, TestUtils.getTenant(), Void.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + } + + private void addCustomerServiceAndGenericVnf() throws Exception, IOException { + final ResponseEntity<Void> customerResponse = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); + assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + final ResponseEntity<Void> serviceInstanceResponse = + testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> genericVnfResponse = + testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); + + } + + private RelationshipData getRelationshipData(final List<RelationshipData> relationshipData, final String key) { + return relationshipData.stream().filter(data -> data.getRelationshipKey().equals(key)).findFirst().orElse(null); + } + + private RelatedToProperty getRelatedToProperty(final List<RelatedToProperty> relatedToPropertyList, + final String key) { + return relatedToPropertyList.stream().filter(data -> data.getPropertyKey().equals(key)).findFirst() + .orElse(null); + } private void invokeCloudRegionHttpPutEndPointAndAssertResponse(final String url) throws IOException { final ResponseEntity<Void> responseEntity = diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java index ba5c85e7..a02900cd 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java @@ -23,6 +23,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_OWNER_NAME; import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_REGION_NAME; import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; @@ -31,7 +34,6 @@ import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; import static org.onap.so.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; import static org.onap.so.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME; import static org.onap.so.aaisimulator.utils.TestConstants.PLATFORM_NAME; -import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL; import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_NAME; @@ -56,6 +58,8 @@ import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider; import org.onap.so.aaisimulator.utils.Constants; import org.onap.so.aaisimulator.utils.TestUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -110,7 +114,7 @@ public class GenericVnfsControllerTest extends AbstractSpringBootTest { addCustomerServiceAndGenericVnf(); - final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_URL); + final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); final ResponseEntity<Void> genericVnfRelationShipResponse = testRestTemplateService .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getRelationShip(), Void.class); @@ -184,7 +188,7 @@ public class GenericVnfsControllerTest extends AbstractSpringBootTest { testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); - final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_URL); + final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); final ResponseEntity<Void> genericVnfRelationShipResponse = testRestTemplateService .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getPlatformRelatedLink(), Void.class); @@ -221,7 +225,7 @@ public class GenericVnfsControllerTest extends AbstractSpringBootTest { testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_URL); + final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); final ResponseEntity<Void> genericVnfRelationShipResponse = testRestTemplateService .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getLineOfBusinessRelatedLink(), Void.class); @@ -259,7 +263,7 @@ public class GenericVnfsControllerTest extends AbstractSpringBootTest { testRestTemplateService.invokeHttpPut(url, TestUtils.getCloudRegion(), Void.class); assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); - final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_URL); + final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); final ResponseEntity<Void> genericVnfRelationShipResponse = testRestTemplateService .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getCloudRegionRelatedLink(), Void.class); @@ -299,6 +303,56 @@ public class GenericVnfsControllerTest extends AbstractSpringBootTest { } + @Test + public void test_putBiDirectionalRelationShip_successfullyAddedToCache() throws Exception { + addCustomerServiceAndGenericVnf(); + + final String relationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, + TestUtils.getTenantRelationShip(), Relationship.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final Optional<GenericVnf> optional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(optional.isPresent()); + + final GenericVnf actual = optional.get(); + + assertNotNull(actual.getRelationshipList()); + final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship(); + assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); + final Relationship relationship = relationshipList.get(0); + + assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); + assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); + } + + @Test + public void test_patchGenericVnf_usingVnfId_OrchStatusChangedInCache() throws Exception { + addCustomerServiceAndGenericVnf(); + + final HttpHeaders httpHeaders = testRestTemplateService.getHttpHeaders(); + httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> orchStatuUpdateServiceInstanceResponse = testRestTemplateService + .invokeHttpPost(httpHeaders, genericVnfUrl, TestUtils.getGenericVnfOrchStatuUpdate(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode()); + + final ResponseEntity<GenericVnf> response = + testRestTemplateService.invokeHttpGet(genericVnfUrl, GenericVnf.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final GenericVnf actualGenericVnf = response.getBody(); + assertEquals(GENERIC_VNF_NAME, actualGenericVnf.getVnfName()); + assertEquals(VNF_ID, actualGenericVnf.getVnfId()); + assertEquals("Assigned", actualGenericVnf.getOrchestrationStatus()); + + } + private void addCustomerServiceAndGenericVnf() throws Exception, IOException { final ResponseEntity<Void> customerResponse = testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java index d0234f6f..3b1b0ac3 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java @@ -23,8 +23,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME; -import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL; import java.util.List; import java.util.Optional; import org.junit.After; @@ -33,6 +33,8 @@ import org.onap.aai.domain.yang.LineOfBusiness; import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; import org.onap.so.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider; import org.onap.so.aaisimulator.utils.Constants; import org.onap.so.aaisimulator.utils.TestConstants; @@ -76,6 +78,27 @@ public class LinesOfBusinessControllerTest extends AbstractSpringBootTest { } @Test + public void test_getLineOfBusinessWithFormatCount() throws Exception { + + final String url = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); + final ResponseEntity<Void> lineOfBusinessResponse = + testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); + assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode()); + + final ResponseEntity<Results> response = testRestTemplateService + .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Results result = response.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.LINE_OF_BUSINESS)); + } + + + @Test public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { final String url = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); @@ -83,7 +106,8 @@ public class LinesOfBusinessControllerTest extends AbstractSpringBootTest { testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - final String relationShipUrl = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME, RELATIONSHIP_URL); + final String relationShipUrl = + getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, TestUtils.getGenericVnfRelationShip(), Relationship.class); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java index f2f43fb0..34ac30ae 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; import org.junit.After; import org.junit.Test; import org.onap.aai.domain.yang.OwningEntity; @@ -99,7 +99,7 @@ public class OwningEntityControllerTest extends AbstractSpringBootTest { testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class); assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - final String owningEntityRelationshipUrl = url + RELATIONSHIP_URL; + final String owningEntityRelationshipUrl = url + RELATIONSHIP_LIST_RELATIONSHIP_URL; final ResponseEntity<Void> putResponse = testRestTemplateService.invokeHttpPut(owningEntityRelationshipUrl, TestUtils.getOwningEntityRelationship(), Void.class); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java index 2769b6a0..ea8f59b6 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java @@ -23,8 +23,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; import static org.onap.so.aaisimulator.utils.TestConstants.PLATFORM_NAME; -import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL; import java.util.List; import java.util.Optional; import org.junit.After; @@ -33,6 +33,8 @@ import org.onap.aai.domain.yang.Platform; import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider; import org.onap.so.aaisimulator.utils.Constants; import org.onap.so.aaisimulator.utils.TestConstants; @@ -75,6 +77,28 @@ public class PlatformControllerTest extends AbstractSpringBootTest { } @Test + public void test_getPlatformWithFormatCount() throws Exception { + + final String platformUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME); + + final ResponseEntity<Void> platformResponse = + testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); + assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); + + final ResponseEntity<Results> response = testRestTemplateService.invokeHttpGet( + platformUrl + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Results result = response.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.PLATFORM)); + + } + + @Test public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { final String platformUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME); @@ -82,7 +106,8 @@ public class PlatformControllerTest extends AbstractSpringBootTest { testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); - final String platformRelationShipUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME, RELATIONSHIP_URL); + final String platformRelationShipUrl = + getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); final ResponseEntity<Relationship> responseEntity = testRestTemplateService .invokeHttpPut(platformRelationShipUrl, TestUtils.getGenericVnfRelationShip(), Relationship.class); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java index 9e477fa4..fd0c4276 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java @@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; import org.junit.After; import org.junit.Test; import org.onap.aai.domain.yang.Project; @@ -84,7 +84,8 @@ public class ProjectControllerTest extends AbstractSpringBootTest { testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class); assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); - final String projectRelationshipUrl = getUrl(Constants.PROJECT_URL, PROJECT_NAME_VALUE, RELATIONSHIP_URL); + final String projectRelationshipUrl = + getUrl(Constants.PROJECT_URL, PROJECT_NAME_VALUE, RELATIONSHIP_LIST_RELATIONSHIP_URL); final ResponseEntity<Void> putResponse = testRestTemplateService.invokeHttpPut(projectRelationshipUrl, TestUtils.getBusinessProjectRelationship(), Void.class); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java index 52973a58..415622c9 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java @@ -45,8 +45,6 @@ public class TestConstants { public static final String CUSTOMERS_URL = Constants.CUSTOMER_URL + GLOBAL_CUSTOMER_ID; - public static final String RELATIONSHIP_URL = "/relationship-list/relationship"; - public static final String VNF_ID = "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701"; public static final String GENERIC_VNF_NAME = "EsyVnfInstantiationTest2"; @@ -65,6 +63,10 @@ public class TestConstants { public static final String CLOUD_REGION_NAME = "EtsiCloudRegion"; + public static final String TENANT_ID = "693c7729b2364a26a3ca602e6f66187d"; + + public static final String TENANTS_TENANT = "/tenants/tenant/"; + private TestConstants() {} } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java index 7e378662..1cdfeb91 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java @@ -136,10 +136,26 @@ public class TestUtils { return getJsonString("test-data/cloud-region.json"); } - public static Object getCloudRegionRelatedLink() throws IOException { + public static String getTenant() throws IOException { + return getJsonString("test-data/tenant.json"); + } + + public static String getCloudRegionRelatedLink() throws IOException { return getJsonString("test-data/cloud-region-related-link.json"); } + public static String getGenericVnfRelatedLink() throws IOException { + return getJsonString("test-data/generic-vnf-related-link.json"); + } + + public static String getTenantRelationShip() throws IOException { + return getJsonString("test-data/tenant-relationship.json"); + } + + public static String getGenericVnfOrchStatuUpdate() throws IOException { + return getJsonString("test-data/generic-vnf-orch-status-update.json"); + } + public static String getUrl(final int port, final String... urls) { final UriComponentsBuilder baseUri = UriComponentsBuilder.fromUriString("https://localhost:" + port); for (final String url : urls) { diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-orch-status-update.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-orch-status-update.json new file mode 100644 index 00000000..2c00ea3a --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-orch-status-update.json @@ -0,0 +1,4 @@ +{ + "vnf-id": "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701", + "orchestration-status": "Assigned" +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-related-link.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-related-link.json new file mode 100644 index 00000000..388773b7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-related-link.json @@ -0,0 +1,3 @@ +{ + "related-link": "/network/generic-vnfs/generic-vnf/dfd02fb5-d7fb-4aac-b3c4-cd6b60058701" +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant-relationship.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant-relationship.json new file mode 100644 index 00000000..e1535727 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant-relationship.json @@ -0,0 +1,25 @@ +{ + "related-to": "tenant", + "relationship-label": "org.onap.relationships.inventory.BelongsTo", + "related-link": "/aai/v15/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/EtsiCloudRegion/tenants/tenant/693c7729b2364a26a3ca602e6f66187d", + "relationship-data": [ + { + "relationship-key": "cloud-region.cloud-owner", + "relationship-value": "CloudOwner" + }, + { + "relationship-key": "cloud-region.cloud-region-id", + "relationship-value": "EtsiCloudRegion" + }, + { + "relationship-key": "tenant.tenant-id", + "relationship-value": "693c7729b2364a26a3ca602e6f66187d" + } + ], + "related-to-property": [ + { + "property-key": "tenant.tenant-name", + "property-value": "admin" + } + ] +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant.json new file mode 100644 index 00000000..746131a6 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant.json @@ -0,0 +1,4 @@ +{ + "tenant-id": "693c7729b2364a26a3ca602e6f66187d", + "tenant-name": "admin" +} |