2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.client;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import java.io.UnsupportedEncodingException;
31 import org.apache.camel.Exchange;
32 import org.apache.camel.Handler;
33 import org.onap.clamp.clds.client.req.policy.GuardPolicyAttributesConstructor;
34 import org.onap.clamp.clds.client.req.policy.PolicyClient;
35 import org.onap.clamp.clds.config.ClampProperties;
36 import org.onap.clamp.clds.model.properties.ModelProperties;
37 import org.onap.clamp.clds.model.properties.Policy;
38 import org.onap.clamp.clds.model.properties.PolicyChain;
39 import org.onap.clamp.clds.model.properties.PolicyItem;
40 import org.onap.clamp.clds.util.LoggingUtils;
41 import org.onap.policy.controlloop.policy.builder.BuilderException;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.stereotype.Component;
46 * Send Guard Policy info to policy API. It uses the policy code to define the
47 * model and communicate with it. See also the PolicyClient class.
50 public class GuardPolicyDelegate {
52 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(GuardPolicyDelegate.class);
53 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
54 private final PolicyClient policyClient;
55 private final ClampProperties refProp;
58 public GuardPolicyDelegate(PolicyClient policyClient, ClampProperties refProp) {
59 this.policyClient = policyClient;
60 this.refProp = refProp;
64 * Perform activity. Send Guard Policies info to policy api.
66 * @param camelExchange
67 * The Camel Exchange object containing the properties
68 * @throws BuilderException
69 * In case of issues with OperationalPolicyRequestAttributesConstructor
70 * @throws UnsupportedEncodingException
71 * In case of issues with the Charset encoding
74 public void execute(Exchange camelExchange) throws BuilderException, UnsupportedEncodingException {
75 ModelProperties prop = ModelProperties.create(camelExchange);
76 Policy policy = prop.getType(Policy.class);
77 if (policy.isFound()) {
78 for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
79 for (PolicyItem policyItem:GuardPolicyAttributesConstructor
80 .getAllPolicyGuardsFromPolicyChain(policyChain)) {
81 prop.setCurrentModelElementId(policy.getId());
82 prop.setPolicyUniqueId(policyChain.getPolicyId());
83 prop.setGuardUniqueId(policyItem.getId());
84 policyClient.sendGuardPolicy(GuardPolicyAttributesConstructor
85 .formatAttributes(prop, policyItem), prop, LoggingUtils.getRequestId(), policyItem);