0ebff497cb257e5b3de07f4d4b7d51c02e035f37
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.examples.adaptive.model;
24
25 import lombok.AccessLevel;
26 import lombok.NoArgsConstructor;
27 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
28 import org.onap.policy.apex.model.basicmodel.handling.ApexModelSaver;
29 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
30 import org.slf4j.ext.XLogger;
31 import org.slf4j.ext.XLoggerFactory;
32
33 /**
34  * This class saves sample domain models to disk in XML and JSON format.
35  *
36  * @author Liam Fallon (liam.fallon@ericsson.com)
37  */
38 @NoArgsConstructor(access = AccessLevel.PRIVATE)
39 public final class AdaptiveDomainModelSaver {
40     // Logger for this class
41     private static final XLogger LOGGER = XLoggerFactory.getXLogger(AdaptiveDomainModelSaver.class);
42
43     /**
44      * Write the AADM model to args[0].
45      *
46      * @param args Not used
47      * @throws ApexException the apex exception
48      */
49     public static void main(final String[] args) throws ApexException {
50         if (args.length != 1) {
51             LOGGER.error("usage: " + AdaptiveDomainModelSaver.class.getName() + " modelDirectory");
52             return;
53         }
54
55         // Save Anomaly Detection model
56         final AxPolicyModel adPolicyModel = new AdaptiveDomainModelFactory().getAnomalyDetectionPolicyModel();
57         final ApexModelSaver<AxPolicyModel> adModelSaver = new ApexModelSaver<>(AxPolicyModel.class, adPolicyModel,
58                         args[0]);
59         adModelSaver.apexModelWriteJson();
60         adModelSaver.apexModelWriteXml();
61
62         // Save Auto Learn model
63         final AxPolicyModel alPolicyModel = new AdaptiveDomainModelFactory().getAutoLearnPolicyModel();
64         final ApexModelSaver<AxPolicyModel> alModelSaver = new ApexModelSaver<>(AxPolicyModel.class, alPolicyModel,
65                         args[0]);
66         alModelSaver.apexModelWriteJson();
67         alModelSaver.apexModelWriteXml();
68     }
69 }