github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/formation_assignment.go (about)

     1  package model
     2  
     3  import (
     4  	"encoding/json"
     5  	"unsafe"
     6  
     7  	"github.com/kyma-incubator/compass/components/director/pkg/pagination"
     8  )
     9  
    10  // FormationAssignmentType describes possible source and target types
    11  type FormationAssignmentType string
    12  
    13  const (
    14  	// FormationAssignmentTypeApplication represent application type in formation assignment
    15  	FormationAssignmentTypeApplication FormationAssignmentType = "APPLICATION"
    16  	// FormationAssignmentTypeRuntime represent runtime type in formation assignment
    17  	FormationAssignmentTypeRuntime FormationAssignmentType = "RUNTIME"
    18  	// FormationAssignmentTypeRuntimeContext represent runtime context type in formation assignment
    19  	FormationAssignmentTypeRuntimeContext FormationAssignmentType = "RUNTIME_CONTEXT"
    20  )
    21  
    22  // FormationAssignment represent structure for FormationAssignment
    23  type FormationAssignment struct {
    24  	ID          string                  `json:"id"`
    25  	FormationID string                  `json:"formation_id"`
    26  	TenantID    string                  `json:"tenant_id"`
    27  	Source      string                  `json:"source"`
    28  	SourceType  FormationAssignmentType `json:"source_type"`
    29  	Target      string                  `json:"target"`
    30  	TargetType  FormationAssignmentType `json:"target_type"`
    31  	State       string                  `json:"state"`
    32  	Value       json.RawMessage         `json:"value"`
    33  }
    34  
    35  // FormationAssignmentInput is an input for creating a new FormationAssignment
    36  type FormationAssignmentInput struct {
    37  	FormationID string                  `json:"formation_id"`
    38  	Source      string                  `json:"source"`
    39  	SourceType  FormationAssignmentType `json:"source_type"`
    40  	Target      string                  `json:"target"`
    41  	TargetType  FormationAssignmentType `json:"target_type"`
    42  	State       string                  `json:"state"`
    43  	Value       json.RawMessage         `json:"value"`
    44  }
    45  
    46  // FormationAssignmentPage missing godoc
    47  type FormationAssignmentPage struct {
    48  	Data       []*FormationAssignment
    49  	PageInfo   *pagination.Page
    50  	TotalCount int
    51  }
    52  
    53  // FormationAssignmentState represents the possible states a formation assignment can be in
    54  type FormationAssignmentState string
    55  
    56  const (
    57  	// InitialAssignmentState indicates that nothing has been done with the formation assignment
    58  	InitialAssignmentState FormationAssignmentState = "INITIAL"
    59  	// ReadyAssignmentState indicates that the formation assignment is in a ready state
    60  	ReadyAssignmentState FormationAssignmentState = "READY"
    61  	// ConfigPendingAssignmentState indicates that the config is either missing or not finalized in the formation assignment
    62  	ConfigPendingAssignmentState FormationAssignmentState = "CONFIG_PENDING"
    63  	// CreateErrorAssignmentState indicates that an error occurred during the creation of the formation assignment
    64  	CreateErrorAssignmentState FormationAssignmentState = "CREATE_ERROR"
    65  	// DeletingAssignmentState indicates that async unassing notification is sent and status report is expected from the receiver
    66  	DeletingAssignmentState FormationAssignmentState = "DELETING"
    67  	// DeleteErrorAssignmentState indicates that an error occurred during the deletion of the formation assignment
    68  	DeleteErrorAssignmentState FormationAssignmentState = "DELETE_ERROR"
    69  	// NotificationRecursionDepthLimit is the maximum count of configuration exchanges during assigning an object to formation
    70  	NotificationRecursionDepthLimit int = 10
    71  )
    72  
    73  // SupportedFormationAssignmentStates contains the supported formation assignment states
    74  var SupportedFormationAssignmentStates = map[string]bool{
    75  	string(InitialAssignmentState):       true,
    76  	string(ReadyAssignmentState):         true,
    77  	string(ConfigPendingAssignmentState): true,
    78  	string(CreateErrorAssignmentState):   true,
    79  	string(DeletingAssignmentState):      true,
    80  	string(DeleteErrorAssignmentState):   true,
    81  }
    82  
    83  // ToModel converts FormationAssignmentInput to FormationAssignment
    84  func (i *FormationAssignmentInput) ToModel(id, tenantID string) *FormationAssignment {
    85  	if i == nil {
    86  		return nil
    87  	}
    88  
    89  	return &FormationAssignment{
    90  		ID:          id,
    91  		FormationID: i.FormationID,
    92  		TenantID:    tenantID,
    93  		Source:      i.Source,
    94  		SourceType:  i.SourceType,
    95  		Target:      i.Target,
    96  		TargetType:  i.TargetType,
    97  		State:       i.State,
    98  		Value:       i.Value,
    99  	}
   100  }
   101  
   102  // Clone clones the formation assignment
   103  func (f *FormationAssignment) Clone() *FormationAssignment {
   104  	return &FormationAssignment{
   105  		ID:          f.ID,
   106  		FormationID: f.FormationID,
   107  		TenantID:    f.TenantID,
   108  		Source:      f.Source,
   109  		SourceType:  f.SourceType,
   110  		Target:      f.Target,
   111  		TargetType:  f.TargetType,
   112  		State:       f.State,
   113  		Value:       f.Value,
   114  	}
   115  }
   116  
   117  // GetAddress returns the memory address of the FormationAssignment in form of an uninterpreted type(integer number)
   118  // Currently, it's used in some formation constraints input templates, so we could propagate the memory address to the formation constraints operators and later on to modify/update it.
   119  func (f *FormationAssignment) GetAddress() uintptr {
   120  	return uintptr(unsafe.Pointer(f))
   121  }