http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/common/CommonPropertyKeys.java ---------------------------------------------------------------------- diff --git a/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/common/CommonPropertyKeys.java b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/common/CommonPropertyKeys.java new file mode 100644 index 0000000..5c3a432 --- /dev/null +++ b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/common/CommonPropertyKeys.java @@ -0,0 +1,50 @@ +/* + * 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.minifi.commons.schema.common; + +public class CommonPropertyKeys { + public static final String CORE_PROPS_KEY = "Core Properties"; + public static final String FLOWFILE_REPO_KEY = "FlowFile Repository"; + public static final String SWAP_PROPS_KEY = "Swap"; + public static final String FLOW_CONTROLLER_PROPS_KEY = "Flow Controller"; + public static final String CONTENT_REPO_KEY = "Content Repository"; + public static final String COMPONENT_STATUS_REPO_KEY = "Component Status Repository"; + public static final String SECURITY_PROPS_KEY = "Security Properties"; + public static final String SENSITIVE_PROPS_KEY = "Sensitive Props"; + public static final String PROCESSORS_KEY = "Processors"; + public static final String CONNECTIONS_KEY = "Connections"; + public static final String PROVENANCE_REPORTING_KEY = "Provenance Reporting"; + public static final String REMOTE_PROCESSING_GROUPS_KEY = "Remote Processing Groups"; + public static final String INPUT_PORTS_KEY = "Input Ports"; + public static final String PROVENANCE_REPO_KEY = "Provenance Repository"; + + + public static final String NAME_KEY = "name"; + public static final String COMMENT_KEY = "comment"; + public static final String ALWAYS_SYNC_KEY = "always sync"; + public static final String YIELD_PERIOD_KEY = "yield period"; + public static final String MAX_CONCURRENT_THREADS_KEY = "max concurrent threads"; + public static final String MAX_CONCURRENT_TASKS_KEY = "max concurrent tasks"; + public static final String ID_KEY = "id"; + public static final String SCHEDULING_STRATEGY_KEY = "scheduling strategy"; + public static final String SCHEDULING_PERIOD_KEY = "scheduling period"; + public static final String USE_COMPRESSION_KEY = "use compression"; + + private CommonPropertyKeys() { + } +}
http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/exception/SchemaLoaderException.java ---------------------------------------------------------------------- diff --git a/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/exception/SchemaLoaderException.java b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/exception/SchemaLoaderException.java new file mode 100644 index 0000000..72adba4 --- /dev/null +++ b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/exception/SchemaLoaderException.java @@ -0,0 +1,24 @@ +/* + * 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.minifi.commons.schema.exception; + +public class SchemaLoaderException extends Exception { + public SchemaLoaderException(String message) { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/ConfigRepresenter.java ---------------------------------------------------------------------- diff --git a/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/ConfigRepresenter.java b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/ConfigRepresenter.java new file mode 100644 index 0000000..56da732 --- /dev/null +++ b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/ConfigRepresenter.java @@ -0,0 +1,27 @@ +/* + * 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.minifi.commons.schema.serialization; + +import org.yaml.snakeyaml.nodes.Tag; +import org.yaml.snakeyaml.representer.Representer; + +public class ConfigRepresenter extends Representer { + public ConfigRepresenter() { + nullRepresenter = data -> representScalar(Tag.NULL, ""); + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/SchemaLoader.java ---------------------------------------------------------------------- diff --git a/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/SchemaLoader.java b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/SchemaLoader.java new file mode 100644 index 0000000..88d501c --- /dev/null +++ b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/SchemaLoader.java @@ -0,0 +1,53 @@ +/* + * 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.minifi.commons.schema.serialization; + +import org.apache.nifi.minifi.commons.schema.ConfigSchema; +import org.apache.nifi.minifi.commons.schema.exception.SchemaLoaderException; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.error.YAMLException; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +public class SchemaLoader { + public static Map<String, Object> loadYamlAsMap(InputStream sourceStream) throws IOException, SchemaLoaderException { + try { + Yaml yaml = new Yaml(); + + // Parse the YAML file + final Object loadedObject = yaml.load(sourceStream); + + // Verify the parsed object is a Map structure + if (loadedObject instanceof Map) { + return (Map<String, Object>) loadedObject; + } else { + throw new SchemaLoaderException("Provided YAML configuration is not a Map"); + } + } catch (YAMLException e ) { + throw new IOException(e); + } finally { + sourceStream.close(); + } + } + + public static ConfigSchema loadConfigSchemaFromYaml(InputStream sourceStream) throws IOException, SchemaLoaderException { + return new ConfigSchema(loadYamlAsMap(sourceStream)); + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/SchemaSaver.java ---------------------------------------------------------------------- diff --git a/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/SchemaSaver.java b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/SchemaSaver.java new file mode 100644 index 0000000..fba71ef --- /dev/null +++ b/minifi-commons/minifi-commons-schema/src/main/java/org/apache/nifi/minifi/commons/schema/serialization/SchemaSaver.java @@ -0,0 +1,46 @@ +/* + * 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.minifi.commons.schema.serialization; + +import org.apache.nifi.minifi.commons.schema.ConfigSchema; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.error.YAMLException; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.Map; + +public class SchemaSaver { + public static void saveConfigSchema(ConfigSchema configSchema, OutputStream output) throws IOException { + DumperOptions dumperOptions = new DumperOptions(); + dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + + Yaml yaml = new Yaml(new ConfigRepresenter(), dumperOptions); + + Map<String, Object> yamlMap = configSchema.toMap(); + try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(output)) { + try { + yaml.dump(yamlMap, outputStreamWriter); + } catch (YAMLException e) { + throw new IOException(e); + } + } + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-commons/minifi-commons-schema/src/test/java/org/apache/nifi/minifi/commons/schema/SecurityPropertiesSchemaTest.java ---------------------------------------------------------------------- diff --git a/minifi-commons/minifi-commons-schema/src/test/java/org/apache/nifi/minifi/commons/schema/SecurityPropertiesSchemaTest.java b/minifi-commons/minifi-commons-schema/src/test/java/org/apache/nifi/minifi/commons/schema/SecurityPropertiesSchemaTest.java new file mode 100644 index 0000000..093adb7 --- /dev/null +++ b/minifi-commons/minifi-commons-schema/src/test/java/org/apache/nifi/minifi/commons/schema/SecurityPropertiesSchemaTest.java @@ -0,0 +1,80 @@ +/* + * 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.minifi.commons.schema; + +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class SecurityPropertiesSchemaTest { + private SecurityPropertiesSchema securityPropertiesSchema; + + @Before + public void setup() { + securityPropertiesSchema = new SecurityPropertiesSchema(new HashMap()); + } + + @Test + public void testKeystoreDefault() { + assertEquals("", securityPropertiesSchema.getKeystore()); + } + + @Test + public void testTruststoreDefault() { + assertEquals("", securityPropertiesSchema.getTruststore()); + } + + @Test + public void testSslProtocolDefault() { + assertEquals("", securityPropertiesSchema.getSslProtocol()); + } + + @Test + public void testKeystoreTypeDefault() { + assertEquals("", securityPropertiesSchema.getKeystoreType()); + } + + @Test + public void testKeyStorePasswdDefault() { + assertEquals("", securityPropertiesSchema.getKeystorePassword()); + } + + @Test + public void testKeyPasswordDefault() { + assertEquals("", securityPropertiesSchema.getKeyPassword()); + } + + @Test + public void testTruststoreTypeDefault() { + assertEquals("", securityPropertiesSchema.getTruststoreType()); + } + + @Test + public void testTruststorePasswdDefault() { + assertEquals("", securityPropertiesSchema.getTruststorePassword()); + } + + @Test + public void testEmptyMapConstructorValid() { + assertTrue(securityPropertiesSchema.isValid()); + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-commons/pom.xml ---------------------------------------------------------------------- diff --git a/minifi-commons/pom.xml b/minifi-commons/pom.xml index 8d44c71..4dc9e1a 100644 --- a/minifi-commons/pom.xml +++ b/minifi-commons/pom.xml @@ -28,8 +28,7 @@ limitations under the License. <packaging>pom</packaging> <modules> + <module>minifi-commons-schema</module> <module>minifi-utils</module> </modules> - - -</project> \ No newline at end of file +</project> http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-assembly/LICENSE ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-assembly/LICENSE b/minifi-toolkit/minifi-toolkit-assembly/LICENSE new file mode 100644 index 0000000..9864230 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-assembly/LICENSE @@ -0,0 +1,236 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + +APACHE NIFI - MINIFI SUBCOMPONENTS: + +The Apache NiFi - MiNiFi project contains subcomponents with separate copyright +notices and license terms. Your use of the source code for the these +subcomponents is subject to the terms and conditions of the following +licenses. + + + The binary distribution of this product bundles 'Slf4j' which is available + under a "3-clause BSD" license. For details see http://www.slf4j.org/ + + Copyright (c) 2004-2013 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-assembly/NOTICE ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-assembly/NOTICE b/minifi-toolkit/minifi-toolkit-assembly/NOTICE new file mode 100644 index 0000000..4ec8741 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-assembly/NOTICE @@ -0,0 +1,23 @@ +Apache NiFi +Copyright 2014-2016 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +=========================================== +Apache Software License v2 +=========================================== + +The following binary components are provided under the Apache Software License v2 + + (ASLv2) Apache NiFi + The following NOTICE information applies: + Apache NiFi + Copyright 2014-2016 The Apache Software Foundation + + This product includes software developed at + The Apache Software Foundation (http://www.apache.org/). + + This product includes the following work from the Apache Hadoop project: + + BoundedByteArrayOutputStream.java adapted to SoftLimitBoundedByteArrayOutputStream.java \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-assembly/pom.xml ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-assembly/pom.xml b/minifi-toolkit/minifi-toolkit-assembly/pom.xml new file mode 100644 index 0000000..fee94bf --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-assembly/pom.xml @@ -0,0 +1,68 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>minifi-toolkit</artifactId> + <groupId>org.apache.nifi.minifi</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>minifi-toolkit-assembly</artifactId> + <packaging>pom</packaging> + <description>This is the assembly of Apache NiFi's - MiNiFi Toolkit</description> + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <finalName>minifi-${project.version}</finalName> + <attach>false</attach> + </configuration> + <executions> + <execution> + <id>make shared resource</id> + <goals> + <goal>single</goal> + </goals> + <phase>package</phase> + <configuration> + <archiverConfig> + <defaultDirectoryMode>0755</defaultDirectoryMode> + <directoryMode>0755</directoryMode> + <fileMode>0644</fileMode> + </archiverConfig> + <descriptors> + <descriptor>src/main/assembly/dependencies.xml</descriptor> + </descriptors> + <tarLongFileMode>posix</tarLongFileMode> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.nifi.minifi</groupId> + <artifactId>minifi-toolkit-configuration</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-assembly/src/main/assembly/dependencies.xml ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-assembly/src/main/assembly/dependencies.xml b/minifi-toolkit/minifi-toolkit-assembly/src/main/assembly/dependencies.xml new file mode 100644 index 0000000..a5aa6d2 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-assembly/src/main/assembly/dependencies.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- + 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. +--> +<assembly> + <id>bin</id> + <formats> + <format>dir</format> + <format>zip</format> + <format>tar.gz</format> + </formats> + <includeBaseDirectory>true</includeBaseDirectory> + <baseDirectory>minifi-toolkit-${project.version}</baseDirectory> + + <dependencySets> + <!-- Write out all dependency artifacts to lib directory --> + <dependencySet> + <outputDirectory>lib</outputDirectory> + <useProjectArtifact>false</useProjectArtifact> + <directoryMode>0770</directoryMode> + <fileMode>0660</fileMode> + </dependencySet> + </dependencySets> + <fileSets> + <fileSet> + <directory>${project.basedir}/src/main/resources</directory> + <outputDirectory>bin/</outputDirectory> + <fileMode>0755</fileMode> + </fileSet> + </fileSets> + <files> + <file> + <source>./LICENSE</source> + <outputDirectory>./</outputDirectory> + <destName>LICENSE</destName> + <fileMode>0644</fileMode> + <filtered>true</filtered> + </file> + <file> + <source>./NOTICE</source> + <outputDirectory>./</outputDirectory> + <destName>NOTICE</destName> + <fileMode>0644</fileMode> + <filtered>true</filtered> + </file> + </files> +</assembly> http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-assembly/src/main/resources/config.bat ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-assembly/src/main/resources/config.bat b/minifi-toolkit/minifi-toolkit-assembly/src/main/resources/config.bat new file mode 100644 index 0000000..596708e --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-assembly/src/main/resources/config.bat @@ -0,0 +1,40 @@ +@echo off +rem +rem Licensed to the Apache Software Foundation (ASF) under one or more +rem contributor license agreements. See the NOTICE file distributed with +rem this work for additional information regarding copyright ownership. +rem The ASF licenses this file to You under the Apache License, Version 2.0 +rem (the "License"); you may not use this file except in compliance with +rem the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. +rem + +rem Use JAVA_HOME if it's set; otherwise, just use java + +if "%JAVA_HOME%" == "" goto noJavaHome +if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome +set JAVA_EXE=%JAVA_HOME%\bin\java.exe +goto startConfig + +:noJavaHome +echo The JAVA_HOME environment variable is not defined correctly. +echo Instead the PATH will be used to find the java executable. +echo. +set JAVA_EXE=java +goto startConfig + +:startConfig +set LIB_DIR=%~dp0..\lib + +SET JAVA_PARAMS=-cp %LIB_DIR%\* -Xms12m -Xmx24m %JAVA_ARGS% org.apache.nifi.minifi.toolkit.configuration.ConfigMain + +cmd.exe /C "%JAVA_EXE%" %JAVA_PARAMS% %* + +popd http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-assembly/src/main/resources/config.sh ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-assembly/src/main/resources/config.sh b/minifi-toolkit/minifi-toolkit-assembly/src/main/resources/config.sh new file mode 100755 index 0000000..cee8a71 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-assembly/src/main/resources/config.sh @@ -0,0 +1,123 @@ +#!/bin/sh +# +# 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. +# +# + +# Script structure inspired from Apache Karaf and other Apache projects with similar startup approaches + +SCRIPT_DIR=$(dirname "$0") +SCRIPT_NAME=$(basename "$0") +MINIFI_TOOLKIT_HOME=$(cd "${SCRIPT_DIR}" && cd .. && pwd) +PROGNAME=$(basename "$0") + + +warn() { + echo "${PROGNAME}: $*" +} + +die() { + warn "$*" + exit 1 +} + +detectOS() { + # OS specific support (must be 'true' or 'false'). + cygwin=false; + aix=false; + os400=false; + darwin=false; + case "$(uname)" in + CYGWIN*) + cygwin=true + ;; + AIX*) + aix=true + ;; + OS400*) + os400=true + ;; + Darwin) + darwin=true + ;; + esac + # For AIX, set an environment variable + if ${aix}; then + export LDR_CNTRL=MAXDATA=0xB0000000@DSA + echo ${LDR_CNTRL} + fi +} + +locateJava() { + # Setup the Java Virtual Machine + if $cygwin ; then + [ -n "${JAVA}" ] && JAVA=$(cygpath --unix "${JAVA}") + [ -n "${JAVA_HOME}" ] && JAVA_HOME=$(cygpath --unix "${JAVA_HOME}") + fi + + if [ "x${JAVA}" = "x" ] && [ -r /etc/gentoo-release ] ; then + JAVA_HOME=$(java-config --jre-home) + fi + if [ "x${JAVA}" = "x" ]; then + if [ "x${JAVA_HOME}" != "x" ]; then + if [ ! -d "${JAVA_HOME}" ]; then + die "JAVA_HOME is not valid: ${JAVA_HOME}" + fi + JAVA="${JAVA_HOME}/bin/java" + else + warn "JAVA_HOME not set; results may vary" + JAVA=$(type java) + JAVA=$(expr "${JAVA}" : '.* \(/.*\)$') + if [ "x${JAVA}" = "x" ]; then + die "java command not found" + fi + fi + fi +} + +init() { + # Determine if there is special OS handling we must perform + detectOS + + # Locate the Java VM to execute + locateJava "$1" +} + +run() { + LIBS="${MINIFI_TOOLKIT_HOME}/lib/*" + + sudo_cmd_prefix="" + if $cygwin; then + MINIFI_TOOLKIT_HOME=$(cygpath --path --windows "${MINIFI_TOOLKIT_HOME}") + CLASSPATH=$(cygpath --path --windows "${LIBS}") + else + CLASSPATH="${LIBS}" + fi + + echo + echo "Java home: ${JAVA_HOME}" + echo "MiNiFi Toolkit home: ${MINIFI_TOOLKIT_HOME}" + echo + echo + + + "${JAVA}" -cp "${CLASSPATH}" -Xms12m -Xmx24m org.apache.nifi.minifi.toolkit.configuration.ConfigMain $@ + return $? +} + + +init "$1" +run "$@" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/pom.xml ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/pom.xml b/minifi-toolkit/minifi-toolkit-configuration/pom.xml new file mode 100644 index 0000000..466d57a --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/pom.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>minifi-toolkit</artifactId> + <groupId>org.apache.nifi.minifi</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>minifi-toolkit-configuration</artifactId> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.nifi.minifi</groupId> + <artifactId>minifi-commons-schema</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-framework-core</artifactId> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/ConfigMain.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/ConfigMain.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/ConfigMain.java new file mode 100644 index 0000000..1d26966 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/ConfigMain.java @@ -0,0 +1,312 @@ +/* + * 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.minifi.toolkit.configuration; + +import org.apache.nifi.minifi.commons.schema.ConfigSchema; +import org.apache.nifi.minifi.commons.schema.common.BaseSchema; +import org.apache.nifi.minifi.commons.schema.serialization.SchemaLoader; +import org.apache.nifi.minifi.commons.schema.serialization.SchemaSaver; +import org.apache.nifi.minifi.commons.schema.exception.SchemaLoaderException; +import org.apache.nifi.minifi.toolkit.configuration.dto.ConfigSchemaFunction; +import org.apache.nifi.web.api.dto.ConnectableDTO; +import org.apache.nifi.web.api.dto.ConnectionDTO; +import org.apache.nifi.web.api.dto.FlowSnippetDTO; +import org.apache.nifi.web.api.dto.NiFiComponentDTO; +import org.apache.nifi.web.api.dto.ProcessorDTO; +import org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO; +import org.apache.nifi.web.api.dto.RemoteProcessGroupDTO; +import org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO; +import org.apache.nifi.web.api.dto.TemplateDTO; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class ConfigMain { + public static final int ERR_INVALID_ARGS = 1; + public static final int ERR_UNABLE_TO_OPEN_OUTPUT = 2; + public static final int ERR_UNABLE_TO_OPEN_INPUT = 3; + public static final int ERR_UNABLE_TO_READ_TEMPLATE = 4; + public static final int ERR_UNABLE_TO_TRANFORM_TEMPLATE = 5; + public static final int ERR_UNABLE_TO_PARSE_CONFIG = 6; + public static final int ERR_INVALID_CONFIG = 7; + + public static final int SUCCESS = 0; + + public static final String TRANSFORM = "transform"; + public static final String VALIDATE = "validate"; + public static final String NO_VALIDATION_ERRORS_FOUND_IN_TEMPLATE = "No validation errors found in template."; + + private final Map<String, Command> commandMap; + private final PathInputStreamFactory pathInputStreamFactory; + private final PathOutputStreamFactory pathOutputStreamFactory; + + public ConfigMain() { + this(FileInputStream::new, FileOutputStream::new); + } + + public ConfigMain(PathInputStreamFactory pathInputStreamFactory, PathOutputStreamFactory pathOutputStreamFactory) { + this.pathInputStreamFactory = pathInputStreamFactory; + this.pathOutputStreamFactory = pathOutputStreamFactory; + this.commandMap = createCommandMap(); + } + + public static void main(String[] args) { + System.exit(new ConfigMain().execute(args)); + } + + public static void printValidateUsage() { + System.out.println("Validate Usage:"); + System.out.println(); + System.out.print("java "); + System.out.print(ConfigMain.class.getCanonicalName()); + System.out.println(" validate INPUT_FILE"); + System.out.println(); + } + + public int validate(String[] args) { + if (args.length != 2) { + printValidateUsage(); + return ERR_INVALID_ARGS; + } + try (InputStream inputStream = pathInputStreamFactory.create(args[1])) { + try { + ConfigSchema configSchema = SchemaLoader.loadConfigSchemaFromYaml(inputStream); + if (!configSchema.isValid()) { + configSchema.getValidationIssues().forEach(s -> System.out.println(s)); + System.out.println(); + return ERR_INVALID_CONFIG; + } else { + System.out.println(NO_VALIDATION_ERRORS_FOUND_IN_TEMPLATE); + } + } catch (IOException|SchemaLoaderException e) { + System.out.println("Unable to load configuration. (" + e + ")"); + System.out.println(); + printValidateUsage(); + return ERR_UNABLE_TO_PARSE_CONFIG; + } + } catch (FileNotFoundException e) { + System.out.println("Unable to open file " + args[1] + " for reading. (" + e + ")"); + System.out.println(); + printValidateUsage(); + return ERR_UNABLE_TO_OPEN_INPUT; + } catch (IOException e) { + System.out.println("Error closing input. (" + e + ")"); + System.out.println(); + } + + return SUCCESS; + } + + public static void printTransformUsage() { + System.out.println("Transform Usage:"); + System.out.println(); + System.out.print("java "); + System.out.print(ConfigMain.class.getCanonicalName()); + System.out.println(" transform INPUT_FILE OUTPUT_FILE"); + System.out.println(); + } + + private static void enrichTemplateDTO(TemplateDTO templateDTO) { + FlowSnippetDTO flowSnippetDTO = templateDTO.getSnippet(); + + Set<RemoteProcessGroupDTO> remoteProcessGroups = flowSnippetDTO.getRemoteProcessGroups(); + if (remoteProcessGroups != null) { + for (RemoteProcessGroupDTO remoteProcessGroupDTO : remoteProcessGroups) { + if (BaseSchema.isNullOrEmpty(remoteProcessGroupDTO.getName())) { + remoteProcessGroupDTO.setName(remoteProcessGroupDTO.getTargetUri()); + } + } + } + Set<ConnectionDTO> connections = flowSnippetDTO.getConnections(); + if (connections != null) { + Map<String, String> connectableNameMap = new HashMap<>(); + Set<ProcessorDTO> processorDTOs = flowSnippetDTO.getProcessors(); + if (processorDTOs != null) { + connectableNameMap.putAll(processorDTOs.stream().collect(Collectors.toMap(NiFiComponentDTO::getId, ProcessorDTO::getName))); + } + + if (remoteProcessGroups != null) { + for (RemoteProcessGroupDTO remoteProcessGroupDTO : remoteProcessGroups) { + RemoteProcessGroupContentsDTO contents = remoteProcessGroupDTO.getContents(); + addRemoteProcessGroupPortDTOs(connectableNameMap, contents.getInputPorts()); + addRemoteProcessGroupPortDTOs(connectableNameMap, contents.getOutputPorts()); + } + } + for (ConnectionDTO connection : connections) { + setName(connectableNameMap, connection.getSource()); + setName(connectableNameMap, connection.getDestination()); + } + for (ConnectionDTO connection : connections) { + if (BaseSchema.isNullOrEmpty(connection.getName())) { + StringBuilder name = new StringBuilder(); + ConnectableDTO connectionSource = connection.getSource(); + if (connectionSource != null) { + name.append(connectionSource.getName()); + } + name.append("/"); + if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) { + name.append(connection.getSelectedRelationships().iterator().next()); + } + name.append("/"); + ConnectableDTO connectionDestination = connection.getDestination(); + if (connectionDestination != null) { + name.append(connectionDestination.getName()); + } + connection.setName(name.toString()); + } + } + } + } + + public static ConfigSchema transformTemplateToSchema(InputStream source) throws JAXBException, IOException { + try { + TemplateDTO templateDTO = (TemplateDTO) JAXBContext.newInstance(TemplateDTO.class).createUnmarshaller().unmarshal(source); + enrichTemplateDTO(templateDTO); + ConfigSchema configSchema = new ConfigSchemaFunction().apply(templateDTO); + return configSchema; + } finally { + source.close(); + } + } + + private static void setName(Map<String, String> connectableNameMap, ConnectableDTO connectableDTO) { + if (connectableDTO != null) { + String name = connectableNameMap.get(connectableDTO.getId()); + if (name != null) { + connectableDTO.setName(name); + } + } + } + + private static void addRemoteProcessGroupPortDTOs(Map<String, String> connectableNameMap, Collection<RemoteProcessGroupPortDTO> ports) { + addConnectables(connectableNameMap, ports, RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getId); + } + + private static <T> void addConnectables(Map<String, String> connectableNameMap, Collection<T> hasIdAndNames, Function<T, String> idGetter, Function<T, String> nameGetter) { + if (hasIdAndNames != null) { + for (T hasIdAndName : hasIdAndNames) { + String id = idGetter.apply(hasIdAndName); + String name = nameGetter.apply(hasIdAndName); + if (!BaseSchema.isNullOrEmpty(name)) { + connectableNameMap.put(id, name); + } + } + } + } + + public int transform(String[] args) { + if (args.length != 3) { + printTransformUsage(); + return ERR_INVALID_ARGS; + } + try (InputStream inputStream = pathInputStreamFactory.create(args[1])) { + try (OutputStream fileOutputStream = pathOutputStreamFactory.create(args[2])) { + try { + ConfigSchema configSchema = transformTemplateToSchema(inputStream); + if (!configSchema.isValid()) { + System.out.println("There are validation errors with the template, still outputting YAML but it will need to be edited."); + for (String s : configSchema.getValidationIssues()) { + System.out.println(s); + } + System.out.println(); + } else { + System.out.println(NO_VALIDATION_ERRORS_FOUND_IN_TEMPLATE); + } + SchemaSaver.saveConfigSchema(configSchema, fileOutputStream); + } catch (JAXBException e) { + System.out.println("Error reading template. (" + e + ")"); + System.out.println(); + printTransformUsage(); + return ERR_UNABLE_TO_READ_TEMPLATE; + } catch (IOException e) { + System.out.println("Error transforming template to YAML. (" + e + ")"); + System.out.println(); + printTransformUsage(); + return ERR_UNABLE_TO_TRANFORM_TEMPLATE; + } + } catch (FileNotFoundException e) { + System.out.println("Unable to open file " + args[2] + " for writing. (" + e + ")"); + System.out.println(); + printTransformUsage(); + return ERR_UNABLE_TO_OPEN_OUTPUT; + } catch (IOException e) { + System.out.println("Error closing output. (" + e + ")"); + System.out.println(); + } + } catch (FileNotFoundException e) { + System.out.println("Unable to open file " + args[1] + " for reading. (" + e + ")"); + System.out.println(); + printTransformUsage(); + return ERR_UNABLE_TO_OPEN_INPUT; + } catch (IOException e) { + System.out.println("Error closing input. (" + e + ")"); + System.out.println(); + } + + return SUCCESS; + } + + public int execute(String[] args) { + if (args.length < 1 || !commandMap.containsKey(args[0].toLowerCase())) { + printUsage(); + return ERR_INVALID_ARGS; + } + return commandMap.get(args[0].toLowerCase()).function.apply(args); + } + + public Map<String, Command> createCommandMap() { + Map<String, Command> result = new TreeMap<>(); + result.put(TRANSFORM, new Command(this::transform, "Transform template xml into MiNiFi config YAML")); + result.put(VALIDATE, new Command(this::validate, "Validate config YAML")); + return result; + } + + public void printUsage() { + System.out.println("Usage:"); + System.out.println(); + System.out.print("java "); + System.out.print(ConfigMain.class.getCanonicalName()); + System.out.println(" <command> options"); + System.out.println(); + System.out.println("Valid commands include:"); + commandMap.forEach((s, command) -> System.out.println(s + ": " + command.description)); + } + + public class Command { + private final Function<String[], Integer> function; + private final String description; + + public Command(Function<String[], Integer> function, String description) { + this.function = function; + this.description = description; + } + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/PathInputStreamFactory.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/PathInputStreamFactory.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/PathInputStreamFactory.java new file mode 100644 index 0000000..e887157 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/PathInputStreamFactory.java @@ -0,0 +1,25 @@ +/* + * 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.minifi.toolkit.configuration; + +import java.io.FileNotFoundException; +import java.io.InputStream; + +public interface PathInputStreamFactory { + InputStream create(String path) throws FileNotFoundException; +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/PathOutputStreamFactory.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/PathOutputStreamFactory.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/PathOutputStreamFactory.java new file mode 100644 index 0000000..ea13376 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/PathOutputStreamFactory.java @@ -0,0 +1,25 @@ +/* + * 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.minifi.toolkit.configuration; + +import java.io.FileNotFoundException; +import java.io.OutputStream; + +public interface PathOutputStreamFactory { + OutputStream create(String path) throws FileNotFoundException; +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ConfigSchemaFunction.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ConfigSchemaFunction.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ConfigSchemaFunction.java new file mode 100644 index 0000000..4fc9f5a --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ConfigSchemaFunction.java @@ -0,0 +1,82 @@ +/* + * 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.minifi.toolkit.configuration.dto; + +import org.apache.nifi.minifi.commons.schema.ConfigSchema; +import org.apache.nifi.minifi.commons.schema.ConnectionSchema; +import org.apache.nifi.minifi.commons.schema.ProcessorSchema; +import org.apache.nifi.minifi.commons.schema.RemoteProcessingGroupSchema; +import org.apache.nifi.minifi.commons.schema.common.BaseSchema; +import org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys; +import org.apache.nifi.web.api.dto.FlowSnippetDTO; +import org.apache.nifi.web.api.dto.TemplateDTO; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class ConfigSchemaFunction implements Function<TemplateDTO, ConfigSchema> { + private final FlowControllerSchemaFunction flowControllerSchemaFunction; + private final ProcessorSchemaFunction processorSchemaFunction; + private final ConnectionSchemaFunction connectionSchemaFunction; + private final RemoteProcessingGroupSchemaFunction remoteProcessingGroupSchemaFunction; + + public ConfigSchemaFunction() { + this(new FlowControllerSchemaFunction(), new ProcessorSchemaFunction(), new ConnectionSchemaFunction(), new RemoteProcessingGroupSchemaFunction(new RemoteInputPortSchemaFunction())); + } + + public ConfigSchemaFunction(FlowControllerSchemaFunction flowControllerSchemaFunction, ProcessorSchemaFunction processorSchemaFunction, + ConnectionSchemaFunction connectionSchemaFunction, RemoteProcessingGroupSchemaFunction remoteProcessingGroupSchemaFunction) { + this.flowControllerSchemaFunction = flowControllerSchemaFunction; + this.processorSchemaFunction = processorSchemaFunction; + this.connectionSchemaFunction = connectionSchemaFunction; + this.remoteProcessingGroupSchemaFunction = remoteProcessingGroupSchemaFunction; + } + + @Override + public ConfigSchema apply(TemplateDTO templateDTO) { + Map<String, Object> map = new HashMap<>(); + + FlowSnippetDTO snippet = templateDTO.getSnippet(); + + map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(templateDTO).toMap()); + + map.put(CommonPropertyKeys.PROCESSORS_KEY, BaseSchema.nullToEmpty(snippet.getProcessors()).stream() + .map(processorSchemaFunction) + .sorted(Comparator.comparing(ProcessorSchema::getName)) + .map(ProcessorSchema::toMap) + .collect(Collectors.toList())); + + map.put(CommonPropertyKeys.CONNECTIONS_KEY, BaseSchema.nullToEmpty(snippet.getConnections()).stream() + .map(connectionSchemaFunction) + .sorted(Comparator.comparing(ConnectionSchema::getName)) + .map(ConnectionSchema::toMap) + .collect(Collectors.toList())); + + map.put(CommonPropertyKeys.REMOTE_PROCESSING_GROUPS_KEY, BaseSchema.nullToEmpty(snippet.getRemoteProcessGroups()).stream() + .map(remoteProcessingGroupSchemaFunction) + .sorted(Comparator.comparing(RemoteProcessingGroupSchema::getName)) + .map(RemoteProcessingGroupSchema::toMap) + .collect(Collectors.toList())); + + ConfigSchema configSchema = new ConfigSchema(map); + return configSchema; + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ConnectionSchemaFunction.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ConnectionSchemaFunction.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ConnectionSchemaFunction.java new file mode 100644 index 0000000..e3b98a7 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ConnectionSchemaFunction.java @@ -0,0 +1,65 @@ +/* + * 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.minifi.toolkit.configuration.dto; + +import org.apache.nifi.connectable.ConnectableType; +import org.apache.nifi.minifi.commons.schema.ConnectionSchema; +import org.apache.nifi.minifi.commons.schema.common.BaseSchema; +import org.apache.nifi.web.api.dto.ConnectionDTO; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; + +import static org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.CONNECTIONS_KEY; +import static org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.NAME_KEY; + +public class ConnectionSchemaFunction implements Function<ConnectionDTO, ConnectionSchema> { + @Override + public ConnectionSchema apply(ConnectionDTO connectionDTO) { + Map<String, Object> map = new HashMap<>(); + map.put(NAME_KEY, connectionDTO.getName()); + map.put(ConnectionSchema.SOURCE_NAME_KEY, connectionDTO.getSource().getName()); + Set<String> selectedRelationships = BaseSchema.nullToEmpty(connectionDTO.getSelectedRelationships()); + if (selectedRelationships.size() > 0) { + map.put(ConnectionSchema.SOURCE_RELATIONSHIP_NAME_KEY, selectedRelationships.iterator().next()); + } + map.put(ConnectionSchema.DESTINATION_NAME_KEY, connectionDTO.getDestination().getName()); + + map.put(ConnectionSchema.MAX_WORK_QUEUE_SIZE_KEY, connectionDTO.getBackPressureObjectThreshold()); + map.put(ConnectionSchema.MAX_WORK_QUEUE_DATA_SIZE_KEY, connectionDTO.getBackPressureDataSizeThreshold()); + map.put(ConnectionSchema.FLOWFILE_EXPIRATION__KEY, connectionDTO.getFlowFileExpiration()); + List<String> queuePrioritizers = BaseSchema.nullToEmpty(connectionDTO.getPrioritizers()); + if (queuePrioritizers.size() > 0) { + map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, queuePrioritizers.get(0)); + } + ConnectionSchema connectionSchema = new ConnectionSchema(map); + if (ConnectableType.FUNNEL.name().equals(connectionDTO.getSource().getType())) { + connectionSchema.validationIssues.add("Connection " + connectionDTO.getName() + " has type " + ConnectableType.FUNNEL.name() + " which is not supported by MiNiFi"); + } + if (selectedRelationships.size() > 1) { + connectionSchema.addValidationIssue(ConnectionSchema.SOURCE_RELATIONSHIP_NAME_KEY, CONNECTIONS_KEY, " has more than one selected relationship"); + } + if (queuePrioritizers.size() > 1) { + connectionSchema.addValidationIssue(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, CONNECTIONS_KEY, " has more than one queue prioritizer"); + } + return connectionSchema; + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/FlowControllerSchemaFunction.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/FlowControllerSchemaFunction.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/FlowControllerSchemaFunction.java new file mode 100644 index 0000000..d2ca157 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/FlowControllerSchemaFunction.java @@ -0,0 +1,36 @@ +/* + * 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.minifi.toolkit.configuration.dto; + +import org.apache.nifi.minifi.commons.schema.FlowControllerSchema; +import org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys; +import org.apache.nifi.web.api.dto.TemplateDTO; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +public class FlowControllerSchemaFunction implements Function<TemplateDTO, FlowControllerSchema> { + @Override + public FlowControllerSchema apply(TemplateDTO templateDTO) { + Map<String, Object> map = new HashMap<>(); + map.put(CommonPropertyKeys.NAME_KEY, templateDTO.getName()); + map.put(CommonPropertyKeys.COMMENT_KEY, templateDTO.getDescription()); + return new FlowControllerSchema(map); + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ProcessorSchemaFunction.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ProcessorSchemaFunction.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ProcessorSchemaFunction.java new file mode 100644 index 0000000..f0a7be9 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/ProcessorSchemaFunction.java @@ -0,0 +1,62 @@ +/* + * 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.minifi.toolkit.configuration.dto; + +import org.apache.nifi.minifi.commons.schema.ProcessorSchema; +import org.apache.nifi.minifi.commons.schema.common.BaseSchema; +import org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys; +import org.apache.nifi.web.api.dto.ProcessorConfigDTO; +import org.apache.nifi.web.api.dto.ProcessorDTO; +import org.apache.nifi.web.api.dto.RelationshipDTO; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.NAME_KEY; +import static org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.SCHEDULING_PERIOD_KEY; +import static org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.SCHEDULING_STRATEGY_KEY; + +public class ProcessorSchemaFunction implements Function<ProcessorDTO, ProcessorSchema> { + @Override + public ProcessorSchema apply(ProcessorDTO processorDTO) { + ProcessorConfigDTO processorDTOConfig = processorDTO.getConfig(); + + Map<String, Object> map = new HashMap<>(); + map.put(NAME_KEY, processorDTO.getName()); + map.put(ProcessorSchema.CLASS_KEY, processorDTO.getType()); + map.put(SCHEDULING_STRATEGY_KEY, processorDTOConfig.getSchedulingStrategy()); + map.put(SCHEDULING_PERIOD_KEY, processorDTOConfig.getSchedulingPeriod()); + + map.put(CommonPropertyKeys.MAX_CONCURRENT_TASKS_KEY, processorDTOConfig.getConcurrentlySchedulableTaskCount()); + map.put(ProcessorSchema.PENALIZATION_PERIOD_KEY, processorDTOConfig.getPenaltyDuration()); + map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, processorDTOConfig.getYieldDuration()); + Long runDurationMillis = processorDTOConfig.getRunDurationMillis(); + if (runDurationMillis != null) { + map.put(ProcessorSchema.RUN_DURATION_NANOS_KEY, runDurationMillis * 1000); + } + map.put(ProcessorSchema.AUTO_TERMINATED_RELATIONSHIPS_LIST_KEY, BaseSchema.nullToEmpty(processorDTO.getRelationships()).stream() + .filter(RelationshipDTO::isAutoTerminate) + .map(RelationshipDTO::getName) + .collect(Collectors.toList())); + map.put(ProcessorSchema.PROCESSOR_PROPS_KEY, new HashMap<>(BaseSchema.nullToEmpty(processorDTOConfig.getProperties()))); + + return new ProcessorSchema(map); + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/RemoteInputPortSchemaFunction.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/RemoteInputPortSchemaFunction.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/RemoteInputPortSchemaFunction.java new file mode 100644 index 0000000..7fe16d0 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/RemoteInputPortSchemaFunction.java @@ -0,0 +1,43 @@ +/* + * 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.minifi.toolkit.configuration.dto; + +import org.apache.nifi.minifi.commons.schema.RemoteInputPortSchema; +import org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys; +import org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import static org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.ID_KEY; +import static org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys.NAME_KEY; + +public class RemoteInputPortSchemaFunction implements Function<RemoteProcessGroupPortDTO, RemoteInputPortSchema> { + @Override + public RemoteInputPortSchema apply(RemoteProcessGroupPortDTO remoteProcessGroupPortDTO) { + Map<String, Object> map = new HashMap<>(); + map.put(ID_KEY, remoteProcessGroupPortDTO.getId()); + map.put(NAME_KEY, remoteProcessGroupPortDTO.getName()); + + map.put(CommonPropertyKeys.COMMENT_KEY, remoteProcessGroupPortDTO.getComments()); + map.put(CommonPropertyKeys.MAX_CONCURRENT_TASKS_KEY, remoteProcessGroupPortDTO.getConcurrentlySchedulableTaskCount()); + map.put(CommonPropertyKeys.USE_COMPRESSION_KEY, remoteProcessGroupPortDTO.getUseCompression()); + return new RemoteInputPortSchema(map); + } +} http://git-wip-us.apache.org/repos/asf/nifi-minifi/blob/2d1e43e7/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/RemoteProcessingGroupSchemaFunction.java ---------------------------------------------------------------------- diff --git a/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/RemoteProcessingGroupSchemaFunction.java b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/RemoteProcessingGroupSchemaFunction.java new file mode 100644 index 0000000..2ad2e67 --- /dev/null +++ b/minifi-toolkit/minifi-toolkit-configuration/src/main/java/org/apache/nifi/minifi/toolkit/configuration/dto/RemoteProcessingGroupSchemaFunction.java @@ -0,0 +1,62 @@ +/* + * 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.minifi.toolkit.configuration.dto; + +import org.apache.nifi.minifi.commons.schema.RemoteInputPortSchema; +import org.apache.nifi.minifi.commons.schema.RemoteProcessingGroupSchema; +import org.apache.nifi.minifi.commons.schema.common.CommonPropertyKeys; +import org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO; +import org.apache.nifi.web.api.dto.RemoteProcessGroupDTO; +import org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class RemoteProcessingGroupSchemaFunction implements Function<RemoteProcessGroupDTO, RemoteProcessingGroupSchema> { + private final RemoteInputPortSchemaFunction remoteInputPortSchemaFunction; + + public RemoteProcessingGroupSchemaFunction(RemoteInputPortSchemaFunction remoteInputPortSchemaFunction) { + this.remoteInputPortSchemaFunction = remoteInputPortSchemaFunction; + } + + @Override + public RemoteProcessingGroupSchema apply(RemoteProcessGroupDTO remoteProcessGroupDTO) { + Map<String, Object> map = new HashMap<>(); + map.put(CommonPropertyKeys.NAME_KEY, remoteProcessGroupDTO.getName()); + map.put(RemoteProcessingGroupSchema.URL_KEY, remoteProcessGroupDTO.getTargetUri()); + + RemoteProcessGroupContentsDTO contents = remoteProcessGroupDTO.getContents(); + if (contents != null) { + Set<RemoteProcessGroupPortDTO> inputPorts = contents.getInputPorts(); + if (inputPorts != null) { + map.put(CommonPropertyKeys.INPUT_PORTS_KEY, inputPorts.stream() + .map(remoteInputPortSchemaFunction) + .map(RemoteInputPortSchema::toMap) + .collect(Collectors.toList())); + } + } + + map.put(CommonPropertyKeys.COMMENT_KEY, remoteProcessGroupDTO.getComments()); + map.put(RemoteProcessingGroupSchema.TIMEOUT_KEY, remoteProcessGroupDTO.getCommunicationsTimeout()); + map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, remoteProcessGroupDTO.getYieldDuration()); + return new RemoteProcessingGroupSchema(map); + } +}
