Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/NifiDataflowOrganizer] Implementation of NifiDataflowOrganizer controller #264

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

### Added

- [PR #258](https://github.com/konpyutaika/nifikop/pull/141) - **[Helm Chart]** Upgraded helm-deployed HPA to v2 and added flowPosition to NiFiDataflow
- [PR #258](https://github.com/konpyutaika/nifikop/pull/141) - **[Helm Chart]** Upgraded helm-deployed HPA to v2 and added flowPosition to NiFiDataflow helm chart.
- [PR #264](https://github.com/konpyutaika/nifikop/pull/264) - **[Operator/NifiDataflowOrganizer]** Implementation on NifiDataflowOrganizer controller.

### Changed

Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ resources:
kind: NifiNodeGroupAutoscaler
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: konpyutaika.com
group: nifi
kind: NifiDataflowOrganizer
path: github.com/konpyutaika/nifikop/api/v1alpha1
version: v1alpha1
version: "3"
29 changes: 24 additions & 5 deletions api/v1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,35 +123,54 @@ type SecretConfigReference struct {
// ClusterReference states a reference to a cluster for dataflow/registryclient/user
// provisioning
type ClusterReference struct {
Name string `json:"name"`
// Name of the NifiCluster.
Name string `json:"name"`
// NifiCluster namespace location.
Namespace string `json:"namespace,omitempty"`
}

// RegistryClientReference states a reference to a registry client for dataflow
// provisioning
type RegistryClientReference struct {
Name string `json:"name"`
// Name of the NifiRegistryClient.
Name string `json:"name"`
// NifiRegistryClient namespace location.
Namespace string `json:"namespace,omitempty"`
}

// ParameterContextReference states a reference to a parameter context for dataflow
// provisioning
type ParameterContextReference struct {
Name string `json:"name"`
// Name of the NifiParameterContext.
Name string `json:"name"`
// NifiParameterContext namespace location.
Namespace string `json:"namespace,omitempty"`
}

// SecretReference states a reference to a secret for parameter context
// provisioning
type SecretReference struct {
Name string `json:"name"`
// Name of the Secret.
Name string `json:"name"`
// Secret namespace location.
Namespace string `json:"namespace,omitempty"`
}

// UserReference states a reference to a user for user group
// provisioning
type UserReference struct {
Name string `json:"name"`
// Name of the NifiUser.
Name string `json:"name"`
// NifiUser namespace location.
Namespace string `json:"namespace,omitempty"`
}

// DataflowReference states a reference to a dataflow for dataflow organizer
// provisioning
type DataflowReference struct {
// Name of the NifiDataflow.
Name string `json:"name"`
// NifiDataflow namespace location.
Namespace string `json:"namespace,omitempty"`
}

Expand Down
15 changes: 15 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,35 +123,54 @@ type SecretConfigReference struct {
// ClusterReference states a reference to a cluster for dataflow/registryclient/user
// provisioning
type ClusterReference struct {
Name string `json:"name"`
// Name of the NifiCluster.
Name string `json:"name"`
// NifiCluster namespace location.
Namespace string `json:"namespace,omitempty"`
}

// RegistryClientReference states a reference to a registry client for dataflow
// provisioning
type RegistryClientReference struct {
Name string `json:"name"`
// Name of the NifiRegistryClient.
Name string `json:"name"`
// NifiRegistryClient namespace location.
Namespace string `json:"namespace,omitempty"`
}

// ParameterContextReference states a reference to a parameter context for dataflow
// provisioning
type ParameterContextReference struct {
Name string `json:"name"`
// Name of the NifiParameterContext.
Name string `json:"name"`
// NifiParameterContext namespace location.
Namespace string `json:"namespace,omitempty"`
}

// SecretReference states a reference to a secret for parameter context
// provisioning
type SecretReference struct {
Name string `json:"name"`
// Name of the Secret.
Name string `json:"name"`
// Secret namespace location.
Namespace string `json:"namespace,omitempty"`
}

// UserReference states a reference to a user for user group
// provisioning
type UserReference struct {
Name string `json:"name"`
// Name of the NifiUser.
Name string `json:"name"`
// NifiUser namespace location.
Namespace string `json:"namespace,omitempty"`
}

// DataflowReference states a reference to a dataflow for dataflow organizer
// provisioning
type DataflowReference struct {
// Name of the NifiDataflow.
Name string `json:"name"`
// NifiDataflow namespace location.
Namespace string `json:"namespace,omitempty"`
}

Expand Down
158 changes: 158 additions & 0 deletions api/v1alpha1/nifidatafloworganizer_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package v1alpha1

import (
"math"
"sort"
"strings"

v1 "github.com/konpyutaika/nifikop/api/v1"
"github.com/konpyutaika/nifikop/pkg/util"
nifiutil "github.com/konpyutaika/nifikop/pkg/util/nifi"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NifiDataflowOrganizerSpec defines the desired state of NifiDataflowOrganizer
type NifiDataflowOrganizerSpec struct {
// contains the reference to the NifiCluster with the one the user is linked.
ClusterRef v1.ClusterReference `json:"clusterRef"`
// the maximum width before moving to the next line.
// +kubebuilder:default=1000
// +kubebuilder:validation:Minimum=0
// +optional
MaxWidth int `json:"maxWidth,omitempty"`
// the initial position of all the groups.
// +optional
InitialPosition OrganizerGroupPosition `json:"initalPosition,omitempty"`
// the groups of dataflow to organize
Groups map[string]OrganizerGroup `json:"groups"`
}

type OrganizerGroup struct {
// the UUID of the parent process group where you want to create your group, if not set deploy at root level.
// +optional
ParentProcessGroupID string `json:"parentProcessGroupID,omitempty"`
// the color of the group.
// +kubebuilder:default="#FFF7D7"
// +kubebuilder:validation:Pattern:="^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$"
// +optional
Color string `json:"color,omitempty"`
// the font size of the group
// +kubebuilder:default="18px"
// +kubebuilder:validation:Pattern:="^([0-9]+px)$"
// +optional
FontSize string `json:"fontSize,omitempty"`
// the maximum number of dataflow on the same line.
// +kubebuilder:default=5
// +kubebuilder:validation:Minimum=1
// +optional
MaxColumnSize int `json:"maxColumnSize,omitempty"`
// contains the reference to the NifiDataflows associated to the group.
DataflowRef []v1.DataflowReference `json:"dataflowRef,omitempty"`
}

type OrganizerGroupPosition struct {
// the x coordinate.
// +kubebuilder:default=0
// +optional
X int64 `json:"posX,omitempty"`
// the y coordinate.
// +kubebuilder:default=0
// +optional
Y int64 `json:"posY,omitempty"`
}

// NifiDataflowOrganizerStatus defines the observed state of NifiDataflowOrganizer
type NifiDataflowOrganizerStatus struct {
// the status of the groups.
GroupStatus map[string]OrganizerGroupStatus `json:"groupStatus"`
}

type OrganizerGroupStatus struct {
// the status of the title label.
TitleStatus OrganizerGroupTitleStatus `json:"titleStatus"`
// the status of the content label.
ContentStatus OrganizerGroupContentStatus `json:"contentStatus"`
}

type OrganizerGroupTitleStatus struct {
// the id of the title label.
Id string `json:"id"`
}

type OrganizerGroupContentStatus struct {
// the id of the content label.
Id string `json:"id"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// NifiDataflowOrganizer is the Schema for the nifidatafloworganizers API
type NifiDataflowOrganizer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec NifiDataflowOrganizerSpec `json:"spec,omitempty"`
Status NifiDataflowOrganizerStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// NifiDataflowOrganizerList contains a list of NifiDataflowOrganizer
type NifiDataflowOrganizerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NifiDataflowOrganizer `json:"items"`
}

func init() {
SchemeBuilder.Register(&NifiDataflowOrganizer{}, &NifiDataflowOrganizerList{})
}

func (d *OrganizerGroup) GetParentProcessGroupID(rootProcessGroupId string) string {
if d.ParentProcessGroupID == "" {
return rootProcessGroupId
}
return d.ParentProcessGroupID
}

func (d *OrganizerGroup) GetTitleWidth(name string) float64 {
return float64(len(name)) * util.ConvertStringToFloat64(strings.Split(d.FontSize, "px")[0]) * 0.7
}

func (d *OrganizerGroup) GetTitleHeight(name string) float64 {
return util.ConvertStringToFloat64(strings.Split(d.FontSize, "px")[0]) * 1.75
}

func (d *OrganizerGroup) GetContentWidth(name string) float64 {
calculatedWidth := float64(nifiutil.ProcessGroupWidth+nifiutil.ProcessGroupPadding)*d.GetNumberOfColumns() + float64(nifiutil.ProcessGroupPadding)
if calculatedWidth < d.GetTitleWidth(name) {
return d.GetTitleWidth(name)
}
return calculatedWidth
}

func (d *OrganizerGroup) GetContentHeight() float64 {
return float64(nifiutil.ProcessGroupHeight+nifiutil.ProcessGroupPadding)*d.GetNumberOfLines() + float64(nifiutil.ProcessGroupPadding)
}

func (d *OrganizerGroup) GetNumberOfLines() float64 {
return math.Ceil(math.Max(float64(len(d.DataflowRef)), 1) / d.GetNumberOfColumns())
}

func (d *OrganizerGroup) GetNumberOfColumns() float64 {
if len(d.DataflowRef) < d.MaxColumnSize {
return math.Max(float64(len(d.DataflowRef)), 1)
}
return float64(d.MaxColumnSize)
}

func (d *NifiDataflowOrganizerSpec) GetGroupNames() []string {
keys := make([]string, 0)
for k := range d.Groups {
keys = append(keys, k)
}

sort.Strings(keys)
return keys
}
Loading