Skip to content

Commit 73c6759

Browse files
committed
[FAB-9059] move current metadata code to use platfrom
Follow through moving of metadata to platform with moving the code that uses metadata to use the platform abstraction. Change-Id: Ibdd3b8e194ff508f7eeb420c50bc548074072478 Signed-off-by: Srinivasan Muralidharan <srinivasan.muralidharan99@gmail.com>
1 parent f791a37 commit 73c6759

File tree

6 files changed

+14
-57
lines changed

6 files changed

+14
-57
lines changed

core/common/ccprovider/metadata/validators.go core/chaincode/platforms/ccmetadata/validators.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@ Copyright IBM Corp. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package metadata
7+
package ccmetadata
88

99
import (
1010
"encoding/json"
1111
"fmt"
1212
"path/filepath"
1313
"reflect"
1414
"strings"
15-
16-
"github.com/hyperledger/fabric/common/flogging"
1715
)
1816

19-
var logger = flogging.MustGetLogger("metadata")
20-
2117
// fileValidators are used as handlers to validate specific metadata directories
2218
type fileValidator func(fileName string, fileBytes []byte) error
2319

core/common/ccprovider/metadata/validators_test.go core/chaincode/platforms/ccmetadata/validators_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright IBM Corp. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package metadata
7+
package ccmetadata
88

