2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
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.ccsdk.sli.core.sli.recording;
24 import java.io.FileWriter;
25 import java.io.PrintWriter;
26 import java.text.DateFormat;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
30 import java.util.TimeZone;
32 import org.onap.ccsdk.sli.core.sli.ConfigurationException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
37 public class FileRecorder implements SvcLogicRecorder {
40 public void record(Map<String, String> parmMap) throws SvcLogicException {
42 String fileName = parmMap.get("file");
45 throw new ConfigurationException("No file parameter specified");
48 String record = parmMap.get("record");
51 String delimiter = parmMap.get("delimiter");
52 if (delimiter == null)
58 boolean moreFields = true;
61 String curField = parmMap.get("field"+idx++);
72 record = record + curField + delimiter;
79 throw new ConfigurationException("No record/fields passed in record node");
82 File recordFile = new File(fileName);
83 PrintWriter recPrinter = null;
84 Date now = new Date();
86 TimeZone tz = TimeZone.getTimeZone("UTC");
87 DateFormat dateFmt = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss:SS'+00:00'");
88 dateFmt.setTimeZone(tz);
89 if (record.indexOf("__TIMESTAMP__") != -1)
91 record = record.replaceFirst("__TIMESTAMP__", dateFmt.format(now));
97 recPrinter = new PrintWriter(new FileWriter(recordFile, true));
98 recPrinter.println(record);
102 throw new SvcLogicException("Cannot write record to file", e);
106 if (recPrinter != null)