1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.service.engine.event.impl.filecarrierplugin;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.common.utils.resources.ResourceUtils;
/**
* This class holds the parameters that allows transport of events into and out of Apex using files and standard input
* and output.
*
* <p>The following parameters are defined: <ol> <li>fileName: The full path to the file from which to read events or to
* which to write events. <li>standardIO: If this flag is set to true, then standard input is used to read events in or
* standard output is used to write events and the fileName parameter is ignored if present <li>standardError: If this
* flag is set to true, then standard error is used to write events <li>streamingMode: If this flag is set to true, then
* streaming mode is set for reading events and event handling will wait on the input stream for events until the stream
* is closed. If streaming model is off, then event reading completes when the end of input is detected. <li>startDelay:
* The amount of milliseconds to wait at startup startup before processing the first event. </ol>
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters {
// @formatter:off
/** The label of this carrier technology. */
public static final String FILE_CARRIER_TECHNOLOGY_LABEL = "FILE";
/** The producer plugin class for the FILE carrier technology. */
public static final String FILE_EVENT_PRODUCER_PLUGIN_CLASS = ApexFileEventProducer.class.getCanonicalName();
/** The consumer plugin class for the FILE carrier technology. */
public static final String FILE_EVENT_CONSUMER_PLUGIN_CLASS = ApexFileEventConsumer.class.getCanonicalName();
private String fileName;
private boolean standardIo = false;
private boolean standardError = false;
private boolean streamingMode = false;
private long startDelay = 0;
// @formatter:on
/**
* Constructor to create a file carrier technology parameters instance and register the instance with the parameter
* service.
*/
public FileCarrierTechnologyParameters() {
super();
// Set the carrier technology properties for the FILE carrier technology
this.setLabel(FILE_CARRIER_TECHNOLOGY_LABEL);
this.setEventProducerPluginClass(FILE_EVENT_PRODUCER_PLUGIN_CLASS);
this.setEventConsumerPluginClass(FILE_EVENT_CONSUMER_PLUGIN_CLASS);
}
/**
* Gets the file name from which to read or to which to write events.
*
* @return the file name from which to read or to which to write events
*/
public String getFileName() {
return ResourceUtils.getFilePath4Resource(fileName);
}
/**
* Checks if is standard IO should be used for input or output.
*
* @return true, if standard IO should be used for input or output
*/
public boolean isStandardIo() {
return standardIo;
}
/**
* Checks if is standard error should be used for output.
*
* @return true, if standard error should be used for output
*/
public boolean isStandardError() {
return standardError;
}
/**
* Checks if is streaming mode is on.
*
* @return true, if streaming mode is on
*/
public boolean isStreamingMode() {
return streamingMode;
}
/**
* Sets the file name from which to read or to which to write events.
*
* @param fileName the file name from which to read or to which to write events
*/
public void setFileName(final String fileName) {
this.fileName = fileName;
}
/**
* Sets if standard IO should be used for event input or output.
*
* @param standardIo if standard IO should be used for event input or output
*/
public void setStandardIo(final boolean standardIo) {
this.standardIo = standardIo;
}
/**
* Sets if standard error should be used for event output.
*
* @param standardError if standard error should be used for event output
*/
public void setStandardError(final boolean standardError) {
this.standardError = standardError;
}
/**
* Sets streaming mode.
*
* @param streamingMode the streaming mode value
*/
public void setStreamingMode(final boolean streamingMode) {
this.streamingMode = streamingMode;
}
/**
* Gets the delay in milliseconds before the plugin starts processing.
*
* @return the delay
*/
public long getStartDelay() {
return startDelay;
}
/**
* Sets the delay in milliseconds before the plugin starts processing.
*
* @param startDelay the delay
*/
public void setStartDelay(final long startDelay) {
this.startDelay = startDelay;
}
/*
* (non-Javadoc)
*
* @see org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters# toString()
*/
@Override
public String toString() {
return "FILECarrierTechnologyParameters [fileName=" + fileName + ", standardIO=" + standardIo
+ ", standardError=" + standardError + ", streamingMode=" + streamingMode + ", startDelay="
+ startDelay + "]";
}
/*
* (non-Javadoc)
*
* @see org.onap.policy.common.parameters.ParameterGroup#getName()
*/
@Override
public String getName() {
return this.getLabel();
}
/*
* (non-Javadoc)
*
* @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
*/
@Override
public GroupValidationResult validate() {
final GroupValidationResult result = super.validate();
if (!standardIo && !standardError && (fileName == null || fileName.trim().length() == 0)) {
result.setResult("fileName", ValidationStatus.INVALID, "fileName not specified or is blank or null, "
+ "it must be specified as a valid file location");
}
if (standardIo || standardError) {
streamingMode = true;
}
if (startDelay < 0) {
result.setResult("startDelay", ValidationStatus.INVALID,
"startDelay must be zero or a positive number of milliseconds");
}
return result;
}
}
|