From: Henrik Andersson Date: Mon, 19 Oct 2020 11:43:21 +0000 (+0000) Subject: Merge "Fix typos in documentation" X-Git-Tag: 2.1.0~27 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=b5cb68ea0e77d0a1421b4f17cc58b981628c29f7;hp=0d271849258e914690dd6d6239580e42d8f266ff;p=nonrtric.git Merge "Fix typos in documentation" --- diff --git a/enrichment-coordinator-service/Dockerfile b/enrichment-coordinator-service/Dockerfile index 34799024..51d45b5d 100644 --- a/enrichment-coordinator-service/Dockerfile +++ b/enrichment-coordinator-service/Dockerfile @@ -25,7 +25,7 @@ WORKDIR /opt/app/enrichment-coordinator-service RUN mkdir -p /var/log/enrichment-coordinator-service RUN mkdir -p /opt/app/enrichment-coordinator-service/etc/cert/ -EXPOSE 8081 8433 +EXPOSE 8083 8434 ADD /config/application.yaml /opt/app/enrichment-coordinator-service/config/application.yaml ADD target/${JAR} /opt/app/enrichment-coordinator-service/enrichment-coordinator-service.jar diff --git a/enrichment-coordinator-service/config/application.yaml b/enrichment-coordinator-service/config/application.yaml index 8582bd99..e64db0c9 100644 --- a/enrichment-coordinator-service/config/application.yaml +++ b/enrichment-coordinator-service/config/application.yaml @@ -22,7 +22,7 @@ logging: name: /var/log/enrichment-coordinator-service/application.log server: port : 8434 - http-port: 8082 + http-port: 8083 ssl: key-store-type: JKS key-store-password: policy_agent diff --git a/enrichment-coordinator-service/docs/api.json b/enrichment-coordinator-service/docs/api.json index e4f7660f..65ff48d1 100644 --- a/enrichment-coordinator-service/docs/api.json +++ b/enrichment-coordinator-service/docs/api.json @@ -68,10 +68,11 @@ "required": true }, { - "schema": {"type": "string"}, - "in": "body", + "in": "query", + "allowEmptyValue": false, "name": "owner", "description": "identifies the owner of the job", + "type": "string", "required": false } ], @@ -285,6 +286,22 @@ }], "tags": ["Enrichment Data Producer API"] }}, + "/status": {"get": { + "summary": "Returns status and statistics of this service", + "deprecated": false, + "produces": ["application/json"], + "operationId": "getStatusUsingGET", + "responses": { + "200": { + "schema": {"$ref": "#/definitions/status_info"}, + "description": "Service is living" + }, + "401": {"description": "Unauthorized"}, + "403": {"description": "Forbidden"}, + "404": {"description": "Not Found"} + }, + "tags": ["Service status"] + }}, "/producer_simulator/job_created_error": {"post": { "summary": "Callback for EI job creation, returns error", "deprecated": false, @@ -554,7 +571,7 @@ "consumes": ["application/json"] }} }, - "host": "localhost:43453", + "host": "localhost:45709", "definitions": { "EiType": { "description": "Information for an EI type", @@ -652,6 +669,31 @@ } } }, + "status_info": { + "type": "object", + "title": "status_info", + "properties": { + "no_of_producers": { + "format": "int32", + "description": "Number of EI producers", + "type": "integer" + }, + "no_of_jobs": { + "format": "int32", + "description": "Number of EI jobs", + "type": "integer" + }, + "no_of_types": { + "format": "int32", + "description": "Number of EI types", + "type": "integer" + }, + "status": { + "description": "status text", + "type": "string" + } + } + }, "EiJobStatus": { "description": "Status for an EI Job", "type": "object", @@ -749,6 +791,10 @@ { "name": "Producer Simulator", "description": "Producer Simulator Controller" + }, + { + "name": "Service status", + "description": "Status Controller" } ] } \ No newline at end of file diff --git a/enrichment-coordinator-service/docs/api.yaml b/enrichment-coordinator-service/docs/api.yaml deleted file mode 100644 index f3fa767b..00000000 --- a/enrichment-coordinator-service/docs/api.yaml +++ /dev/null @@ -1,764 +0,0 @@ -basePath: / -paths: - /producer_simulator/job_deleted_error: - post: - summary: 'Callback for EI job creation, returns error' - deprecated: false - produces: - - application/json - operationId: jobDeletedCallbackReturnErrorUsingPOST - responses: - '200': - description: OK - '201': - description: Created - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - parameters: - - schema: - $ref: '#/definitions/producer_ei_job_request' - in: body - name: request - description: request - required: true - tags: - - Producer Simulator - consumes: - - application/json - /producer_simulator/supervision: - get: - summary: Producer supervision - deprecated: false - produces: - - application/json - operationId: producerSupervisionUsingGET - responses: - '200': - schema: - type: string - description: OK - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - tags: - - Producer Simulator - '/A1-EI/v1/eitypes/{eiTypeId}/eijobs': - get: - summary: EI job identifiers - deprecated: false - produces: - - application/json - operationId: getEiJobIdsUsingGET - responses: - '200': - schema: - type: array - items: - type: string - description: EI job identifiers - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information type is not found - parameters: - - in: path - name: eiTypeId - description: eiTypeId - type: string - required: true - - schema: - type: string - in: body - name: owner - description: identifies the owner of the job - required: false - tags: - - A1-E Enrichment Data Consumer API - '/A1-EI/v1/eitypes/{eiTypeId}': - get: - summary: Individual EI type - deprecated: false - produces: - - application/json - operationId: getEiTypeUsingGET - responses: - '200': - schema: - $ref: '#/definitions/EiType' - description: EI type - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information type is not found - parameters: - - in: path - name: eiTypeId - description: eiTypeId - type: string - required: true - tags: - - A1-E Enrichment Data Consumer API - /ei-producer/v1/eitypes: - get: - summary: EI type identifiers - deprecated: false - produces: - - application/json - operationId: getEiTypeIdentifiersUsingGET_1 - responses: - '200': - schema: - type: array - items: - type: string - description: EI type identifiers - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - tags: - - Enrichment Data Producer API - /A1-EI/v1/eitypes: - get: - summary: EI type identifiers - deprecated: false - produces: - - application/json - operationId: getEiTypeIdentifiersUsingGET - responses: - '200': - schema: - type: array - items: - type: string - description: EI type identifiers - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - tags: - - A1-E Enrichment Data Consumer API - /producer_simulator/job_deleted: - post: - summary: Callback for EI job deletion - deprecated: false - produces: - - application/json - operationId: jobDeletedCallbackUsingPOST - responses: - '200': - description: OK - '201': - description: Created - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - parameters: - - schema: - $ref: '#/definitions/producer_ei_job_request' - in: body - name: request - description: request - required: true - tags: - - Producer Simulator - consumes: - - application/json - '/A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status': - get: - summary: EI Job status - deprecated: false - produces: - - application/json - operationId: getEiJobStatusUsingGET - responses: - '200': - schema: - $ref: '#/definitions/EiJobStatus' - description: EI Job status - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information type or job is not found - parameters: - - in: path - name: eiJobId - description: eiJobId - type: string - required: true - - in: path - name: eiTypeId - description: eiTypeId - type: string - required: true - tags: - - A1-E Enrichment Data Consumer API - '/ei-producer/v1/eiproducers/{eiProducerId}/status': - get: - summary: EI producer status - deprecated: false - produces: - - application/json - operationId: getEiProducerStatusUsingGET - responses: - '200': - schema: - $ref: '#/definitions/producer_status' - description: EI jobs - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information producer is not found - parameters: - - in: path - name: eiProducerId - description: eiProducerId - type: string - required: true - tags: - - Enrichment Data Producer API - /producer_simulator/supervision_error: - get: - summary: Producer supervision error - deprecated: false - produces: - - application/json - operationId: producerSupervisionErrorUsingGET - responses: - '200': - schema: - type: string - description: OK - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - tags: - - Producer Simulator - /ei-producer/v1/eiproducers: - get: - summary: EI producer identifiers - deprecated: false - produces: - - application/json - operationId: getEiProducerIdentifiersUsingGET - responses: - '200': - schema: - type: array - items: - type: string - description: EI producer identifiers - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - tags: - - Enrichment Data Producer API - '/ei-producer/v1/eitypes/{eiTypeId}': - get: - summary: Individual EI Type - deprecated: false - produces: - - application/json - operationId: getEiTypeUsingGET_1 - responses: - '200': - schema: - $ref: '#/definitions/producer_ei_type_info' - description: EI type - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information type is not found - parameters: - - in: path - name: eiTypeId - description: eiTypeId - type: string - required: true - tags: - - Enrichment Data Producer API - /producer_simulator/job_created_error: - post: - summary: 'Callback for EI job creation, returns error' - deprecated: false - produces: - - application/json - operationId: jobCreatedCallbackReturnErrorUsingPOST - responses: - '200': - description: OK - '201': - description: Created - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - parameters: - - schema: - $ref: '#/definitions/producer_ei_job_request' - in: body - name: request - description: request - required: true - tags: - - Producer Simulator - consumes: - - application/json - '/A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}': - get: - summary: Individual EI Job - deprecated: false - produces: - - application/json - operationId: getIndividualEiJobUsingGET - responses: - '200': - schema: - $ref: '#/definitions/EiJob' - description: EI Job - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information type or job is not found - parameters: - - in: path - name: eiJobId - description: eiJobId - type: string - required: true - - in: path - name: eiTypeId - description: eiTypeId - type: string - required: true - tags: - - A1-E Enrichment Data Consumer API - delete: - summary: Individual EI Job - deprecated: false - produces: - - application/json - operationId: deleteIndividualEiJobUsingDELETE - responses: - '200': - description: Not used - '204': - description: Job deleted - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information type or job is not found - parameters: - - in: path - name: eiJobId - description: eiJobId - type: string - required: true - - in: path - name: eiTypeId - description: eiTypeId - type: string - required: true - tags: - - A1-E Enrichment Data Consumer API - put: - summary: Individual EI Job - deprecated: false - produces: - - application/json - operationId: putIndividualEiJobUsingPUT - responses: - '200': - description: Job updated - '201': - description: Job created - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information type is not found - parameters: - - in: path - name: eiJobId - description: eiJobId - type: string - required: true - - schema: - $ref: '#/definitions/EiJob' - in: body - name: eiJobInfo - description: eiJobInfo - required: true - - in: path - name: eiTypeId - description: eiTypeId - type: string - required: true - tags: - - A1-E Enrichment Data Consumer API - consumes: - - application/json - '/ei-producer/v1/eiproducers/{eiProducerId}': - get: - summary: Individual EI producer - deprecated: false - produces: - - application/json - operationId: getEiProducerUsingGET - responses: - '200': - schema: - $ref: '#/definitions/producer_registration_info' - description: EI Jobs - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information producer is not found - parameters: - - in: path - name: eiProducerId - description: eiProducerId - type: string - required: true - tags: - - Enrichment Data Producer API - delete: - summary: Individual EI producer - deprecated: false - produces: - - application/json - operationId: deleteEiProducerUsingDELETE - responses: - '200': - description: Not used - '204': - description: Producer deleted - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Producer is not found - parameters: - - in: path - name: eiProducerId - description: eiProducerId - type: string - required: true - tags: - - Enrichment Data Producer API - put: - summary: Individual EI producer - deprecated: false - produces: - - application/json - operationId: putEiProducerUsingPUT - responses: - '200': - description: Producer updated - '201': - description: Producer created - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - parameters: - - in: path - name: eiProducerId - description: eiProducerId - type: string - required: true - - schema: - $ref: '#/definitions/producer_registration_info' - in: body - name: registrationInfo - description: registrationInfo - required: true - tags: - - Enrichment Data Producer API - consumes: - - application/json - '/ei-producer/v1/eiproducers/{eiProducerId}/eijobs': - get: - summary: EI job definitions - deprecated: false - produces: - - application/json - description: EI job definitions for one EI producer - operationId: getEiProducerJobsUsingGET - responses: - '200': - schema: - type: array - items: - $ref: '#/definitions/producer_ei_job_request' - description: EI jobs - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - schema: - $ref: '#/definitions/error_information' - description: Enrichment Information producer is not found - parameters: - - in: path - name: eiProducerId - description: eiProducerId - type: string - required: true - tags: - - Enrichment Data Producer API - /producer_simulator/job_created: - post: - summary: Callback for EI job creation - deprecated: false - produces: - - application/json - operationId: jobCreatedCallbackUsingPOST - responses: - '200': - description: OK - '201': - description: Created - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - parameters: - - schema: - $ref: '#/definitions/producer_ei_job_request' - in: body - name: request - description: request - required: true - tags: - - Producer Simulator - consumes: - - application/json -host: 'localhost:43453' -definitions: - EiType: - description: Information for an EI type - type: object - title: EiType - properties: - eiJobParametersSchema: - description: Json schema for the job data - type: object - producer_ei_job_request: - description: The body of the EI producer callbacks for EI job creation and deletion - type: object - title: producer_ei_job_request - required: - - ei_job_identity - properties: - ei_job_identity: - description: Idenitity of the EI job - type: string - ei_job_data: - description: Json for the job data - type: object - target_uri: - description: URI for the target of the EI - type: string - ei_type_identity: - description: Type idenitity for the job - type: string - error_information: - description: 'Problem as defined in https://tools.ietf.org/html/rfc7807' - type: object - title: error_information - properties: - detail: - description: A human-readable explanation specific to this occurrence of the problem. - type: string - example: EI job type not found - status: - format: int32 - description: The HTTP status code generated by the origin server for this occurrence of the problem. - type: integer - example: 404 - void: - description: Void/empty - type: object - title: void - EiJob: - description: Information for an Enrichment Information Job - type: object - title: EiJob - required: - - jobOwner - - jobParameters - - targetUri - properties: - targetUri: - description: The target of the EI data - type: string - jobOwner: - description: Identity of the owner of the job - type: string - jobParameters: - description: EI Type specific job data - type: object - producer_ei_type_registration_info: - description: Information for an EI type - type: object - title: producer_ei_type_registration_info - required: - - ei_type_identity - properties: - ei_type_identity: - description: EI type identity - type: string - ei_job_data_schema: - description: Json schema for the job data - type: object - EiJobStatus: - description: Status for an EI Job - type: object - title: EiJobStatus - required: - - operationalState - properties: - operationalState: - description: |- - Operational state, values: - ENABLED: TBD - DISABLED: TBD. - type: string - enum: - - ENABLED - - DISABLED - Mono«ResponseEntity«object»»: - type: object - title: Mono«ResponseEntity«object»» - producer_ei_type_info: - description: Information for an EI type - type: object - title: producer_ei_type_info - properties: - ei_producer_ids: - description: Registered producers - type: array - items: - type: string - ei_job_data_schema: - description: Json schema for the job data - type: object - producer_registration_info: - description: Information for an EI producer - type: object - title: producer_registration_info - required: - - ei_job_creation_callback_url - - ei_job_deletion_callback_url - - ei_producer_supervision_callback_url - - supported_ei_types - properties: - supported_ei_types: - description: Supported EI types - type: array - items: - $ref: '#/definitions/producer_ei_type_registration_info' - ei_job_creation_callback_url: - description: callback for job creation - type: string - ei_job_deletion_callback_url: - description: callback for job deletion - type: string - ei_producer_supervision_callback_url: - description: callback for producer supervision - type: string - producer_status: - description: Status for an EI Producer - type: object - title: producer_status - required: - - operational_state - properties: - operational_state: - description: |- - Operational state, values: - ENABLED: TBD - DISABLED: TBD. - type: string - enum: - - ENABLED - - DISABLED -swagger: '2.0' -info: - description: This page lists all the rest apis for the service. - title: Enrichment Data service - version: '1.0' -tags: - - name: A1-E Enrichment Data Consumer API - description: Consumer Controller - - name: Enrichment Data Producer API - description: Producer Controller - - name: Producer Simulator - description: Producer Simulator Controller - diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/BeanFactory.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/BeanFactory.java index 9e2142e6..ce419562 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/BeanFactory.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/BeanFactory.java @@ -78,7 +78,7 @@ class BeanFactory { @Bean public ProducerCallbacks getProducerCallbacks() { - return new ProducerCallbacks(); + return new ProducerCallbacks(this.applicationConfig); } private static Connector getHttpConnector(int httpPort) { diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java index 2782f94a..76da6246 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClient.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2019 Nordix Foundation + * Copyright (C) 2020 Nordix Foundation * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,36 +22,18 @@ package org.oransc.enrichment.clients; import io.netty.channel.ChannelOption; import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.SslContextBuilder; -import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import io.netty.handler.timeout.ReadTimeoutHandler; import io.netty.handler.timeout.WriteTimeoutHandler; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; import java.lang.invoke.MethodHandles; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.Collections; -import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; -import javax.net.ssl.KeyManagerFactory; - -import org.oransc.enrichment.configuration.WebClientConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.lang.Nullable; -import org.springframework.util.ResourceUtils; import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; @@ -66,22 +48,25 @@ import reactor.netty.tcp.TcpClient; * Generic reactive REST client. */ public class AsyncRestClient { + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private WebClient webClient = null; private final String baseUrl; private static final AtomicInteger sequenceNumber = new AtomicInteger(); - private final WebClientConfig clientConfig; - static KeyStore clientTrustStore = null; - private boolean sslEnabled = true; + private final SslContext sslContext; + /** + * Note that only http (not https) will work when this constructor is used. + * + * @param baseUrl + */ public AsyncRestClient(String baseUrl) { this(baseUrl, null); - this.sslEnabled = false; } - public AsyncRestClient(String baseUrl, WebClientConfig config) { + public AsyncRestClient(String baseUrl, SslContext sslContext) { this.baseUrl = baseUrl; - this.clientConfig = config; + this.sslContext = sslContext; } public Mono> postForEntity(String uri, @Nullable String body) { @@ -185,10 +170,14 @@ public class AsyncRestClient { final Class clazz = String.class; return request.retrieve() // .toEntity(clazz) // - .doOnNext(entity -> logger.trace("{} Received: {}", traceTag, entity.getBody())) // + .doOnNext(entity -> logReceivedData(traceTag, entity)) // .doOnError(throwable -> onHttpError(traceTag, throwable)); } + private void logReceivedData(Object traceTag, ResponseEntity entity) { + logger.trace("{} Received: {} {}", traceTag, entity.getBody(), entity.getHeaders().getContentType()); + } + private static Object createTraceTag() { return sequenceNumber.incrementAndGet(); } @@ -211,65 +200,6 @@ public class AsyncRestClient { } } - private boolean isCertificateEntry(KeyStore trustStore, String alias) { - try { - return trustStore.isCertificateEntry(alias); - } catch (KeyStoreException e) { - logger.error("Error reading truststore {}", e.getMessage()); - return false; - } - } - - private Certificate getCertificate(KeyStore trustStore, String alias) { - try { - return trustStore.getCertificate(alias); - } catch (KeyStoreException e) { - logger.error("Error reading truststore {}", e.getMessage()); - return null; - } - } - - private static synchronized KeyStore getTrustStore(String trustStorePath, String trustStorePass) - throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException { - if (clientTrustStore == null) { - KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType()); - store.load(new FileInputStream(ResourceUtils.getFile(trustStorePath)), trustStorePass.toCharArray()); - clientTrustStore = store; - } - return clientTrustStore; - } - - private SslContext createSslContextRejectingUntrustedPeers(String trustStorePath, String trustStorePass, - KeyManagerFactory keyManager) - throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException { - - final KeyStore trustStore = getTrustStore(trustStorePath, trustStorePass); - List certificateList = Collections.list(trustStore.aliases()).stream() // - .filter(alias -> isCertificateEntry(trustStore, alias)) // - .map(alias -> getCertificate(trustStore, alias)) // - .collect(Collectors.toList()); - final X509Certificate[] certificates = certificateList.toArray(new X509Certificate[certificateList.size()]); - - return SslContextBuilder.forClient() // - .keyManager(keyManager) // - .trustManager(certificates) // - .build(); - } - - private SslContext createSslContext(KeyManagerFactory keyManager) - throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException { - if (this.clientConfig.isTrustStoreUsed()) { - return createSslContextRejectingUntrustedPeers(this.clientConfig.trustStore(), - this.clientConfig.trustStorePassword(), keyManager); - } else { - // Trust anyone - return SslContextBuilder.forClient() // - .keyManager(keyManager) // - .trustManager(InsecureTrustManagerFactory.INSTANCE) // - .build(); - } - } - private TcpClient createTcpClientSecure(SslContext sslContext) { return TcpClient.create(ConnectionProvider.newConnection()) // .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10_000) // @@ -305,18 +235,7 @@ public class AsyncRestClient { private Mono getWebClient() { if (this.webClient == null) { try { - if (this.sslEnabled) { - final KeyManagerFactory keyManager = - KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); - final KeyStore keyStore = KeyStore.getInstance(this.clientConfig.keyStoreType()); - final String keyStoreFile = this.clientConfig.keyStore(); - final String keyStorePassword = this.clientConfig.keyStorePassword(); - final String keyPassword = this.clientConfig.keyPassword(); - try (final InputStream inputStream = new FileInputStream(keyStoreFile)) { - keyStore.load(inputStream, keyStorePassword.toCharArray()); - } - keyManager.init(keyStore, keyPassword.toCharArray()); - SslContext sslContext = createSslContext(keyManager); + if (this.sslContext != null) { TcpClient tcpClient = createTcpClientSecure(sslContext); this.webClient = createWebClient(this.baseUrl, tcpClient); } else { diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClientFactory.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClientFactory.java new file mode 100644 index 00000000..07f23e9e --- /dev/null +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/AsyncRestClientFactory.java @@ -0,0 +1,179 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ + +package org.oransc.enrichment.clients; + +import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; +import io.netty.handler.ssl.util.InsecureTrustManagerFactory; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.invoke.MethodHandles; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import javax.net.ssl.KeyManagerFactory; + +import org.oransc.enrichment.configuration.WebClientConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.ResourceUtils; + +/** + * Factory for a generic reactive REST client. + */ +public class AsyncRestClientFactory { + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + + private final SslContextFactory sslContextFactory; + + public AsyncRestClientFactory(WebClientConfig clientConfig) { + if (clientConfig != null) { + this.sslContextFactory = new CachingSslContextFactory(clientConfig); + } else { + this.sslContextFactory = null; + } + } + + public AsyncRestClient createRestClient(String baseUrl) { + if (this.sslContextFactory != null) { + try { + return new AsyncRestClient(baseUrl, this.sslContextFactory.createSslContext()); + } catch (Exception e) { + String exceptionString = e.toString(); + logger.error("Could not init SSL context, reason: {}", exceptionString); + } + } + return new AsyncRestClient(baseUrl); + } + + private class SslContextFactory { + private final WebClientConfig clientConfig; + + public SslContextFactory(WebClientConfig clientConfig) { + this.clientConfig = clientConfig; + } + + public SslContext createSslContext() throws UnrecoverableKeyException, NoSuchAlgorithmException, + CertificateException, KeyStoreException, IOException { + return this.createSslContext(createKeyManager()); + } + + private SslContext createSslContext(KeyManagerFactory keyManager) + throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException { + if (this.clientConfig.isTrustStoreUsed()) { + return createSslContextRejectingUntrustedPeers(this.clientConfig.trustStore(), + this.clientConfig.trustStorePassword(), keyManager); + } else { + // Trust anyone + return SslContextBuilder.forClient() // + .keyManager(keyManager) // + .trustManager(InsecureTrustManagerFactory.INSTANCE) // + .build(); + } + } + + private SslContext createSslContextRejectingUntrustedPeers(String trustStorePath, String trustStorePass, + KeyManagerFactory keyManager) + throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException { + + final KeyStore trustStore = getTrustStore(trustStorePath, trustStorePass); + List certificateList = Collections.list(trustStore.aliases()).stream() // + .filter(alias -> isCertificateEntry(trustStore, alias)) // + .map(alias -> getCertificate(trustStore, alias)) // + .collect(Collectors.toList()); + final X509Certificate[] certificates = certificateList.toArray(new X509Certificate[certificateList.size()]); + + return SslContextBuilder.forClient() // + .keyManager(keyManager) // + .trustManager(certificates) // + .build(); + } + + private boolean isCertificateEntry(KeyStore trustStore, String alias) { + try { + return trustStore.isCertificateEntry(alias); + } catch (KeyStoreException e) { + logger.error("Error reading truststore {}", e.getMessage()); + return false; + } + } + + private Certificate getCertificate(KeyStore trustStore, String alias) { + try { + return trustStore.getCertificate(alias); + } catch (KeyStoreException e) { + logger.error("Error reading truststore {}", e.getMessage()); + return null; + } + } + + private KeyManagerFactory createKeyManager() throws NoSuchAlgorithmException, CertificateException, IOException, + UnrecoverableKeyException, KeyStoreException { + final KeyManagerFactory keyManager = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + final KeyStore keyStore = KeyStore.getInstance(this.clientConfig.keyStoreType()); + final String keyStoreFile = this.clientConfig.keyStore(); + final String keyStorePassword = this.clientConfig.keyStorePassword(); + final String keyPassword = this.clientConfig.keyPassword(); + try (final InputStream inputStream = new FileInputStream(keyStoreFile)) { + keyStore.load(inputStream, keyStorePassword.toCharArray()); + } + keyManager.init(keyStore, keyPassword.toCharArray()); + return keyManager; + } + + private synchronized KeyStore getTrustStore(String trustStorePath, String trustStorePass) + throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException { + + KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType()); + store.load(new FileInputStream(ResourceUtils.getFile(trustStorePath)), trustStorePass.toCharArray()); + return store; + } + } + + public class CachingSslContextFactory extends SslContextFactory { + private SslContext cachedContext = null; + + public CachingSslContextFactory(WebClientConfig clientConfig) { + super(clientConfig); + } + + @Override + public SslContext createSslContext() throws UnrecoverableKeyException, NoSuchAlgorithmException, + CertificateException, KeyStoreException, IOException { + if (this.cachedContext == null) { + this.cachedContext = super.createSslContext(); + } + return this.cachedContext; + + } + } + +} diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java index 7f28a12b..9b238654 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerCallbacks.java @@ -30,7 +30,6 @@ import org.oransc.enrichment.repository.EiJob; import org.oransc.enrichment.repository.EiProducer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -46,11 +45,14 @@ public class ProducerCallbacks { .serializeNulls() // .create(); // - @Autowired - ApplicationConfig applicationConfig; + private final AsyncRestClient restClient; + + public ProducerCallbacks(ApplicationConfig config) { + AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig()); + this.restClient = restClientFactory.createRestClient(""); + } public void notifyProducersJobDeleted(EiJob eiJob) { - AsyncRestClient restClient = restClient(); ProducerJobInfo request = new ProducerJobInfo(eiJob); String body = gson.toJson(request); for (EiProducer producer : eiJob.type().getProducers()) { @@ -81,7 +83,6 @@ public class ProducerCallbacks { * @return the body of the response from the REST call */ public Mono notifyProducerJobStarted(EiProducer producer, EiJob eiJob) { - AsyncRestClient restClient = restClient(); ProducerJobInfo request = new ProducerJobInfo(eiJob); String body = gson.toJson(request); @@ -93,8 +94,4 @@ public class ProducerCallbacks { }); } - private AsyncRestClient restClient() { - return new AsyncRestClient("", this.applicationConfig.getWebClientConfig()); - } - } diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerJobInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerJobInfo.java index 164159b3..ada16e2f 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerJobInfo.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/clients/ProducerJobInfo.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/configuration/ApplicationConfig.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/configuration/ApplicationConfig.java index 225b83a5..2d4087fa 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/configuration/ApplicationConfig.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/configuration/ApplicationConfig.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/ErrorResponse.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/ErrorResponse.java index 4e68c1a9..28c40bf6 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/ErrorResponse.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/ErrorResponse.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/StatusController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/StatusController.java new file mode 100644 index 00000000..42ab7cb8 --- /dev/null +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/StatusController.java @@ -0,0 +1,100 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ + +package org.oransc.enrichment.controllers; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.gson.annotations.SerializedName; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +import org.immutables.gson.Gson; +import org.oransc.enrichment.repository.EiJobs; +import org.oransc.enrichment.repository.EiProducers; +import org.oransc.enrichment.repository.EiTypes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +@RestController("StatusController") +@Api(tags = "Service status") +public class StatusController { + + @Autowired + private EiJobs eiJobs; + + @Autowired + private EiTypes eiTypes; + + @Autowired + private EiProducers eiProducers; + + @Gson.TypeAdapters + @ApiModel(value = "status_info") + public static class StatusInfo { + @ApiModelProperty(value = "status text") + @SerializedName("status") + @JsonProperty(value = "status", required = true) + public final String status; + + @ApiModelProperty(value = "Number of EI producers") + @SerializedName("no_of_producers") + @JsonProperty(value = "no_of_producers", required = true) + public final int noOfProducers; + + @ApiModelProperty(value = "Number of EI types") + @SerializedName("no_of_types") + @JsonProperty(value = "no_of_types", required = true) + public final int noOfTypes; + + @ApiModelProperty(value = "Number of EI jobs") + @SerializedName("no_of_jobs") + @JsonProperty(value = "no_of_jobs", required = true) + public final int noOfJobs; + + public StatusInfo(String status, EiProducers producers, EiTypes types, EiJobs jobs) { + this.status = status; + this.noOfJobs = jobs.size(); + this.noOfProducers = producers.size(); + this.noOfTypes = types.size(); + } + } + + @GetMapping(path = "/status", produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation(value = "Returns status and statistics of this service") + @ApiResponses( + value = { // + @ApiResponse(code = 200, message = "Service is living", response = StatusInfo.class) // + }) + public Mono> getStatus() { + StatusInfo info = new StatusInfo("hunky dory", this.eiProducers, this.eiTypes, this.eiJobs); + return Mono.just(new ResponseEntity<>(info, HttpStatus.OK)); + } + +} diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/VoidResponse.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/VoidResponse.java index 1933c2b9..80b6a80b 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/VoidResponse.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/VoidResponse.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerConsts.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerConsts.java index dcddef38..a8e88d8b 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerConsts.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerConsts.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerController.java index 288421a1..39796ee1 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerController.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerController.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -55,6 +55,7 @@ import org.springframework.web.bind.annotation.GetMapping; 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.RequestParam; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono; @@ -140,12 +141,20 @@ public class ConsumerController { name = ConsumerConsts.OWNER_PARAM, required = false, // value = ConsumerConsts.OWNER_PARAM_DESCRIPTION) // - String owner) { + @RequestParam(name = ConsumerConsts.OWNER_PARAM, required = false) String owner) { try { this.eiTypes.getType(eiTypeId); // Just to check that the type exists List result = new ArrayList<>(); - for (EiJob job : this.eiJobs.getJobsForType(eiTypeId)) { - result.add(job.id()); + if (owner != null) { + for (EiJob job : this.eiJobs.getJobsForOwner(owner)) { + if (eiTypeId == null || job.type().getId().equals(eiTypeId)) { + result.add(job.id()); + } + } + } else { + for (EiJob job : this.eiJobs.getJobsForType(eiTypeId)) { + result.add(job.id()); + } } return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK); } catch (Exception e) { diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiJobInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiJobInfo.java index 3111d103..47abcbb7 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiJobInfo.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiJobInfo.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiTypeInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiTypeInfo.java index 0d041152..3a2ab41c 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiTypeInfo.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/consumer/ConsumerEiTypeInfo.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerConsts.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerConsts.java index 9e56197f..9722594f 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerConsts.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerConsts.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java index 8adff419..d67b8ed4 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerController.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java index 9a821619..f13f9813 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerEiTypeInfo.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java index 19bb541e..859443d6 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/producer/ProducerRegistrationInfo.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiJobs.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiJobs.java index 606ee416..7a0dcfd1 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiJobs.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/repository/EiJobs.java @@ -34,10 +34,12 @@ public class EiJobs { private Map allEiJobs = new HashMap<>(); private MultiMap jobsByType = new MultiMap<>(); + private MultiMap jobsByOwner = new MultiMap<>(); public synchronized void put(EiJob job) { allEiJobs.put(job.id(), job); jobsByType.put(job.type().getId(), job.id(), job); + jobsByOwner.put(job.owner(), job.id(), job); } public synchronized Collection getJobs() { @@ -60,6 +62,10 @@ public class EiJobs { return jobsByType.get(type.getId()); } + public synchronized Collection getJobsForOwner(String owner) { + return jobsByOwner.get(owner); + } + public synchronized EiJob get(String id) { return allEiJobs.get(id); } @@ -75,6 +81,7 @@ public class EiJobs { public synchronized void remove(EiJob job) { this.allEiJobs.remove(job.id()); jobsByType.remove(job.type().getId(), job.id()); + jobsByOwner.remove(job.owner(), job.id()); } public synchronized int size() { @@ -84,6 +91,7 @@ public class EiJobs { public synchronized void clear() { this.allEiJobs.clear(); this.jobsByType.clear(); + jobsByOwner.clear(); } } diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java index 3b62fa74..f239a487 100644 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java +++ b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/tasks/ProducerSupervision.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,6 +21,7 @@ package org.oransc.enrichment.tasks; import org.oransc.enrichment.clients.AsyncRestClient; +import org.oransc.enrichment.clients.AsyncRestClientFactory; import org.oransc.enrichment.configuration.ApplicationConfig; import org.oransc.enrichment.repository.EiJobs; import org.oransc.enrichment.repository.EiProducer; @@ -45,17 +46,20 @@ import reactor.core.publisher.Mono; public class ProducerSupervision { private static final Logger logger = LoggerFactory.getLogger(ProducerSupervision.class); - @Autowired - ApplicationConfig applicationConfig; - - @Autowired - EiProducers eiProducers; - - @Autowired - EiJobs eiJobs; + private final EiProducers eiProducers; + private final EiJobs eiJobs; + private final EiTypes eiTypes; + private final AsyncRestClient restClient; @Autowired - EiTypes eiTypes; + public ProducerSupervision(ApplicationConfig applicationConfig, EiProducers eiProducers, EiJobs eiJobs, + EiTypes eiTypes) { + AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(applicationConfig.getWebClientConfig()); + this.restClient = restClientFactory.createRestClient(""); + this.eiJobs = eiJobs; + this.eiProducers = eiProducers; + this.eiTypes = eiTypes; + } @Scheduled(fixedRate = 1000 * 60 * 5) public void checkAllProducers() { @@ -69,7 +73,7 @@ public class ProducerSupervision { } private Mono checkOneProducer(EiProducer producer) { - return restClient().get(producer.getProducerSupervisionCallbackUrl()) // + return restClient.get(producer.getProducerSupervisionCallbackUrl()) // .onErrorResume(throwable -> { handleNonRespondingProducer(throwable, producer); return Mono.empty(); @@ -91,8 +95,4 @@ public class ProducerSupervision { producer.setAliveStatus(true); } - private AsyncRestClient restClient() { - return new AsyncRestClient("", this.applicationConfig.getWebClientConfig()); - } - } diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java index 67b0d8a4..e564fef1 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -42,6 +42,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.oransc.enrichment.clients.AsyncRestClient; +import org.oransc.enrichment.clients.AsyncRestClientFactory; import org.oransc.enrichment.clients.ProducerJobInfo; import org.oransc.enrichment.configuration.ApplicationConfig; import org.oransc.enrichment.configuration.ImmutableWebClientConfig; @@ -163,6 +164,13 @@ class ApplicationTest { assertThat(rsp).isEqualTo("[\"test\"]"); } + @Test + void testGetEiTypesEmpty() throws Exception { + String url = ConsumerConsts.API_ROOT + "/eitypes"; + String rsp = restClient().get(url).block(); + assertThat(rsp).isEqualTo("[]"); + } + @Test void testGetEiType() throws Exception { putEiProducerWithOneType(EI_PRODUCER_ID, "test"); @@ -185,6 +193,14 @@ class ApplicationTest { String url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs"; String rsp = restClient().get(url).block(); assertThat(rsp).isEqualTo("[\"jobId\"]"); + + url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs?owner=owner"; + rsp = restClient().get(url).block(); + assertThat(rsp).isEqualTo("[\"jobId\"]"); + + url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs?owner=JUNK"; + rsp = restClient().get(url).block(); + assertThat(rsp).isEqualTo("[]"); } @Test @@ -474,6 +490,16 @@ class ApplicationTest { assertThat(this.eiTypes.size()).isEqualTo(0); } + @Test + void testGetStatus() throws JsonMappingException, JsonProcessingException, ServiceException { + putEiProducerWithOneTypeRejecting("simulateProducerError", EI_TYPE_ID); + putEiProducerWithOneTypeRejecting("simulateProducerError2", EI_TYPE_ID); + + String url = "/status"; + ResponseEntity resp = restClient().getForEntity(url).block(); + assertThat(resp.getBody()).contains("hunky dory"); + } + ProducerEiTypeRegistrationInfo producerEiTypeRegistrationInfo(String typeId) throws JsonMappingException, JsonProcessingException { return new ProducerEiTypeRegistrationInfo(jsonSchemaObject(), typeId); @@ -576,7 +602,8 @@ class ApplicationTest { .trustStorePassword(config.trustStorePassword()) // .build(); - return new AsyncRestClient(baseUrl(), config); + AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config); + return restClientFactory.createRestClient(baseUrl()); } private AsyncRestClient restClient() { diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java index fa110445..d51007b5 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/MockEnrichmentService.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/clients/AsyncRestClientTest.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/clients/AsyncRestClientTest.java index e2273cfa..f879c7be 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/clients/AsyncRestClientTest.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/clients/AsyncRestClientTest.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java index 479c1b2d..c4651961 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/controller/ProducerSimulatorController.java @@ -1,9 +1,9 @@ /*- * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved. - * ====================================================================== + * O-RAN-SC + * %% + * Copyright (C) 2020 Nordix Foundation + * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/test/auto-test/FTC1.sh b/test/auto-test/FTC1.sh index 413b22e4..e4482b60 100755 --- a/test/auto-test/FTC1.sh +++ b/test/auto-test/FTC1.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Sanity test, create service and then create,update and delete a policy using http/https and Agent REST/DMAAP with/without SDNC controller" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -45,61 +45,49 @@ for __httpx in $TESTED_PROTOCOLS ; do echo "#####################################################################" echo "#####################################################################" - #Local vars in test script - ########################## if [ $__httpx == "HTTPS" ]; then - # Path to callback receiver CR_PATH="https://$CR_APP_NAME:$CR_EXTERNAL_SECURE_PORT/callbacks" use_cr_https + use_simulator_https + use_mr_https + if [[ $interface = *"SDNC"* ]]; then + use_sdnc_https + fi + if [[ $interface = *"DMAAP"* ]]; then + use_agent_dmaap_https + else + use_agent_rest_https + fi else - # Path to callback receiver CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" use_cr_http + use_simulator_http + use_mr_http + if [[ $interface = *"SDNC"* ]]; then + use_sdnc_http + fi + if [[ $interface = *"DMAAP"* ]]; then + use_agent_dmaap_http + else + use_agent_rest_http + fi fi # Clean container and start all needed containers # clean_containers - if [ $__httpx == "HTTPS" ]; then - #"Using secure ports towards simulators" - use_simulator_https - else - #"Using non-secure ports towards simulators" - use_simulator_http - fi - start_ric_simulators ricsim_g1 1 OSC_2.1.0 start_ric_simulators ricsim_g2 1 STD_1.1.3 start_mr - if [ $__httpx == "HTTPS" ]; then - #echo "Using secure ports between agent and MR" - use_mr_https - else - #"Using non-secure ports between agent and MR" - use_mr_http - fi - start_cr - if [ $interface == "REST+SDNC" ] || [ $interface == "DMAAP+SDNC" ]; then - - start_sdnc - - if [ $__httpx == "HTTPS" ]; then - # "Using secure ports towards SDNC" - use_sdnc_https - else - #"Using non-secure ports towards SDNC" - use_sdnc_http - fi - fi - start_consul_cbs - if [ $interface == "REST+SDNC" ] || [ $interface == "DMAAP+SDNC" ]; then + if [[ $interface = *"SDNC"* ]]; then + start_sdnc prepare_consul_config SDNC ".consul_config.json" else prepare_consul_config NOSDNC ".consul_config.json" @@ -112,25 +100,7 @@ for __httpx in $TESTED_PROTOCOLS ; do start_policy_agent set_agent_debug - - if [ $interface == "DMAAP" ] || [ $interface == "DMAAP+SDNC" ]; then - if [ $__httpx == "HTTPS" ]; then - echo "Using secure ports towards dmaap" - use_agent_dmaap_https - else - echo "Using non-secure ports towards dmaap" - use_agent_dmaap_http - fi - else - if [ $__httpx == "HTTPS" ]; then - echo "Using secure ports towards the agent" - use_agent_rest_https - else - echo "Using non-secure ports towards the agent" - use_agent_rest_http - fi - fi - + set_agent_trace cr_equal received_callbacks 0 mr_equal requests_submitted 0 @@ -189,7 +159,7 @@ for __httpx in $TESTED_PROTOCOLS ; do cr_equal received_callbacks 0 - if [ $interface == "DMAAP" ] || [ $interface == "DMAAP+SDNC" ]; then + if [[ $interface = *"DMAAP"* ]]; then VAL=11 # Number of Agent API calls over DMAAP mr_equal requests_fetched $VAL mr_equal responses_submitted $VAL @@ -200,7 +170,7 @@ for __httpx in $TESTED_PROTOCOLS ; do mr_equal requests_submitted 0 fi - if [ $interface == "REST+SDNC" ] || [ $interface == "DMAAP+SDNC" ]; then + if [[ $interface = *"SDNC"* ]]; then sim_contains_str ricsim_g1_1 remote_hosts "a1-controller" sim_contains_str ricsim_g2_1 remote_hosts "a1-controller" else diff --git a/test/auto-test/FTC10.sh b/test/auto-test/FTC10.sh index 2e627fc8..42b8f587 100755 --- a/test/auto-test/FTC10.sh +++ b/test/auto-test/FTC10.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Basic use case, register service, create/update policy, delete policy, de-register service using both STD and OSC interface while mixing REST and Dmaap" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -34,7 +34,12 @@ generate_uuid ########################## # Path to callback receiver CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" + use_cr_http +use_simulator_http +use_mr_http +use_agent_rest_http + clean_containers diff --git a/test/auto-test/FTC100.sh b/test/auto-test/FTC100.sh index 728252d0..b617d3f1 100755 --- a/test/auto-test/FTC100.sh +++ b/test/auto-test/FTC100.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Full agent API walk through using agent REST/DMAAP and with/without SDNC A1 Controller" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -44,61 +44,48 @@ for __httpx in $TESTED_PROTOCOLS ; do echo "#####################################################################" echo "#####################################################################" - #Local vars in test script - ########################## - if [ $__httpx == "HTTPS" ]; then - # Path to callback receiver CR_PATH="https://$CR_APP_NAME:$CR_EXTERNAL_SECURE_PORT/callbacks" use_cr_https + use_simulator_https + use_mr_https + if [[ $interface = *"SDNC"* ]]; then + use_sdnc_https + fi + if [[ $interface = *"DMAAP"* ]]; then + use_agent_dmaap_https + else + use_agent_rest_https + fi else - # Path to callback receiver CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" use_cr_http + use_simulator_http + use_mr_http + if [[ $interface = *"SDNC"* ]]; then + use_sdnc_http + fi + if [[ $interface = *"DMAAP"* ]]; then + use_agent_dmaap_http + else + use_agent_rest_http + fi fi # Clean container and start all needed containers # clean_containers - if [ $__httpx == "HTTPS" ]; then - #"Using secure ports towards simulators" - use_simulator_https - else - #"Using non-secure ports towards simulators" - use_simulator_http - fi - start_ric_simulators ricsim_g1 1 OSC_2.1.0 start_ric_simulators ricsim_g2 1 STD_1.1.3 start_mr - if [ $__httpx == "HTTPS" ]; then - #echo "Using secure ports between agent and MR" - use_mr_https - else - #"Using non-secure ports between agent and MR" - use_mr_http - fi - start_cr - if [ $interface == "REST+SDNC" ] || [ $interface == "DMAAP+SDNC" ]; then - - start_sdnc - - if [ $__httpx == "HTTPS" ]; then - # "Using secure ports towards SDNC" - use_sdnc_https - else - #"Using non-secure ports towards SDNC" - use_sdnc_http - fi - fi - start_consul_cbs - if [ $interface == "REST+SDNC" ] || [ $interface == "DMAAP+SDNC" ]; then + if [[ $interface = *"SDNC"* ]]; then + start_sdnc prepare_consul_config SDNC ".consul_config.json" else prepare_consul_config NOSDNC ".consul_config.json" @@ -112,25 +99,6 @@ for __httpx in $TESTED_PROTOCOLS ; do set_agent_debug - if [ $interface == "DMAAP" ] || [ $interface == "DMAAP+SDNC" ]; then - if [ $__httpx == "HTTPS" ]; then - echo "Using secure ports towards dmaap" - use_agent_dmaap_https - else - echo "Using non-secure ports towards dmaap" - use_agent_dmaap_http - fi - else - if [ $__httpx == "HTTPS" ]; then - #"Using secure ports towards the agent" - use_agent_rest_https - else - #"Using non-secure ports towards the agent" - use_agent_rest_http - fi - fi - - cr_equal received_callbacks 0 mr_equal requests_submitted 0 @@ -148,8 +116,6 @@ for __httpx in $TESTED_PROTOCOLS ; do api_equal json:policy_ids 0 - - echo "############################################" echo "############## Health check ################" echo "############################################" @@ -388,7 +354,7 @@ for __httpx in $TESTED_PROTOCOLS ; do cr_equal received_callbacks 0 - if [ $interface == "DMAAP" ] || [ $interface == "DMAAP+SDNC" ]; then + if [[ $interface = *"DMAAP"* ]]; then mr_greater requests_submitted 0 VAL=$(mr_read requests_submitted) mr_equal requests_fetched $VAL @@ -400,7 +366,7 @@ for __httpx in $TESTED_PROTOCOLS ; do mr_equal requests_submitted 0 fi - if [ $interface == "REST+SDNC" ] || [ $interface == "DMAAP+SDNC" ]; then + if [[ $interface = *"SDNC"* ]]; then sim_contains_str ricsim_g1_1 remote_hosts "a1-controller" sim_contains_str ricsim_g2_1 remote_hosts "a1-controller" else diff --git a/test/auto-test/FTC110.sh b/test/auto-test/FTC110.sh index d6894b50..c840800a 100755 --- a/test/auto-test/FTC110.sh +++ b/test/auto-test/FTC110.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Testing of service registration timeouts and keepalive" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDMC SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -33,7 +33,11 @@ generate_uuid ########################## # Path to callback receiver CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" + use_cr_http +use_simulator_http +use_mr_http +use_agent_rest_http #### TEST BEGIN #### @@ -57,8 +61,6 @@ start_policy_agent set_agent_debug -use_agent_rest_http - #Verify no callbacks or dmaap messages has been sent cr_equal received_callbacks 0 mr_equal requests_submitted 0 @@ -187,7 +189,7 @@ sim_equal ricsim_g1_1 num_instances 0 api_get_service_ids 200 deviation "TR18 Agents sends callback with empty body" -cr_equal received_callbacks 0 +cr_equal received_callbacks 4 mr_equal requests_submitted 0 check_policy_agent_logs diff --git a/test/auto-test/FTC1100.sh b/test/auto-test/FTC1100.sh new file mode 100755 index 00000000..a61f1bb9 --- /dev/null +++ b/test/auto-test/FTC1100.sh @@ -0,0 +1,225 @@ +#!/bin/bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + + +TC_ONELINE_DESCR="Experimental ECS test case" + +#App names to include in the test, space separated list +INCLUDED_IMAGES="ECS PRODSTUB" + +. ../common/testcase_common.sh $@ +. ../common/ecs_api_functions.sh +. ../common/prodstub_api_functions.sh + +#### TEST BEGIN #### + +clean_containers + +use_ecs_rest_http + +use_prod_stub_http + +start_ecs + +start_prod_stub + +set_ecs_debug + +set_ecs_trace + +# Setup prodstub sim to accept calls for producers, types and jobs +prodstub_arm_supervision 200 prod-a +prodstub_arm_supervision 200 prod-b +prodstub_arm_supervision 200 prod-c + +prodstub_arm_type 200 prod-a type1 +prodstub_arm_type 200 prod-b type2 +prodstub_arm_type 200 prod-b type3 + +prodstub_disarm_type 200 prod-b type3 +prodstub_arm_type 200 prod-b type1 +prodstub_disarm_type 200 prod-b type1 + +prodstub_arm_create 200 prod-a job1 +prodstub_arm_create 200 prod-a job2 +prodstub_arm_create 200 prod-b job3 + +prodstub_arm_delete 200 prod-a job1 +prodstub_arm_delete 200 prod-a job2 +prodstub_arm_delete 200 prod-b job3 + +prodstub_arm_create 200 prod-b job4 +prodstub_arm_create 200 prod-a job4 + +prodstub_arm_create 200 prod-b job5 +prodstub_arm_create 200 prod-a job5 +prodstub_arm_delete 200 prod-a job5 + +prodstub_arm_create 200 prod-b job6 + +# ecs status +ecs_api_service_status 200 + +# Initial tests - no config made +ecs_api_a1_get_type_ids 200 EMPTY +ecs_api_a1_get_type 404 test-type + +ecs_api_edp_get_type_ids 200 EMPTY +ecs_api_edp_get_type 404 test-type + +ecs_api_edp_get_producer_ids 200 EMPTY +ecs_api_edp_get_producer 404 test-prod + +ecs_api_edp_get_producer_status 404 test-prod + +ecs_api_edp_delete_producer 404 test-prod + +ecs_api_a1_get_job_ids 404 test-type NOWNER +ecs_api_a1_get_job_ids 404 test-type test-owner + +ecs_api_a1_get_job 404 test-type test-job + +ecs_api_a1_get_job_status 404 test-type test-job + +ecs_api_a1_delete_job 404 test-type test-job + +ecs_api_edp_get_producer_jobs 404 test-prod + + +# Setup of producer/job and test apis +#prod-a +ecs_api_edp_put_producer 201 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json +ecs_api_edp_put_producer 200 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json + +ecs_api_a1_get_type_ids 200 type1 +ecs_api_a1_get_type 200 type1 testdata/ecs/ei-type-1.json + +ecs_api_edp_get_type_ids 200 type1 +ecs_api_edp_get_type 200 type1 testdata/ecs/ei-type-1.json prod-a + +ecs_api_edp_get_producer_ids 200 prod-a +ecs_api_edp_get_producer 200 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json + +ecs_api_edp_get_producer_status 200 prod-a ENABLED + +ecs_api_a1_get_job_ids 200 type1 NOWNER EMPTY +ecs_api_a1_get_job_ids 200 type1 test-owner EMPTY + +ecs_api_a1_get_job 404 type1 test-job + +ecs_api_a1_get_job_status 404 type1 test-job + +ecs_api_edp_get_producer_jobs 200 prod-a EMPTY + + +#job1 - prod-a +ecs_api_a1_put_job 201 type1 job1 http://localhost:80/target1 ric1 testdata/ecs/job-template.json + +prodstub_check_jobdata 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json + +ecs_api_a1_get_job_ids 200 type1 NOWNER job1 +ecs_api_a1_get_job_ids 200 type1 ric1 job1 + +ecs_api_a1_get_job 200 type1 job1 http://localhost:80/target1 ric1 testdata/ecs/job-template.json + +ecs_api_a1_get_job_status 200 type1 job1 ENABLED + +ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json + + +#job2 - prod-a +ecs_api_a1_put_job 201 type1 job2 http://localhost:80/target2 ric2 testdata/ecs/job-template.json + +prodstub_check_jobdata 200 prod-a job2 type1 http://localhost:80/target2 testdata/ecs/job-template.json + +ecs_api_a1_get_job_ids 200 type1 NOWNER job1 job2 +ecs_api_a1_get_job_ids 200 type1 ric1 job1 +ecs_api_a1_get_job_ids 200 type1 ric2 job2 + +ecs_api_a1_get_job 200 type1 job2 http://localhost:80/target2 ric2 testdata/ecs/job-template.json + +ecs_api_a1_get_job_status 200 type1 job2 ENABLED + +ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json job2 type1 http://localhost:80/target2 testdata/ecs/job-template.json + + +#prod-b +ecs_api_edp_put_producer 201 prod-b http://producer-stub:8092/callbacks/create/prod-b http://producer-stub:8092/callbacks/delete/prod-b http://producer-stub:8092/callbacks/supervision/prod-b type2 testdata/ecs/ei-type-2.json + +ecs_api_a1_get_type_ids 200 type1 type2 +ecs_api_a1_get_type 200 type1 testdata/ecs/ei-type-1.json +ecs_api_a1_get_type 200 type2 testdata/ecs/ei-type-2.json + +ecs_api_edp_get_type_ids 200 type1 type2 +ecs_api_edp_get_type 200 type1 testdata/ecs/ei-type-1.json prod-a +ecs_api_edp_get_type 200 type2 testdata/ecs/ei-type-2.json prod-b + +ecs_api_edp_get_producer_ids 200 prod-a prod-b +ecs_api_edp_get_producer 200 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json +ecs_api_edp_get_producer 200 prod-b http://producer-stub:8092/callbacks/create/prod-b http://producer-stub:8092/callbacks/delete/prod-b http://producer-stub:8092/callbacks/supervision/prod-b type2 testdata/ecs/ei-type-2.json + +ecs_api_edp_get_producer_status 200 prod-b ENABLED + + +#job3 - prod-b +ecs_api_a1_put_job 201 type2 job3 http://localhost:80/target3 ric3 testdata/ecs/job-template.json + +prodstub_check_jobdata 200 prod-b job3 type2 http://localhost:80/target3 testdata/ecs/job-template.json + +ecs_api_a1_get_job_ids 200 type1 NOWNER job1 job2 +ecs_api_a1_get_job_ids 200 type2 NOWNER job3 +ecs_api_a1_get_job_ids 200 type1 ric1 job1 +ecs_api_a1_get_job_ids 200 type1 ric2 job2 +ecs_api_a1_get_job_ids 200 type2 ric3 job3 + +ecs_api_a1_get_job 200 type2 job3 http://localhost:80/target3 ric3 testdata/ecs/job-template.json + +ecs_api_a1_get_job_status 200 type2 job3 ENABLED + +ecs_api_edp_get_producer_jobs 200 prod-a job1 type1 http://localhost:80/target1 testdata/ecs/job-template.json job2 type1 http://localhost:80/target2 testdata/ecs/job-template.json +ecs_api_edp_get_producer_jobs 200 prod-b job3 type2 http://localhost:80/target3 testdata/ecs/job-template.json + + +#prod-c (no types) +ecs_api_edp_put_producer 201 prod-c http://producer-stub:8092/callbacks/create/prod-c http://producer-stub:8092/callbacks/delete/prod-c http://producer-stub:8092/callbacks/supervision/prod-c NOTYPE + +ecs_api_edp_get_producer_ids 200 prod-a prod-b prod-c +ecs_api_edp_get_producer 200 prod-a http://producer-stub:8092/callbacks/create/prod-a http://producer-stub:8092/callbacks/delete/prod-a http://producer-stub:8092/callbacks/supervision/prod-a type1 testdata/ecs/ei-type-1.json +ecs_api_edp_get_producer 200 prod-b http://producer-stub:8092/callbacks/create/prod-b http://producer-stub:8092/callbacks/delete/prod-b http://producer-stub:8092/callbacks/supervision/prod-b type2 testdata/ecs/ei-type-2.json +ecs_api_edp_get_producer 200 prod-c http://producer-stub:8092/callbacks/create/prod-c http://producer-stub:8092/callbacks/delete/prod-c http://producer-stub:8092/callbacks/supervision/prod-c EMPTY + +ecs_api_edp_get_producer_status 200 prod-c ENABLED + +ecs_api_a1_delete_job 204 type2 job3 + +ecs_api_edp_delete_producer 204 prod-b + + +check_sndc_logs + +check_ecs_logs + +store_logs END + +#### TEST COMPLETE #### + + +print_result + +auto_clean_containers diff --git a/test/auto-test/FTC150.sh b/test/auto-test/FTC150.sh index 3e13bf53..ead424c3 100755 --- a/test/auto-test/FTC150.sh +++ b/test/auto-test/FTC150.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Sample tests of the SDNC A1 controller restconf API using http/https (no agent)" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="PA CP SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/controller_api_functions.sh @@ -100,6 +100,8 @@ for __nb_httpx in $NB_TESTED_PROTOCOLS ; do controller_api_delete_A1_policy 202 OSC ricsim_g1_1 1 4000 controller_api_delete_A1_policy 204 STD ricsim_g2_1 5000 + check_sdnc_logs + store_logs "NB_"$__nb_httpx"_SB_"$__sb_httpx done diff --git a/test/auto-test/FTC300.sh b/test/auto-test/FTC300.sh index 13647c9f..fb7bc342 100755 --- a/test/auto-test/FTC300.sh +++ b/test/auto-test/FTC300.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Resync 10000 policies using OSC interface over REST" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -43,34 +43,37 @@ for __httpx in $TESTED_PROTOCOLS ; do echo "#####################################################################" echo "#####################################################################" - #Local vars in test script - ########################## - if [ $__httpx == "HTTPS" ]; then - # Path to callback receiver CR_PATH="https://$CR_APP_NAME:$CR_EXTERNAL_SECURE_PORT/callbacks" use_cr_https + use_simulator_https + use_mr_https + if [[ $interface = *"SDNC"* ]]; then + use_sdnc_https + fi + if [[ $interface = *"DMAAP"* ]]; then + use_agent_dmaap_https + else + use_agent_rest_https + fi else - # Path to callback receiver CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" use_cr_http + use_simulator_http + use_mr_http + if [[ $interface = *"SDNC"* ]]; then + use_sdnc_http + fi + if [[ $interface = *"DMAAP"* ]]; then + use_agent_dmaap_http + else + use_agent_rest_http + fi fi # Clean container and start all needed containers # clean_containers - if [ $__httpx == "HTTPS" ]; then - #echo "Using secure ports between agent and MR" - use_mr_https - echo "Using secure ports towards simulators" - use_simulator_https - else - #"Using non-secure ports between agent and MR" - use_mr_http - echo "Using non-secure ports towards simulators" - use_simulator_http - fi - start_ric_simulators ricsim_g1 4 OSC_2.1.0 start_ric_simulators ricsim_g2 4 STD_1.1.3 @@ -83,14 +86,7 @@ for __httpx in $TESTED_PROTOCOLS ; do if [[ $interface = *"SDNC"* ]]; then start_sdnc - if [ $__httpx == "HTTPS" ]; then - # "Using secure ports towards SDNC" - use_sdnc_https - else - #"Using non-secure ports towards SDNC" - use_sdnc_http - fi - prepare_consul_config SDNC ".consul_config.json" + prepare_consul_config SDNC ".consul_config.json" else prepare_consul_config NOSDNC ".consul_config.json" fi @@ -103,24 +99,6 @@ for __httpx in $TESTED_PROTOCOLS ; do set_agent_debug - if [[ $interface == *"DMAAP"* ]]; then - if [ $__httpx == "HTTPS" ]; then - echo "Using secure ports towards dmaap" - use_agent_dmaap_https - else - echo "Using non-secure ports towards dmaap" - use_agent_dmaap_http - fi - else - if [ $__httpx == "HTTPS" ]; then - echo "Using secure ports towards the agent" - use_agent_rest_https - else - echo "Using non-secure ports towards the agent" - use_agent_rest_http - fi - fi - api_get_status 200 sim_print ricsim_g1_1 interface diff --git a/test/auto-test/FTC310.sh b/test/auto-test/FTC310.sh index 7eb3c19b..856d6f56 100755 --- a/test/auto-test/FTC310.sh +++ b/test/auto-test/FTC310.sh @@ -20,8 +20,8 @@ TC_ONELINE_DESCR="Resync of RIC via changes in the consul config" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC350.sh b/test/auto-test/FTC350.sh index 692d9b56..4b2e3cb2 100755 --- a/test/auto-test/FTC350.sh +++ b/test/auto-test/FTC350.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Change supported policy types and reconfigure rics" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -78,7 +78,6 @@ for interface in $TESTED_VARIANTS ; do start_ric_simulators ricsim_g1 $NUM_RICS OSC_2.1.0 if [[ $interface = *"SDNC"* ]]; then - start_sdnc prepare_consul_config SDNC ".consul_config_all.json" else prepare_consul_config NOSDNC ".consul_config_all.json" @@ -87,6 +86,7 @@ for interface in $TESTED_VARIANTS ; do start_policy_agent set_agent_debug + set_agent_trace api_get_status 200 @@ -226,13 +226,13 @@ for interface in $TESTED_VARIANTS ; do ricsim_g1_7:me1_ricsim_g1_7,me2_ricsim_g1_7:3,4,5:???? \ ricsim_g1_8:me1_ricsim_g1_8,me2_ricsim_g1_8:4,5:???? " - sleep 120 + sleep_wait 120 api_equal json:policy_ids 0 api_get_policy_types 404 ricsim_g1_9 - sim_equal ricsim_g1_9 num_instances 1 + sim_equal ricsim_g1_9 num_instances 0 api_delete_policy 404 2000 @@ -264,7 +264,7 @@ for interface in $TESTED_VARIANTS ; do ricsim_g1_9:me1_ricsim_g1_9,me2_ricsim_g1_9:5:???? \ ricsim_g1_10:me1_ricsim_g1_10,me2_ricsim_g1_10:NOTYPE:???? " - sleep 120 + sleep_wait 120 api_equal json:policy_ids 0 @@ -276,7 +276,7 @@ for interface in $TESTED_VARIANTS ; do sim_delete_policy_type 204 ricsim_g1_6 4 sim_delete_policy_type 204 ricsim_g1_7 4 - sleep 120 + sleep_wait 120 api_equal json:policy_types?ric=ricsim_g1_1 1 120 api_equal json:policy_types?ric=ricsim_g1_2 2 120 @@ -319,6 +319,7 @@ for interface in $TESTED_VARIANTS ; do check_policy_agent_logs store_logs ${interface} + done diff --git a/test/auto-test/FTC800.sh b/test/auto-test/FTC800.sh index b1e9f53f..25678bed 100755 --- a/test/auto-test/FTC800.sh +++ b/test/auto-test/FTC800.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Create 10000 policies in sequence using http/https and Agent REST/DMAAP with/without SDNC controller" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -49,17 +49,20 @@ for __httpx in $TESTED_PROTOCOLS ; do echo "#####################################################################" echo "#####################################################################" - #Local vars in test script - ########################## - if [ $__httpx == "HTTPS" ]; then # Path to callback receiver CR_PATH="https://$CR_APP_NAME:$CR_EXTERNAL_SECURE_PORT/callbacks" use_cr_https + use_simulator_https + use_mr_https + use_agent_rest_https else # Path to callback receiver CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" use_cr_http + use_simulator_http + use_mr_http + use_agent_rest_http fi # Policy instance start id @@ -67,50 +70,22 @@ for __httpx in $TESTED_PROTOCOLS ; do clean_containers - if [ $__httpx == "HTTPS" ]; then - #"Using secure ports towards simulators" - use_simulator_https - else - #"Using non-secure ports towards simulators" - use_simulator_http - fi - start_ric_simulators ricsim_g1 1 OSC_2.1.0 start_ric_simulators ricsim_g2 1 STD_1.1.3 start_mr - if [ $__httpx == "HTTPS" ]; then - #echo "Using secure ports between agent and MR" - use_mr_https - else - #"Using non-secure ports between agent and MR" - use_mr_http - fi - start_cr - if [ $interface == "SDNC" ]; then - + if [[ $interface == "SDNC" ]]; then start_sdnc - - if [ $__httpx == "HTTPS" ]; then - # "Using secure ports towards SDNC" - use_sdnc_https - else - #"Using non-secure ports towards SDNC" - use_sdnc_http - fi - fi - - start_consul_cbs - - if [ $interface == "SDNC" ]; then prepare_consul_config SDNC ".consul_config.json" else prepare_consul_config NOSDNC ".consul_config.json" fi + start_consul_cbs + consul_config_app ".consul_config.json" start_control_panel @@ -119,15 +94,6 @@ for __httpx in $TESTED_PROTOCOLS ; do set_agent_debug - if [ $__httpx == "HTTPS" ]; then - # "Using secure ports towards the agent" - use_agent_rest_https - else - # "Using non-secure ports towards the agent" - use_agent_rest_http - fi - - cr_equal received_callbacks 0 mr_equal requests_submitted 0 diff --git a/test/auto-test/FTC810.sh b/test/auto-test/FTC810.sh index 7fa5ea6e..009efc04 100755 --- a/test/auto-test/FTC810.sh +++ b/test/auto-test/FTC810.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Repeatedly create and delete policies in each RICs for 24h (or configured number of days). Via agent REST/DMAAP/DMAAP_BATCH and SDNC using http or https" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/FTC850.sh b/test/auto-test/FTC850.sh index b5c991c3..7391331b 100755 --- a/test/auto-test/FTC850.sh +++ b/test/auto-test/FTC850.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Create/delete policies in parallel over a number of ric using a number of child process" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL, CP, CR, MR, PA, RICSIM, SDNC" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh @@ -51,32 +51,29 @@ for __httpx in $TESTED_PROTOCOLS ; do echo "#####################################################################" echo "#####################################################################" - #Local vars in test script - ########################## - if [ $__httpx == "HTTPS" ]; then - # Path to callback receiver CR_PATH="https://$CR_APP_NAME:$CR_EXTERNAL_SECURE_PORT/callbacks" use_cr_https + use_simulator_https + use_mr_https + if [[ $interface = *"SDNC"* ]]; then + use_sdnc_https + fi + use_agent_rest_https else - # Path to callback receiver CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" use_cr_http + use_simulator_http + use_mr_http + if [[ $interface = *"SDNC"* ]]; then + use_sdnc_http + fi + use_agent_rest_http fi # Clean container and start all needed containers # clean_containers - if [ $__httpx == "HTTPS" ]; then - echo "Using secure ports towards simulators and sdnc" - use_simulator_https - use_sdnc_https - else - echo "Using non-secure ports towards simulators and sdnc" - use_simulator_http - use_sdnc_http - fi - start_ric_simulators ricsim_g1 $NUM_RICS OSC_2.1.0 start_consul_cbs @@ -98,14 +95,6 @@ for __httpx in $TESTED_PROTOCOLS ; do set_agent_debug - if [ $__httpx == "HTTPS" ]; then - echo "Using secure ports towards the agent" - use_agent_rest_https - else - echo "Using non-secure ports towards the agent" - use_agent_rest_http - fi - api_get_status 200 for ((i=1; i<=$NUM_RICS; i++)) diff --git a/test/auto-test/FTC900.sh b/test/auto-test/FTC900.sh index c483504d..32567973 100755 --- a/test/auto-test/FTC900.sh +++ b/test/auto-test/FTC900.sh @@ -19,8 +19,8 @@ TC_ONELINE_DESCR="Preparation for test of the Control Panel and the Health Check app - populating a number of ric simulators with types and instances" -#App names to exclude checking pulling images for, space separated list -EXCLUDED_IMAGES="SDNC SDNC_ONAP" +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM" . ../common/testcase_common.sh $@ . ../common/agent_api_functions.sh diff --git a/test/auto-test/PM_DEMO.sh b/test/auto-test/PM_DEMO.sh new file mode 100755 index 00000000..3696d567 --- /dev/null +++ b/test/auto-test/PM_DEMO.sh @@ -0,0 +1,147 @@ +#!/usr/bin/env bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +TC_ONELINE_DESCR="Preparation demo setup - populating a number of ric simulators with types and instances" + +#App names to include in the test, space separated list +INCLUDED_IMAGES="CBS CONSUL CP CR MR PA RICSIM SDNC" + +. ../common/testcase_common.sh $@ +. ../common/agent_api_functions.sh +. ../common/ricsimulator_api_functions.sh + +#### TEST BEGIN #### + +#Local vars in test script +########################## +# Path to callback receiver +CR_PATH="http://$CR_APP_NAME:$CR_EXTERNAL_PORT/callbacks" +use_cr_http +use_agent_rest_http +use_sdnc_http +use_simulator_http + +clean_containers + +OSC_NUM_RICS=6 +STD_NUM_RICS=5 + +start_ric_simulators $RIC_SIM_PREFIX"_g1" $OSC_NUM_RICS OSC_2.1.0 + +start_ric_simulators $RIC_SIM_PREFIX"_g2" $STD_NUM_RICS STD_1.1.3 + +start_mr #Just to prevent errors in the agent log... + +start_control_panel + +CR_PATH="https://$CR_APP_NAME:$CR_EXTERNAL_SECURE_PORT/callbacks" +use_cr_http + +start_sdnc + +start_consul_cbs + +prepare_consul_config SDNC ".consul_config.json" +consul_config_app ".consul_config.json" + +start_policy_agent + +api_get_status 200 + +# Print the A1 version for OSC +for ((i=1; i<=$OSC_NUM_RICS; i++)) +do + sim_print $RIC_SIM_PREFIX"_g1_"$i interface +done + + +# Print the A1 version for STD +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + sim_print $RIC_SIM_PREFIX"_g2_"$i interface +done + + +# Load the polictypes in osc +for ((i=1; i<=$OSC_NUM_RICS; i++)) +do + sim_put_policy_type 201 $RIC_SIM_PREFIX"_g1_"$i 100 demo-testdata/OSC/sim_qos.json + sim_put_policy_type 201 $RIC_SIM_PREFIX"_g1_"$i 20008 demo-testdata/OSC/sim_tsa.json +done + + +#Check the number of schemas and the individual schemas in OSC +api_equal json:policy_types 3 120 + +for ((i=1; i<=$OSC_NUM_RICS; i++)) +do + api_equal json:policy_types?ric=$RIC_SIM_PREFIX"_g1_"$i 2 120 +done + +# Check the schemas in OSC +for ((i=1; i<=$OSC_NUM_RICS; i++)) +do + api_get_policy_schema 200 100 demo-testdata/OSC/qos-agent-modified.json + api_get_policy_schema 200 20008 demo-testdata/OSC/tsa-agent-modified.json +done + + +# Create policies +use_agent_rest_http + +api_put_service 201 "Emergency-response-app" 0 "$CR_PATH/1" + +# Create policies in OSC +for ((i=1; i<=$OSC_NUM_RICS; i++)) +do + generate_uuid + api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g1_"$i 100 $((3000+$i)) NOTRANSIENT demo-testdata/OSC/piqos_template.json 1 + generate_uuid + api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g1_"$i 20008 $((4000+$i)) NOTRANSIENT demo-testdata/OSC/pitsa_template.json 1 +done + + +# Check the number of policies in OSC +for ((i=1; i<=$OSC_NUM_RICS; i++)) +do + sim_equal $RIC_SIM_PREFIX"_g1_"$i num_instances 2 +done + + +# Create policies in STD +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + generate_uuid + api_put_policy 201 "Emergency-response-app" $RIC_SIM_PREFIX"_g2_"$i NOTYPE $((2100+$i)) NOTRANSIENT demo-testdata/STD/pi1_template.json 1 +done + + +# Check the number of policies in STD +for ((i=1; i<=$STD_NUM_RICS; i++)) +do + sim_equal $RIC_SIM_PREFIX"_g2_"$i num_instances 1 +done + +check_policy_agent_logs + +#### TEST COMPLETE #### + +store_logs END + +print_result diff --git a/test/auto-test/demo-testdata/OSC/hw-agent-modified.json b/test/auto-test/demo-testdata/OSC/hw-agent-modified.json new file mode 100644 index 00000000..5ea5802a --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/hw-agent-modified.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "2", + "description": "Hello World policy type", + "type": "object", + "properties": { + "threshold": { + "type": "integer", + "default": 0 + } + }, + "additionalProperties": false + } \ No newline at end of file diff --git a/test/auto-test/demo-testdata/OSC/pihw_template.json b/test/auto-test/demo-testdata/OSC/pihw_template.json new file mode 100644 index 00000000..75749959 --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/pihw_template.json @@ -0,0 +1,3 @@ +{ + "threshold": XXX +} \ No newline at end of file diff --git a/test/auto-test/demo-testdata/OSC/piqos_template.json b/test/auto-test/demo-testdata/OSC/piqos_template.json new file mode 100644 index 00000000..4446ac5b --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/piqos_template.json @@ -0,0 +1,9 @@ +{ + "scope": { + "ueId": "0x349d230330ea60XXX", + "qosId": "4" + }, + "qosObjectives": { + "priorityLevel": 30 + } + } \ No newline at end of file diff --git a/test/auto-test/demo-testdata/OSC/pitsa_template.json b/test/auto-test/demo-testdata/OSC/pitsa_template.json new file mode 100644 index 00000000..75749959 --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/pitsa_template.json @@ -0,0 +1,3 @@ +{ + "threshold": XXX +} \ No newline at end of file diff --git a/test/auto-test/demo-testdata/OSC/qos-agent-modified.json b/test/auto-test/demo-testdata/OSC/qos-agent-modified.json new file mode 100644 index 00000000..3a012cd8 --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/qos-agent-modified.json @@ -0,0 +1,40 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "100", + "description": "Quality of Service policy type", + "type": "object", + "properties": { + "scope": { + "type": "object", + "properties": { + "ueId": { + "type": "string" + }, + "qosId": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "ueId", + "qosId" + ] + }, + "qosObjectives": { + "type": "object", + "properties": { + "priorityLevel": { + "type": "number" + } + }, + "additionalProperties": false, + "required": [ + "priorityLevel" + ] + } + }, + "additionalProperties": false, + "required": [ + "scope", "qosObjectives" + ] + } diff --git a/test/auto-test/demo-testdata/OSC/sim_hw.json b/test/auto-test/demo-testdata/OSC/sim_hw.json new file mode 100644 index 00000000..47e0ae05 --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/sim_hw.json @@ -0,0 +1,18 @@ +{ + "name": "hwpolicy", + "description": "Hellow World policy type", + "policy_type_id": 2, + "create_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "HW Policy", + "description": "Hello World policy type", + "type": "object", + "properties": { + "threshold": { + "type": "integer", + "default": 0 + } + }, + "additionalProperties": false + } + } \ No newline at end of file diff --git a/test/auto-test/demo-testdata/OSC/sim_qos.json b/test/auto-test/demo-testdata/OSC/sim_qos.json new file mode 100644 index 00000000..92eaa6ff --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/sim_qos.json @@ -0,0 +1,45 @@ +{ + "name": "pt1", + "description": "pt1 policy type", + "policy_type_id": 100, + "create_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OSC_Type1_1.0.0", + "description": "Quality of Service policy type", + "type": "object", + "properties": { + "scope": { + "type": "object", + "properties": { + "ueId": { + "type": "string" + }, + "qosId": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "ueId", + "qosId" + ] + }, + "qosObjectives": { + "type": "object", + "properties": { + "priorityLevel": { + "type": "number" + } + }, + "additionalProperties": false, + "required": [ + "priorityLevel" + ] + } + }, + "additionalProperties": false, + "required": [ + "scope", "qosObjectives" + ] + } +} diff --git a/test/auto-test/demo-testdata/OSC/sim_tsa.json b/test/auto-test/demo-testdata/OSC/sim_tsa.json new file mode 100644 index 00000000..9227b5ea --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/sim_tsa.json @@ -0,0 +1,18 @@ +{ + "name": "tsapolicy", + "description": "tsa parameters", + "policy_type_id": 20008, + "create_schema": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "TS Policy", + "description": "Traffic Steering - High prio traffic - policy type", + "type": "object", + "properties": { + "threshold": { + "type": "integer", + "default": 0 + } + }, + "additionalProperties": false + } +} \ No newline at end of file diff --git a/test/auto-test/demo-testdata/OSC/tsa-agent-modified.json b/test/auto-test/demo-testdata/OSC/tsa-agent-modified.json new file mode 100644 index 00000000..d9426c79 --- /dev/null +++ b/test/auto-test/demo-testdata/OSC/tsa-agent-modified.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "20008", + "description": "Traffic Steering - High prio traffic - policy type", + "type": "object", + "properties": { + "threshold": { + "type": "integer", + "default": 0 + } + }, + "additionalProperties": false + } \ No newline at end of file diff --git a/test/auto-test/demo-testdata/STD/pi1_template.json b/test/auto-test/demo-testdata/STD/pi1_template.json new file mode 100644 index 00000000..e06b0316 --- /dev/null +++ b/test/auto-test/demo-testdata/STD/pi1_template.json @@ -0,0 +1,9 @@ +{ + "scope": { + "ueId": "ueXXX", + "qosId": "qosXXX" + }, + "qosObjectives": { + "priorityLevel": XXX + } +} \ No newline at end of file diff --git a/test/auto-test/testdata/ecs/ei-type-1.json b/test/auto-test/testdata/ecs/ei-type-1.json new file mode 100644 index 00000000..c74ba28d --- /dev/null +++ b/test/auto-test/testdata/ecs/ei-type-1.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "STD_Type1_1.0.0", + "description": "EI-Type 1", + "type": "object" +} \ No newline at end of file diff --git a/test/auto-test/testdata/ecs/ei-type-2.json b/test/auto-test/testdata/ecs/ei-type-2.json new file mode 100644 index 00000000..68a11371 --- /dev/null +++ b/test/auto-test/testdata/ecs/ei-type-2.json @@ -0,0 +1,6 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "STD_Type2_1.0.0", + "description": "EI-Type 2", + "type": "object" +} \ No newline at end of file diff --git a/test/auto-test/testdata/ecs/job-template.json b/test/auto-test/testdata/ecs/job-template.json new file mode 100644 index 00000000..9426d277 --- /dev/null +++ b/test/auto-test/testdata/ecs/job-template.json @@ -0,0 +1,5 @@ +{ + "jobparam1":"value1_XXXX", + "jobparam2":"value2_XXXX", + "jobparam3":"value3_XXXX" +} \ No newline at end of file diff --git a/test/common/README.md b/test/common/README.md index 09e8e220..b35966a3 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -159,7 +159,7 @@ Function to prepare a Consul config based on the previously configured (and star | parameter | description | | --------- | ----------- | -| `SDNC|SDNC_ONAP|NOSDNC` | Configure based on a1-controller (SNDC), a1-adapter (SDNC_ONAP) or without a controller/adapter (NOSDNC) | +| `SDNC|NOSDNC` | Configure based on a1-controller (SNDC) or without a controller/adapter (NOSDNC) | | `` | The path to the json output file containing the prepared config. This file is used in 'consul_config_app' | #### Function: start_consul_cbs #### @@ -216,18 +216,6 @@ Use https for all API calls towards the SDNC A1 Controller. Note that this funct |--| | None | -#### Function: start_sdnc_onap #### -Start the SDNC A1 Adapter container and its database container -| arg list | -|--| -| None | - -#### Function: config_sdnc_onap #### -Configure the SDNC A1 adapter - Not implemented -| arg list | -|--| -| None | - #### Function: start_mr #### Start the Message Router stub interface container | arg list | diff --git a/test/common/agent_api_functions.sh b/test/common/agent_api_functions.sh index 2091d65a..29e1bf1a 100644 --- a/test/common/agent_api_functions.sh +++ b/test/common/agent_api_functions.sh @@ -21,196 +21,7 @@ ### API functiond towards the Policy Agent -# Generic function to query the agent via the REST or DMAAP interface. -# Used by all other agent api test functions -# If operation prefix is '_BATCH' the the send and get response is split in two sequences, -# one for sending the requests and one for receiving the response -# but only when using the DMAAP interface -# REST or DMAAP is controlled of the base url of $ADAPTER -# arg: (GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH []) | (RESPONSE ) -# (Not for test scripts) -__do_curl_to_agent() { - echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG - paramError=0 - - if [ $# -lt 2 ] || [ $# -gt 3 ]; then - paramError=1 - else - timeout="" - oper="" - file='' - httpcode=" -sw %{http_code}" - accept='' - content='' - batch=0 - if [[ $1 == *"_BATCH" ]]; then - batch=1 - fi - if [ $# -gt 2 ]; then - content=" -H Content-Type:application/json" - fi - if [ $1 == "GET" ] || [ $1 == "GET_BATCH" ]; then - oper="GET" - if [ $# -ne 2 ]; then - paramError=1 - fi - elif [ $1 == "PUT" ] || [ $1 == "PUT_BATCH" ]; then - oper="PUT" - if [ $# -eq 3 ]; then - file=" --data-binary @$3" - fi - accept=" -H accept:application/json" - elif [ $1 == "POST" ] || [ $1 == "POST_BATCH" ]; then - oper="POST" - accept=" -H accept:*/*" - if [ $# -ne 2 ]; then - paramError=1 - fi - elif [ $1 == "DELETE" ] || [ $1 == "DELETE_BATCH" ]; then - oper="DELETE" - if [ $# -ne 2 ]; then - paramError=1 - fi - elif [ $1 == "RESPONSE" ]; then - oper="RESPONSE" - if [ $# -ne 2 ]; then - paramError=1 - fi - if [ $ADAPTER == $RESTBASE ] || [ $ADAPTER == $RESTBASE_SECURE ]; then - paramError=1 - fi - else - paramError=1 - fi - fi - - if [ $paramError -eq 1 ]; then - ((RES_CONF_FAIL++)) - echo "-Incorrect number of parameters to __do_curl_agent " $@ >> $HTTPLOG - echo "-Expected: (GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH []) | (RESPONSE ) []" >> $HTTPLOG - echo "-Returning response 000" >> $HTTPLOG - echo "-000" - return 1 - fi - - if [ $ADAPTER == $RESTBASE ] || [ $ADAPTER == $RESTBASE_SECURE ]; then - url=" "${ADAPTER}${2} - oper=" -X "$oper - curlString="curl -k "${oper}${timeout}${httpcode}${accept}${content}${url}${file} - echo " CMD: "$curlString >> $HTTPLOG - if [ $# -eq 3 ]; then - echo " FILE: $(<$3)" >> $HTTPLOG - fi - - # Do retry for configured response codes, otherwise only one attempt - maxretries=5 - while [ $maxretries -ge 0 ]; do - - let maxretries=maxretries-1 - res=$($curlString) - retcode=$? - if [ $retcode -ne 0 ]; then - echo " RETCODE: "$retcode >> $HTTPLOG - echo "000" - return 1 - fi - retry=0 - echo " RESP: "$res >> $HTTPLOG - status=${res:${#res}-3} - if [ ! -z "${AGENT_RETRY_CODES}" ]; then - for retrycode in $AGENT_RETRY_CODES; do - if [ $retrycode -eq $status ]; then - echo -e $RED" Retrying (according to set codes for retry), got status $status....."$ERED >> $HTTPLOG - sleep 1 - retry=1 - fi - done - fi - if [ $retry -eq 0 ]; then - maxretries=-1 - fi - done - echo $res - return 0 - else - if [ $oper != "RESPONSE" ]; then - requestUrl=$2 - if [ $1 == "PUT" ] && [ $# -eq 3 ]; then - payload="$(cat $3 | tr -d '\n' | tr -d ' ' )" - echo "payload: "$payload >> $HTTPLOG - file=" --data-binary "$payload - fi - #urlencode the request url since it will be carried by send-request url - requestUrl=$(python3 -c "from __future__ import print_function; import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$2") - url=" "${ADAPTER}"/send-request?url="${requestUrl}"&operation="${oper} - curlString="curl -k -X POST${timeout}${httpcode}${content}${url}${file}" - echo " CMD: "$curlString >> $HTTPLOG - res=$($curlString) - retcode=$? - if [ $retcode -ne 0 ]; then - echo " RETCODE: "$retcode >> $HTTPLOG - echo "000" - return 1 - fi - echo " RESP: "$res >> $HTTPLOG - status=${res:${#res}-3} - if [ $status -ne 200 ]; then - echo "000" - return 1 - fi - cid=${res:0:${#res}-3} - if [[ $batch -eq 1 ]]; then - echo $cid"200" - return 0 - fi - fi - if [ $oper == "RESPONSE" ] || [ $batch -eq 0 ]; then - if [ $oper == "RESPONSE" ]; then - cid=$2 - fi - url=" "${ADAPTER}"/receive-response?correlationid="${cid} - curlString="curl -k -X GET"${timeout}${httpcode}${url} - echo " CMD: "$curlString >> $HTTPLOG - res=$($curlString) - retcode=$? - if [ $retcode -ne 0 ]; then - echo " RETCODE: "$retcode >> $HTTPLOG - echo "000" - return 1 - fi - echo " RESP: "$res >> $HTTPLOG - status=${res:${#res}-3} - TS=$SECONDS - # wait of the reply from the agent... - while [ $status -eq 204 ]; do - if [ $(($SECONDS - $TS)) -gt 90 ]; then - echo " RETCODE: (timeout after 90s)" >> $HTTPLOG - echo "000" - return 1 - fi - sleep 0.01 - echo " CMD: "$curlString >> $HTTPLOG - res=$($curlString) - if [ $retcode -ne 0 ]; then - echo " RETCODE: "$retcode >> $HTTPLOG - echo "000" - return 1 - fi - echo " RESP: "$res >> $HTTPLOG - status=${res:${#res}-3} - done - if [ $status -eq 200 ]; then - body=${res:0:${#res}-3} - echo $body - return 0 - fi - echo "Status not 200, returning response 000" >> $HTTPLOG - echo "0000" - return 1 - fi - fi -} - +. ../common/api_curl.sh ######################################################### #### Test case functions A1 Policy management service @@ -274,7 +85,7 @@ api_get_policies() { fi query="/policies"$queryparams - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -303,7 +114,7 @@ api_get_policies() { else targetJson=$targetJson"\"${arr[$i+3]}\"," fi - file=".p.json" + file="./tmp/.p.json" sed 's/XXX/'${arr[$i]}'/g' ${arr[$i+4]} > $file json=$(cat $file) targetJson=$targetJson"\"json\":"$json"}" @@ -342,7 +153,7 @@ api_get_policy() { fi query="/policy?id=$UUID$2" - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -355,7 +166,7 @@ api_get_policy() { if [ $# -eq 3 ]; then #Create a policy json to compare with body=${res:0:${#res}-3} - file=".p.json" + file="./tmp/.p.json" sed 's/XXX/'${2}'/g' $3 > $file targetJson=$(< $file) echo "TARGET JSON: $targetJson" >> $HTTPLOG @@ -408,13 +219,13 @@ api_put_policy() { query=$query"&transient=$6" fi - file=".p.json" + file="./tmp/.p.json" sed 's/XXX/'${pid}'/g' $7 > $file - res="$(__do_curl_to_agent PUT $query $file)" + res="$(__do_curl_to_api PA PUT $query $file)" status=${res:${#res}-3} - echo -ne " Creating "$count"("$max")${SAMELINE}" + echo -ne " Executing "$count"("$max")${SAMELINE}" if [ $status -ne $1 ]; then - echo " Created "$count"?("$max")" + echo " Executed "$count"?("$max")" echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED ((RES_FAIL++)) __check_stop_at_error @@ -423,7 +234,7 @@ api_put_policy() { let pid=$pid+1 let count=$count+1 - echo -ne " Created "$count"("$max")${SAMELINE}" + echo -ne " Executed "$count"("$max")${SAMELINE}" done echo "" @@ -467,11 +278,11 @@ api_put_policy_batch() { query=$query"&transient=$6" fi - file=".p.json" + file="./tmp/.p.json" sed 's/XXX/'${pid}'/g' $7 > $file - res="$(__do_curl_to_agent PUT_BATCH $query $file)" + res="$(__do_curl_to_api PA PUT_BATCH $query $file)" status=${res:${#res}-3} - echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" + echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" if [ $status -ne 200 ]; then echo " Requested(batch) "$count"?("$max")" @@ -491,12 +302,12 @@ api_put_policy_batch() { count=0 for cid in $ARR; do - res="$(__do_curl_to_agent RESPONSE $cid)" + res="$(__do_curl_to_api PA RESPONSE $cid)" status=${res:${#res}-3} - echo -ne " Created(batch) "$count"("$max")${SAMELINE}" + echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" if [ $status -ne $1 ]; then - echo " Created(batch) "$count"?("$max")" + echo " Requested(batch) "$count"?("$max")" echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED ((RES_FAIL++)) __check_stop_at_error @@ -504,7 +315,7 @@ api_put_policy_batch() { fi let count=$count+1 - echo -ne " Created(batch) "$count"("$max")${SAMELINE}" + echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" done echo "" @@ -563,19 +374,19 @@ api_put_policy_parallel() { if [ -z "$uuid" ]; then uuid="NOUUID" fi - echo "" > ".pid${i}.res.txt" - echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > ".pid${i}.txt" + echo "" > "./tmp/.pid${i}.res.txt" + echo $resp_code $urlbase $ric_base $num_rics $uuid $start_id $template $count $pids $i > "./tmp/.pid${i}.txt" echo $i done | xargs -n 1 -I{} -P $pids bash -c '{ arg=$(echo {}) echo " Parallel process $arg started" - tmp=$(< ".pid${arg}.txt") - python3 ../common/create_policies_process.py $tmp > .pid${arg}.res.txt + tmp=$(< "./tmp/.pid${arg}.txt") + python3 ../common/create_policies_process.py $tmp > ./tmp/.pid${arg}.res.txt }' msg="" for ((i=1; i<=$pids; i++)) do - file=".pid${i}.res.txt" + file="./tmp/.pid${i}.res.txt" tmp=$(< $file) if [ -z "$tmp" ]; then echo " Process $i : unknown result (result file empty" @@ -591,7 +402,7 @@ api_put_policy_parallel() { fi done if [ -z $msg ]; then - echo " $(($count*$num_rics)) policies created/updated" + echo " $(($count*$num_rics)) policy request(s) executed" ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 @@ -627,12 +438,12 @@ api_delete_policy() { while [ $count -lt $max ]; do query="/policy?id="$UUID$pid - res="$(__do_curl_to_agent DELETE $query)" + res="$(__do_curl_to_api PA DELETE $query)" status=${res:${#res}-3} - echo -ne " Deleting "$count"("$max")${SAMELINE}" + echo -ne " Executing "$count"("$max")${SAMELINE}" if [ $status -ne $1 ]; then - echo " Deleted "$count"?("$max")" + echo " Executed "$count"?("$max")" echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED ((RES_FAIL++)) __check_stop_at_error @@ -640,7 +451,7 @@ api_delete_policy() { fi let pid=$pid+1 let count=$count+1 - echo -ne " Deleted "$count"("$max")${SAMELINE}" + echo -ne " Executed "$count"("$max")${SAMELINE}" done echo "" @@ -673,9 +484,9 @@ api_delete_policy_batch() { ARR="" while [ $count -lt $max ]; do query="/policy?id="$UUID$pid - res="$(__do_curl_to_agent DELETE_BATCH $query)" + res="$(__do_curl_to_api PA DELETE_BATCH $query)" status=${res:${#res}-3} - echo -ne " Requested(batch) "$count"("$max")${SAMELINE}" + echo -ne " Requesting(batch) "$count"("$max")${SAMELINE}" if [ $status -ne 200 ]; then echo " Requested(batch) "$count"?("$max")" @@ -696,7 +507,7 @@ api_delete_policy_batch() { count=0 for cid in $ARR; do - res="$(__do_curl_to_agent RESPONSE $cid)" + res="$(__do_curl_to_api PA RESPONSE $cid)" status=${res:${#res}-3} echo -ne " Deleted(batch) "$count"("$max")${SAMELINE}" @@ -750,19 +561,19 @@ api_delete_policy_parallel() { if [ -z "$uuid" ]; then uuid="NOUUID" fi - echo "" > ".pid${i}.del.res.txt" - echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > ".pid${i}.del.txt" + echo "" > "./tmp/.pid${i}.del.res.txt" + echo $resp_code $urlbase $num_rics $uuid $start_id $count $pids $i > "./tmp/.pid${i}.del.txt" echo $i done | xargs -n 1 -I{} -P $pids bash -c '{ arg=$(echo {}) echo " Parallel process $arg started" - tmp=$(< ".pid${arg}.del.txt") - python3 ../common/delete_policies_process.py $tmp > .pid${arg}.del.res.txt + tmp=$(< "./tmp/pid${arg}.del.txt") + python3 ../common/delete_policies_process.py $tmp > ./tmp/pid${arg}.del.res.txt }' msg="" for ((i=1; i<=$pids; i++)) do - file=".pid${i}.del.res.txt" + file="./tmp/.pid${i}.del.res.txt" tmp=$(< $file) if [ -z "$tmp" ]; then echo " Process $i : unknown result (result file empty" @@ -778,7 +589,7 @@ api_delete_policy_parallel() { fi done if [ -z $msg ]; then - echo " $(($count*$num_rics)) deleted" + echo " $(($count*$num_rics)) policy request(s) executed" ((RES_PASS++)) echo -e $GREEN" PASS"$EGREEN return 0 @@ -825,7 +636,7 @@ api_get_policy_ids() { fi query="/policy_ids"$queryparams - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -879,7 +690,7 @@ api_get_policy_schema() { fi query="/policy_schema?id=$2" - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -928,7 +739,7 @@ api_get_policy_schemas() { query=$query"?ric="$2 fi - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1003,7 +814,7 @@ api_get_policy_status() { query="/policy_status?id="$UUID$2 - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1050,7 +861,7 @@ api_get_policy_types() { query="/policy_types?ric=$2" fi - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1107,7 +918,7 @@ api_get_status() { return 1 fi query="/status" - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1140,7 +951,7 @@ api_get_ric() { query="/ric?managedElementId="$2 - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1185,7 +996,7 @@ api_get_rics() { query="/rics?policyType="$2 fi - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1197,7 +1008,7 @@ api_get_rics() { if [ $# -gt 2 ]; then body=${res:0:${#res}-3} - res=$(python3 ../common/create_rics_json.py ".tmp_rics.json" "$3" ) + res=$(python3 ../common/create_rics_json.py "./tmp/.tmp_rics.json" "$3" ) if [ $res -ne 0 ]; then echo -e $RED" FAIL, could not create target ric info json"$ERED ((RES_FAIL++)) @@ -1205,7 +1016,7 @@ api_get_rics() { return 1 fi - targetJson=$(<.tmp_rics.json) + targetJson=$(<./tmp/.tmp_rics.json) echo "TARGET JSON: $targetJson" >> $HTTPLOG res=$(python3 ../common/compare_json.py "$targetJson" "$body") if [ $res -ne 0 ]; then @@ -1239,10 +1050,10 @@ api_put_service() { query="/service" json="{\"callbackUrl\": \""$4"\",\"keepAliveIntervalSeconds\": \""$3"\",\"serviceName\": \""$2"\"}" - file=".tmp.json" + file="./tmp/.tmp.json" echo "$json" > $file - res="$(__do_curl_to_agent PUT $query $file)" + res="$(__do_curl_to_api PA PUT $query $file)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1290,7 +1101,7 @@ api_get_services() { query="/services?name="$2 fi - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1347,7 +1158,7 @@ api_get_service_ids() { fi query="/services" - res="$(__do_curl_to_agent GET $query)" + res="$(__do_curl_to_api PA GET $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1396,7 +1207,7 @@ api_delete_services() { fi query="/services?name="$2 - res="$(__do_curl_to_agent DELETE $query)" + res="$(__do_curl_to_api PA DELETE $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then @@ -1425,7 +1236,7 @@ api_put_services_keepalive() { fi query="/services/keepalive?name="$2 - res="$(__do_curl_to_agent PUT $query)" + res="$(__do_curl_to_api PA PUT $query)" status=${res:${#res}-3} if [ $status -ne $1 ]; then diff --git a/test/common/api_curl.sh b/test/common/api_curl.sh new file mode 100644 index 00000000..2aff131f --- /dev/null +++ b/test/common/api_curl.sh @@ -0,0 +1,223 @@ +#!/bin/bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +# Generic function to query the agent/ECS via the REST or DMAAP interface. +# Used by all other agent/ECS api test functions +# If operation prefix is '_BATCH' the the send and get response is split in two sequences, +# one for sending the requests and one for receiving the response +# but only when using the DMAAP interface +# REST or DMAAP is controlled of the base url of $ADAPTER +# arg: (PA|ECS GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH []) | (PA|ECS RESPONSE ) +# (Not for test scripts) +__do_curl_to_api() { + echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + paramError=0 + + if [ $# -gt 0 ]; then + if [ $1 == "PA" ]; then + __ADAPTER=$ADAPTER + __RESTBASE=$RESTBASE + __RESTBASE_SECURE=$RESTBASE_SECURE + __RETRY_CODES=$AGENT_RETRY_CODES + elif [ $1 == "ECS" ]; then + __ADAPTER=$ECS_ADAPTER + __RESTBASE=$ECS_RESTBASE + __RESTBASE_SECURE=$ECS_RESTBASE_SECURE + __RETRY_CODES=$ECS_RETRY_CODES + else + paramError=1 + fi + fi + if [ $# -lt 3 ] || [ $# -gt 4 ]; then + paramError=1 + else + timeout="" + oper="" + file='' + httpcode=" -sw %{http_code}" + accept='' + content='' + batch=0 + if [[ $2 == *"_BATCH" ]]; then + batch=1 + fi + if [ $# -gt 3 ]; then + content=" -H Content-Type:application/json" + fi + if [ $2 == "GET" ] || [ $2 == "GET_BATCH" ]; then + oper="GET" + if [ $# -ne 3 ]; then + paramError=1 + fi + elif [ $2 == "PUT" ] || [ $2 == "PUT_BATCH" ]; then + oper="PUT" + if [ $# -eq 4 ]; then + file=" --data-binary @$4" + fi + accept=" -H accept:application/json" + elif [ $2 == "POST" ] || [ $2 == "POST_BATCH" ]; then + oper="POST" + accept=" -H accept:*/*" + if [ $# -ne 3 ]; then + paramError=1 + fi + elif [ $2 == "DELETE" ] || [ $2 == "DELETE_BATCH" ]; then + oper="DELETE" + if [ $# -ne 3 ]; then + paramError=1 + fi + elif [ $2 == "RESPONSE" ]; then + oper="RESPONSE" + if [ $# -ne 3 ]; then + paramError=1 + fi + if [ $__ADAPTER == $__RESTBASE ] || [ $__ADAPTER == $__RESTBASE_SECURE ]; then + paramError=1 + fi + else + paramError=1 + fi + fi + + if [ $paramError -eq 1 ]; then + ((RES_CONF_FAIL++)) + echo "-Incorrect number of parameters to __do_curl_agent " $@ >> $HTTPLOG + echo "-Expected: (PA|ECS GET|PUT|POST|DELETE|GET_BATCH|PUT_BATCH|POST_BATCH|DELETE_BATCH []) | (PA|ECS RESPONSE )" >> $HTTPLOG + echo "-Returning response 000" >> $HTTPLOG + echo "-000" + return 1 + fi + + if [ $__ADAPTER == $__RESTBASE ] || [ $__ADAPTER == $__RESTBASE_SECURE ]; then + url=" "${__ADAPTER}${3} + oper=" -X "$oper + curlString="curl -k "${oper}${timeout}${httpcode}${accept}${content}${url}${file} + echo " CMD: "$curlString >> $HTTPLOG + if [ $# -eq 4 ]; then + echo " FILE: $(<$4)" >> $HTTPLOG + fi + + # Do retry for configured response codes, otherwise only one attempt + maxretries=5 + while [ $maxretries -ge 0 ]; do + + let maxretries=maxretries-1 + res=$($curlString) + retcode=$? + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + retry=0 + echo " RESP: "$res >> $HTTPLOG + status=${res:${#res}-3} + if [ ! -z "${__RETRY_CODES}" ]; then + for retrycode in $__RETRY_CODES; do + if [ $retrycode -eq $status ]; then + echo -e $RED" Retrying (according to set codes for retry), got status $status....."$ERED >> $HTTPLOG + sleep 1 + retry=1 + fi + done + fi + if [ $retry -eq 0 ]; then + maxretries=-1 + fi + done + echo $res + return 0 + else + if [ $oper != "RESPONSE" ]; then + requestUrl=$3 + if [ $2 == "PUT" ] && [ $# -eq 4 ]; then + payload="$(cat $4 | tr -d '\n' | tr -d ' ' )" + echo "payload: "$payload >> $HTTPLOG + file=" --data-binary "$payload + fi + #urlencode the request url since it will be carried by send-request url + requestUrl=$(python3 -c "from __future__ import print_function; import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$3") + url=" "${__ADAPTER}"/send-request?url="${requestUrl}"&operation="${oper} + curlString="curl -k -X POST${timeout}${httpcode}${content}${url}${file}" + echo " CMD: "$curlString >> $HTTPLOG + res=$($curlString) + retcode=$? + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + echo " RESP: "$res >> $HTTPLOG + status=${res:${#res}-3} + if [ $status -ne 200 ]; then + echo "000" + return 1 + fi + cid=${res:0:${#res}-3} + if [[ $batch -eq 1 ]]; then + echo $cid"200" + return 0 + fi + fi + if [ $oper == "RESPONSE" ] || [ $batch -eq 0 ]; then + if [ $oper == "RESPONSE" ]; then + cid=$3 + fi + url=" "${__ADAPTER}"/receive-response?correlationid="${cid} + curlString="curl -k -X GET"${timeout}${httpcode}${url} + echo " CMD: "$curlString >> $HTTPLOG + res=$($curlString) + retcode=$? + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + echo " RESP: "$res >> $HTTPLOG + status=${res:${#res}-3} + TS=$SECONDS + # wait of the reply from the agent/ECS... + while [ $status -eq 204 ]; do + if [ $(($SECONDS - $TS)) -gt 90 ]; then + echo " RETCODE: (timeout after 90s)" >> $HTTPLOG + echo "000" + return 1 + fi + sleep 0.01 + echo " CMD: "$curlString >> $HTTPLOG + res=$($curlString) + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode >> $HTTPLOG + echo "000" + return 1 + fi + echo " RESP: "$res >> $HTTPLOG + status=${res:${#res}-3} + done + if [ $status -eq 200 ]; then + body=${res:0:${#res}-3} + echo $body + return 0 + fi + echo "Status not 200, returning response 000" >> $HTTPLOG + echo "0000" + return 1 + fi + fi +} \ No newline at end of file diff --git a/test/common/controller_api_functions.sh b/test/common/controller_api_functions.sh index 378a6d45..b0ae6418 100644 --- a/test/common/controller_api_functions.sh +++ b/test/common/controller_api_functions.sh @@ -41,9 +41,10 @@ __do_curl_to_controller() { body=$(echo "$3" | sed 's/"/\\"/g') json='{"input":{"near-rt-ric-url":"'$2'","body":"'"$body"'"}}' fi - echo "$json" > .sdnc.payload.json - echo " FILE: $json" >> $HTTPLOG - curlString="curl -skw %{http_code} -X POST $SDNC_HTTPX://$SDNC_USER:$SDNC_PWD@localhost:$SDNC_LOCAL_PORT$SDNC_API_URL$1 -H accept:application/json -H Content-Type:application/json --data-binary @.sdnc.payload.json" + payload="./tmp/.sdnc.payload.json" + echo "$json" > $payload + echo " FILE ($payload) : $json" >> $HTTPLOG + curlString="curl -skw %{http_code} -X POST $SDNC_HTTPX://$SDNC_USER:$SDNC_PWD@localhost:$SDNC_LOCAL_PORT$SDNC_API_URL$1 -H accept:application/json -H Content-Type:application/json --data-binary @$payload" echo " CMD: "$curlString >> $HTTPLOG res=$($curlString) retcode=$? @@ -62,8 +63,9 @@ __do_curl_to_controller() { fi body=${res:0:${#res}-3} echo " JSON: "$body >> $HTTPLOG - echo "$body" > .sdnc-reply.json - res=$(python3 ../common/extract_sdnc_reply.py .sdnc-reply.json) + reply="./tmp/.sdnc-reply.json" + echo "$body" > $reply + res=$(python3 ../common/extract_sdnc_reply.py $reply) echo " EXTRACED BODY+CODE: "$res >> $HTTPLOG echo "$res" return 0 diff --git a/test/common/do_curl_function.sh b/test/common/do_curl_function.sh index c4365d8b..ac945fe0 100755 --- a/test/common/do_curl_function.sh +++ b/test/common/do_curl_function.sh @@ -88,8 +88,8 @@ do_curl() { count=${RESULT:16:${#RESULT}} #Find dir of the common dir DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - echo $body > .tmp.json - res=$(python ${DIR}/count_json_elements.py .tmp.json) + echo $body > ./tmp/.tmp.json + res=$(python ${DIR}/count_json_elements.py ./tmp/.tmp.json) if [ $res -eq $count ]; then echo " Body (array size) as expected" else diff --git a/test/common/ecs_api_functions.sh b/test/common/ecs_api_functions.sh new file mode 100644 index 00000000..6c726b9c --- /dev/null +++ b/test/common/ecs_api_functions.sh @@ -0,0 +1,848 @@ +#!/bin/bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +# This is a script that contains specific test functions for ECS NB/SB API + +. ../common/api_curl.sh + +############### EXPERIMENTAL ############# + +########################################## +###### Mainly only function skeletons #### +########################################## + +########################################## +### A1-E Enrichment Data Consumer API #### +########################################## +#Function prefix: ecs_api_a1 + +# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs +# args: |NOOWNER [ EMPTY | + ] +# (Function for test scripts) +ecs_api_a1_get_job_ids() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + # Valid number of parameters 3,4,5,6 etc + if [ $# -lt 1 ]; then + __print_err " |NOOWNER [ EMPTY | + ]" $@ + return 1 + fi + owner="" + if [ $3 != "NOWNER" ]; then + owner="?owner="$3 + fi + + query="/A1-EI/v1/eitypes/$2/eijobs$owner" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + if [ $# -gt 3 ]; then + body=${res:0:${#res}-3} + targetJson="[" + + for pid in ${@:4} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ $pid != "EMPTY" ]; then + targetJson=$targetJson"\"$pid\"" + fi + done + + targetJson=$targetJson"]" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId} +# args: [] +# (Function for test scripts) +ecs_api_a1_get_type() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " []" $@ + return 1 + fi + + query="/A1-EI/v1/eitypes/$2" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + if [ $# -eq 3 ]; then + body=${res:0:${#res}-3} + if [ -f $3 ]; then + schema=$(cat $3) + else + echo -e $RED" FAIL. Schema file "$3", does not exist"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + targetJson="{\"eiJobParametersSchema\":$schema}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET ​/A1-EI​/v1​/eitypes +# args: (EMPTY | []+) +# (Function for test scripts) +ecs_api_a1_get_type_ids() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ]; then + __print_err " (EMPTY | []+)" $@ + return 1 + fi + + query="/A1-EI/v1/eitypes" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + body=${res:0:${#res}-3} + targetJson="[" + if [ $2 != "EMPTY" ]; then + for pid in ${@:2} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"\"$pid\"" + done + fi + targetJson=$targetJson"]" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status +# args: [] +# (Function for test scripts) +ecs_api_a1_get_job_status() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -ne 3 ] && [ $# -ne 4 ]; then + __print_err " " $@ + return 1 + fi + + query="/A1-EI/v1/eitypes/$2/eijobs/$3/status" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + if [ $# -eq 4 ]; then + body=${res:0:${#res}-3} + targetJson="{\"operationalState\": \"$4\"}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} +# args: [ ] +# (Function for test scripts) +ecs_api_a1_get_job() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -ne 3 ] && [ $# -ne 6 ]; then + __print_err " [ ]" $@ + return 1 + fi + + query="/A1-EI/v1/eitypes/$2/eijobs/$3" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + if [ $# -eq 6 ]; then + body=${res:0:${#res}-3} + + if [ -f $6 ]; then + jobfile=$(cat $6) + jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") + else + echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} +# args: +# (Function for test scripts) +ecs_api_a1_delete_job() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 3 ]; then + __print_err " " $@ + return 1 + fi + + query="/A1-EI/v1/eitypes/$2/eijobs/$3" + res="$(__do_curl_to_api ECS DELETE $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId} +# args: +# (Function for test scripts) +ecs_api_a1_put_job() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 6 ]; then + __print_err " " $@ + return 1 + fi + if [ -f $6 ]; then + jobfile=$(cat $6) + jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") + else + echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}" + file="./tmp/.p.json" + echo "$inputJson" > $file + + query="/A1-EI/v1/eitypes/$2/eijobs/$3" + res="$(__do_curl_to_api ECS PUT $query $file)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + + +########################################## +#### Enrichment Data Producer API #### +########################################## +# Function prefix: ecs_api_edp + +# API Test function: GET /ei-producer/v1/eitypes +# args: [ EMPTY | +] +# (Function for test scripts) +ecs_api_edp_get_type_ids() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 1 ]; then + __print_err " [ EMPTY | +]" $@ + return 1 + fi + + query="/ei-producer/v1/eitypes" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + if [ $# -gt 1 ]; then + body=${res:0:${#res}-3} + targetJson="[" + if [ $2 != "EMPTY" ]; then + for pid in ${@:2} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"\"$pid\"" + done + fi + targetJson=$targetJson"]" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status +# args: [] +# (Function for test scripts) +ecs_api_edp_get_producer_status() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ] || [ $# -gt 3 ]; then + __print_err " " $@ + return 1 + fi + + query="/ei-producer/v1/eiproducers/$2/status" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + if [ $# -eq 3 ]; then + body=${res:0:${#res}-3} + targetJson="{\"operational_state\": \"$3\"}" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + + +# API Test function: GET /ei-producer/v1/eiproducers +# args: [ EMPTY | +] +# (Function for test scripts) +ecs_api_edp_get_producer_ids() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 1 ]; then + __print_err " [ EMPTY | +]" $@ + return 1 + fi + + query="/ei-producer/v1/eiproducers" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + if [ $# -gt 1 ]; then + body=${res:0:${#res}-3} + targetJson="[" + + for pid in ${@:2} ; do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ $pid != "EMPTY" ]; then + targetJson=$targetJson"\"$pid\"" + fi + done + + targetJson=$targetJson"]" + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId} +# args: [ (NOID | []+)] +# (Function for test scripts) +ecs_api_edp_get_type() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + paramError=1 + if [ $# -eq 2 ]; then + paramError=0 + fi + if [ $# -gt 3 ]; then + paramError=0 + fi + if [ $paramError -ne 0 ]; then + __print_err " [ NOID | ([]+)]" $@ + return 1 + fi + + query="/ei-producer/v1/eitypes/$2" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + if [ $# -gt 3 ]; then + body=${res:0:${#res}-3} + + if [ -f $3 ]; then + schema=$(cat $3) + else + echo -e $RED" FAIL. Job template file "$3", does not exist"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + targetJson="" + if [ $4 != "EMPTY" ]; then + for pid in ${@:4} ; do + if [ "$targetJson" != "" ]; then + targetJson=$targetJson"," + fi + targetJson=$targetJson"\"$pid\"" + done + fi + targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}" + + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId} +# args: [ (EMPTY | [ ]+) ] +# (Function for test scripts) +ecs_api_edp_get_producer() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + #Possible arg count: 2, 6 7, 9, 11 etc + paramError=1 + if [ $# -eq 2 ]; then + paramError=0 + fi + if [ $# -eq 6 ] && [ "$6" == "EMPTY" ]; then + paramError=0 + fi + variablecount=$(($#-5)) + if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then + paramError=0 + fi + + if [ $paramError -ne 0 ]; then + __print_err " [ (NOID | [ ]+) ]" $@ + return 1 + fi + + query="/ei-producer/v1/eiproducers/$2" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + if [ $# -gt 2 ]; then + body=${res:0:${#res}-3} + targetJson="[" + if [ $# -gt 6 ]; then + arr=(${@:6}) + for ((i=0; i<$(($#-6)); i=i+2)); do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ -f ${arr[$i+1]} ]; then + schema=$(cat ${arr[$i+1]}) + else + echo -e $RED" FAIL. Schema file "${arr[$i+1]}", does not exist"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" + done + fi + targetJson=$targetJson"]" + if [ $# -gt 4 ]; then + targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\"}" + fi + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId} +# args: +# (Function for test scripts) +ecs_api_edp_delete_producer() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 2 ]; then + __print_err " " $@ + return 1 + fi + + query="/ei-producer/v1/eiproducers/$2" + res="$(__do_curl_to_api ECS DELETE $query)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId} +# args: NOTYPE|[ ]+ +# (Function for test scripts) +ecs_api_edp_put_producer() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + #Valid number of parametrer 6,7,9,11, + paramError=1 + if [ $# -eq 6 ] && [ "$6" == "NOTYPE" ]; then + paramError=0 + elif [ $# -gt 6 ] && [ $(($#%2)) -eq 1 ]; then + paramError=0 + fi + if [ $paramError -ne 0 ]; then + __print_err " [ ]+" $@ + return 1 + fi + + inputJson="[" + if [ $# -gt 6 ]; then + arr=(${@:6}) + for ((i=0; i<$(($#-6)); i=i+2)); do + if [ "$inputJson" != "[" ]; then + inputJson=$inputJson"," + fi + if [ -f ${arr[$i+1]} ]; then + schema=$(cat ${arr[$i+1]}) + else + echo -e $RED" FAIL. Schema file "${arr[$i+1]}", does not exist"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}" + done + fi + inputJson="\"supported_ei_types\":"$inputJson"]" + + inputJson=$inputJson",\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\"" + + inputJson="{"$inputJson"}" + + file="./tmp/.p.json" + echo "$inputJson" > $file + query="/ei-producer/v1/eiproducers/$2" + res="$(__do_curl_to_api ECS PUT $query $file)" + status=${res:${#res}-3} + + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + +# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs +# args: (EMPTY | [ ]+) +# (Function for test scripts) +ecs_api_edp_get_producer_jobs() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + #Valid number of parameter 2,3,6,10 + paramError=1 + if [ $# -eq 2 ]; then + paramError=0 + fi + if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then + paramError=0 + fi + variablecount=$(($#-2)) + if [ $# -gt 3 ] && [ $(($variablecount%4)) -eq 0 ]; then + paramError=0 + fi + if [ $paramError -eq 1 ]; then + __print_err " (EMPTY | [ ]+)" $@ + return 1 + fi + + query="/ei-producer/v1/eiproducers/$2/eijobs" + res="$(__do_curl_to_api ECS GET $query)" + status=${res:${#res}-3} + if [ $status -ne $1 ]; then + echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + if [ $# -gt 2 ]; then + body=${res:0:${#res}-3} + targetJson="[" + if [ $# -gt 3 ]; then + arr=(${@:3}) + for ((i=0; i<$(($#-3)); i=i+4)); do + if [ "$targetJson" != "[" ]; then + targetJson=$targetJson"," + fi + if [ -f ${arr[$i+3]} ]; then + jobfile=$(cat ${arr[$i+3]}) + jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g") + else + echo -e $RED" FAIL. Job template file "${arr[$i+3]}", does not exist"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"ei_job_data\":$jobfile}" + done + fi + targetJson=$targetJson"]" + + echo " TARGET JSON: $targetJson" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$targetJson" "$body") + + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + ((RES_FAIL++)) + __check_stop_at_error + return 1 + fi + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} + + +########################################## +#### Service status #### +########################################## +# Function prefix: ecs_api_service + +# API Test function: GET ​/status +# args: +# (Function for test scripts) +ecs_api_service_status() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + ((RES_TEST++)) + + if [ $# -lt 1 ]; then + __print_err " []*|NOID" $@ + return 1 + fi + + ((RES_PASS++)) + echo -e $GREEN" PASS"$EGREEN + return 0 +} \ No newline at end of file diff --git a/test/common/prodstub_api_functions.sh b/test/common/prodstub_api_functions.sh new file mode 100644 index 00000000..b41c79b1 --- /dev/null +++ b/test/common/prodstub_api_functions.sh @@ -0,0 +1,210 @@ +#!/bin/bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + + +### Admin API functions producer stub + + +# Excute a curl cmd towards the prodstub simulator and check the response code. +# args: TEST|CONF [] +__execute_curl_to_prodstub() { + #echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG + echo "(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG + echo " CMD: $3" >> $HTTPLOG + res="$($3)" + echo " RESP: $res" >> $HTTPLOG + retcode=$? + if [ $retcode -ne 0 ]; then + echo " RETCODE: "$retcode + echo -e $RED" FAIL - fatal error when executing curl."$ERED + return 1 + fi + status=${res:${#res}-3} + if [ $status -eq $2 ]; then + if [ $# -eq 4 ]; then + body=${res:0:${#res}-3} + jobfile=$(cat $4) + echo " TARGET JSON: $jobfile" >> $HTTPLOG + res=$(python3 ../common/compare_json.py "$jobfile" "$body") + if [ $res -ne 0 ]; then + echo -e $RED" FAIL, returned body not correct"$ERED + return 1 + fi + fi + if [ $1 == "TEST" ]; then + echo -e $GREEN" PASS"$EGREEN + else + echo -e $GREEN" OK"$EGREEN + fi + return 0 + fi + echo -e $RED" FAIL - expected http response: "$2" but got http response: "$status $ERED + return 1 +} + +# Prodstub API: Set (or reset) response code for producer supervision +# [] +# (Function for test scripts) +prodstub_arm_supervision() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 2 ] && [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " []" $@ + return 1 + fi + + curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/supervision/"$2 + if [ $# -eq 3 ]; then + curlString=$curlString"?response="$3 + fi + + __execute_curl_to_prodstub CONF $1 "$curlString" + retcode=$? + if [ $? -ne 0 ]; then + ((RES_CONF_FAIL++)) + fi + return $retcode +} + +# Prodstub API: Set (or reset) response code job create +# [] +# (Function for test scripts) +prodstub_arm_create() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 3 ] && [ $# -ne 4 ]; then + ((RES_CONF_FAIL++)) + __print_err " []" $@ + return 1 + fi + + curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/create/$2/$3" + if [ $# -eq 4 ]; then + curlString=$curlString"?response="$4 + fi + + __execute_curl_to_prodstub CONF $1 "$curlString" + retcode=$? + if [ $? -ne 0 ]; then + ((RES_CONF_FAIL++)) + fi + return $retcode +} + +# Prodstub API: Set (or reset) response code job delete +# [] +# (Function for test scripts) +prodstub_arm_delete() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 3 ] && [ $# -ne 4 ]; then + ((RES_CONF_FAIL++)) + __print_err " []" $@ + return 1 + fi + + curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/delete/$2/$3" + if [ $# -eq 4 ]; then + curlString=$curlString"?response="$4 + fi + + __execute_curl_to_prodstub CONF $1 "$curlString" + retcode=$? + if [ $? -ne 0 ]; then + ((RES_CONF_FAIL++)) + fi + return $retcode +} + +# Prodstub API: Arm a type of a producer +# +# (Function for test scripts) +prodstub_arm_type() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + + curlString="curl -X PUT -skw %{http_code} $PROD_STUB_LOCALHOST/arm/type/$2/$3" + + __execute_curl_to_prodstub CONF $1 "$curlString" + retcode=$? + if [ $? -ne 0 ]; then + ((RES_CONF_FAIL++)) + fi + return $retcode +} + +# Prodstub API: Disarm a type in a producer +# +# (Function for test scripts) +prodstub_disarm_type() { + echo -e $BOLD"CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "CONF(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 3 ]; then + ((RES_CONF_FAIL++)) + __print_err " " $@ + return 1 + fi + + curlString="curl -X DELETE -skw %{http_code} $PROD_STUB_LOCALHOST/arm/type/$2/$3" + + __execute_curl_to_prodstub CONF $1 "$curlString" + retcode=$? + if [ $? -ne 0 ]; then + ((RES_CONF_FAIL++)) + fi + return $retcode +} + +# Prodstub API: Get job data for a job and compare with a target job json +# +# (Function for test scripts) +prodstub_check_jobdata() { + echo -e $BOLD"TEST(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ $EBOLD + echo "TEST(${BASH_LINENO[0]}): "${FUNCNAME[0]} $@ >> $HTTPLOG + if [ $# -ne 6 ]; then + ((RES_FAIL++)) + __print_err " " $@ + return 1 + fi + if [ -f $6 ]; then + jobfile=$(cat $6) + jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g") + else + echo -e $RED" FAIL. Template file "$6" for jobdata, does not exist"$ERED + return 1 + fi + targetJson="{\"ei_job_identity\":\"$3\",\"ei_type_identity\":\"$4\",\"target_uri\":\"$5\",\"ei_job_data\":$jobfile}" + file="./tmp/.p.json" + echo "$targetJson" > $file + + curlString="curl -X GET -skw %{http_code} $PROD_STUB_LOCALHOST/jobdata/$2/$3" + + __execute_curl_to_prodstub TEST $1 "$curlString" $file + retcode=$? + if [ $? -ne 0 ]; then + ((RES_FAIL++)) + fi + return $retcode +} \ No newline at end of file diff --git a/test/common/ricsimulator_api_functions.sh b/test/common/ricsimulator_api_functions.sh index f0035592..67a398e1 100644 --- a/test/common/ricsimulator_api_functions.sh +++ b/test/common/ricsimulator_api_functions.sh @@ -22,13 +22,10 @@ # Excute a curl cmd towards a ricsimulator and check the response code. -# args: [] +# args: __execute_curl_to_sim() { echo ${FUNCNAME[1]} "line: "${BASH_LINENO[1]} >> $HTTPLOG echo " CMD: $2" >> $HTTPLOG - if [ $# -eq 3 ]; then - echo " FILE: $(<$3)" >> $HTTPLOG - fi res="$($2)" echo " RESP: $res" >> $HTTPLOG retcode=$? @@ -118,7 +115,7 @@ sim_put_policy_type() { curlString="curl -X PUT -skw %{http_code} $RIC_SIM_LOCALHOST"$res"/policytype?id="$3" -H Content-Type:application/json --data-binary @"$4 - __execute_curl_to_sim $1 "$curlString" $4 + __execute_curl_to_sim $1 "$curlString" return $? } diff --git a/test/common/test_env.sh b/test/common/test_env.sh index 8417ecea..ac5cfa42 100755 --- a/test/common/test_env.sh +++ b/test/common/test_env.sh @@ -30,6 +30,12 @@ POLICY_AGENT_LOCAL_IMAGE_TAG="2.1.0-SNAPSHOT" POLICY_AGENT_REMOTE_IMAGE="nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-policy-agent" POLICY_AGENT_REMOTE_IMAGE_TAG="2.1.0" +# Local ECS image and tag +ECS_LOCAL_IMAGE="o-ran-sc/nonrtric-enrichment-coordinator-service" +ECS_LOCAL_IMAGE_TAG="1.0.0-SNAPSHOT" +# Remote ECS image and tag +ECS_REMOTE_IMAGE="nexus3.o-ran-sc.org:10003/o-ran-sc/nonrtric-enrichment-coordinator-service" +ECS_REMOTE_IMAGE_TAG="1.0.0-SNAPSHOT" # Control Panel local image and tag CONTROL_PANEL_LOCAL_IMAGE="o-ran-sc/nonrtric-controlpanel" @@ -53,17 +59,6 @@ SDNC_DB_REMOTE_IMAGE_TAG="5.6" #No local image for DB, remote image always used -# SDNC ONAP A1 Adapte remote image and tag -SDNC_ONAP_A1_ADAPTER_REMOTE_IMAGE="nexus3.onap.org:10003/onap/sdnc-image" -SDNC_ONAP_A1_ADAPTER_REMOTE_IMAGE_TAG="1.8-STAGING-latest" -#No local image for the A1 adapter, remote image always used - -#ONAP A1 Adatper remote image and tag -SDNC_ONAP_DB_REMOTE_IMAGE="mysql/mysql-server" -SDNC_ONAP_DB_REMOTE_IMAGE_TAG="5.6" -#No local image for DB, remote image always used - - # Near RT RIC Simulator local image and tag RIC_SIM_LOCAL_IMAGE="nexus3.o-ran-sc.org:10004/o-ran-sc/a1-simulator" RIC_SIM_LOCAL_IMAGE_TAG="latest" @@ -80,7 +75,6 @@ CONSUL_REMOTE_IMAGE_TAG="1.7.2" #CBS remote image and tag CBS_REMOTE_IMAGE="nexus3.onap.org:10001/onap/org.onap.dcaegen2.platform.configbinding.app-app" -CBS_REMOTE_IMAGE="onap/org.onap.dcaegen2.platform.configbinding.app-app" CBS_REMOTE_IMAGE_TAG="2.3.0" #No local image for CBS, remote image always used @@ -95,6 +89,11 @@ CR_LOCAL_IMAGE="callback-receiver" CR_LOCAL_IMAGE_TAG="latest" #No remote image for CR, local image always used +#Producer stub image and tag +PROD_STUB_LOCAL_IMAGE="producer-stub" +PROD_STUB_LOCAL_IMAGE_TAG="latest" +#No remote image for producer stub, local image always used + # Common env var for auto-test. Vars used by docker-compose need to be exported export DOCKER_SIM_NWNAME="nonrtric-docker-net" # Name of docker private network @@ -107,6 +106,15 @@ export POLICY_AGENT_APP_NAME="policy-agent" # Name for Polic POLICY_AGENT_LOGPATH="/var/log/policy-agent/application.log" # Path the application log in the Policy Agent container export POLICY_AGENT_APP_NAME_ALIAS="policy-agent-container" # Alias name, name used by the control panel +export ECS_EXTERNAL_PORT=8083 # ECS container external port (host -> container) +export ECS_INTERNAL_PORT=8083 # ECS container internal port (container -> container) +export ECS_EXTERNAL_SECURE_PORT=8434 # ECS container external secure port (host -> container) +export ECS_INTERNAL_SECURE_PORT=8434 # ECS container internal secure port (container -> container) + +export ECS_APP_NAME="ecs" # Name for ECS container +ECS_LOGPATH="/var/log/enrichment-coordinator-service/application.log" # Path the application log in the ECS container +export ECS_APP_NAME_ALIAS="enrichment-service-container" # Alias name, name used by the control panel + export MR_EXTERNAL_PORT=3905 # MR stub container external port (host -> container) export MR_INTERNAL_PORT=3905 # MR stub container internal port (container -> container) export MR_EXTERNAL_SECURE_PORT=3906 # MR stub container external secure port (host -> container) @@ -121,6 +129,12 @@ export CR_EXTERNAL_SECURE_PORT=8091 # Callback recei export CR_INTERNAL_SECURE_PORT=8091 # Callback receiver container internal secure port (container -> container) export CR_APP_NAME="callback-receiver" # Name for the Callback receiver +export PROD_STUB_EXTERNAL_PORT=8092 # Producer stub container external port (host -> container) +export PROD_STUB_INTERNAL_PORT=8092 # Producer stub container internal port (container -> container) +export PROD_STUB_EXTERNAL_SECURE_PORT=8093 # Producer stub container external secure port (host -> container) +export PROD_STUB_INTERNAL_SECURE_PORT=8093 # Producer stub container internal secure port (container -> container) +export PROD_STUB_APP_NAME="producer-stub" # Name for the Producer stub + export CONSUL_HOST="consul-server" # Host name of consul export CONSUL_EXTERNAL_PORT=8500 # Consul container external port (host -> container) export CONSUL_INTERNAL_PORT=8500 # Consul container internal port (container -> container) @@ -153,30 +167,23 @@ SDNC_API_URL="/restconf/operations/A1-ADAPTER-API:" # Base url path SDNC_ALIVE_URL="/apidoc/explorer/" # Base url path for SNDC API docs (for alive check) SDNC_KARAF_LOG="/opt/opendaylight/data/log/karaf.log" # Path to karaf log -export SDNC_ONAP_APP_NAME="a1-adapter" # Name of the ONAP A1 Adapter container -export SDNC_ONAP_EXTERNAL_PORT=8282 # ONAP A1 Adapter container external port (host -> container) -export SDNC_ONAP_INTERNAL_PORT=8181 # ONAP A1 Adapter container internal port (container -> container) -export SDNC_ONAP_EXTERNAL_SECURE_PORT=8443 # SNDC A1 Adapter container external securee port (host -> container) -export SDNC_ONAP_INTERNAL_SECURE_PORT=8343 # SNDC A1 Adapter container internal secure port (container -> container) -export SDNC_ONAP_DB_APP_NAME="sdnc-onap-db" # Name of the ONAP A1 Adapter DB container -SDNC_ONAP_USER="admin" # ONAP A1 Adapter username -SDNC_ONAP_PWD="Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U" # ONAP A1 Adapter PWD -SDNC_ONAP_API_URL="/restconf/operations/A1-ADAPTER-API:" # Base url path for ONAP A1 Adapter API -SDNC_ONAP_ALIVE_URL="/apidoc/explorer/" # Base url path for ONAP A1 Adapter API docs (for alive check) -SDNC_ONAP_PROPERTIES_FILE="/opt/onap/ccsdk/data/properties/a1-adapter-api-dg.properties" -SDNC_ONAP_KARAF_LOG="/opt/opendaylight/data/log/karaf.log" # Path to karaf log - export CONTROL_PANEL_APP_NAME="control-panel" # Name of the Control Panel container export CONTROL_PANEL_EXTERNAL_PORT=8080 # Control Panel container external port (host -> container) export CONTROL_PANEL_INTERNAL_PORT=8080 # Control Panel container external port (host -> container) CONTROL_PANEL_LOGPATH="/logs/nonrtric-controlpanel.log" # Path the application log in the Control Panel container UUID="" # UUID used as prefix to the policy id to simulate a real UUID - # Testscript need to set the UUID to use other this empty prefix is used + # Testscript need to set the UUID otherwise this empty prefix is used RESTBASE="http://localhost:"$POLICY_AGENT_EXTERNAL_PORT # Base url to the Agent NB REST interface RESTBASE_SECURE="https://localhost:"$POLICY_AGENT_EXTERNAL_SECURE_PORT # Base url to the secure Agent NB REST interface DMAAPBASE="http://localhost:"$MR_EXTERNAL_PORT # Base url to the Dmaap adapter, http DMAAPBASE_SECURE="https://localhost:"$MR_EXTERNAL_SECURE_PORT # Base url to the Dmaap adapter, https ADAPTER=$RESTBASE # Adapter holds the address the agent R-APP interface (REST OR DMAAP) - # The values of this var is swiched between the two base url when needed \ No newline at end of file + # The values of this var is swiched between the four base url when needed +ECS_RESTBASE="http://localhost:"$ECS_EXTERNAL_PORT # Base url to the ECS NB REST interface +ECS_RESTBASE_SECURE="https://localhost:"$ECS_EXTERNAL_SECURE_PORT # Base url to the secure ECS NB REST interface +ECS_DMAAPBASE="http://localhost:"$MR_EXTERNAL_PORT # Base url to the Dmaap adapter, http +ECS_DMAAPBASE_SECURE="https://localhost:"$MR_EXTERNAL_SECURE_PORT # Base url to the Dmaap adapter, https +ECS_ADAPTER=$ECS_RESTBASE # Adapter holds the address the ECS R-APP interface (REST OR DMAAP) + # The values of this var is swiched between the four base url when needed \ No newline at end of file diff --git a/test/common/testcase_common.sh b/test/common/testcase_common.sh index 39a593c8..ed02c7b1 100755 --- a/test/common/testcase_common.sh +++ b/test/common/testcase_common.sh @@ -21,6 +21,14 @@ # Arg: local|remote|remote-remove [auto-clean] [--stop-at-error] [--ricsim-prefix ] [ --env-file ] [--use-local-image []*] +# Create a test case id, ATC (Auto Test Case), from the name of the test case script. +# FTC1.sh -> ATC == FTC1 +ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh) + +#Create result file (containing '1' for error) for this test case +#Will be replaced with a file containing '0' if all test cases pass +echo "1" > "$PWD/.result$ATC.txt" + #Formatting for 'echo' cmd BOLD="\033[1m" EBOLD="\033[0m" @@ -60,7 +68,10 @@ echo "Test case started as: ${BASH_SOURCE[$i+1]} "$@ #Localhost constant LOCALHOST="http://localhost:" -# Make curl retries for http response codes set in this env var, space separated list of codes +# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes +ECS_RETRY_CODES="" + +# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes AGENT_RETRY_CODES="" # Var to contol if the agent runs in a container (normal = 0) or as application on the local machine ( = 1) @@ -73,11 +84,17 @@ AUTO_CLEAN="" USE_LOCAL_IMAGES="" # List of available apps to override with local image -AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA CP SDNC RICSIM" +AVAILABLE_LOCAL_IMAGES_OVERRIDE="PA ECS CP SDNC RICSIM" # Use this var (STOP_AT_ERROR=1 in the test script) for debugging/trouble shooting to take all logs and exit at first FAIL test case STOP_AT_ERROR=0 +# Function to indent cmd output with one space +indent1() { sed 's/^/ /'; } + +# Function to indent cmd output with two spaces +indent2() { sed 's/^/ /'; } + # Set a description string for the test case if [ -z "$TC_ONELINE_DESCR" ]; then TC_ONELINE_DESCR="" @@ -91,24 +108,22 @@ if [ -f .tmp_tcsuite_ctr ]; then echo $tmpval > .tmp_tcsuite_ctr fi -# Create a test case id, ATC (Auto Test Case), from the name of the test case script. -# FTC1.sh -> ATC == FTC1 -ATC=$(basename "${BASH_SOURCE[$i+1]}" .sh) - # Create the logs dir if not already created in the current dir if [ ! -d "logs" ]; then mkdir logs fi TESTLOGS=$PWD/logs +# Create the tmp dir for temporary files that is not needed after the test +# hidden files for the test env is still stored in the current dir +if [ ! -d "tmp" ]; then + mkdir tmp +fi + # Create a http message log for this testcase HTTPLOG=$PWD"/.httplog_"$ATC".txt" echo "" > $HTTPLOG -#Create result file (containing '1' for error) for this test case -#Will be replaced with a file containing '0' if script is ok - -echo "1" > "$PWD/.result$ATC.txt" # Create a log dir for the test case mkdir -p $TESTLOGS/$ATC @@ -243,7 +258,7 @@ if [ -f "$TEST_ENV_VAR_FILE" ]; then echo -e $BOLD"Sourcing env vars from: "$TEST_ENV_VAR_FILE$EBOLD . $TEST_ENV_VAR_FILE else - echo -e $RED"Selected env var fle does not exist: "$TEST_ENV_VAR_FILE$ERED + echo -e $RED"Selected env var file does not exist: "$TEST_ENV_VAR_FILE$ERED exit 1 fi @@ -269,6 +284,11 @@ export CR_HTTPX="http" export CR_PORT=$CR_INTERNAL_PORT export CR_LOCAL_PORT=$CR_EXTERNAL_PORT #When CR is running outside the docker net +export PROD_STUB_HTTPX="http" +export PROD_STUB_PORT=$PROD_STUB_INTERNAL_PORT +export PROD_STUB_LOCAL_PORT=$PROD_STUB_EXTERNAL_PORT #When CR is running outside the docker net +export PROD_STUB_LOCALHOST=$PROD_STUB_HTTPX"://localhost:"$PROD_STUB_LOCAL_PORT + export SDNC_HTTPX="http" export SDNC_PORT=$SDNC_INTERNAL_PORT export SDNC_LOCAL_PORT=$SDNC_EXTERNAL_PORT #When agent is running outside the docker net @@ -278,17 +298,23 @@ echo -e $BOLD"Checking configured image setting for this test case"$EBOLD #Temp var to check for image variable name errors IMAGE_ERR=0 #Create a file with image info for later printing as a table -image_list_file=".image-list" +image_list_file="./tmp/.image-list" echo -e " Container\tImage\ttag" > $image_list_file # Check if image env var is set and if so export the env var with image to use (used by docker compose files) -# arg: