summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/main/java/org
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2022-02-09 19:04:25 +0000
committerGerrit Code Review <gerrit@onap.org>2022-02-09 19:04:25 +0000
commitc9da04cc4ff4b133edd68ceee77f5bb5128d6574 (patch)
tree701523daabcb77f4ded20bd3dfe4c3660bb1fb90 /services/services-engine/src/main/java/org
parent143d9c2e74ebe962640810140aa028637af88a6c (diff)
parent59b90519eda3b95b0cfc49b6349a591c7d0c78e2 (diff)
Merge "Remove JAXB and XML, use GSON for JSON"
Diffstat (limited to 'services/services-engine/src/main/java/org')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java3
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java58
2 files changed, 42 insertions, 19 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
index f69eae664..ebb1cdf2d 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -449,7 +449,6 @@ final class EngineWorker implements EngineService {
try {
final var baOutputStream = new ByteArrayOutputStream();
final ApexModelWriter<AxEngineModel> modelWriter = new ApexModelWriter<>(AxEngineModel.class);
- modelWriter.setJsonOutput(true);
modelWriter.write(apexEngineModel, baOutputStream);
return baOutputStream.toString();
} catch (final Exception e) {
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
index cc19080f9..2e97c54fc 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -41,6 +41,7 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParame
import org.onap.policy.common.parameters.ParameterException;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.ext.XLogger;
@@ -61,6 +62,8 @@ public class ApexParameterHandler {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexParameterHandler.class);
private static final String POLICY_TYPE_IMPL = "policy_type_impl";
+ private static final String APEX_POLICY_MODEL = "apexPolicyModel";
+
private String policyModel;
private String apexConfig;
@@ -81,13 +84,13 @@ public class ApexParameterHandler {
// Register the adapters for our carrier technologies and event protocols with GSON
// @formatter:off
final var gson = new GsonBuilder()
- .registerTypeAdapter(EngineParameters.class,
- new EngineServiceParametersJsonAdapter())
- .registerTypeAdapter(CarrierTechnologyParameters.class,
- new CarrierTechnologyParametersJsonAdapter())
- .registerTypeAdapter(EventProtocolParameters.class,
- new EventProtocolParametersJsonAdapter())
- .create();
+ .registerTypeAdapter(EngineParameters.class,
+ new EngineServiceParametersJsonAdapter())
+ .registerTypeAdapter(CarrierTechnologyParameters.class,
+ new CarrierTechnologyParametersJsonAdapter())
+ .registerTypeAdapter(EventProtocolParameters.class,
+ new EventProtocolParametersJsonAdapter())
+ .create();
// @formatter:on
parameters = gson.fromJson(apexConfig, ApexParameters.class);
} catch (final Exception e) {
@@ -135,13 +138,13 @@ public class ApexParameterHandler {
ParameterService.register(parameters.getEngineServiceParameters().getEngineParameters());
ParameterService.register(parameters.getEngineServiceParameters().getEngineParameters().getContextParameters());
ParameterService.register(parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getSchemaParameters());
+ .getSchemaParameters());
ParameterService.register(parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getDistributorParameters());
+ .getDistributorParameters());
ParameterService.register(parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getLockManagerParameters());
+ .getLockManagerParameters());
ParameterService.register(parameters.getEngineServiceParameters().getEngineParameters().getContextParameters()
- .getPersistorParameters());
+ .getPersistorParameters());
}
private void parseConfigAndModel(final String toscaPolicyFilePath) throws ApexException {
@@ -162,11 +165,7 @@ public class ApexParameterHandler {
|| EVENT_OUTPUT_PARAMETERS.equals(property.getKey())) {
body = standardCoder.convert(property.getValue(), JsonObject.class);
if (ENGINE_SERVICE_PARAMETERS.equals(property.getKey())) {
- JsonElement policyModelObject = ((JsonObject) body).get(POLICY_TYPE_IMPL);
- if (null != policyModelObject) {
- policyModel = standardCoder.encode(policyModelObject);
- }
- ((JsonObject) body).remove(POLICY_TYPE_IMPL);
+ policyModel = extractPolicyModel(standardCoder, body);
}
}
apexConfigJsonObject.add(property.getKey(), body);
@@ -176,4 +175,29 @@ public class ApexParameterHandler {
throw new ApexException("Parsing config and model from the tosca policy failed.", e);
}
}
+
+ private String extractPolicyModel(StandardCoder standardCoder, JsonElement body) throws CoderException {
+ // Check for "policy_type_impl"
+ JsonElement policyTypeImplObject = ((JsonObject) body).get(POLICY_TYPE_IMPL);
+ if (null == policyTypeImplObject) {
+ return null;
+ }
+
+ // "policy_type_impl" found
+ if (policyTypeImplObject instanceof JsonObject) {
+
+ // Check for "apexPolicyModel", this is used to encapsulate policy models sometimes
+ JsonElement policyModelObject = ((JsonObject) policyTypeImplObject).get(APEX_POLICY_MODEL);
+
+ if (policyModelObject != null) {
+ // Policy model encased in an "apexPolicyModel" object
+ return standardCoder.encode(policyModelObject);
+ } else {
+ // No encasement
+ return standardCoder.encode(policyTypeImplObject);
+ }
+ } else {
+ return policyTypeImplObject.getAsString();
+ }
+ }
}