types

Last updated: 2025-11-05 01:15:14.488464 File source: link on GitLab

types

Table of Contents

Specification

Description

types package defines and keeps data structures and interfaces that are used across the whole DMS component by different packages.

Structure and Organisation

Here is quick overview of the contents of this pacakge:

  • README: Current file which is aimed towards developers who wish to use and modify the package functionality.

  • capability: This file contains data structures to describe machine capability.

  • comparison: This file contains constans and types used for capability comparison.

  • constants: This file contains constants that are used across different packages.

  • deployment: This file contains data structure related to job deployment.

  • elk_stats: This file contains data structure to be sent to elasticsearch collector.

  • encryption: This file contains data structure related to encryption in DMS.

  • execution: This file contains data structure related to executor functionality.

  • firecracker: This file contains data structure related to firecracker.

  • machine: This file contains data structure related to the machine - resources, peer details, services etc.

  • network: This file contains data structure related to networking functionality of DMS

  • network_config: This file defines message types, network types (libp2p, NATS) with configurations, and libp2p specific configurations (DHT, keys, peers, scheduling etc).

  • onboarding: This file contains data structure related to compute provider onboarding.

  • resource: This file contains data structures of GPU and execution resources.

  • spec_config: This file defines a SpecConfig struct for configuration data with type, parameters, normalization, validation, and type checking functionalities.

  • storage: This file contains data structures related to storage.

  • telemetry: This file defines structs related to telemetry configuration and methods to load configuration from environment variables.

  • types: This file defines a base model for entities in the application with auto-generated UUIDs, timestamps, and soft delete functionality using GORM hooks.

Class Diagram

Source

types class diagram

Rendered from source file

Functionality

types package holds interfaces and methods that are used by multiple packages. The functionality of these interfaces/methods are typically implemented in other packages.

Here are some methods defined in types package:

NewExecutionResult

  • signature: NewExecutionResult(code int) *ExecutionResult

  • input: exit code

  • output: types.ExecutionResult

NewExecutionResult creates a new ExecutionResult object.

NewFailedExecutionResult

  • signature: NewFailedExecutionResult(err error) *ExecutionResult

  • input: error

  • output: types.ExecutionResult

NewFailedExecutionResult creates a new ExecutionResult object for a failed execution. It sets the error message from the provided error and sets the exit code to -1.

Config interface TBD

GetNetworkConfig will return the network configuration parameters.

NewSpecConfig

  • signature: NewSpecConfig(t string) *SpecConfig

  • input: type for the configuration object

  • output: types.SpecConfig

NewSpecConfig creates new SpecConfig with the given type and an empty params map.

WithParam

  • signature: (s *SpecConfig) WithParam(key string, value interface{}) *SpecConfig

  • input #1 : key

  • input #2 : value associated with the key

  • output: types.SpecConfig

WithParam adds a new key-value pair to the spec parameters and returns the updated SpecConfig object.

Normalize

  • signature: (s *SpecConfig) Normalize()

  • input: None

  • output: None

Normalize ensures that the spec config is in a valid state by trimming whitespace from the Type field and initializing the Params map if empty.

Validate

  • signature: (s *SpecConfig) Validate() error

  • input: None

  • output: error

Validate checks if the spec config is valid. It returns an error if the SpecConfig is nil or if the Type field is missing (blank). Otherwise, it returns no error indicating a valid configuration.

IsType

  • signature: (s *SpecConfig) IsType(t string) bool

  • input: type

  • output: bool

IsType checks if the SpecConfig matches the provided type, ignoring case sensitivity. It returns true if there's a match, otherwise false.

IsEmpty

  • signature: (s *SpecConfig) IsEmpty() bool

  • input: None

  • output: bool

IsEmpty checks if the SpecConfig is empty, meaning it's either nil or has an empty Type and no parameters. It returns true if empty, otherwise false.

GetID

  • signature: (m types.BaseDBModel) GetID() string

  • input: None

  • output: identifier of the entity

GetID returns the identifier of the entity.

BeforeCreate

  • signature: (m *Model) BeforeCreate(tx *gorm.DB) error

  • input: gorm database object to be created

  • output: bool

BeforeCreate sets the ID and CreatedAt fields before creating a new entity.

BeforeUpdate

  • signature: (m *Model) BeforeUpdate(tx *gorm.DB) error

  • input: gorm database object to be updated

  • output: bool

BeforeUpdate returns true if the spec config is empty.

LoadConfigFromEnv

  • signature: LoadConfigFromEnv() (*TelemetryConfig, error)

  • input: none

  • output: types.TelemetryConfig

  • output (error): error message

LoadConfigFromEnv loads the telemetry configuration from environment variables. This includes observabilitty level and collector configuration. It returns the final configuration as types.TelemetryConfig object.

parseObservabilityLevel

  • signature: parseObservabilityLevel(levelStr string) int

  • input: observability level

  • output: int value corresponding to the input observability level

parseObservabilityLevel returns the integer representation of the provided observability level string. When the input string does not match the defined observability levels, default observability level INFO is considered and its integer value is returned.

Data Types

Deployment

  • types.DeploymentRequest

  • types.DeploymentResponse

  • types.DeploymentUpdate

  • types.DeploymentRequestFlat

  • types.BlockchainTxStatus

ELK

  • types.NewDeviceOnboarded

  • types.DeviceStatusChange

  • types.DeviceResourceChange

  • types.DeviceResourceConfig

  • types.NewService