99
import (
1010
"io/ioutil"

core/chaincode/platforms/golang/platform.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/hyperledger/fabric/common/metadata"
3535
"github.com/hyperledger/fabric/core/chaincode/platforms/ccmetadata"
3636
"github.com/hyperledger/fabric/core/chaincode/platforms/util"
37-
ccprovmetadata "github.com/hyperledger/fabric/core/common/ccprovider/metadata"
3837
cutil "github.com/hyperledger/fabric/core/container/util"
3938
pb "github.com/hyperledger/fabric/protos/peer"
4039
"github.com/spf13/viper"
@@ -461,11 +460,7 @@ func (goPlatform *Platform) GetDeploymentPayload(spec *pb.ChaincodeSpec) ([]byte
461460
// Validate metadata file for inclusion in tar
462461
// Validation is based on the passed metadata directory, e.g. META-INF/statedb/couchdb/indexes
463462
// Clean metadata directory to remove trailing slash
464-
//
465-
// NOTE: given we now have a platform specific metadata, it would likely make sense to move
466-
// core/common/ccprovider/metadata to this package (core/common/chaincode/platforms/metadata)
467-
// in future.
468-
err = ccprovmetadata.ValidateMetadataFile(filename, fileBytes, filepath.Clean(packageDir))
463+
err = ccmetadata.ValidateMetadataFile(filename, fileBytes, filepath.Clean(packageDir))
469464
if err != nil {
470465
return nil, err
471466
}

core/common/ccprovider/cc_statedb_artifacts_provider.go

+8-42
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ package ccprovider
99
import (
1010
"archive/tar"
1111
"bytes"
12-
"compress/gzip"
12+
"fmt"
1313
"io"
1414
"io/ioutil"
1515
"path/filepath"
16-
"strings"
16+
17+
"github.com/hyperledger/fabric/core/chaincode/platforms"
1718
)
1819

1920
const (
@@ -47,49 +48,14 @@ func ExtractStatedbArtifactsForChaincode(ccname, ccversion string) (installed bo
4748
// The state db artifacts are expected to contain state db specific artifacts such as index specification in the case of couchdb.
4849
// This function is called during chaincode instantiate/upgrade (from above), and from install, so that statedb artifacts can be created.
4950
func ExtractStatedbArtifactsFromCCPackage(ccpackage CCPackage) (statedbArtifactsTar []byte, err error) {
50-
5151
cds := ccpackage.GetDepSpec()
52-
is := bytes.NewReader(cds.CodePackage)
53-
gr, err := gzip.NewReader(is)
52+
pform, err := platforms.Find(cds.ChaincodeSpec.Type)
5453
if err != nil {
55-
ccproviderLogger.Errorf("Failure opening codepackage gzip stream: %s", err)
56-
return nil, err
57-
}
58-
tr := tar.NewReader(gr)
59-
statedbTarBuffer := bytes.NewBuffer(nil)
60-
tw := tar.NewWriter(statedbTarBuffer)
61-
62-
// For each file in the code package tar,
63-
// add it to the statedb artifact tar if it has "statedb" in the path
64-
for {
65-
header, err := tr.Next()
66-
if err == io.EOF {
67-
// We only get here if there are no more entries to scan
68-
break
69-
}
70-
71-
if err != nil {
72-
return nil, err
73-
}
74-
ccproviderLogger.Debugf("header.Name = %s", header.Name)
75-
if !strings.HasPrefix(header.Name, ccPackageStatedbDir) {
76-
continue
77-
}
78-
if err = tw.WriteHeader(header); err != nil {
79-
ccproviderLogger.Error("Error adding header to statedb tar:", err, header.Name)
80-
return nil, err
81-
}
82-
if _, err := io.Copy(tw, tr); err != nil {
83-
ccproviderLogger.Error("Error copying file to statedb tar:", err, header.Name)
84-
return nil, err
85-
}
86-
ccproviderLogger.Debug("Wrote file to statedb tar:", header.Name)
87-
}
88-
if err = tw.Close(); err != nil {
89-
return nil, err
54+
ccproviderLogger.Infof("invalid deployment spec (bad platform type:%s)", cds.ChaincodeSpec.Type)
55+
return nil, fmt.Errorf("invalid deployment spec")
9056
}
91-
ccproviderLogger.Debug("Created statedb artifact tar")
92-
return statedbTarBuffer.Bytes(), nil
57+
metaprov := pform.GetMetadataProvider(cds)
58+
return metaprov.GetMetadataAsTarEntries()
9359
}
9460

9561
// ExtractFileEntries extract file entries from the given `tarBytes`. A file entry is included in the

core/container/util/writer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"time"
1919

2020
"github.com/hyperledger/fabric/common/flogging"
21-
"github.com/hyperledger/fabric/core/common/ccprovider/metadata"
21+
"github.com/hyperledger/fabric/core/chaincode/platforms/ccmetadata"
2222
"github.com/pkg/errors"
2323
)
2424

@@ -111,7 +111,7 @@ func WriteFolderToTarPackage(tw *tar.Writer, srcPath string, excludeDir string,
111111
// Validate metadata file for inclusion in tar
112112
// Validation is based on the passed metadata directory, e.g. META-INF/statedb/couchdb/indexes
113113
// Clean metadata directory to remove trailing slash
114-
err = metadata.ValidateMetadataFile(filename, fileBytes, filepath.Clean(packageDir))
114+
err = ccmetadata.ValidateMetadataFile(filename, fileBytes, filepath.Clean(packageDir))
115115
if err != nil {
116116
return err
117117
}

core/scc/lscc/lscc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import (
2626
"github.com/hyperledger/fabric/common/flogging"
2727
"github.com/hyperledger/fabric/core/aclmgmt"
2828
"github.com/hyperledger/fabric/core/aclmgmt/resources"
29+
"github.com/hyperledger/fabric/core/chaincode/platforms/ccmetadata"
2930
"github.com/hyperledger/fabric/core/chaincode/shim"
3031
"github.com/hyperledger/fabric/core/common/ccprovider"
31-
ccmetadata "github.com/hyperledger/fabric/core/common/ccprovider/metadata"
3232
"github.com/hyperledger/fabric/core/common/privdata"
3333
"github.com/hyperledger/fabric/core/common/sysccprovider"
3434
"github.com/hyperledger/fabric/core/ledger/cceventmgmt"

0 commit comments

Comments
 (0)