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 public static ArrayList<String> getConfig(PolicyEngine policyEngine,
71 String eCOMPComponentName, String configName,
72 Map<String, String> configAttributes) {
73 ArrayList<String> resultReceived = new ArrayList<String>();
75 UUID requestID = UUID.randomUUID();
76 Collection<PolicyConfig> policyConfigs;
77 if (configName == null) {
78 policyConfigs = policyEngine.getConfig(eCOMPComponentName, requestID);
80 if (configAttributes == null) {
81 policyConfigs = policyEngine.getConfig(eCOMPComponentName,
82 configName, requestID);
85 policyConfigs = policyEngine.getConfig(eCOMPComponentName,
86 configName, configAttributes, requestID);
89 if (policyConfigs != null && !policyConfigs.isEmpty()) {
90 for (PolicyConfig policyConfig : policyConfigs) {
91 resultReceived.add("Policy Name: "
92 + policyConfig.getPolicyName()
94 + policyConfig.getPolicyVersion() + " - "
95 + policyConfig.getPolicyConfigStatus());
98 } catch (PolicyConfigException e) {
99 // e.printStackTrace();
100 resultReceived.add(""+e);
102 return resultReceived;
106 * This functions make API call to policy engine to get decision. And
107 * returns policy Decision
109 * @param org.openecomp.policyEngine
110 * @param eCOMPComponentName
111 * @param decisionAttributes
114 public static ArrayList<String> getDecision(PolicyEngine policyEngine,
115 String eCOMPComponentName, Map<String, String> decisionAttributes) {
116 ArrayList<String> resultReceived = new ArrayList<String>();
119 UUID requestID = UUID.randomUUID();
120 DecisionResponse policyDecision = policyEngine.getDecision(
121 eCOMPComponentName, decisionAttributes, requestID);
122 resultReceived.add(policyDecision.getDecision().toString());
123 } catch (PolicyDecisionException e) {
124 // e.printStackTrace();
125 resultReceived.add(""+e);
127 return resultReceived;
131 * This function makes API call to policy engine to get action. And returns
132 * responseMessage and responseStatus
134 * @param org.openecomp.policyEngine
135 * @param eventAttributes
138 public static ArrayList<String> getAction(PolicyEngine policyEngine,
139 Map<String, String> eventAttributes) {
140 ArrayList<String> resultReceived = new ArrayList<String>();
142 UUID requestID = UUID.randomUUID();
143 Collection<PolicyResponse> policyResponses = policyEngine
144 .sendEvent(eventAttributes, requestID);
145 if (policyResponses != null && !policyResponses.isEmpty()) {
146 for (PolicyResponse policyResponse : policyResponses) {
147 resultReceived.add(policyResponse
148 .getPolicyResponseMessage()
150 + policyResponse.getPolicyResponseStatus());
153 } catch (PolicyEventException e) {
154 // e.printStackTrace();
155 resultReceived.add(""+e);
157 return resultReceived;
161 * This function makes API call to policy engine to get manual
164 * @param org.openecomp.policyEngine
167 public static void getManualNotifications(PolicyEngine policyEngine) {
168 policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS);
169 System.out.println(policyEngine.getNotification().getNotificationType());
170 for (LoadedPolicy updated : policyEngine.getNotification().getLoadedPolicies()) {
171 System.out.println(updated.getPolicyName());
172 System.out.println(updated.getVersionNo());
173 System.out.println(updated.getMatches());
175 for (RemovedPolicy removed : policyEngine.getNotification()
176 .getRemovedPolicies()) {
177 System.out.println(removed.getPolicyName());
178 System.out.println(removed.getVersionNo());
183 * This function makes API call to policy engine to get automatic
186 * @param org.openecomp.policyEngine
188 public static void getAutoNotifications(PolicyEngine policyEngine) {
189 Handler handler = new Handler();
190 policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS,
193 System.out.println("Enter a any key to exit");
196 } catch (IOException e) {