2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 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;
42 * @param args String[] args
44 public static void main(String[] args) {
46 PolicyEngine policyEngine = new PolicyEngine("config.properties");
47 PolicyParameters policyParameters = new PolicyParameters();
49 policyParameters.setPolicyConfigType(PolicyConfigType.Base); // required
50 policyParameters.setPolicyName("MikeConsole.testDeleteAPI6"); // required
51 policyParameters.setPolicyDescription("This is a sample Config Base policy creation example"); // optional
52 policyParameters.setOnapName("DCAE"); // required
53 policyParameters.setConfigName("testBase"); // required
54 policyParameters.setConfigBodyType(PolicyType.OTHER); // required
55 policyParameters.setConfigBody("testing"); // required
57 // Set the Config Attributes... These are Optional
58 Map<String, String> configAttributes = new HashMap<>();
59 configAttributes.put("Template", "SampleTemplate");
60 configAttributes.put("controller", "default");
61 configAttributes.put("SamPoll", "30");
62 configAttributes.put("value", "abcd");
63 Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
64 attributes.put(AttributeType.MATCHING, configAttributes);
65 policyParameters.setAttributes(attributes);
66 policyParameters.setRequestID(UUID.randomUUID());
67 // Set Safe Policy value for Risk Type
68 SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
69 Date date = dateformat3.parse("15/10/2016");
70 policyParameters.setTtlDate(date);
71 // Set Safe Policy value for Guard
72 policyParameters.setGuard(true);
73 // Set Safe Policy value for Risk Level
74 policyParameters.setRiskLevel("5");
75 // Set Safe Policy value for Risk Type
76 policyParameters.setRiskType("PROD");
78 // API method to create Policy or update policy
79 PolicyChangeResponse response = null;
81 response = policyEngine.createPolicy(policyParameters);
83 response = policyEngine.updatePolicy(policyParameters);
86 if (response.getResponseCode() == 200) {
87 System.out.println(response.getResponseMessage());
88 System.out.println("Policy Created Successfully!");
90 System.out.println("Error! " + response.getResponseMessage());
92 } catch (Exception e) {
93 System.err.println(e.getMessage());