// NewService defines the schema of the data to be sent to stats db when a new service gets registered in the platform type NewService struct { ServiceID string ServiceName string ServiceDescription string Timestamp float32 }

  • types.ServiceCall

  • types.ServiceStatus

  • types.ServiceRemove

  • types.NtxPayment

Executor

  • types.Executor: This defines the type of executor that is used to execute the job.

  • types.ExecutionRequest: This is the input that executor receives to initiate a job execution.

  • types.ExecutionResult: This contains the result of the job execution.

  • types.SpecConfig TBD: This allows arbitrary configuration/parameters as needed during implementation of specific executor.

  • types.LogStreamRequest: This is the input provided when a request to stream logs of an execution is made.

Firecracker

  • types.BootSource: This contains configuration parameters for booting a Firecracker VM.

  • types.Drives: This contains properties of a virtual drive for Firecracker VM.

  • types.MachineConfig: This defines the configuration parameters of the machine to be used while creating a new Firecracker VM.

  • types.NetworkInterfaces: This defines the network configuration parameters.

  • types.MMDSConfig: This contains a list of the network configuration parameters defined by NetworkInterfaces struct.

  • types.MMDSMsg TBD: This contains the latest metadata of the machine.

  • types.MMDSMetadata TBD: This contains the metadata of the machine.

  • types.Actions TBD: This contains the type of action to be performed on the Firecracker VM.

  • types.VirtualMachine: This contains the configuration parameters of Firecracker virtual machine.

Machine

  • types.IP

  • types.PeerInfo TBD: This contains parameters of the peer node.

  • types.Machine: This contains the configuration parameters of the machine.

  • types.FreeResources: This contains the resources currently available for a job.

  • types.AvailableResources: This contains the resources onboarded to Nunet by the user.

  • types.Services TBD: This contains the details of the services running on the machine.

  • types.ServiceResourceRequirements: This contains the resource requirements for a service.

  • types.ContainerImages: This contains parameters of a container image.

  • types.Libp2pInfo: This contains parameters of Libp2p node.

  • types.MachineUUID: This defines the unique identifier for the machine.

  • types.Gpu: This contains the GPU parameters of the machine.

  • types.resources: This defines the resource parameters of the machine.

  • types.PeerData: This contains the details of the peer node.

  • types.Connection: TBD

  • types.PingResult: The contains the details of the ping result.

  • types.Machines: TBD

  • types.KadDHTMachineUpdate: This contains machine info for KAD-DHT.

  • types.ElasticToken: TBD

Onboarding

  • types.BlockchainAddressPrivKey

  • types.CapacityForNunet

  • types.Provisioned

  • types.Metadata

  • types.OnboardingStatus

  • types.LogBinAuth: This stores the authorisation token for LogBin.

Resource

  • types.Resources: resources defined for the machine.

  • types.AvailableResources: resources onboarded to Nunet.

  • types.FreeResources: resources currently available for new jobs.

  • types.RequiredResources: resources required by the jobs running on the machine.

types.GPUVendor: GPU vendors available on the machine.

  • types.GPU: GPU details.

  • types.GPUList: A slice of GPU.

  • types.CPUInfo: CPU information of the machine.

  • types.SpecInfo: detailed specifications of the machine.

  • types.CPU: CPU details.

  • types.RAM: RAM details.

  • types.Disk: Disk details.

  • types.NetworkInfo: Network details.

  • types.Resource: resources resources required to execute a task

Spec_config

  • types.SpecConfig: This allows arbitrary configuration to be defined as needed.

Storage

  • types.StorageVolume: This contains the parameters related to the storage volume that is created by the DMS on the local machine.

Telemetry Config

  • types.CollectorConfig: This contains the parameters for a collector.

  • types.TelemetryConfig: This defines the telemetry parameters such as obervability level, collector configurations etc.

ObservabilityLevel is an enum that defines the level of observability. Currently logging is done at these observability levels.

Types

  • types.BaseDBModel

Testing

Test are defined in other packages where functionality is implemented.

Proposed Functionality / Requirements

List of issues

All issues that are related to the implementation of types package can be found below. These include any proposals for modifications to the package or new data structures needed to cover the requirements of other packages.

proposed Encryption interfaces

These are placeholder interface definitions which will be developed in the future.

Encryptor must support encryption of files/directories

Decryptor must support decryption of files/directories

proposed Network types and methods

This section contains the proposed data types and methods related to network functionality.

  • types.NetworkSpec

  • types.NetConfig

types.NetConfig struct will implement a GetNetworkConfig method which returns network configuration parameters.

  • types.NetworkStats

  • types.MessageInfo

proposed Network configuration data type

  • types.MessageEnvelope

  • types.NetworkConfig

  • types.Libp2pConfig

// Libp2pConfig holds the libp2p configuration type Libp2pConfig struct { DHTPrefix string //crypto is Go-libp2p package that implements various cryptographic utilities PrivateKey crypto.PrivKey BootstrapPeers []multiaddr.Multiaddr Rendezvous string Server bool Scheduler *bt.Scheduler CustomNamespace string ListenAddress []string PeerCountDiscoveryLimit int PrivateNetwork types.PrivateNetworkConfig GracePeriodMs int GossipMaxMessageSize int }

  • types.PrivateNetworkConfig

References

Last updated