http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingContext.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingContext.java b/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingContext.java new file mode 100644 index 0000000..281194c --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingContext.java @@ -0,0 +1,89 @@ +/* + * 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.reporting; + +import java.util.Map; + +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.PropertyValue; +import org.apache.nifi.controller.ControllerServiceLookup; + +/** + * This interface provides a bridge between the NiFi Framework and a + * {@link ReportingTask}. This context allows a ReportingTask to access + * statistics, metrics, and monitoring information, as well as configuration + * supplied by the user. + */ +public interface ReportingContext { + + /** + * @return a Map of all known {@link PropertyDescriptor}s to their + * configured properties. This Map will contain a <code>null</code> for any + * Property that has not been configured by the user, even if the + * PropertyDescriptor has a default value + */ + Map<PropertyDescriptor, String> getProperties(); + + /** + * @param propertyName descriptor of property to lookup the value of + * @return PropertyValue that represents the user-configured value for the given + * {@link PropertyDescriptor} + */ + PropertyValue getProperty(PropertyDescriptor propertyName); + + /** + * @return the {@link EventAccess} object that can be used to obtain + * information about specific events and reports that have happened + */ + EventAccess getEventAccess(); + + /** + * @return the {@link BulletinRepository} that can be used to analyze + * Bulletins that have been emitted and register new Bulletins + */ + BulletinRepository getBulletinRepository(); + + /** + * Creates a system-level {@link Bulletin} with the given category, severity + * level, and message, so that the Bulletin can be added to the + * {@link BulletinRepository}. + * + * @param category of bulletin + * @param severity of bulletin + * @param message of bulletin + * @return new bulletin + */ + Bulletin createBulletin(String category, Severity severity, String message); + + /** + * Creates a {@link Bulletin} for the component with the specified + * identifier + * + * @param componentId the ID of the component + * @param category the name of the bulletin's category + * @param severity the severity level of the bulletin + * @param message the bulletin's message + * @return new bulletin + */ + Bulletin createBulletin(String componentId, String category, Severity severity, String message); + + /** + * @return the {@link ControllerServiceLookup} which can be used to obtain + * Controller Services + */ + ControllerServiceLookup getControllerServiceLookup(); +}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java b/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java new file mode 100644 index 0000000..d014b26 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingInitializationContext.java @@ -0,0 +1,77 @@ +/* + * 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.reporting; + +import java.util.concurrent.TimeUnit; + +import org.apache.nifi.controller.ControllerServiceLookup; +import org.apache.nifi.logging.ComponentLog; +import org.apache.nifi.scheduling.SchedulingStrategy; + +/** + * A ReportingConfiguration provides configuration information to a + * ReportingTask at the time of initialization + */ +public interface ReportingInitializationContext { + + /** + * @return the identifier for this ReportingTask + */ + String getIdentifier(); + + /** + * @return the configured name for this ReportingTask + */ + String getName(); + + /** + * Returns the amount of time, in the given {@link TimeUnit} that will + * elapsed between the return of one execution of the + * {@link ReportingTask}'s + * {@link ReportingTask#onTrigger(ReportingContext) onTrigger} method and + * the time at which the method is invoked again. This method will return + * <code>-1L</code> if the Scheduling Strategy is not set to + * {@link SchedulingStrategy#TIMER_DRIVEN} + * + * @param timeUnit unit of time for scheduling + * @return period of time + */ + long getSchedulingPeriod(TimeUnit timeUnit); + + /** + * @return the {@link ControllerServiceLookup} which can be used to obtain + * Controller Services + */ + ControllerServiceLookup getControllerServiceLookup(); + + /** + * @return a String representation of the scheduling period + */ + String getSchedulingPeriod(); + + /** + * @return the {@link SchedulingStrategy} that is used to trigger the task + * to run + */ + SchedulingStrategy getSchedulingStrategy(); + + /** + * @return a logger that can be used to log important events in a standard + * way and generate bulletins when appropriate + */ + ComponentLog getLogger(); +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingTask.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingTask.java b/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingTask.java new file mode 100644 index 0000000..3de9b93 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/reporting/ReportingTask.java @@ -0,0 +1,75 @@ +/* + * 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.reporting; + +import org.apache.nifi.components.ConfigurableComponent; +import org.apache.nifi.controller.annotation.OnConfigured; + +/** + * Defines a task that is responsible for reporting status information to + * external destinations. All implementations of this class must have a default + * constructor. + * + * <p> + * <code>ReportingTask</code>s are discovered using Java's + * <code>ServiceLoader</code> mechanism. As a result, all implementations must + * follow these rules: + * + * <ul> + * <li>The implementation must implement this interface.</li> + * <li>The implementation must have a file named + * org.apache.nifi.reporting.ReportingTask located within the jar's + * <code>META-INF/services</code> directory. This file contains a list of + * fully-qualified class names of all <code>ReportingTask</code>s in the jar, + * one-per-line. + * <li>The implementation must support a default constructor.</li> + * </ul> + * </p> + * + * <p> + * ReportingTasks are scheduled on a delayed interval with a single thread. + * Therefore, implementations are not required to be thread-safe. + * </p> + * + * <p> + * ReportingTasks may choose to annotate a method with the + * {@link OnConfigured @OnConfigured} annotation. If this is done, that method + * will be invoked after all properties have been set for the ReportingTask and + * before it is scheduled to run. If the method throws an Exception, the + * ReportingTask will be Administratively yielded and will not run for the + * configured period of time. + * </p> + */ +public interface ReportingTask extends ConfigurableComponent { + + /** + * Provides the Reporting Task with access to objects that may be of use + * throughout the life of the service + * + * @param config of initialization context + * @throws org.apache.nifi.reporting.InitializationException if unable to init + */ + void initialize(ReportingInitializationContext config) throws InitializationException; + + /** + * This method is called on a scheduled interval to allow the Reporting Task + * to perform its tasks. + * + * @param context reporting context + */ + void onTrigger(ReportingContext context); +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/reporting/Severity.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/reporting/Severity.java b/nifi-api/src/main/java/org/apache/nifi/reporting/Severity.java new file mode 100644 index 0000000..8c2b27f --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/reporting/Severity.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.reporting; + +public enum Severity { + + INFO, + WARNING, + ERROR; +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/scheduling/SchedulingStrategy.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/scheduling/SchedulingStrategy.java b/nifi-api/src/main/java/org/apache/nifi/scheduling/SchedulingStrategy.java new file mode 100644 index 0000000..ccf4281 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/scheduling/SchedulingStrategy.java @@ -0,0 +1,86 @@ +/* + * 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.scheduling; + +/** + * Defines a Scheduling Strategy to use when scheduling Components (Ports, + * Funnels, Processors) to run + */ +public enum SchedulingStrategy { + + /** + * Components should be scheduled to run whenever a relevant Event occurs. + * Examples of "relevant Events" are: + * + * <ul> + * <li>A FlowFile is added to one of the Component's incoming + * Connections</li> + * <li>A FlowFile is removed from one of the Component's outgoing + * Connections</li> + * <li>The Component is scheduled to run (started)</li> + * </ul> + * + * <p> + * When using this mode, the user will be unable to configure the scheduling + * period. Instead, the framework will manage this. + * </p> + * + * <p> + * When using this mode, the maximum number of concurrent tasks can be set + * to 0, indicating no maximum. + * </p> + * + * <p> + * Not all Components support Event-Driven mode. + * </p> + */ + EVENT_DRIVEN(0, null), + /** + * Components should be scheduled to run on a periodic interval that is + * user-defined with a user-defined number of concurrent tasks. All + * Components support Timer-Driven mode. + */ + TIMER_DRIVEN(1, "0 sec"), + /** + * Indicates that the component will be scheduled via timer only on the + * Primary Node. If the instance is not part of a cluster and this + * Scheduling Strategy is used, the component will be scheduled in the same + * manner as if {@link TIMER_DRIVEN} were used. + */ + PRIMARY_NODE_ONLY(1, "0 sec"), + /** + * Indicates that the component will be scheduled to run according to a + * Cron-style expression + */ + CRON_DRIVEN(1, "* * * * * ?"); + + private final int defaultConcurrentTasks; + private final String defaultSchedulingPeriod; + + private SchedulingStrategy(final int defaultConcurrentTasks, final String defaultSchedulingPeriod) { + this.defaultConcurrentTasks = defaultConcurrentTasks; + this.defaultSchedulingPeriod = defaultSchedulingPeriod; + } + + public int getDefaultConcurrentTasks() { + return defaultConcurrentTasks; + } + + public String getDefaultSchedulingPeriod() { + return defaultSchedulingPeriod; + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/search/SearchContext.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/search/SearchContext.java b/nifi-api/src/main/java/org/apache/nifi/search/SearchContext.java new file mode 100644 index 0000000..1da8c90 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/search/SearchContext.java @@ -0,0 +1,49 @@ +/* + * 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.search; + +import java.util.Map; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.PropertyValue; + +/** + * + */ +public interface SearchContext { + + /** + * @return the search term + */ + String getSearchTerm(); + + /** + * @return the annotation data + */ + String getAnnotationData(); + + /** + * @param property to get value of + * @return a PropertyValue that encapsulates the value configured for the + * given PropertyDescriptor + */ + PropertyValue getProperty(PropertyDescriptor property); + + /** + * @return a Map of all configured Properties + */ + Map<PropertyDescriptor, String> getProperties(); +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/search/SearchResult.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/search/SearchResult.java b/nifi-api/src/main/java/org/apache/nifi/search/SearchResult.java new file mode 100644 index 0000000..29e490a --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/search/SearchResult.java @@ -0,0 +1,78 @@ +/* + * 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.search; + +/** + * + */ +public class SearchResult { + + private final String label; + private final String match; + + private SearchResult(final Builder builder) { + this.label = builder.label; + this.match = builder.match; + } + + /** + * @return the label for this search result + */ + public String getLabel() { + return label; + } + + /** + * @return the matching string for this search result + */ + public String getMatch() { + return match; + } + + public static final class Builder { + + private String label; + private String match; + + /** + * Set the label for the search result. + * + * @param label to set + * @return the builder + */ + public Builder label(final String label) { + this.label = label; + return this; + } + + /** + * Set the matching string for the search result. + * + * @param match string + * @return the builder + */ + public Builder match(final String match) { + this.match = match; + return this; + } + + public SearchResult build() { + return new SearchResult(this); + } + + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/search/Searchable.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/search/Searchable.java b/nifi-api/src/main/java/org/apache/nifi/search/Searchable.java new file mode 100644 index 0000000..64f32f9 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/search/Searchable.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.search; + +import java.util.Collection; + +/** + * + */ +public interface Searchable { + + Collection<SearchResult> search(SearchContext context); +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/ClusterRequestException.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ClusterRequestException.java b/nifi-api/src/main/java/org/apache/nifi/web/ClusterRequestException.java new file mode 100644 index 0000000..ee5f417 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/ClusterRequestException.java @@ -0,0 +1,39 @@ +/* + * 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.web; + +/** + * An general error occurred when attempting to communicate with the cluster. + */ +public class ClusterRequestException extends RuntimeException { + + public ClusterRequestException(Throwable cause) { + super(cause); + } + + public ClusterRequestException(String message, Throwable cause) { + super(message, cause); + } + + public ClusterRequestException(String message) { + super(message); + } + + public ClusterRequestException() { + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java b/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java new file mode 100644 index 0000000..5614fc2 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/ComponentDetails.java @@ -0,0 +1,144 @@ +/* + * 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.web; + +import java.util.Collection; +import java.util.Map; + +/** + * Details about a given component. Contains configuration and current + * validation errors. + */ +public class ComponentDetails { + + private final String id; + private final String name; + private final String type; + private final String state; + private final String annotationData; + private final Map<String, String> properties; + private final Collection<String> validationErrors; + + private ComponentDetails(final Builder builder) { + this.id = builder.id; + this.name = builder.name; + this.type = builder.type; + this.state = builder.state; + this.annotationData = builder.annotationData; + this.properties = builder.properties; + this.validationErrors = builder.validationErrors; + } + + /** + * @return component id + */ + public String getId() { + return id; + } + + /** + * @return component name + */ + public String getName() { + return name; + } + + /** + * @return component type + */ + public String getType() { + return type; + } + + /** + * @return component state + */ + public String getState() { + return state; + } + + /** + * @return component's annotation data + */ + public String getAnnotationData() { + return annotationData; + } + + /** + * @return Mapping of component properties + */ + public Map<String, String> getProperties() { + return properties; + } + + /** + * @return Current validation errors for the component + */ + public Collection<String> getValidationErrors() { + return validationErrors; + } + + public static final class Builder { + + private String id; + private String name; + private String type; + private String state; + private String annotationData; + private Map<String, String> properties; + private Collection<String> validationErrors; + + public Builder id(final String id) { + this.id = id; + return this; + } + + public Builder name(final String name) { + this.name = name; + return this; + } + + public Builder type(final String type) { + this.type = type; + return this; + } + + public Builder state(final String state) { + this.state = state; + return this; + } + + public Builder annotationData(final String annotationData) { + this.annotationData = annotationData; + return this; + } + + public Builder properties(final Map<String, String> properties) { + this.properties = properties; + return this; + } + + public Builder validateErrors(final Collection<String> validationErrors) { + this.validationErrors = validationErrors; + return this; + } + + public ComponentDetails build() { + return new ComponentDetails(this); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/ConfigurationAction.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ConfigurationAction.java b/nifi-api/src/main/java/org/apache/nifi/web/ConfigurationAction.java new file mode 100644 index 0000000..96f2abf --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/ConfigurationAction.java @@ -0,0 +1,125 @@ +/* + * 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.web; + +/** + * An action that represents the configuration of a component. + */ +public class ConfigurationAction { + + private final String id; + private final String name; + private final String type; + private final String field; + private final String previousValue; + private final String value; + + private ConfigurationAction(final Builder builder) { + this.id = builder.id; + this.name = builder.name; + this.type = builder.type; + this.field = builder.field; + this.previousValue = builder.previousValue; + this.value = builder.value; + } + + /** + * @return id of the component being modified + */ + public String getId() { + return id; + } + + /** + * @return name of the component being modified + */ + public String getName() { + return name; + } + + /** + * @return type of the component being modified + */ + public String getType() { + return type; + } + + /** + * @return the name of the field, property, etc that has been modified + */ + public String getField() { + return field; + } + + /** + * @return the previous value + */ + public String getPreviousValue() { + return previousValue; + } + + /** + * @return the new value + */ + public String getValue() { + return value; + } + + public static class Builder { + + private String id; + private String name; + private String type; + private String field; + private String previousValue; + private String value; + + public Builder id(final String id) { + this.id = id; + return this; + } + + public Builder name(final String name) { + this.name = name; + return this; + } + + public Builder type(final String type) { + this.type = type; + return this; + } + + public Builder field(final String field) { + this.field = field; + return this; + } + + public Builder previousValue(final String previousValue) { + this.previousValue = previousValue; + return this; + } + + public Builder value(final String value) { + this.value = value; + return this; + } + + public ConfigurationAction build() { + return new ConfigurationAction(this); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/InvalidRevisionException.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/InvalidRevisionException.java b/nifi-api/src/main/java/org/apache/nifi/web/InvalidRevisionException.java new file mode 100644 index 0000000..8e04f69 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/InvalidRevisionException.java @@ -0,0 +1,33 @@ +/* + * 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.web; + +/** + * Exception indicating that the client has included an old revision in their + * request. + */ +@SuppressWarnings("serial") +public class InvalidRevisionException extends RuntimeException { + + public InvalidRevisionException(String message) { + super(message); + } + + public InvalidRevisionException(String message, Throwable cause) { + super(message, cause); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java new file mode 100644 index 0000000..ae32b10 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationContext.java @@ -0,0 +1,100 @@ +/* + * 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.web; + +import java.util.Collection; + +import org.apache.nifi.controller.ControllerService; + +/** + * NiFi web context providing limited access to dataflow configuration for + * component custom UIs. + */ +public interface NiFiWebConfigurationContext { + + /** + * @param serviceIdentifier of the controller service + * @return the ControllerService for the specified identifier. If a + * corresponding service cannot be found, null is returned. If this NiFi is + * clustered, the only services available will be those those availability + * is NCM only + */ + ControllerService getControllerService(String serviceIdentifier); + + /** + * Provides a mechanism for custom UIs to save actions to appear in NiFi + * configuration history. Note all fields within each Action must be + * populated. Null values will result in a failure to insert the audit + * record. Since the saving to these actions is separate from the actual + * configuration change, a failure to insert here will just generate a + * warning log message. The recording of these actions typically happens + * after a configuration change is applied. Since those changes have already + * been applied to the flow, we cannot revert them because of a failure to + * insert an audit record. + * + * @param requestContext context of the request + * @param actions to save + * @throws IllegalArgumentException When the requestContext isn't fully + * populated or isn't appropriate for the given request + */ + void saveActions(NiFiWebRequestContext requestContext, Collection<ConfigurationAction> actions); + + /** + * @return the current user dn. Returns null if no user is found + */ + String getCurrentUserDn(); + + /** + * @return the current user name. Returns null if no user is found + */ + String getCurrentUserName(); + + /** + * Sets the annotation data for the underlying component. + * + * @param configurationContext config context + * @param annotationData the data + * @return the configuration for the underlying component + * @throws ResourceNotFoundException if the underlying component does not + * exit + * @throws InvalidRevisionException if a revision other than the current + * revision is given + * @throws ClusterRequestException if the annotation data was unable to be + * set for the underlying component. This exception will only be thrown when + * operating in a cluster. + * @throws IllegalArgumentException When the requestContext isn't fully + * populated or isn't appropriate for the given request + */ + ComponentDetails setAnnotationData(NiFiWebConfigurationRequestContext configurationContext, String annotationData) + throws ResourceNotFoundException, InvalidRevisionException, ClusterRequestException; + + /** + * Gets the details for the underlying component (including configuration, + * validation errors, and annotation data). + * + * @param requestContext context of request + * @return the configuration for the underlying component + * @throws ResourceNotFoundException if the underlying component does not + * exit + * @throws ClusterRequestException if the underlying component was unable to + * be retrieved from the cluster. This exception will only be thrown when + * operating in a cluster. + * @throws IllegalArgumentException When the requestContext isn't fully + * populated or isn't appropriate for the given request + */ + ComponentDetails getComponentDetails(NiFiWebRequestContext requestContext) throws ResourceNotFoundException, ClusterRequestException; +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationRequestContext.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationRequestContext.java b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationRequestContext.java new file mode 100644 index 0000000..c75d9dc --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebConfigurationRequestContext.java @@ -0,0 +1,32 @@ +/* + * 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.web; + +/** + * Contextual details required to make a configuration request from a UI + * extension. + */ +public interface NiFiWebConfigurationRequestContext extends NiFiWebRequestContext { + + /** + * The revision to include in the request. + * + * @return the revision + */ + Revision getRevision(); + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebContext.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebContext.java b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebContext.java new file mode 100644 index 0000000..55e90e8 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebContext.java @@ -0,0 +1,116 @@ +/* + * 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.web; + +import java.util.Collection; + +import org.apache.nifi.controller.ControllerService; + +/** + * NiFi web context providing limited access to dataflow configuration for + * processor custom UIs. + */ +@Deprecated +public interface NiFiWebContext { + + /** + * @param serviceIdentifier identifier of the service + * @return the ControllerService for the specified identifier. If a + * corresponding service cannot be found, null is returned. If this NiFi is + * clustered, the ControllerService is loaded from the NCM + */ + ControllerService getControllerService(String serviceIdentifier); + + /** + * Provides a mechanism for custom UIs to save actions to appear in NiFi + * configuration history. Note all fields within each Action must be + * populated. Null values will result in a failure to insert the audit + * record. Since the saving to these actions is separate from the actual + * configuration change, a failure to insert here will just generate a + * warning log message. The recording of these actions typically happens + * after a configuration change is applied. Since those changes have already + * been applied to the flow, we cannot revert them because of a failure to + * insert an audit record. + * + * @param actions to save + */ + void saveActions(Collection<ProcessorConfigurationAction> actions); + + /** + * @return the current user dn. Returns null if no user is found + */ + String getCurrentUserDn(); + + /** + * @return the current user name. Returns null if no user is found + */ + String getCurrentUserName(); + + /** + * Gets the Processor configuration. The given configuration is expected to + * contain the following configuration: + * + * <ul> + * <li>revision -- the client identifier and optionally the version + * number</li> + * <li>processorId -- the id of the processor to retrieve information + * for</li> + * <li>X509Certificate -- the certificate if this is a secure request</li> + * </ul> + * + * When operating in a clustered environment, if the configuration contains + * a X509Certificate, then the certificate information will be forwarded to + * the nodes. + * + * @param config the configuration + * @return the processor info object + * @throws ResourceNotFoundException if the processor does not exit + * @throws ClusterRequestException if the processor was unable to be + * retrieved from the cluster. This exception will only be thrown when + * operating in a cluster. + */ + ProcessorInfo getProcessor(NiFiWebContextConfig config) throws ResourceNotFoundException, ClusterRequestException; + + /** + * Sets the Processor annotation data. The given configuration is expected + * to contain the following configuration: + * + * <ul> + * <li>revision -- the client identifier and optionally the version + * number</li> + * <li>processorId -- the id of the processor to retrieve information + * for</li> + * <li>X509Certificate -- the certificate if this is a secure request</li> + * </ul> + * + * When operating in a clustered environment, if the configuration contains + * a X509Certificate, then the certificate information will be forwarded to + * the nodes. + * + * @param config the configuration + * @param annotationData the annotation data + * @throws ResourceNotFoundException if the processor does not exit + * @throws InvalidRevisionException if a revision other than the current + * revision is given + * @throws ClusterRequestException if the annotation data was unable to be + * set for the processor. This exception will only be thrown when operating + * in a cluster. + */ + void setProcessorAnnotationData(NiFiWebContextConfig config, String annotationData) + throws ResourceNotFoundException, InvalidRevisionException, ClusterRequestException; + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebContextConfig.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebContextConfig.java b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebContextConfig.java new file mode 100644 index 0000000..2df94e4 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebContextConfig.java @@ -0,0 +1,55 @@ +/* + * 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.web; + +/** + * Context configuration for methods invoked from the NiFiWebContext. + */ +@Deprecated +public interface NiFiWebContextConfig { + + /** + * The request protocol scheme (http or https). When scheme is https, the + * X509Certificate can be used for subsequent remote requests. + * + * @return the protocol scheme + */ + String getScheme(); + + /** + * @return the processor ID + */ + String getProcessorId(); + + /** + * @return the revision + */ + Revision getRevision(); + + /** + * Returns the proxied entities chain. The format of the chain is as + * follows: + * + * <code> + * <CN=original-proxied-entity><CN=first-proxy><CN=second-proxy>... + * </code> + * + * @return the proxied entities chain or null if no chain + */ + String getProxiedEntitiesChain(); + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebRequestContext.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebRequestContext.java b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebRequestContext.java new file mode 100644 index 0000000..9dd44ab --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/NiFiWebRequestContext.java @@ -0,0 +1,56 @@ +/* + * 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.web; + +/** + * Contextual details required to make a request from a UI extension. + */ +public interface NiFiWebRequestContext { + + /** + * @return the type of UI extension is making the request + */ + UiExtensionType getExtensionType(); + + /** + * The request protocol scheme (http or https). When scheme is https, the + * X509Certificate can be used for subsequent remote requests. + * + * @return the protocol scheme + */ + String getScheme(); + + /** + * The id of the component. + * + * @return the ID + */ + String getId(); + + /** + * Returns the proxied entities chain. The format of the chain is as + * follows: + * + * <code> + * <CN=original-proxied-entity><CN=first-proxy><CN=second-proxy>... + * </code> + * + * @return the proxied entities chain or null if no chain + */ + String getProxiedEntitiesChain(); + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/ProcessorConfigurationAction.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ProcessorConfigurationAction.java b/nifi-api/src/main/java/org/apache/nifi/web/ProcessorConfigurationAction.java new file mode 100644 index 0000000..f42063f --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/ProcessorConfigurationAction.java @@ -0,0 +1,126 @@ +/* + * 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.web; + +/** + * + */ +@Deprecated +public class ProcessorConfigurationAction { + + private final String processorId; + private final String processorName; + private final String processorType; + private final String name; + private final String previousValue; + private final String value; + + private ProcessorConfigurationAction(final Builder builder) { + this.processorId = builder.processorId; + this.processorName = builder.processorName; + this.processorType = builder.processorType; + this.name = builder.name; + this.previousValue = builder.previousValue; + this.value = builder.value; + } + + /** + * @return the id of the processor + */ + public String getProcessorId() { + return processorId; + } + + /** + * @return the name of the processor being modified + */ + public String getProcessorName() { + return processorName; + } + + /** + * @return the type of the processor being modified + */ + public String getProcessorType() { + return processorType; + } + + /** + * @return the name of the field, property, etc that has been modified. + */ + public String getName() { + return name; + } + + /** + * @return the previous value + */ + public String getPreviousValue() { + return previousValue; + } + + /** + * @return the new value + */ + public String getValue() { + return value; + } + + public static class Builder { + + private String processorId; + private String processorName; + private String processorType; + private String name; + private String previousValue; + private String value; + + public Builder processorId(final String processorId) { + this.processorId = processorId; + return this; + } + + public Builder processorName(final String processorName) { + this.processorName = processorName; + return this; + } + + public Builder processorType(final String processorType) { + this.processorType = processorType; + return this; + } + + public Builder name(final String name) { + this.name = name; + return this; + } + + public Builder previousValue(final String previousValue) { + this.previousValue = previousValue; + return this; + } + + public Builder value(final String value) { + this.value = value; + return this; + } + + public ProcessorConfigurationAction build() { + return new ProcessorConfigurationAction(this); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/ProcessorInfo.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ProcessorInfo.java b/nifi-api/src/main/java/org/apache/nifi/web/ProcessorInfo.java new file mode 100644 index 0000000..e87e73e --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/ProcessorInfo.java @@ -0,0 +1,111 @@ +/* + * 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.web; + +import java.util.Collection; +import java.util.Map; + +/** + * + */ +@Deprecated +public class ProcessorInfo { + + private final String id; + private final String name; + private final String state; + private final String annotationData; + private final Map<String, String> properties; + private final Collection<String> validationErrors; + + private ProcessorInfo(final Builder builder) { + this.id = builder.id; + this.name = builder.name; + this.state = builder.state; + this.annotationData = builder.annotationData; + this.properties = builder.properties; + this.validationErrors = builder.validationErrors; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getState() { + return state; + } + + public String getAnnotationData() { + return annotationData; + } + + public Map<String, String> getProperties() { + return properties; + } + + public Collection<String> getValidationErrors() { + return validationErrors; + } + + public static final class Builder { + + private String id; + private String name; + private String state; + private String annotationData; + private Map<String, String> properties; + private Collection<String> validationErrors; + + public Builder id(final String id) { + this.id = id; + return this; + } + + public Builder name(final String name) { + this.name = name; + return this; + } + + public Builder state(final String state) { + this.state = state; + return this; + } + + public Builder annotationData(final String annotationData) { + this.annotationData = annotationData; + return this; + } + + public Builder properties(final Map<String, String> properties) { + this.properties = properties; + return this; + } + + public Builder validateErrors(final Collection<String> validationErrors) { + this.validationErrors = validationErrors; + return this; + } + + public ProcessorInfo build() { + return new ProcessorInfo(this); + } + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/ResourceNotFoundException.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ResourceNotFoundException.java b/nifi-api/src/main/java/org/apache/nifi/web/ResourceNotFoundException.java new file mode 100644 index 0000000..b2f2e57 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/ResourceNotFoundException.java @@ -0,0 +1,32 @@ +/* + * 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.web; + +/** + * Exception indicating that the desired resource was not found. + */ +@SuppressWarnings("serial") +public class ResourceNotFoundException extends RuntimeException { + + public ResourceNotFoundException(String message) { + super(message); + } + + public ResourceNotFoundException(String message, Throwable cause) { + super(message, cause); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/Revision.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/Revision.java b/nifi-api/src/main/java/org/apache/nifi/web/Revision.java new file mode 100644 index 0000000..a4d36d2 --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/Revision.java @@ -0,0 +1,81 @@ +/* + * 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.web; + +import java.io.Serializable; + +/** + * A model object representing a revision. Equality is defined as either a + * matching version number or matching non-empty client IDs. + * + * @Immutable + * @Threadsafe + */ +public class Revision implements Serializable { + + /** + * the version number + */ + private final Long version; + + /** + * the client ID + */ + private final String clientId; + + public Revision(Long revision, String clientId) { + this.version = revision; + this.clientId = clientId; + } + + public String getClientId() { + return clientId; + } + + public Long getVersion() { + return version; + } + + @Override + public boolean equals(final Object obj) { + + if ((obj instanceof Revision) == false) { + return false; + } + + Revision thatRevision = (Revision) obj; + if (this.version != null && this.version.equals(thatRevision.version)) { + return true; + } else { + return clientId != null && !clientId.trim().isEmpty() && clientId.equals(thatRevision.getClientId()); + } + + } + + @Override + public int hashCode() { + int hash = 5; + hash = 59 * hash + (this.version != null ? this.version.hashCode() : 0); + hash = 59 * hash + (this.clientId != null ? this.clientId.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + return "[" + version + ", " + clientId + ']'; + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/UiExtensionType.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/UiExtensionType.java b/nifi-api/src/main/java/org/apache/nifi/web/UiExtensionType.java new file mode 100644 index 0000000..e3b0f8a --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/UiExtensionType.java @@ -0,0 +1,32 @@ +/* + * 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.web; + +/** + * Types of UI extensions. Since a UI extension could support multiple types of + * custom UIs it will need to include the type so the framework can appropriate + * understand and process the request (recording actions in the audit database, + * replicating a request throughout the cluster to the appropriate endpoints, + * etc). + */ +public enum UiExtensionType { + + ContentViewer, + ProcessorConfiguration, + ControllerServiceConfiguration, + ReportingTaskConfiguration +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java b/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.java new file mode 100644 index 0000000..180385e --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/web/ViewableContent.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.web; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Interface for obtaining content from the NiFi content repository. + */ +public interface ViewableContent { + + public static final String CONTENT_REQUEST_ATTRIBUTE = "org.apache.nifi.web.content"; + + public enum DisplayMode { + + Original, + Formatted, + Hex; + } + + /** + * @return stream to the viewable content. The data stream can only be read once + * so an extension can call this method or getContent + */ + InputStream getContentStream(); + + /** + * @return the content as a string. The data stream can only be read once so an + * extension can call this method or getContentStream + * @throws java.io.IOException if unable to read content + */ + String getContent() throws IOException; + + /** + * @return the desired display mode. If the mode is Hex the framework will + * handle generating the mark up. The only values that an extension will see + * is Original or Formatted + */ + DisplayMode getDisplayMode(); + + /** + * @return contents file name + */ + String getFileName(); + + /** + * @return mime type of the content + */ + String getContentType(); +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/test/java/org/apache/nifi/components/TestPropertyDescriptor.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/test/java/org/apache/nifi/components/TestPropertyDescriptor.java b/nifi-api/src/test/java/org/apache/nifi/components/TestPropertyDescriptor.java new file mode 100644 index 0000000..e3043be --- /dev/null +++ b/nifi-api/src/test/java/org/apache/nifi/components/TestPropertyDescriptor.java @@ -0,0 +1,59 @@ +/* + * 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.components; + +import static org.junit.Assert.assertNotNull; + +import org.apache.nifi.components.PropertyDescriptor.Builder; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * Regression test for issue NIFI-49, to ensure that if a Processor's Property's + * Default Value is not allowed, the Exception thrown should indicate what the + * default value is + */ +public class TestPropertyDescriptor { + + private static Builder invalidDescriptorBuilder; + private static Builder validDescriptorBuilder; + private static String DEFAULT_VALUE = "Default Value"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @BeforeClass + public static void setUp() { + validDescriptorBuilder = new PropertyDescriptor.Builder().name("").allowableValues("Allowable Value", "Another Allowable Value").defaultValue("Allowable Value"); + invalidDescriptorBuilder = new PropertyDescriptor.Builder().name("").allowableValues("Allowable Value", "Another Allowable Value").defaultValue(DEFAULT_VALUE); + } + + @Test + public void testExceptionThrownByDescriptorWithInvalidDefaultValue() { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("[" + DEFAULT_VALUE + "]"); + + invalidDescriptorBuilder.build(); + } + + @Test + public void testNoExceptionThrownByPropertyDescriptorWithValidDefaultValue() { + assertNotNull(validDescriptorBuilder.build()); + } +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/test/java/org/apache/nifi/processor/TestDataUnit.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/test/java/org/apache/nifi/processor/TestDataUnit.java b/nifi-api/src/test/java/org/apache/nifi/processor/TestDataUnit.java new file mode 100644 index 0000000..3e6a235 --- /dev/null +++ b/nifi-api/src/test/java/org/apache/nifi/processor/TestDataUnit.java @@ -0,0 +1,44 @@ +/* + * 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.processor; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * + */ +public class TestDataUnit { + + @Test + public void testParseWithIntegerValue() { + assertEquals(300L, DataUnit.parseDataSize("300 B", DataUnit.B).longValue()); + assertEquals(300L * 1024L, DataUnit.parseDataSize("300 KB", DataUnit.B).longValue()); + assertEquals(300L * 1024L * 1024L, DataUnit.parseDataSize("300 MB", DataUnit.B).longValue()); + assertEquals(300L * 1024L * 1024L * 1024L, DataUnit.parseDataSize("300 GB", DataUnit.B).longValue()); + } + + @Test + public void testParseWithDecimalValue() { + assertEquals(300L, DataUnit.parseDataSize("300 B", DataUnit.B).longValue()); + assertEquals((long) (3.22D * 1024D), DataUnit.parseDataSize("3.22 KB", DataUnit.B).longValue()); + assertEquals((long) (3.22D * 1024D * 1024D), DataUnit.parseDataSize("3.22 MB", DataUnit.B).longValue()); + assertEquals((long) (3.22D * 1024D * 1024D * 1024D), DataUnit.parseDataSize("3.22 GB", DataUnit.B).longValue()); + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/test/resources/logback-test.xml ---------------------------------------------------------------------- diff --git a/nifi-api/src/test/resources/logback-test.xml b/nifi-api/src/test/resources/logback-test.xml new file mode 100644 index 0000000..162b71b --- /dev/null +++ b/nifi-api/src/test/resources/logback-test.xml @@ -0,0 +1,27 @@ +<?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. +--> + +<configuration> + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> + <pattern>%-4r [%t] %-5p %c - %m%n</pattern> + </encoder> + </appender> + <logger name="org.apache.nifi.processor" level="DEBUG"/> + <root level ="DEBUG"> + <appender-ref ref="CONSOLE"/> + </root> +</configuration>
