Remove outdated doc for A1 Adaptor
[integration.git] / test / mocks / masspnfsim / pnf-sim-lightweight / src / main / java / org / onap / pnfsimulator / netconfmonitor / netconf / NetconfConfigurationWriter.java
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA 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.onap.pnfsimulator.netconfmonitor.netconf;
22
23 import java.io.BufferedWriter;
24 import java.io.FileWriter;
25 import java.io.IOException;
26 import java.text.DateFormat;
27 import java.text.SimpleDateFormat;
28 import org.onap.pnfsimulator.rest.util.DateUtil;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class NetconfConfigurationWriter {
33
34     private static final Logger LOGGER = LoggerFactory.getLogger(NetconfConfigurationWriter.class);
35     private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
36     private String pathToLog;
37
38     public NetconfConfigurationWriter(String pathToLog) {
39         this.pathToLog = pathToLog;
40     }
41
42     public void writeToFile(String configuration) {
43         String fileName = String.format("%s/config[%s].xml", pathToLog, DateUtil.getTimestamp(dateFormat));
44         try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) {
45             writer.write(configuration);
46             LOGGER.info("Configuration wrote to file {}/{} ", pathToLog, fileName);
47         } catch (IOException e) {
48             LOGGER.warn("Failed to write configuration to file: {}", e.getMessage());
49         }
50     }
51 }