3d80fe2ef9f52adc84ae8daa54f5a48e2ad7d3df
[policy/engine.git] / PolicyEngineClient / src / main / java / org / openecomp / policyEngine / BrmsParamPolicyClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineClient
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policyEngine;
22
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.UUID;
28
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;
34
35
36 public class BrmsParamPolicyClient {
37         
38         public static void main(String[] args) {
39                 try {
40
41             PolicyEngine policyEngine = new PolicyEngine("config.properties");
42
43             PolicyParameters policyParameters = new PolicyParameters();
44
45             // Set Policy Type(Mandatory) 
46             policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
47             
48             // Set Policy Name(Mandatory) 
49             policyParameters.setPolicyName("Lakshman.testParamPolicyThree");
50             
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");
61             
62             // Set description of the policy(Optional)
63             policyParameters.setPolicyDescription("This is a sample BRMS Param policy creation example");
64             
65             //Set Scope folder where the policy needs to be created(Mandatory)
66             //policyParameters.setPolicyScope("Lakshman");
67
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);
77             
78             //Set a random UUID(Mandatory)
79             policyParameters.setRequestID(UUID.randomUUID());
80
81             // CreatePolicy method to create Policy. 
82
83             PolicyChangeResponse response = policyEngine.updatePolicy(policyParameters);
84
85             if(response.getResponseCode()==200){
86
87                 System.out.println(response.getResponseMessage());
88
89                 System.out.println("Policy Created Successfully!");
90
91             }else{
92
93                 System.out.println("Error! " + response.getResponseMessage());
94
95             }
96
97         } catch (Exception e) {
98
99             System.err.println(e.getMessage());
100
101         }
102                 
103         }
104         
105 }
106
107