summaryrefslogtreecommitdiffstats
path: root/policy-executor-stub/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'policy-executor-stub/src/main')
-rw-r--r--policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java22
-rw-r--r--policy-executor-stub/src/main/resources/application.yml5
2 files changed, 11 insertions, 16 deletions
diff --git a/policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java b/policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java
index 5b3a9931a0..cdd26c96e9 100644
--- a/policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java
+++ b/policy-executor-stub/src/main/java/org/onap/cps/policyexecutor/stub/controller/PolicyExecutorStubController.java
@@ -20,12 +20,12 @@
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;
@@ -34,18 +34,15 @@ import org.onap.cps.policyexecutor.stub.model.Request;
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
@@ -53,25 +50,24 @@ public class PolicyExecutorStubController implements PolicyExecutorApi {
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);
}
@@ -97,7 +93,7 @@ public class PolicyExecutorStubController implements PolicyExecutorApi {
decision = "deny";
message = "Only FDNs containing 'cps-is-great' are allowed";
}
-
+ log.info("Decision: {} ({})", decision, message);
final PolicyExecutionResponse policyExecutionResponse =
new PolicyExecutionResponse(decisionId, decision, message);
diff --git a/policy-executor-stub/src/main/resources/application.yml b/policy-executor-stub/src/main/resources/application.yml
index f713a157fe..8ed5742a41 100644
--- a/policy-executor-stub/src/main/resources/application.yml
+++ b/policy-executor-stub/src/main/resources/application.yml
@@ -15,6 +15,5 @@
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
-rest:
- api:
- policy-executor-base-path: /policy-executor/api
+server:
+ port: 8093