import org.onap.policy.api.main.rest.provider.PolicyProvider;\r
import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;\r
import org.onap.policy.api.main.rest.provider.StatisticsProvider;\r
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;\r
import org.onap.policy.common.endpoints.report.HealthCheckReport;\r
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil;\r
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;\r
+import org.onap.policy.common.utils.coder.Coder;\r
+import org.onap.policy.common.utils.coder.CoderException;\r
+import org.onap.policy.common.utils.coder.StandardCoder;\r
import org.onap.policy.models.base.PfModelException;\r
import org.onap.policy.models.base.PfModelRuntimeException;\r
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;\r
\r
private static final Logger LOGGER = LoggerFactory.getLogger(ApiRestController.class);\r
\r
+ private final Coder coder = new StandardCoder();\r
+\r
/**\r
* Retrieves the healthcheck status of the API component.\r
*\r
@ApiParam(value = "Entity body of policy type", required = true) ToscaServiceTemplate body,\r
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
\r
+ if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));\r
+ }\r
+\r
try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {\r
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);\r
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);\r
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,\r
@ApiParam(value = "Entity body of policy", required = true) ToscaServiceTemplate body) {\r
\r
+ if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,\r
+ "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies",\r
+ toJson(body));\r
+ }\r
+\r
try (PolicyProvider policyProvider = new PolicyProvider()) {\r
ToscaServiceTemplate serviceTemplate = policyProvider\r
.createPolicy(policyTypeId, policyTypeVersion, body);\r
return rb.header("X-ONAP-RequestID", requestId);\r
}\r
\r
+ /**\r
+ * Converts an object to a JSON string.\r
+ *\r
+ * @param object object to convert\r
+ * @return a JSON string representing the object\r
+ */\r
+ private String toJson(Object object) {\r
+ if (object == null) {\r
+ return null;\r
+ }\r
+\r
+ try {\r
+ return coder.encode(object);\r
+\r
+ } catch (CoderException e) {\r
+ LOGGER.warn("cannot convert {} to JSON", object.getClass().getName(), e);\r
+ return null;\r
+ }\r
+ }\r
+\r
private enum Target {\r
POLICY, POLICY_TYPE, OTHER\r
}\r
import javax.ws.rs.core.Response.ResponseBuilder;
import org.onap.policy.api.main.rest.provider.LegacyGuardPolicyProvider;
import org.onap.policy.api.main.rest.provider.LegacyOperationalPolicyProvider;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyApiRestController.class);
+ private final Coder coder = new StandardCoder();
+
/**
* Retrieves the latest version of a particular guard policy.
*
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
@ApiParam(value = "Entity body of policy", required = true) LegacyGuardPolicyInput body) {
+ if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
+ "/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies", toJson(body));
+ }
+
try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
Map<String, LegacyGuardPolicyOutput> policy = guardPolicyProvider.createGuardPolicy(body);
return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
@HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId,
@ApiParam(value = "Entity body of policy", required = true) LegacyOperationalPolicy body) {
+ if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
+ "/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies", toJson(body));
+ }
+
try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
LegacyOperationalPolicy policy = operationalPolicyProvider.createOperationalPolicy(body);
return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
}
return rb.header("X-ONAP-RequestID", requestId);
}
+
+ /**
+ * Converts an object to a JSON string.
+ *
+ * @param object object to convert
+ * @return a JSON string representing the object
+ */
+ private String toJson(Object object) {
+ if (object == null) {
+ return null;
+ }
+
+ try {
+ return coder.encode(object);
+
+ } catch (CoderException e) {
+ LOGGER.warn("cannot convert {} to JSON", object.getClass().getName(), e);
+ return null;
+ }
+ }
}
\ No newline at end of file