2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
23 * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
24 * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
25 * ACCORDANCE WITH APPLICABLE AGREEMENTS.
27 * Copyright (c) 2014 AT&T Knowledge Ventures
28 * Unpublished and Not for Publication
31 package org.openecomp.policyEngine;
33 import java.io.IOException;
34 import java.util.ArrayList;
35 import java.util.Collection;
37 import java.util.UUID;
39 import org.openecomp.policy.api.DecisionResponse;
40 import org.openecomp.policy.api.LoadedPolicy;
41 import org.openecomp.policy.api.NotificationScheme;
42 import org.openecomp.policy.api.PolicyConfig;
43 import org.openecomp.policy.api.PolicyConfigException;
44 import org.openecomp.policy.api.PolicyDecisionException;
45 import org.openecomp.policy.api.PolicyEngine;
46 import org.openecomp.policy.api.PolicyEventException;
47 import org.openecomp.policy.api.PolicyResponse;
48 import org.openecomp.policy.api.RemovedPolicy;
51 * Class contains static functions which make call to policy engine using API.
52 * This class is used by generalTestClient.java
58 public class PolicyEngineTestClient {
60 * This fuction make API call to policy engine to get config. And returns
61 * policy name, policy version and policy configStatus
63 * @param org.openecomp.policyEngine
64 * @param eCOMPComponentName
66 * @param configAttributes
70 @SuppressWarnings("deprecation")
71 public static ArrayList<String> getConfig(PolicyEngine policyEngine,
72 String eCOMPComponentName, String configName,
73 Map<String, String> configAttributes) {
74 ArrayList<String> resultReceived = new ArrayList<>();
76 UUID requestID = UUID.randomUUID();
77 Collection<PolicyConfig> policyConfigs;
78 if (configName == null) {
79 policyConfigs = policyEngine.getConfig(eCOMPComponentName, requestID);
81 if (configAttributes == null) {
82 policyConfigs = policyEngine.getConfig(eCOMPComponentName,
83 configName, requestID);
86 policyConfigs = policyEngine.getConfig(eCOMPComponentName,
87 configName, configAttributes, requestID);
90 if (policyConfigs != null && !policyConfigs.isEmpty()) {
91 for (PolicyConfig policyConfig : policyConfigs) {
92 resultReceived.add("Policy Name: "
93 + policyConfig.getPolicyName()
95 + policyConfig.getPolicyVersion() + " - "
96 + policyConfig.getPolicyConfigStatus());
99 } catch (PolicyConfigException e) {
100 // logger.error("Exception Occured"+e);
101 resultReceived.add(""+e);
103 return resultReceived;
107 * This functions make API call to policy engine to get decision. And
108 * returns policy Decision
110 * @param org.openecomp.policyEngine
111 * @param eCOMPComponentName
112 * @param decisionAttributes
115 public static ArrayList<String> getDecision(PolicyEngine policyEngine,
116 String eCOMPComponentName, Map<String, String> decisionAttributes) {
117 ArrayList<String> resultReceived = new ArrayList<>();
120 UUID requestID = UUID.randomUUID();
121 @SuppressWarnings("deprecation")
122 DecisionResponse policyDecision = policyEngine.getDecision(
123 eCOMPComponentName, decisionAttributes, requestID);
124 resultReceived.add(policyDecision.getDecision().toString());
125 } catch (PolicyDecisionException e) {
126 // logger.error("Exception Occured"+e);
127 resultReceived.add(""+e);
129 return resultReceived;
133 * This function makes API call to policy engine to get action. And returns
134 * responseMessage and responseStatus
136 * @param org.openecomp.policyEngine
137 * @param eventAttributes
140 public static ArrayList<String> getAction(PolicyEngine policyEngine,
141 Map<String, String> eventAttributes) {
142 ArrayList<String> resultReceived = new ArrayList<>();
144 UUID requestID = UUID.randomUUID();
145 @SuppressWarnings("deprecation")
146 Collection<PolicyResponse> policyResponses = policyEngine
147 .sendEvent(eventAttributes, requestID);
148 if (policyResponses != null && !policyResponses.isEmpty()) {
149 for (PolicyResponse policyResponse : policyResponses) {
150 resultReceived.add(policyResponse
151 .getPolicyResponseMessage()
153 + policyResponse.getPolicyResponseStatus());
156 } catch (PolicyEventException e) {
157 // logger.error("Exception Occured"+e);
158 resultReceived.add(""+e);
160 return resultReceived;
164 * This function makes API call to policy engine to get manual
167 * @param org.openecomp.policyEngine
170 public static void getManualNotifications(PolicyEngine policyEngine) {
171 policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS);
172 System.out.println(policyEngine.getNotification().getNotificationType());
173 for (LoadedPolicy updated : policyEngine.getNotification().getLoadedPolicies()) {
174 System.out.println(updated.getPolicyName());
175 System.out.println(updated.getVersionNo());
176 System.out.println(updated.getMatches());
178 for (RemovedPolicy removed : policyEngine.getNotification()
179 .getRemovedPolicies()) {
180 System.out.println(removed.getPolicyName());
181 System.out.println(removed.getVersionNo());
186 * This function makes API call to policy engine to get automatic
189 * @param org.openecomp.policyEngine
191 public static void getAutoNotifications(PolicyEngine policyEngine) {
192 Handler handler = new Handler();
193 policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS,
196 System.out.println("Enter a any key to exit");
199 } catch (IOException e) {