Repository: nifi
Updated Branches:
  refs/heads/master 2c69c2532 -> c955ec168


http://git-wip-us.apache.org/repos/asf/nifi/blob/c955ec16/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/ControllerServiceDAO.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/ControllerServiceDAO.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/ControllerServiceDAO.java
index eac7a5a..b79bd76 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/ControllerServiceDAO.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/ControllerServiceDAO.java
@@ -51,11 +51,12 @@ public interface ControllerServiceDAO {
     ControllerServiceNode getControllerService(String controllerServiceId);
 
     /**
-     * Gets all of the controller services.
+     * Gets all of the controller services for the group with the given ID or 
all
+     * controller-level services if the group id is null
      *
      * @return The controller services
      */
-    Set<ControllerServiceNode> getControllerServices();
+    Set<ControllerServiceNode> getControllerServices(String groupId);
 
     /**
      * Updates the specified controller service.

http://git-wip-us.apache.org/repos/asf/nifi/blob/c955ec16/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java
index 435d5ce..3db3973 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java
@@ -16,31 +16,34 @@
  */
 package org.apache.nifi.web.dao.impl;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.nifi.components.state.Scope;
 import org.apache.nifi.components.state.StateMap;
 import org.apache.nifi.controller.ConfiguredComponent;
+import org.apache.nifi.controller.FlowController;
 import org.apache.nifi.controller.ScheduledState;
 import 
org.apache.nifi.controller.exception.ControllerServiceInstantiationException;
 import org.apache.nifi.controller.exception.ValidationException;
 import org.apache.nifi.controller.service.ControllerServiceNode;
 import org.apache.nifi.controller.service.ControllerServiceProvider;
 import org.apache.nifi.controller.service.ControllerServiceState;
+import org.apache.nifi.groups.ProcessGroup;
 import org.apache.nifi.web.NiFiCoreException;
 import org.apache.nifi.web.ResourceNotFoundException;
 import org.apache.nifi.web.api.dto.ControllerServiceDTO;
 import org.apache.nifi.web.dao.ComponentStateDAO;
 import org.apache.nifi.web.dao.ControllerServiceDAO;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 public class StandardControllerServiceDAO extends ComponentDAO implements 
ControllerServiceDAO {
 
     private ControllerServiceProvider serviceProvider;
     private ComponentStateDAO componentStateDAO;
+    private FlowController flowController;
 
     private ControllerServiceNode locateControllerService(final String 
controllerServiceId) {
         // get the controller service
@@ -71,6 +74,24 @@ public class StandardControllerServiceDAO extends 
ComponentDAO implements Contro
             // perform the update
             configureControllerService(controllerService, 
controllerServiceDTO);
 
+            final String groupId = controllerServiceDTO.getParentGroupId();
+            if (groupId == null) {
+                flowController.addRootControllerService(controllerService);
+            } else {
+                final ProcessGroup group;
+                if (groupId.equals(FlowController.ROOT_GROUP_ID_ALIAS)) {
+                    group = 
flowController.getGroup(flowController.getRootGroupId());
+                } else {
+                    group = 
flowController.getGroup(flowController.getRootGroupId()).findProcessGroup(groupId);
+                }
+
+                if (group == null) {
+                    throw new ResourceNotFoundException(String.format("Unable 
to locate group with id '%s'.", groupId));
+                }
+
+                group.addControllerService(controllerService);
+            }
+
             return controllerService;
         } catch (final ControllerServiceInstantiationException csie) {
             throw new NiFiCoreException(csie.getMessage(), csie);
@@ -88,8 +109,17 @@ public class StandardControllerServiceDAO extends 
ComponentDAO implements Contro
     }
 
     @Override
-    public Set<ControllerServiceNode> getControllerServices() {
-        return serviceProvider.getAllControllerServices();
+    public Set<ControllerServiceNode> getControllerServices(final String 
groupId) {
+        if (groupId == null) {
+            return flowController.getRootControllerServices();
+        } else {
+            final ProcessGroup procGroup = 
flowController.getGroup(flowController.getRootGroupId()).findProcessGroup(groupId);
+            if (procGroup == null) {
+                throw new ResourceNotFoundException("Could not find Process 
Group with ID " + groupId);
+            }
+
+            return procGroup.getControllerServices(true);
+        }
     }
 
     @Override
@@ -162,7 +192,7 @@ public class StandardControllerServiceDAO extends 
ComponentDAO implements Contro
     }
 
     @Override
-    public void verifyUpdateReferencingComponents(String controllerServiceId, 
ScheduledState scheduledState, ControllerServiceState controllerServiceState) {
+    public void verifyUpdateReferencingComponents(final String 
controllerServiceId, final ScheduledState scheduledState, final 
ControllerServiceState controllerServiceState) {
         final ControllerServiceNode controllerService = 
locateControllerService(controllerServiceId);
 
         if (controllerServiceState != null) {
@@ -200,7 +230,7 @@ public class StandardControllerServiceDAO extends 
ComponentDAO implements Contro
                         controllerService.verifyCanDisable();
                     }
                 }
-            } catch (IllegalArgumentException iae) {
+            } catch (final IllegalArgumentException iae) {
                 throw new IllegalArgumentException("Controller Service state: 
Value must be one of [ENABLED, DISABLED]");
             }
         }
@@ -255,35 +285,39 @@ public class StandardControllerServiceDAO extends 
ComponentDAO implements Contro
     }
 
     @Override
-    public void deleteControllerService(String controllerServiceId) {
+    public void deleteControllerService(final String controllerServiceId) {
         final ControllerServiceNode controllerService = 
locateControllerService(controllerServiceId);
         serviceProvider.removeControllerService(controllerService);
     }
 
     @Override
-    public StateMap getState(String controllerServiceId, Scope scope) {
+    public StateMap getState(final String controllerServiceId, final Scope 
scope) {
         final ControllerServiceNode controllerService = 
locateControllerService(controllerServiceId);
         return componentStateDAO.getState(controllerService, scope);
     }
 
     @Override
-    public void verifyClearState(String controllerServiceId) {
+    public void verifyClearState(final String controllerServiceId) {
         final ControllerServiceNode controllerService = 
locateControllerService(controllerServiceId);
         controllerService.verifyCanClearState();
     }
 
     @Override
-    public void clearState(String controllerServiceId) {
+    public void clearState(final String controllerServiceId) {
         final ControllerServiceNode controllerService = 
locateControllerService(controllerServiceId);
         componentStateDAO.clearState(controllerService);
     }
 
     /* setters */
-    public void setServiceProvider(ControllerServiceProvider serviceProvider) {
+    public void setServiceProvider(final ControllerServiceProvider 
serviceProvider) {
         this.serviceProvider = serviceProvider;
     }
 
-    public void setComponentStateDAO(ComponentStateDAO componentStateDAO) {
+    public void setComponentStateDAO(final ComponentStateDAO 
componentStateDAO) {
         this.componentStateDAO = componentStateDAO;
     }
+
+    public void setFlowController(final FlowController flowController) {
+        this.flowController = flowController;
+    }
 }

http://git-wip-us.apache.org/repos/asf/nifi/blob/c955ec16/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
index 1ca34dc..39c386d 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/resources/nifi-web-api-context.xml
@@ -91,6 +91,7 @@
     <bean id="controllerServiceDAO" 
class="org.apache.nifi.web.dao.impl.StandardControllerServiceDAO">
         <property name="serviceProvider" ref="controllerServiceProvider"/>
         <property name="componentStateDAO" ref="componentStateDAO"/>
+        <property name="flowController" ref="flowController" />
     </bean>
     <bean id="reportingTaskDAO" 
class="org.apache.nifi.web.dao.impl.StandardReportingTaskDAO">
         <property name="reportingTaskProvider" ref="reportingTaskProvider"/>
@@ -150,7 +151,7 @@
         <property name="clusterCoordinator" ref="clusterCoordinator" />
         <property name="requestReplicator" ref="requestReplicator" />
         <property name="auditService" ref="auditService"/>
-        <property name="controllerServiceLookup" 
ref="controllerServiceProvider"/>
+        <property name="controllerServiceProvider" 
ref="controllerServiceProvider"/>
         <property name="reportingTaskProvider" ref="reportingTaskProvider"/>
         <property name="authorizer" ref="authorizer"/>
     </bean>

Reply via email to