bobpaulin commented on code in PR #11872:
URL: https://github.com/apache/nifi/pull/11872#discussion_r4459646363


##########
nifi-system-tests/nifi-system-test-extensions2-bundle/nifi-system-test-extensions2/src/main/java/org/apache/nifi/connectors/tests/system/FileConnectorConfigurationProvider.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.nifi.connectors.tests.system;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.components.connector.ConnectorConfigurationProvider;
+import 
org.apache.nifi.components.connector.ConnectorConfigurationProviderInitializationContext;
+import org.apache.nifi.components.connector.ConnectorSyncDirective;
+import org.apache.nifi.components.connector.ConnectorWorkingConfiguration;
+import org.apache.nifi.flow.VersionedConnectorState;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+
+/**
+ * File-backed provider used by upgrade-drain system tests. {@code load} and 
{@code getSyncDirective} return the live
+ * configuration when present and the committed configuration otherwise. 
{@code save} writes live configuration and
+ * {@code discard} removes it.
+ */
+public class FileConnectorConfigurationProvider implements 
ConnectorConfigurationProvider {
+
+    public static final String STATE_DIRECTORY_PROPERTY = "state.directory";
+
+    private final ObjectMapper objectMapper = new ObjectMapper();
+    private Path stateDirectory;
+
+    @Override
+    public synchronized void initialize(final 
ConnectorConfigurationProviderInitializationContext context) {
+        final String configuredDirectory = 
context.getProperties().get(STATE_DIRECTORY_PROPERTY);
+        if (configuredDirectory == null || configuredDirectory.isBlank()) {
+            throw new 
IllegalStateException("FileConnectorConfigurationProvider requires " + 
STATE_DIRECTORY_PROPERTY);
+        }
+        stateDirectory = Path.of(configuredDirectory);
+        try {
+            Files.createDirectories(stateDirectory);
+        } catch (final IOException e) {
+            throw new IllegalStateException("Unable to create provider state 
directory " + stateDirectory, e);
+        }
+    }
+
+    @Override
+    public synchronized Optional<ConnectorWorkingConfiguration> load(final 
String connectorId) {
+        return readCurrent(connectorId);
+    }
+
+    @Override
+    public synchronized void save(final String connectorId, final 
ConnectorWorkingConfiguration configuration) {
+        writeAtomically(liveConfiguration(connectorId), configuration);
+    }
+
+    @Override
+    public synchronized void discard(final String connectorId) {
+        try {
+            Files.deleteIfExists(liveConfiguration(connectorId));
+        } catch (final IOException e) {
+            throw new IllegalStateException("Unable to discard live 
configuration for " + connectorId, e);
+        }
+    }
+
+    @Override
+    public synchronized void delete(final String connectorId) {
+        try {
+            Files.deleteIfExists(liveConfiguration(connectorId));
+            Files.deleteIfExists(committedConfiguration(connectorId));

Review Comment:
   This is a. test support class.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to