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.onap.policyengine;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.HashMap;
27 import java.util.UUID;
29 import org.onap.policy.api.AttributeType;
30 import org.onap.policy.api.PolicyChangeResponse;
31 import org.onap.policy.api.PolicyConfigType;
32 import org.onap.policy.api.PolicyEngine;
33 import org.onap.policy.api.PolicyParameters;
34 import org.onap.policy.api.PolicyType;
36 public class ConfigBasePolicyClient{
37 static Boolean isEdit = false;
38 public static void main(String[] args) {
40 PolicyEngine policyEngine = new PolicyEngine("config.properties");
41 PolicyParameters policyParameters = new PolicyParameters();
43 policyParameters.setPolicyConfigType(PolicyConfigType.Base); //required
44 policyParameters.setPolicyName("MikeConsole.testDeleteAPI6"); //required
45 policyParameters.setPolicyDescription("This is a sample Config Base policy creation example"); //optional
46 policyParameters.setOnapName("DCAE"); //required
47 policyParameters.setConfigName("testBase"); //required
48 policyParameters.setConfigBodyType(PolicyType.OTHER); //required
49 policyParameters.setConfigBody("testing"); //required
51 //Set the Config Attributes... These are Optional
52 Map<String, String> configAttributes = new HashMap<>();
53 configAttributes.put("Template", "SampleTemplate");
54 configAttributes.put("controller", "default");
55 configAttributes.put("SamPoll", "30");
56 configAttributes.put("value", "abcd");
57 Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
58 attributes.put(AttributeType.MATCHING, configAttributes);
59 policyParameters.setAttributes(attributes);
60 policyParameters.setRequestID(UUID.randomUUID());
61 // Set Safe Policy value for Risk Type
62 SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
63 Date date = dateformat3.parse("15/10/2016");
64 policyParameters.setTtlDate(date);
65 // Set Safe Policy value for Guard
66 policyParameters.setGuard(true);
67 // Set Safe Policy value for Risk Level
68 policyParameters.setRiskLevel("5");
69 // Set Safe Policy value for Risk Type
70 policyParameters.setRiskType("PROD");
72 // API method to create Policy or update policy
73 PolicyChangeResponse response = null;
75 response = policyEngine.createPolicy(policyParameters);
77 response = policyEngine.updatePolicy(policyParameters);
80 if(response.getResponseCode()==200){
81 System.out.println(response.getResponseMessage());
82 System.out.println("Policy Created Successfully!");
84 System.out.println("Error! " + response.getResponseMessage());
86 } catch (Exception e) {
87 System.err.println(e.getMessage());