|
48 | 48 | import org.eclipse.milo.opcua.sdk.client.api.identity.UsernameProvider; |
49 | 49 | import org.eclipse.milo.opcua.sdk.server.OpcUaServer; |
50 | 50 | import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy; |
| 51 | +import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode; |
51 | 52 | import org.slf4j.Logger; |
52 | 53 | import org.slf4j.LoggerFactory; |
53 | 54 |
|
|
68 | 69 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_IOTDB_USERNAME_KEY; |
69 | 70 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_IOTDB_USER_DEFAULT_VALUE; |
70 | 71 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_IOTDB_USER_KEY; |
| 72 | +import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_OPC_UA_DEFAULT_QUALITY_BAD_VALUE; |
| 73 | +import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_OPC_UA_DEFAULT_QUALITY_GOOD_VALUE; |
| 74 | +import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_OPC_UA_DEFAULT_QUALITY_KEY; |
| 75 | +import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_OPC_UA_DEFAULT_QUALITY_UNCERTAIN_VALUE; |
71 | 76 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_OPC_UA_ENABLE_ANONYMOUS_ACCESS_DEFAULT_VALUE; |
72 | 77 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_OPC_UA_ENABLE_ANONYMOUS_ACCESS_KEY; |
73 | 78 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.CONNECTOR_OPC_UA_HISTORIZING_DEFAULT_VALUE; |
|
102 | 107 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.SINK_IOTDB_PASSWORD_KEY; |
103 | 108 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.SINK_IOTDB_USERNAME_KEY; |
104 | 109 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.SINK_IOTDB_USER_KEY; |
| 110 | +import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.SINK_OPC_UA_DEFAULT_QUALITY_KEY; |
105 | 111 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.SINK_OPC_UA_ENABLE_ANONYMOUS_ACCESS_KEY; |
106 | 112 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.SINK_OPC_UA_HISTORIZING_KEY; |
107 | 113 | import static org.apache.iotdb.commons.pipe.config.constant.PipeSinkConstant.SINK_OPC_UA_HTTPS_BIND_PORT_KEY; |
@@ -133,11 +139,12 @@ public class OpcUaSink implements PipeConnector { |
133 | 139 | SERVER_KEY_TO_REFERENCE_COUNT_AND_NAME_SPACE_MAP = new ConcurrentHashMap<>(); |
134 | 140 |
|
135 | 141 | private String serverKey; |
136 | | - boolean isClientServerModel; |
137 | | - String databaseName; |
138 | | - String placeHolder; |
139 | | - @Nullable String valueName; |
140 | | - @Nullable String qualityName; |
| 142 | + private boolean isClientServerModel; |
| 143 | + private String databaseName; |
| 144 | + private String placeHolder; |
| 145 | + private @Nullable String valueName; |
| 146 | + private @Nullable String qualityName; |
| 147 | + private StatusCode defaultQuality; |
141 | 148 |
|
142 | 149 | // Inner server |
143 | 150 | private @Nullable OpcUaNameSpace nameSpace; |
@@ -203,6 +210,14 @@ public void customize( |
203 | 210 | Arrays.asList(CONNECTOR_OPC_UA_QUALITY_NAME_KEY, SINK_OPC_UA_QUALITY_NAME_KEY), |
204 | 211 | CONNECTOR_OPC_UA_QUALITY_NAME_DEFAULT_VALUE) |
205 | 212 | : null; |
| 213 | + defaultQuality = |
| 214 | + getQuality( |
| 215 | + withQuality |
| 216 | + ? parameters.getStringOrDefault( |
| 217 | + Arrays.asList( |
| 218 | + CONNECTOR_OPC_UA_DEFAULT_QUALITY_KEY, SINK_OPC_UA_DEFAULT_QUALITY_KEY), |
| 219 | + CONNECTOR_OPC_UA_DEFAULT_QUALITY_UNCERTAIN_VALUE) |
| 220 | + : CONNECTOR_OPC_UA_DEFAULT_QUALITY_GOOD_VALUE); |
206 | 221 | isClientServerModel = |
207 | 222 | parameters |
208 | 223 | .getStringOrDefault( |
@@ -396,6 +411,19 @@ private SecurityPolicy getSecurityPolicy(final String securityPolicy) { |
396 | 411 | } |
397 | 412 | } |
398 | 413 |
|
| 414 | + private StatusCode getQuality(final String quality) { |
| 415 | + switch (quality.toUpperCase()) { |
| 416 | + case CONNECTOR_OPC_UA_DEFAULT_QUALITY_GOOD_VALUE: |
| 417 | + return StatusCode.GOOD; |
| 418 | + case CONNECTOR_OPC_UA_DEFAULT_QUALITY_BAD_VALUE: |
| 419 | + return StatusCode.BAD; |
| 420 | + case CONNECTOR_OPC_UA_DEFAULT_QUALITY_UNCERTAIN_VALUE: |
| 421 | + return StatusCode.UNCERTAIN; |
| 422 | + default: |
| 423 | + throw new PipeException("The default quality can only be 'GOOD', 'BAD' or 'UNCERTAIN'."); |
| 424 | + } |
| 425 | + } |
| 426 | + |
399 | 427 | @Override |
400 | 428 | public void handshake() throws Exception { |
401 | 429 | // Server side, do nothing |
@@ -538,4 +566,8 @@ public String getValueName() { |
538 | 566 | public String getQualityName() { |
539 | 567 | return qualityName; |
540 | 568 | } |
| 569 | + |
| 570 | + public StatusCode getDefaultQuality() { |
| 571 | + return defaultQuality; |
| 572 | + } |
541 | 573 | } |
0 commit comments