github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/pkg/fftypes/operation.go (about)

     1  // Copyright © 2021 Kaleido, Inc.
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package fftypes
    18  
    19  // OpType describes mechanical steps in the process that have to be performed,
    20  // might be asynchronous, and have results in the back-end systems that might need
    21  // to be correlated with messages by operators.
    22  type OpType = LowerCasedType
    23  
    24  const (
    25  	// OpTypeBlockchainBatchPin is a blockchain transaction to pin a batch
    26  	OpTypeBlockchainBatchPin OpType = "blockchain_batch_pin"
    27  	// OpTypePublicStorageBatchBroadcast is a public storage operation to store broadcast data
    28  	OpTypePublicStorageBatchBroadcast OpType = "publicstorage_batch_broadcast"
    29  	// OpTypeDataExchangeBatchSend is a private send
    30  	OpTypeDataExchangeBatchSend OpType = "dataexchange_batch_send"
    31  )
    32  
    33  // OpStatus is the current status of an operation
    34  type OpStatus string
    35  
    36  const (
    37  	// OpStatusPending indicates the operation has been submitted, but is not yet confirmed as successful or failed
    38  	OpStatusPending OpStatus = "Pending"
    39  	// OpStatusSucceeded the infrastructure runtime has returned success for the operation.
    40  	OpStatusSucceeded OpStatus = "Succeeded"
    41  	// OpStatusFailed happens when an error is reported by the infrastructure runtime
    42  	OpStatusFailed OpStatus = "Failed"
    43  )
    44  
    45  type Named interface {
    46  	Name() string
    47  }
    48  
    49  // NewTXOperation creates a new operation for a transaction
    50  func NewTXOperation(plugin Named, tx *UUID, backendID string, opType OpType, opStatus OpStatus, member string) *Operation {
    51  	return &Operation{
    52  		ID:          NewUUID(),
    53  		Plugin:      plugin.Name(),
    54  		BackendID:   backendID,
    55  		Transaction: tx,
    56  		Type:        opType,
    57  		Member:      member,
    58  		Status:      opStatus,
    59  		Created:     Now(),
    60  	}
    61  }
    62  
    63  // Operation is a description of an action performed as part of a transaction submitted by this node
    64  type Operation struct {
    65  	ID          *UUID      `json:"id"`
    66  	Transaction *UUID      `json:"tx"`
    67  	Type        OpType     `json:"type"`
    68  	Member      string     `json:"member,omitempty"`
    69  	Status      OpStatus   `json:"status"`
    70  	Error       string     `json:"error,omitempty"`
    71  	Plugin      string     `json:"plugin"`
    72  	BackendID   string     `json:"backendID"`
    73  	Info        JSONObject `json:"info,omitempty"`
    74  	Created     *FFTime    `json:"created,omitempty"`
    75  	Updated     *FFTime    `json:"updated,omitempty"`
    76  }