Added bundle information to NiFi get service types call
@@ -28,6 +28,8 @@ import com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException;
import com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException;
import com.thinkbiganalytics.nifi.rest.support.NifiConstants;
+import org.apache.nifi.web.api.dto.BundleDTO;
+import org.apache.nifi.web.api.dto.ControllerServiceApiDTO;
import org.apache.nifi.web.api.dto.ControllerServiceDTO;
import org.apache.nifi.web.api.dto.DocumentedTypeDTO;
import org.apache.nifi.web.api.dto.RevisionDTO;
@@ -36,6 +38,8 @@ import org.apache.nifi.web.api.entity.ControllerServiceTypesEntity;
import org.apache.nifi.web.api.entity.ControllerServicesEntity;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -88,8 +92,7 @@ if(controllerServiceEntity.isPresent()) {
return Optional.empty();
}
});
-}
-else {
+ } else {
return Optional.empty();
}
}
@@ -136,7 +139,30 @@ else {
@Nonnull
@Override
public Set<DocumentedTypeDTO> getTypes(@Nonnull final String serviceType) {
- return client.get("/flow/controller-service-types", Collections.singletonMap("serviceType", serviceType), ControllerServiceTypesEntity.class).getControllerServiceTypes();
+ // Find the bundle that contains the API
+ final Optional<ControllerServiceApiDTO> controllerServiceApi = getTypes().stream()
+ .flatMap(type -> type.getControllerServiceApis().stream())
+ .filter(api -> api.getType().equals(serviceType))
+ .findAny();
+
+ // Query for types implementing the API
+ return controllerServiceApi
+ .map(api -> {
+ final Map<String, Object> query = new HashMap<>();
+ query.put("serviceType", serviceType);
+
+ final BundleDTO bundle = api.getBundle();
+ if (bundle != null) {
+ query.put("serviceBundleGroup", bundle.getGroup());
+ query.put("serviceBundleArtifact", bundle.getArtifact());
+ query.put("serviceBundleVersion", bundle.getVersion());
+ }
+
+ return query;
+ })
+ .map(query -> client.get("/flow/controller-service-types", query, ControllerServiceTypesEntity.class))
+ .map(ControllerServiceTypesEntity::getControllerServiceTypes)
+ .orElseGet(Collections::emptySet);
}
@Nonnull
