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=========================================================
21 package org.openecomp.policyEngine;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.HashMap;
27 import java.util.UUID;
29 import org.openecomp.policy.api.AttributeType;
30 import org.openecomp.policy.api.PolicyChangeResponse;
31 import org.openecomp.policy.api.PolicyConfigType;
32 import org.openecomp.policy.api.PolicyEngine;
33 import org.openecomp.policy.api.PolicyParameters;
36 public class BrmsParamPolicyClient {
38 public static void main(String[] args) {
41 PolicyEngine policyEngine = new PolicyEngine("config.properties");
43 PolicyParameters policyParameters = new PolicyParameters();
45 // Set Policy Type(Mandatory)
46 policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
48 // Set Policy Name(Mandatory)
49 policyParameters.setPolicyName("Lakshman.testParamPolicyThree");
51 // Set Safe Policy value for Risk Type
52 SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
53 Date date = dateformat3.parse("15/10/2016");
54 policyParameters.setTtlDate(date);
55 // Set Safe Policy value for Guard
56 policyParameters.setGuard(true);
57 // Set Safe Policy value for Risk Level
58 policyParameters.setRiskLevel("5");
59 // Set Safe Policy value for Risk Type
60 policyParameters.setRiskType("PROD");
62 // Set description of the policy(Optional)
63 policyParameters.setPolicyDescription("This is a sample BRMS Param policy creation example");
65 //Set Scope folder where the policy needs to be created(Mandatory)
66 //policyParameters.setPolicyScope("Lakshman");
68 // Set BRMS Param Template Attributes(Mandatory)
69 Map<String, String> ruleAttributes = new HashMap<String, String>();
70 ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary.
71 ruleAttributes.put("controller", "default"); // Set Rule to a PDP Controller, default is the controller name.
72 ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us.
73 ruleAttributes.put("value", "abcd"); // Template specific key and value set by us.
74 Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>();
75 attributes.put(AttributeType.RULE, ruleAttributes);
76 policyParameters.setAttributes(attributes);
78 //Set a random UUID(Mandatory)
79 policyParameters.setRequestID(UUID.randomUUID());
81 // CreatePolicy method to create Policy.
83 PolicyChangeResponse response = policyEngine.updatePolicy(policyParameters);
85 if(response.getResponseCode()==200){
87 System.out.println(response.getResponseMessage());
89 System.out.println("Policy Created Successfully!");
93 System.out.println("Error! " + response.getResponseMessage());
97 } catch (Exception e) {
99 System.err.println(e.getMessage());