### Multi-Tenant Setup Configuration Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Example configuration for a multi-tenant setup using fixed placement rules. This pattern dynamically creates queues based on tenant names. ```yaml partitions: - name: default placementrules: - name: fixed value: root.tenant-${TENANT_NAME} create: true queues: - name: root parent: true # Tenants create child queues ``` -------------------------------- ### Complete Yunikorn Configuration Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md This is a comprehensive example of a Yunikorn configuration file, demonstrating partitions, queues, limits, and placement rules. ```yaml partitions: - name: default usergroupresolver: type: os nodesortpolicy: type: binpacking resourceweights: cpu: 1.0 memory: 2.0 preemption: enabled: true placementrules: - name: tag value: namespace create: true limits: - limit: "partition-limit" users: - ".*" maxresources: cpu: "100" memory: "10000Gi" queues: - name: root parent: true submitacl: "*" resources: guaranteed: cpu: "100" memory: "1000Gi" max: cpu: "500" memory: "5000Gi" childtemplate: maxapplications: 100 resources: guaranteed: cpu: "1" memory: "4Gi" max: cpu: "50" memory: "200Gi" queues: - name: analytics maxapplications: 50 submitacl: "analytics-team" adminacl: "admin@company.com" resources: guaranteed: cpu: "20" memory: "100Gi" max: cpu: "100" memory: "500Gi" limits: - limit: "per-user" users: - ".*" maxapplications: 5 maxresources: cpu: "4" memory: "16Gi" - name: batch maxapplications: 100 submitacl: "*" resources: guaranteed: cpu: "50" memory: "500Gi" max: cpu: "200" memory: "2000Gi" ``` -------------------------------- ### Start YuniKorn Core Services Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/INDEX.md Demonstrates how to initialize and start all core YuniKorn services. Ensure to defer the stop function for proper cleanup. ```go import "github.com/apache/yunikorn-core/pkg/entrypoint" func main() { // Start all services ctx := entrypoint.StartAllServices() defer ctx.StopAll() // Access scheduler scheduler := ctx.Scheduler clusterContext := scheduler.GetClusterContext() // Access web service webService := ctx.WebApp // Access RM proxy rmProxy := ctx.RMProxy } ``` -------------------------------- ### Complete Event Usage Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/events.md Demonstrates creating application and node event records. This example shows how to initialize resources and call event creation functions. ```go package main import ( "github.com/apache/yunikorn-core/pkg/common/resources" "github.com/apache/yunikorn-core/pkg/events" "github.com/apache/yunikorn-scheduler-interface/lib/go/si" ) func main() { // Create resource with CPU and memory resource := resources.NewResource() resource.Resources["cpu"] = 4000 resource.Resources["memory"] = 8192 // Create application event appEvent := events.CreateAppEventRecord( "app-123", "Application started", "root.analytics", si.EventRecord_ADD, si.EventRecord_DETAILS_NONE, resource, ) // Create node event nodeResource := resources.NewResource() nodeResource.Resources["cpu"] = 16000 nodeResource.Resources["memory"] = 32768 nodeEvent := events.CreateNodeEventRecord( "worker-1", "Node joined cluster", "default", si.EventRecord_ADD, si.EventRecord_DETAILS_NONE, nodeResource, ) // Events can now be published to event system or stored _ = appEvent _ = nodeEvent } ``` -------------------------------- ### Resource Limits Configuration Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Example showing how to configure resource limits for users or groups, specifying maximum resources and application counts. ```yaml limits: - limit: "batch-job-limit" users: - "batch.*" maxresources: cpu: "4" memory: "8Gi" maxapplications: 10 - limit: "data-team-limit" groups: - "data-engineering" - "data-science" maxresources: cpu: "20" memory: "100Gi" maxapplications: 50 ``` -------------------------------- ### Partition Configuration Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md An example of partition-level configuration, specifying user group resolution, preemption settings, and node sorting policy. ```yaml partitions: - name: production usergroupresolver: type: ldap preemption: enabled: true quotapreemptionenabled: false nodesortpolicy: type: binpacking ``` -------------------------------- ### Queue Configuration Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Example demonstrating the structure of a queue definition, including submit/admin ACLs, resource guarantees, and nested queues. ```yaml queues: - name: root submitacl: "*" resources: guaranteed: cpu: "100" memory: "1000Gi" max: cpu: "200" memory: "2000Gi" queues: - name: analytics maxapplications: 50 submitacl: "analytics-team@company.com" adminacl: "admin@company.com" ``` -------------------------------- ### Resources Format Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/types.md Example of how to specify resource guarantees and maximums in YAML format. This format is used for queue resource configurations. ```yaml resources: guaranteed: cpu: "4" memory: "8Gi" max: cpu: "8" memory: "16Gi" ``` -------------------------------- ### Get Queue Applications Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to list applications within a specific queue in a partition. ```go func getQueueApplications(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### getMetrics Handler Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Example output for the getMetrics handler, showing Prometheus metrics in text format. ```text # HELP yunikorn_scheduler_scheduling_latency_seconds Scheduling latency # TYPE yunikorn_scheduler_scheduling_latency_seconds histogram ``` -------------------------------- ### Start Scheduler Services with Defaults Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/entrypoint.md Starts all scheduler services with default parameters, including disabled manual scheduling, enabled web application, and a metrics history size of 1440 entries. Ensure to defer the StopAll() call for proper cleanup. ```go ctx := entrypoint.StartAllServices() defer ctx.StopAll() ``` -------------------------------- ### Get Application Details Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to retrieve details for a specific application, supporting different URL structures. ```go func getApplication(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Preemption Configuration Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Enables both general preemption and quota-based preemption. ```yaml preemption: enabled: true quotapreemptionenabled: true ``` -------------------------------- ### Start Scheduler Services with Custom Logger Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/entrypoint.md Starts all scheduler services using a pre-configured Zap logger instance and Zap configuration. This allows for customized logging behavior. Remember to defer the StopAll() call for graceful shutdown. ```go cfg := zap.NewDevelopmentConfig() logger, _ := cfg.Build() ctx := entrypoint.StartAllServicesWithLogger(logger, &cfg) defer ctx.StopAll() ``` -------------------------------- ### StartWebApp Method Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Starts the web service, registering routes, setting up the HTTP server, enabling compression, and beginning to listen for requests. Returns an error if startup fails. ```go func (ws *WebService) StartWebApp() error ``` ```go webService := webservice.NewWebApp(clusterContext, metricsHistory) if err := webService.StartWebApp(); err != nil { log.Fatal(err) } ``` -------------------------------- ### Start Yunikorn Core Web Service Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md This Go code snippet demonstrates how to start all services in Yunikorn Core, including the web service. The web service will be accessible at http://localhost:9080 by default. Ensure the SCHEDULER_PORT environment variable is set if a different port is desired. ```go package main import ( "github.com/apache/yunikorn-core/pkg/entrypoint" ) func main() { // Start all services including web ctx := entrypoint.StartAllServices() defer ctx.StopAll() // Web service is now running at http://localhost:9080 // Access endpoints like: // - http://localhost:9080/ws/v1/clusters // - http://localhost:9080/ws/v1/partitions // - http://localhost:9080/ws/v1/metrics } ``` -------------------------------- ### Start Scheduler Service Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/scheduler.md Activates the scheduler by starting its event handling and scheduling loops. Requires event handlers and a flag to control automatic scheduling. ```go sched := scheduler.NewScheduler() eventHandlers := handler.EventHandlers{ SchedulerEventHandler: sched, RMProxyEventHandler: rmProxy, } sched.StartService(eventHandlers, false) ``` -------------------------------- ### Get Partition Nodes Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to list nodes within a specific partition. ```go func getPartitionNodes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Queue Resource Configuration Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Illustrates how to define guaranteed and maximum resources for a queue, including CPU, memory, and custom resources like GPUs. ```yaml resources: guaranteed: cpu: "10" memory: "100Gi" gpu: "2" max: cpu: "50" memory: "500Gi" gpu: "8" ``` -------------------------------- ### StartService Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/rmproxy.md Starts the RM proxy service, activating event processing and initializing internal structures. ```APIDOC ## StartService ### Description Starts the RM proxy service, activating event processing. ### Method ```go func (rp *RMProxy) StartService() ``` ### Behavior - Starts goroutine for event handling - Initializes RM tracking structures - Enables communication with scheduler ### Example Usage ```go proxy.StartService() ``` ``` -------------------------------- ### Get Partition Node Details Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to retrieve details for a specific node within a partition. ```go func getPartitionNode(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Get Node Utilizations Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to retrieve node utilization metrics. ```go func getNodeUtilisations(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Start Scheduler Services for Testing Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/entrypoint.md Starts scheduler services in a testing mode, enabling manual scheduling and disabling the web service. This configuration is optimized for test execution. The StopAll() method should be deferred for cleanup. ```go ctx := entrypoint.StartAllServicesWithManualScheduler() ctx.Scheduler.MultiStepSchedule(10) ctx.StopAll() ``` -------------------------------- ### UpdateAllocation Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/rmproxy.md Demonstrates how to update allocation states by allocating or releasing containers. Requires RmID, PartitionName, and lists of allocations or releases. ```go req := &si.AllocationRequest{ RmID: "rm-1", PartitionName: "default", Allocations: []*si.AllocationAsk{ { AllocationKey: "ask-1", ApplicationID: "app-1", Resource: &si.Resource{ Resources: map[string]*si.Quantity{ "cpu": {Value: 4000}, }, }, }, }, } response, err := proxy.UpdateAllocation(req) ``` -------------------------------- ### Get Users Resource Usage Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to retrieve resource usage information for all users within a partition. ```go func getUsersResourceUsage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Get Stack Info Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to the /debug/stack endpoint for a stack trace dump. Response format is text. ```go func getStackInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### StartService Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/scheduler.md Starts the scheduler service, enabling event handling and scheduling loops. It configures event handlers, initiates background goroutines for event processing, node monitoring, and health checks. If `manualSchedule` is false, it also starts the main scheduling loop. ```APIDOC ## StartService ### Description Starts the scheduler service, activating event handling and scheduling loops. ### Parameters #### Parameters - **handlers** (handler.EventHandlers) - Event handler implementations for RM and scheduler events - **manualSchedule** (bool) - If true, disables automatic scheduling; useful for testing ### Behavior: - Sets up event handler in cluster context - Starts RM event handling goroutine - Starts node resource usage monitor - Starts health checker - If not manual: starts scheduling loop, outstanding request inspector, and quota preemption loop ### Example Usage: ```go sched := scheduler.NewScheduler() eventHandlers := handler.EventHandlers{ SchedulerEventHandler: sched, RMProxyEventHandler: rmProxy, } sched.StartService(eventHandlers, false) ``` ``` -------------------------------- ### Create New Scheduler Instance Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/scheduler.md Initializes a new Scheduler instance. The service must be explicitly started using `StartService` before it can be used. ```go sched := scheduler.NewScheduler() ``` -------------------------------- ### UpdateNode Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/rmproxy.md Shows how to update node states and resources, including adding, removing, or updating nodes. Requires RmID and a list of node updates with actions and resources. ```go req := &si.NodeRequest{ RmID: "rm-1", Nodes: []*si.NodeRequest_NodeInfo{ { NodeID: "node-1", Action: si.NodeRequest_ADD, Resource: nodeCapacity, }, }, } response, err := proxy.UpdateNode(req) ``` -------------------------------- ### Start Scheduler Services with Custom Flags Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/entrypoint.md Starts scheduler services with custom flags for manual scheduling and the web application. This is useful for testing scenarios. Always defer the StopAll() call to ensure services are shut down correctly. ```go ctx := entrypoint.StartAllServicesWithParams(true, false) defer ctx.StopAll() ``` -------------------------------- ### Get Groups Resource Usage Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to retrieve resource usage information for all groups within a partition. ```go func getGroupsResourceUsage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Get User Resource Usage Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to retrieve resource usage information for a specific user within a partition. ```go func getUserResourceUsage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Example ResourceManagerCallback UpdateContainerSchedulingState Request Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/plugins.md An example of a request object used to update the container scheduling state, often for notifying the resource manager of failures or allocations. ```go &si.UpdateContainerSchedulingStateRequest{ ApplicationID: "app-1", AllocationKey: "ask-1", State: si.UpdateContainerSchedulingStateRequest_FAILED, Reason: "request is waiting for cluster resources become available", } ``` -------------------------------- ### GET /ws/v1/partition/:partition/placementrules Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves the placement rules configured for a specific partition. ```APIDOC ## GET /ws/v1/partition/:partition/placementrules ### Description Retrieves the placement rules configured for a specific partition. ### Method GET ### Endpoint /ws/v1/partition/:partition/placementrules #### Path Parameters - **partition** (string) - Required - The name of the partition ``` -------------------------------- ### ACL Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Sets administrative ACLs to specific users and groups, and submit ACLs to everyone. ```yaml adminacl: "admin@company.com,@sre-team" submitacl: "*" # Everyone can submit ``` -------------------------------- ### StartService Method Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/rmproxy.md Starts the RM proxy service, activating event processing. This method initiates a goroutine for event handling and enables communication with the scheduler. ```go func (rp *RMProxy) StartService() ``` ```go proxy.StartService() ``` -------------------------------- ### Node Sorting Policy Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Configures the node sorting policy to 'binpacking' with specific resource weights for CPU, memory, and GPU. ```yaml nodesortpolicy: type: binpacking resourceweights: cpu: 1.0 memory: 2.0 gpu: 5.0 ``` -------------------------------- ### Get Partition Applications by State Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to filter applications within a partition by their state. Supports path parameters for partition and state. ```go func getPartitionApplicationsByState(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Example Plugin Implementation in Go Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/plugins.md This Go code demonstrates a basic plugin structure for YuniKorn. It shows how to implement the `UpdateContainerSchedulingState` method and register the plugin using `plugins.RegisterSchedulerPlugin`. Ensure thread-safe implementation and avoid long-running operations within plugin methods. ```go package myscheduler import ( "github.com/apache/yunikorn-core/pkg/plugins" "github.com/apache/yunikorn-scheduler-interface/lib/go/si" ) type MyPlugin struct { // Plugin state } func (p *MyPlugin) UpdateContainerSchedulingState(req *si.UpdateContainerSchedulingStateRequest) error { // Notify external system about container state switch req.State { case si.UpdateContainerSchedulingStateRequest_FAILED: // Trigger scaling return p.notifyScaling(req.ApplicationID, req.AllocationKey, req.Reason) case si.UpdateContainerSchedulingStateRequest_SCHEDULED: // Container scheduled return p.notifyScheduled(req.ApplicationID, req.AllocationKey) } return nil } // Register plugin during initialization func init() { plugins.RegisterSchedulerPlugin(&MyPlugin{}) } ``` -------------------------------- ### StartAllServices Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/entrypoint.md Starts all scheduler services with default parameters. It enables the web application and sets the metrics history size to 1440 entries. Returns a ServiceContext containing all initialized services. ```APIDOC ## StartAllServices ### Description Starts all scheduler services with default parameters, including enabling the web application and setting a default metrics history size. This function is a convenient way to initialize the YuniKorn scheduler for basic usage. ### Function Signature ```go func StartAllServices() *ServiceContext ``` ### Returns *ServiceContext: A pointer to the ServiceContext which holds all initialized scheduler services. ### Example Usage ```go ctx := entrypoint.StartAllServices() defer ctx.StopAll() ``` ``` -------------------------------- ### StartAllServicesWithParams Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/entrypoint.md Starts scheduler services with custom flags for manual scheduling and web application enablement. This is particularly useful for testing scenarios where specific configurations are required. ```APIDOC ## StartAllServicesWithParams ### Description Starts scheduler services with the ability to customize manual scheduling and web application enablement. This function provides flexibility for testing and specific deployment needs. ### Function Signature ```go func StartAllServicesWithParams(manualSchedule, withWebapp bool) *ServiceContext ``` ### Parameters #### Parameters - **manualSchedule** (bool) - If true, disables the automatic scheduling loop, allowing for manual control. - **withWebapp** (bool) - If true, starts the web service for REST endpoints. ### Returns *ServiceContext: A pointer to the ServiceContext with initialized services based on the provided parameters. ### Example Usage ```go ctx := entrypoint.StartAllServicesWithParams(true, false) defer ctx.StopAll() ``` ``` -------------------------------- ### NewResource Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/resources.md Creates a new, empty Resource object with no quantities initialized. This is the starting point for building a resource representation. ```APIDOC ## NewResource ### Description Creates a new empty resource with no quantities set. ### Method ```go func NewResource() *Resource ``` ### Returns Pointer to empty Resource. ### Example Usage ```go res := resources.NewResource() ``` ``` -------------------------------- ### NewScheduler Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/scheduler.md Creates a new, uninitialized Scheduler instance. The service must be started using `StartService` before it can be activated. ```APIDOC ## NewScheduler ### Description Creates a new uninitialized scheduler instance. Must call StartService to activate. ### Returns Initialized Scheduler with default values. ### Example Usage: ```go sched := scheduler.NewScheduler() ``` ``` -------------------------------- ### Resolve User with OS Resolver Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/security.md Example of resolving a user from the system's user database using UserGroupOSResolver. Ensure the resolver is initialized before use. ```go resolver := NewUserGroupOSResolver() userInfo, err := resolver.ResolveUser("alice") if err != nil { // User not found } ``` -------------------------------- ### Manual Scheduling Test Mode Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/INDEX.md Start services with a manual scheduler for testing purposes. Run a specified number of scheduling cycles. ```go ctx := entrypoint.StartAllServicesWithManualScheduler() ctx.Scheduler.MultiStepSchedule(10) // Run 10 cycles ctx.StopAll() ``` -------------------------------- ### Placement Filter Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Demonstrates using filters for placement rules. The first rule allows placement based on a regex for groups, while the second denies placement for specific users. ```yaml placementrules: - name: tag value: namespace create: true filter: type: allow groups: - "prod-.*" # Regex for prod teams - name: fixed value: root.batch create: false filter: type: deny users: - "admin" - "root" ``` -------------------------------- ### getPartitions Handler Response Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Example JSON response for the getPartitions handler, listing available partitions with their state and capacity. ```json { "partitions": [ { "name": "default", "state": "RUNNING", "capacity": {"cpu": 16000, "memory": 32768} } ] } ``` -------------------------------- ### Register ResourceManager and Update Applications/Nodes Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/rmproxy.md This Go code snippet demonstrates how to start YuniKorn services, obtain the RMProxy, register a resource manager, and then update applications and nodes. ```go package main import ( "github.com/apache/yunikorn-core/pkg/entrypoint" "github.com/apache/yunikorn-scheduler-interface/lib/go/si" ) func main() { // Start all services ctx := entrypoint.StartAllServices() defer ctx.StopAll() // Get RM proxy proxy := ctx.RMProxy // Register resource manager regReq := &si.RegisterResourceManagerRequest{ RmId: "kubernetes", PolicyGroup: "default", Config: []byte(configYAML), } regResp, err := proxy.RegisterResourceManager(regReq) if err != nil || !regResp.Success { panic("Registration failed") } // Update applications appReq := &si.ApplicationRequest{ RmID: "kubernetes", New: []*si.ApplicationSubmission{ { ApplicationID: "app-1", QueueName: "root", }, }, } appResp, err := proxy.UpdateApplication(appReq) // Update nodes nodeReq := &si.NodeRequest{ RmID: "kubernetes", Nodes: []*si.NodeRequest_NodeInfo{ { NodeID: "node-1", Action: si.NodeRequest_ADD, }, }, } nodeResp, err := proxy.UpdateNode(nodeReq) } ``` -------------------------------- ### Child Queue Template Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Defines a template for automatically created child queues. Sets limits on applications, resources, and properties. ```yaml queues: - name: root parent: true childtemplate: maxapplications: 100 resources: guaranteed: cpu: "1" memory: "4Gi" max: cpu: "10" memory: "40Gi" properties: tier: "standard" ``` -------------------------------- ### Get Partitions List Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves a list of all partitions and their states. This endpoint provides an overview of the active partitions in the scheduler. ```text GET /ws/v1/partitions ``` -------------------------------- ### GET /ws/v1/clusters Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves general cluster information, including its ID, name, start time, and resource manager build details. ```APIDOC ## GET /ws/v1/clusters ### Description Retrieves general cluster information including capacity and utilization. ### Method GET ### Endpoint /ws/v1/clusters ### Response #### Success Response (200) - **clusterId** (string) - Cluster identifier - **clusterName** (string) - Human-readable cluster name - **startTime** (int64) - Cluster start time (Unix timestamp) - **rmBuildInfo** (object) - Resource manager build information ### Response Example { "clusterId": "cluster-1", "clusterName": "kubernetes", "startTime": 1234567890, "rmBuildInfo": { "buildVersion": "1.7.0" } } ``` -------------------------------- ### ACL Configuration Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/security.md Defines submit and admin ACLs using a combination of exact user matches and regex patterns, or group memberships. ```yaml submitacl: "alice,bob,^service-.*" # alice, bob, or service-* adminacl: "@admin,@sre" # members of admin or sre groups ``` -------------------------------- ### GET /ws/v1/config Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves the current scheduler configuration in YAML format, optionally validating it against a provided checksum. ```APIDOC ## GET /ws/v1/config ### Description Retrieves current scheduler configuration as YAML. ### Method GET ### Endpoint /ws/v1/config ### Parameters #### Query Parameters - **checksum** (string) - If provided, compares with current checksum ### Response #### Success Response (200) - **config** (string) - YAML configuration content - **checksum** (string) - SHA256 checksum of configuration #### Error Response (400) Invalid checksum parameter ``` -------------------------------- ### Get Resource String Representation Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/resources.md Returns a formatted string representation of the resource, suitable for logging purposes. Displays resource types and their quantities. ```go res := resources.NewResource() res.Resources["cpu"] = 4000 fmt.Println(res.String()) // {cpu: 4000} ``` -------------------------------- ### GET /ws/v1/partitions Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves a list of all partitions within the scheduler, including their names, states, capacities, and resource utilization. ```APIDOC ## GET /ws/v1/partitions ### Description Retrieves list of all partitions and their states. ### Method GET ### Endpoint /ws/v1/partitions ### Response #### Success Response (200) - **partitions** (array) - Array of partition objects - **partitions[].name** (string) - Partition name - **partitions[].state** (string) - Partition state (RUNNING, STOPPED, DRAINING) - **partitions[].capacity** (object) - Total available resources - **partitions[].used** (object) - Currently used resources ``` -------------------------------- ### GET /ws/v1/events/batch Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves a batch of recent scheduler events. Supports pagination using a start event ID and limiting the number of returned events. ```APIDOC ## GET /ws/v1/events/batch ### Description Retrieves a batch of recent scheduler events. Supports pagination using a start event ID and limiting the number of returned events. ### Method GET ### Endpoint /ws/v1/events/batch ### Parameters #### Query Parameters - **id** (string) - Optional - Start event ID (for pagination) - **limit** (integer) - Optional - Maximum events to return (default: 100) ### Response #### Success Response (200) - **events** (array) - Array of event records - **events[].eventId** (string) - Event identifier - **events[].type** (string) - Event type (REQUEST, APP, NODE, QUEUE, USERGROUP) - **events[].objectId** (string) - Primary object - **events[].timestamp** (int64) - Event timestamp (nanoseconds) - **events[].message** (string) - Event description ``` -------------------------------- ### GET /debug/stack Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Returns stack traces for all goroutines in the scheduler process, formatted in pprof text format for debugging. ```APIDOC ## GET /debug/stack ### Description Returns stack traces for all goroutines in the scheduler process, formatted in pprof text format for debugging. ### Method GET ### Endpoint /debug/stack ### Response Format Text (pprof format) ``` -------------------------------- ### GET /debug/pprof/* Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Provides access to standard Go pprof profiling endpoints for detailed performance analysis, including heap, goroutine, CPU, and mutex profiles. ```APIDOC ## GET /debug/pprof/* ### Description Provides access to standard Go pprof profiling endpoints for detailed performance analysis, including heap, goroutine, CPU, and mutex profiles. ### Method GET ### Endpoint /debug/pprof/* ### Available Profiles - /debug/pprof/ - /debug/pprof/heap - /debug/pprof/goroutine - /debug/pprof/threadcreate - /debug/pprof/allocs - /debug/pprof/block - /debug/pprof/mutex - /debug/pprof/profile - /debug/pprof/trace ### Response Format Pprof format ``` -------------------------------- ### StartAllServicesWithManualScheduler Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/entrypoint.md Starts scheduler services specifically for testing, enabling manual scheduling and disabling the web service. This provides a controlled environment for scheduler testing. ```APIDOC ## StartAllServicesWithManualScheduler ### Description Starts scheduler services in a testing-oriented mode, characterized by manual scheduling being enabled and the web service being disabled. This setup is ideal for unit and integration tests. ### Function Signature ```go func StartAllServicesWithManualScheduler() *ServiceContext ``` ### Returns *ServiceContext: A pointer to the ServiceContext configured for test execution. ### Example Usage ```go ctx := entrypoint.StartAllServicesWithManualScheduler() ctx.Scheduler.MultiStepSchedule(10) ctx.StopAll() ``` ``` -------------------------------- ### GET /ws/v1/partition/:partition/application/:application Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves detailed information for a specific application within a partition. Provides details on state, allocations, requests, and placeholders. ```APIDOC ## GET /ws/v1/partition/:partition/application/:application ### Description Retrieves detailed application information. ### Method GET ### Endpoint /ws/v1/partition/:partition/application/:application ### Parameters #### Path Parameters - **partition** (string) - Required - Partition name - **application** (string) - Required - Application ID ### Response #### Success Response (200) - **applicationId** (string) - Application identifier - **queueName** (string) - Associated queue - **state** (string) - Application state (SUBMITTED, RUNNING, COMPLETED, etc.) - **allocations** (array) - Current allocations - **requests** (array) - Pending resource requests - **placeholders** (array) - Placeholder pods #### Error Response (404) Application not found ``` -------------------------------- ### Get Events Batch Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests for batch event retrieval using query parameters for ID and limit. ```go func getEvents(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Resolve User with LDAP Resolver Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/security.md Example of resolving a user from an LDAP server using UserGroupLDAPResolver. Requires a properly configured LDAPConfig. ```go resolver := NewUserGroupLDAPResolver(ldapConfig) userInfo, err := resolver.ResolveUser("alice") if err != nil { // LDAP lookup failed } ``` -------------------------------- ### Create and Manipulate Resources Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/INDEX.md Demonstrates how to create, clone, and add resources using the YuniKorn resource package. Ensure the resources package is imported. ```go import "github.com/apache/yunikorn-core/pkg/common/resources" res := resources.NewResource() res.Resources["cpu"] = 4000 res.Resources["memory"] = 8192 // Clone resource resCopy := res.Clone() // Add resources res2 := resources.NewResource() res2.Resources["cpu"] = 2000 res.AddTo(res2) ``` -------------------------------- ### Create Application Event Record Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/INDEX.md Shows how to create an application event record using the events package. Requires importing the events package and having necessary variables like 'resource' defined. ```go import "github.com/apache/yunikorn-core/pkg/events" event := events.CreateAppEventRecord( "app-1", "Application started", "root.queue1", si.EventRecord_ADD, si.EventRecord_DETAILS_NONE, resource, ) ``` -------------------------------- ### Get Group Resource Usage Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to retrieve resource usage information for a specific group within a partition. ```go func getGroupResourceUsage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### GET /ws/v1/partition/:partition/queue/:queue/applications Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves a list of applications within a specific queue in a given partition. Includes application ID, queue name, state, and resource allocation/request counts. ```APIDOC ## GET /ws/v1/partition/:partition/queue/:queue/applications ### Description Retrieves applications in a queue. ### Method GET ### Endpoint /ws/v1/partition/:partition/queue/:queue/applications ### Parameters #### Path Parameters - **partition** (string) - Required - Partition name - **queue** (string) - Required - Queue path ### Response #### Success Response (200) - **applications** (array) - Array of application objects - **applications[].applicationId** (string) - Application ID - **applications[].queueName** (string) - Queue name - **applications[].state** (string) - Application state - **applications[].allocations** (integer) - Number of allocations - **applications[].requests** (integer) - Pending requests #### Error Response (404) Queue not found ``` -------------------------------- ### GET /ws/v1/partition/:partition/usage/users Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves resource usage statistics for all users within a partition. Includes details on resources used and maximum allowed resources per user. ```APIDOC ## GET /ws/v1/partition/:partition/usage/users ### Description Retrieves resource usage by all users in partition. ### Method GET ### Endpoint /ws/v1/partition/:partition/usage/users ### Response #### Success Response (200) - **users** (array) - User usage objects - **users[].username** (string) - Username - **users[].resourceUsage** (object) - Resources used - **users[].maxResources** (object) - Maximum allowed (Note: Partition parameter is implied by the path but not explicitly listed in the source for this endpoint's parameters.) ``` -------------------------------- ### Handle Configuration Loading Errors Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/errors.md Shows how to load scheduler configuration from a byte array and gracefully handle errors by logging the issue and falling back to a default configuration. ```go config, err := configs.LoadSchedulerConfigFromByteArray(yamlBytes) if err != nil { // Log error and use default config log.Log(log.Config).Error("failed to load config", zap.Error(err)) config = getDefaultConfig() } ``` -------------------------------- ### Get Event Stream Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests for a Server-Sent Events stream. Opens a persistent connection and streams events as they occur, with rate limiting applied. ```go func getStream(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### NewWebApp Constructor Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Creates a new instance of the WebService. It requires the cluster context and optionally accepts historical metrics. ```go func NewWebApp(clusterContext *scheduler.ClusterContext, metricsHistory *history.InternalMetricsHistory) *WebService ``` ```go ctx := scheduler.NewClusterContext() webService := webservice.NewWebApp(ctx, nil) ``` -------------------------------- ### Get Full State Dump Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Handles GET requests to the /debug/fullstatedump endpoint for a complete state dump. Response format can be JSON or text and may include plugin dump. ```go func getFullStateDump(w http.ResponseWriter, r *http.Request, ps httprouter.Params) ``` -------------------------------- ### Create Resource from Configuration Map Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/resources.md Builds a Resource from a map of string key-value pairs, commonly used for configuration. It specifically parses 'cpu' as VCore quantity. ```go confMap := map[string]string{ "cpu": "4", "memory": "8Gi", } res, err := resources.NewResourceFromConf(confMap) ``` -------------------------------- ### Create New Resource Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/resources.md Creates a new empty resource with no quantities set. Use this to initialize a resource object. ```go res := resources.NewResource() ``` -------------------------------- ### StartAllServicesWithLogger Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/entrypoint.md Initializes all scheduler services using a custom Zap logging configuration. This allows for advanced control over logging behavior within the YuniKorn scheduler. ```APIDOC ## StartAllServicesWithLogger ### Description Starts all scheduler services with a custom Zap logging configuration, allowing for fine-grained control over how logs are generated and managed. ### Function Signature ```go func StartAllServicesWithLogger(logger *zap.Logger, zapConfigs *zap.Config) *ServiceContext ``` ### Parameters #### Parameters - **logger** (*zap.Logger) - A pre-configured Zap logger instance to be used by the services. - **zapConfigs** (*zap.Config) - The Zap logger configuration to apply. ### Returns *ServiceContext: A pointer to the ServiceContext with initialized services, including the custom logger. ### Example Usage ```go cfg := zap.NewDevelopmentConfig() logger, _ := cfg.Build() ctx := entrypoint.StartAllServicesWithLogger(logger, &cfg) defer ctx.StopAll() ``` ``` -------------------------------- ### GET /ws/v1/history/containers Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves historical container or allocation data. ```APIDOC ## GET /ws/v1/history/containers ### Description Retrieves historical container or allocation data. ### Method GET ### Endpoint /ws/v1/history/containers ``` -------------------------------- ### GET /ws/v1/history/apps Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves historical application data. Supports pagination with limit and offset parameters. ```APIDOC ## GET /ws/v1/history/apps ### Description Retrieves historical application data. Supports pagination with limit and offset parameters. ### Method GET ### Endpoint /ws/v1/history/apps ### Parameters #### Query Parameters - **limit** (integer) - Optional - Maximum records (default: 1000) - **offset** (integer) - Optional - Record offset for pagination ``` -------------------------------- ### Create New Resource by Adding Only Existing Types Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/resources.md Use AddOnlyExisting to add resources only for quantity types that exist in both the base and delta resources. ```go func AddOnlyExisting(base, delta *Resource) *Resource ``` -------------------------------- ### GET /ws/v1/metrics Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves scheduler metrics, such as queue utilization and allocation rates, in Prometheus format. ```APIDOC ## GET /ws/v1/metrics ### Description Retrieves scheduler metrics including queue utilization and allocation rates. ### Method GET ### Endpoint /ws/v1/metrics ### Response #### Success Response (200) - **metrics** (object) - Prometheus-format metrics **Format:** Prometheus text format (Content-Type: text/plain) ``` -------------------------------- ### getClusterInfo Handler Response Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Example JSON response for the getClusterInfo handler, which provides details about the cluster. ```json { "clusterId": "cluster-1", "clusterName": "kubernetes", "startTime": 1234567890 } ``` -------------------------------- ### Load Scheduler Configuration from Byte Array Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/INDEX.md Shows how to load YuniKorn scheduler configuration from a byte array containing YAML data. Handles potential errors during loading. ```go import "github.com/apache/yunikorn-core/pkg/common/configs" yamlConfig := []byte(` partitions: - name: default queues: - name: root submitacl: '*' `) config, err := configs.LoadSchedulerConfigFromByteArray(yamlConfig) ``` -------------------------------- ### Load Scheduler Configuration Programmatically in Go Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md This Go snippet shows how to load scheduler configuration from a byte array. Ensure proper error handling for validation failures. ```go import "github.com/apache/yunikorn-core/pkg/common/configs" yamlBytes := []byte(`...`) config, err := configs.LoadSchedulerConfigFromByteArray(yamlBytes) if err != nil { // Handle validation error } ``` -------------------------------- ### User Group Resolver Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/configuration.md Configures the user group resolver to use LDAP for resolution. ```yaml usergroupresolver: type: ldap ``` -------------------------------- ### Build Yunikorn Core Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/INDEX.md Command to build the Yunikorn core project. ```bash make build ``` -------------------------------- ### getClusterConfig Handler Response Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Example JSON response for the getClusterConfig handler, including configuration details and a checksum. ```json { "config": "partitions:\n - name: default\n...", "checksum": "ABC123..." } ``` -------------------------------- ### NewResourceFromConf Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/resources.md Generates a Resource from a configuration map where values are strings. It specifically handles CPU parsing as VCore quantities. ```APIDOC ## NewResourceFromConf ### Description Creates a Resource from configuration map with string values. Handles CPU parsing specially with VCore conversion. ### Method ```go func NewResourceFromConf(configMap map[string]string) (*Resource, error) ``` ### Parameters #### Path Parameters - **configMap** (map[string]string) - Description: Configuration map with resource type strings and values ### Returns Resource and error if parsing fails. ### Example Usage ```go confMap := map[string]string{ "cpu": "4", "memory": "8Gi", } res, err := resources.NewResourceFromConf(confMap) ``` ``` -------------------------------- ### Create New Resource by Adding Two Resources Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/resources.md Use the Add function to create a new resource that is the sum of two existing resources. This function is nil-safe. ```go func Add(left, right *Resource) *Resource ``` -------------------------------- ### Query Queues via REST API Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/INDEX.md Use the REST GET endpoint to query queue information from the ClusterContext. ```text REST GET /ws/v1/partition/:partition/queues → WebService handler fetches from ClusterContext → Serializes to DAO objects → Returns JSON ``` -------------------------------- ### getPartitionApplicationsByState Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Filters and retrieves applications within a partition based on their current state. This allows for targeted querying of applications, such as those that are running or completed. ```APIDOC ## GET /ws/v1/partition/:partition/applications/:state ### Description Filter by state. ### Method GET ### Endpoint /ws/v1/partition/:partition/applications/:state ### Parameters #### Path Parameters - **partition** (string) - Required - Partition name - **state** (string) - Required - Application state (RUNNING, COMPLETED, etc.) ``` -------------------------------- ### YAML Parse Error Example Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/errors.md Illustrates a typical YAML parsing error message indicating a syntax issue. ```text error parsing YAML: yaml: line 5: mapping values are not allowed in this context ``` -------------------------------- ### getApplication Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/webservice.md Retrieves details for a specific application, identified by its ID. This endpoint supports fetching application details from within a specific queue or directly from the partition. ```APIDOC ## GET /ws/v1/partition/:partition/queue/:queue/application/:application ## GET /ws/v1/partition/:partition/application/:application ### Description Gets application details. ### Method GET ### Endpoint /ws/v1/partition/:partition/queue/:queue/application/:application /ws/v1/partition/:partition/application/:application ``` -------------------------------- ### Create New Resource by Subtracting and Eliminating Negatives Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/resources.md Use SubEliminateNegative to subtract resources while ensuring that any resulting negative values are set to zero. ```go func SubEliminateNegative(left, right *Resource) *Resource ``` -------------------------------- ### GET /debug/fullstatedump Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Returns a complete dump of the internal scheduler state for debugging purposes. The response can be in JSON or text format. ```APIDOC ## GET /debug/fullstatedump ### Description Returns a complete dump of the internal scheduler state for debugging purposes. The response can be in JSON or text format. ### Method GET ### Endpoint /debug/fullstatedump ### Response Format JSON or text ``` -------------------------------- ### GET /ws/v1/scheduler/node-utilizations Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves node resource utilization metrics, providing per-node utilization details and cluster-wide average utilization. ```APIDOC ## GET /ws/v1/scheduler/node-utilizations ### Description Retrieves node resource utilization metrics, providing per-node utilization details and cluster-wide average utilization. ### Method GET ### Endpoint /ws/v1/scheduler/node-utilizations ### Response #### Success Response (200) - **utilizationMetrics** (object) - Per-node utilization - **averageUtilization** (object) - Cluster average utilization ``` -------------------------------- ### Create Application Event Record Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/api-reference/events.md Use this function to create an event record for application state changes. It requires an application ID, a message, a reference ID, change type, change detail, and application resources. ```Go resource := resources.NewResource() resource.Resources["cpu"] = 8000 event := events.CreateAppEventRecord( "app-1", "Application submitted", "root.queue1", si.EventRecord_ADD, si.EventRecord_DETAILS_NONE, resource, ) ``` -------------------------------- ### GET /ws/v1/scheduler/healthcheck Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves the overall health status of the scheduler, including the last successful scheduling time and the count of scheduling failures. ```APIDOC ## GET /ws/v1/scheduler/healthcheck ### Description Retrieves the overall health status of the scheduler, including the last successful scheduling time and the count of scheduling failures. ### Method GET ### Endpoint /ws/v1/scheduler/healthcheck ### Response #### Success Response (200) - **healthy** (boolean) - Overall scheduler health - **lastSchedulingSuccess** (int64) - Last successful scheduling (timestamp) - **schedulingFailures** (integer) - Number of scheduling failures ``` -------------------------------- ### GET /ws/v1/partition/:partition/usage/groups Source: https://github.com/apache/yunikorn-core/blob/master/_autodocs/endpoints.md Retrieves resource usage statistics for all groups within a partition. Provides an overview of group-level resource consumption. ```APIDOC ## GET /ws/v1/partition/:partition/usage/groups ### Description Retrieves resource usage by all groups in partition. ### Method GET ### Endpoint /ws/v1/partition/:partition/usage/groups ### Response #### Success Response (200) (No specific response schema provided in source) (Note: Partition parameter is implied by the path but not explicitly listed in the source for this endpoint's parameters.) ```