- Remove servers from yaml.
- Add prefix to path in yaml.
- Remove basepath prefix from Controller Impl.
- Added policy server port to 8093.
- Exposed docker env. vars for policy services.
Issue-ID: CPS-2291
Change-Id: Idcc9e23f9d63bad2480537dc8d39523fe82b4b83
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
cps: INFO
ncmp:
policy-executor:
- enabled: false
+ enabled: ${POLICY_SERVICE_ENABLED:false}
server:
- address: http://localhost
- port: 8785
+ address: ${POLICY_SERVICE_URL:http://policy-executor-stub}
+ port: ${POLICY_SERVICE_PORT:8093}
httpclient:
all-services:
maximumInMemorySizeInMegabytes: 16
"Invalid Json: " + changeRequestAsJson);
}
}
-
final Map<String, Object> request = new HashMap<>(2);
request.put("schema", getAssociatedPolicyDataSchemaName(operationType));
request.put("data", data);
final String authorization,
final String resourceIdentifier,
final String changeRequestAsJson) {
- final String serviceBaseUrl = serverAddress + ":" + serverPort;
+
final Map<String, Object> requestAsMap = getSingleRequestAsMap(yangModelCmHandle,
operationType,
final Object bodyAsObject = createBodyAsObject(Collections.singletonList(requestAsMap));
final UrlTemplateParameters urlTemplateParameters = RestServiceUrlTemplateBuilder.newInstance()
- .fixedPathSegment("execute")
- .createUrlTemplateParameters(serviceBaseUrl, "");
+ .fixedPathSegment("execute")
+ .createUrlTemplateParameters(String.format("%s:%s", serverAddress, serverPort),
+ "policy-executor/api");
return policyExecutorWebClient.post()
.uri(urlTemplateParameters.urlTemplate(), urlTemplateParameters.urlVariables())
### docker-compose --profile dmi-service up -d -> run CPS services incl. dmi-plugin ###
### docker-compose --profile dmi-stub --profile monitoring up -d -> run CPS with stubbed dmi-plugin (for registration performance testing)
### docker-compose --profile dmi-stub --profile tracing up -d -> run CPS with stubbed dmi-plugin (for open telemetry tracing testing make ONAP_TRACING_ENABLED "true" later "http://localhost:16686" can be accessed from browser)
+ ### docker-compose --profile dmi-stub --profile policy-executor-stub up -d -> run CPS with stubbed dmi-plugin and policy executor stub (for policy executor service testing make POLICY_SERVICE_ENABLED "true")
### to disable notifications make notification.enabled to false & comment out kafka/zookeeper services ###
dbpostgresql:
ONAP_TRACING_ENABLED: 'false'
ONAP_OTEL_SAMPLER_JAEGER_REMOTE_ENDPOINT: http://jaeger-service:14250
ONAP_OTEL_EXPORTER_ENDPOINT: http://jaeger-service:4317
+ POLICY_SERVICE_ENABLED: 'false'
restart: unless-stopped
depends_on:
- dbpostgresql
container_name: policy-executor-stub
image: ${DOCKER_REPO:-nexus3.onap.org:10003}/onap/policy-executor-stub:latest
ports:
- - 8785:8080
+ - 8785:8093
restart: unless-stopped
profiles:
- policy-executor-stub
title: Policy Executor
description: "Allows NCMP to execute a policy defined by a third party implementation before proceeding with a CM operation"
version: 1.0.0
-servers:
- - url: /policy-executor/api
tags:
- name: policy-executor
description: "Execute all your policies"
paths:
- /v1/{action}:
+ /policy-executor/api/v1/{action}:
post:
description: "Fire a Policy action"
operationId: executePolicyAction
return new MockResponse().setResponseCode(401)
}
- if (recordedRequest.path != '/v1/execute') {
+ if (recordedRequest.path != '/policy-executor/api/v1/execute') {
return new MockResponse().setResponseCode(400)
}
package org.onap.cps.policyexecutor.stub.controller;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.onap.cps.policyexecutor.stub.api.PolicyExecutorApi;
import org.onap.cps.policyexecutor.stub.model.NcmpDelete;
import org.onap.cps.policyexecutor.stub.model.PolicyExecutionRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
-@RequestMapping("${rest.api.policy-executor-base-path}")
@RequiredArgsConstructor
+@Slf4j
public class PolicyExecutorStubController implements PolicyExecutorApi {
private final ObjectMapper objectMapper;
-
private static final Pattern ERROR_CODE_PATTERN = Pattern.compile("(\\d{3})");
-
private int decisionCounter = 0;
@Override
final String action,
final PolicyExecutionRequest policyExecutionRequest,
final String authorization) {
+ log.info("Stub Policy Executor Invoked (only supports 'delete' operations)");
if (policyExecutionRequest.getRequests().isEmpty()) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
final Request firstRequest = policyExecutionRequest.getRequests().iterator().next();
- if ("ncmp-delete-schema:1.0.0".equals(firstRequest.getSchema())) {
+ log.info("1st Request Schema:{}", firstRequest.getSchema());
+ if (firstRequest.getSchema().contains("ncmp-delete-schema:1.0.0")) {
return handleNcmpDeleteSchema(firstRequest);
}
+ log.warn("This stub only supports 'delete' operations");
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
private ResponseEntity<PolicyExecutionResponse> handleNcmpDeleteSchema(final Request request) {
- final NcmpDelete ncmpDelete;
- try {
- ncmpDelete = objectMapper.readValue((String) request.getData(), NcmpDelete.class);
- } catch (final JsonProcessingException e) {
- return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
- }
+ final NcmpDelete ncmpDelete = objectMapper.convertValue(request.getData(), NcmpDelete.class);
final String targetIdentifier = ncmpDelete.getTargetIdentifier();
+
if (targetIdentifier == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
decision = "deny";
message = "Only FDNs containing 'cps-is-great' are allowed";
}
-
+ log.info("Decision: {} ({})", decision, message);
final PolicyExecutionResponse policyExecutionResponse =
new PolicyExecutionResponse(decisionId, decision, message);
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
-rest:
- api:
- policy-executor-base-path: /policy-executor/api
+server:
+ port: 8093
}
def 'Execute policy action with invalid json for request data.'() {
- given: 'a policy execution request'
- def request = new Request('ncmp-delete-schema:1.0.0', 'invalid json')
- def policyExecutionRequest = new PolicyExecutionRequest('some decision type', [request])
- def requestBody = objectMapper.writeValueAsString(policyExecutionRequest)
when: 'request is posted'
def response = mockMvc.perform(post(url)
.header('Authorization','some string')
.contentType(MediaType.APPLICATION_JSON)
- .content(requestBody))
+ .content('invalid json'))
.andReturn().response
then: 'response status is Bad Request'
assert response.status == HttpStatus.BAD_REQUEST.value()
def createRequestBody(decisionType, schema, targetIdentifier) {
def ncmpDelete = new NcmpDelete(targetIdentifier: targetIdentifier)
- def request = new Request(schema, objectMapper.writeValueAsString(ncmpDelete))
+ def request = new Request(schema, ncmpDelete)
def policyExecutionRequest = new PolicyExecutionRequest(decisionType, [request])
return objectMapper.writeValueAsString(policyExecutionRequest)
}