github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/api/apc/tcb.go (about)

     1  // Package apc: API control messages and constants
     2  /*
     3   * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package apc
     6  
     7  import (
     8  	"errors"
     9  	"strings"
    10  
    11  	"github.com/NVIDIA/aistore/cmn/cos"
    12  )
    13  
    14  // copy & (offline) transform bucket to bucket
    15  type (
    16  	CopyBckMsg struct {
    17  		Prepend   string `json:"prepend"`     // destination naming, as in: dest-obj-name = Prepend + source-obj-name
    18  		Prefix    string `json:"prefix"`      // prefix to select matching _source_ objects or virtual directories
    19  		DryRun    bool   `json:"dry_run"`     // visit all source objects, don't make any modifications
    20  		Force     bool   `json:"force"`       // force running in presence of "limited coexistence" type conflicts
    21  		LatestVer bool   `json:"latest-ver"`  // see also: QparamLatestVer, 'versioning.validate_warm_get', PrefetchMsg
    22  		Sync      bool   `json:"synchronize"` // see also: 'versioning.synchronize'
    23  	}
    24  	Transform struct {
    25  		Name    string       `json:"id,omitempty"`
    26  		Timeout cos.Duration `json:"request_timeout,omitempty"`
    27  	}
    28  	TCBMsg struct {
    29  		// NOTE: objname extension ----------------------------------------------------------------------
    30  		// - resulting object names will have this extension, if specified.
    31  		// - if source bucket has two (or more) objects with the same base name but different extension,
    32  		//   specifying this field might cause unintended override.
    33  		// - this field might not be any longer required - TODO review
    34  		Ext cos.StrKVs `json:"ext"`
    35  
    36  		Transform
    37  		CopyBckMsg
    38  	}
    39  )
    40  
    41  ////////////
    42  // TCBMsg //
    43  ////////////
    44  
    45  func (msg *TCBMsg) Validate(isEtl bool) (err error) {
    46  	if isEtl && msg.Transform.Name == "" {
    47  		err = errors.New("ETL name can't be empty")
    48  	}
    49  	return
    50  }
    51  
    52  // Replace extension and add suffix if provided.
    53  func (msg *TCBMsg) ToName(name string) string {
    54  	if msg.Ext != nil {
    55  		if idx := strings.LastIndexByte(name, '.'); idx >= 0 {
    56  			ext := name[idx+1:]
    57  			if replacement, exists := msg.Ext[ext]; exists {
    58  				name = name[:idx+1] + strings.TrimLeft(replacement, ".")
    59  			}
    60  		}
    61  	}
    62  	if msg.Prepend != "" {
    63  		name = msg.Prepend + name
    64  	}
    65  	return name
    66  }