Skip to content

Commit

Permalink
Merge pull request #1420 from sodafoundation/metadata-management
Browse files Browse the repository at this point in the history
merge code form metadata management to master
  • Loading branch information
skdwriting authored Jun 12, 2023
2 parents c155cd8 + fcd0668 commit 2b363b5
Show file tree
Hide file tree
Showing 268 changed files with 25,119 additions and 26,432 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
--always --dirty --abbrev=8)
BUILD_TGT := soda-multicloud-$(VERSION)-linux-amd64

.PHONY: all build prebuild api aksk backend s3 dataflow block file docker clean
.PHONY: all build prebuild api aksk backend s3 dataflow block file metadata docker clean

all: build

build: api aksk backend s3 dataflow datamover block file
build: api aksk backend s3 dataflow datamover block file metadata

prebuild:
mkdir -p $(BUILD_DIR)
Expand Down Expand Up @@ -53,6 +53,9 @@ file: prebuild
block: prebuild
CGO_ENABLED=0 GOOS=linux go build -ldflags '-w -s -extldflags "-static"' -o $(BUILD_DIR)/block github.com/opensds/multi-cloud/block/cmd

metadata: prebuild
CGO_ENABLED=0 GOOS=linux go build -ldflags '-w -s -extldflags "-static"' -o $(BUILD_DIR)/metadata github.com/opensds/multi-cloud/metadata/cmd

docker: build

cp $(BUILD_DIR)/api api
Expand All @@ -75,6 +78,10 @@ docker: build
chmod 755 block/block
docker build block -t sodafoundation/multi-cloud-block:latest

cp $(BUILD_DIR)/metadata metadata
chmod 755 metadata/metadata
docker build metadata -t sodafoundation/multi-cloud-metadata:latest

cp $(BUILD_DIR)/s3 s3
chmod 755 s3/s3
chmod 755 s3/initdb.sh
Expand Down Expand Up @@ -119,6 +126,7 @@ dist: build
cp ../datamover $(BUILD_TGT)/bin/ && \
cp ../block $(BUILD_TGT)/bin/ && \
cp ../file $(BUILD_TGT)/bin/ && \
cp ../metadata $(BUILD_TGT)/bin/ && \
cp $(BASE_DIR)/LICENSE $(BUILD_TGT) && \
zip -r $(DIST_DIR)/$(BUILD_TGT).zip $(BUILD_TGT) && \
tar zcvf $(DIST_DIR)/$(BUILD_TGT).tar.gz $(BUILD_TGT)
Expand Down
2 changes: 2 additions & 0 deletions api/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/opensds/multi-cloud/api/pkg/filters/context"
"github.com/opensds/multi-cloud/api/pkg/filters/logging"
"github.com/opensds/multi-cloud/api/pkg/filters/signature/signer"
"github.com/opensds/multi-cloud/api/pkg/metadata"
"github.com/opensds/multi-cloud/api/pkg/s3"
"github.com/opensds/multi-cloud/api/pkg/utils/obs"

Expand Down Expand Up @@ -82,6 +83,7 @@ func main() {
block.RegisterRouter(ws)
file.RegisterRouter(ws)
aksk.RegisterRouter(ws)
metadata.RegisterRouter(ws)
// add filter for authentication context
ws.Filter(logging.FilterFactory())
ws.Filter(context.FilterFactory())
Expand Down
17 changes: 17 additions & 0 deletions api/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,20 @@ func InitCtxWithVal(request *restful.Request, md map[string]string) context.Cont

return metadata.NewContext(context.Background(), md)
}

func GetSizeRequestParamAsInt64(request *restful.Request, param string) (int64, error) {

var val int
if request.QueryParameter(param) != "" {
val, err := strconv.Atoi(request.QueryParameter(param))
if err != nil {
log.Errorf("Param Value is invalid: %v", err)
return int64(val), err
}

return int64(val), nil

}
return int64(val), nil

}
28 changes: 28 additions & 0 deletions api/pkg/metadata/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2021 The OpenSDS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metadata

import (
"github.com/emicklei/go-restful"
"github.com/micro/go-micro/v2/client"
)

func RegisterRouter(ws *restful.WebService) {
handler := NewAPIService(client.DefaultClient)
ws.Route(ws.POST("/backends/sync").To(handler.SyncMetadata)).Doc("Sync metdata from cloud")
ws.Route(ws.POST("/backends/{backendID}/sync").To(handler.SyncMetadata)).Doc(
"Sync metdata from cloud for a particular backend")
ws.Route(ws.GET("/backends/metadata").To(handler.ListMetadata)).Doc("Show metdata details")
}
122 changes: 122 additions & 0 deletions api/pkg/metadata/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2021 The OpenSDS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metadata

import (
"net/http"

"github.com/emicklei/go-restful"
"github.com/micro/go-micro/v2/client"
"github.com/opensds/multi-cloud/api/pkg/common"
mt "github.com/opensds/multi-cloud/metadata/proto"
log "github.com/sirupsen/logrus"
)

const (
metadataService = "metadata"
)

type APIService struct {
metaClient mt.MetadataService
}

func NewAPIService(c client.Client) *APIService {
return &APIService{
metaClient: mt.NewMetadataService(metadataService, c),
}
}

func (s *APIService) SyncMetadata(request *restful.Request, response *restful.Response) {
log.Info("sync metadata called in api service.")
ctx := common.InitCtxWithAuthInfo(request)
var id string
id = request.PathParameter("backendID")
log.Infof("the request recieved for backend is:%s", id)
_, err := s.metaClient.SyncMetadata(ctx, &mt.SyncMetadataRequest{Id: id})
if err != nil {
log.Errorf("failed to sync metadata details: %v\n", err)
response.WriteError(http.StatusInternalServerError, err)
return
}
response.WriteEntity("sync request sent successfully")
}

func (s *APIService) ListMetadata(request *restful.Request, response *restful.Response) {
log.Infof("received request for list metadata details: %s\n", request.PathParameter("id"))

ctx := common.InitCtxWithAuthInfo(request)

listMetadataRequest, err := GetListMetaDataRequest(request)

if err != nil {
log.Errorf("Failed to construct list metadata request err: %v", err)
response.WriteEntity("Invalid type for sizeOfObject or sizeOfBucket request params. It should be integer type.")
return
}

//* calling the ListMetaData method from metadata manager m8s
res, err := s.metaClient.ListMetadata(ctx, &listMetadataRequest)
if err != nil {
log.Errorf("Failed to get metadata details err: %v", err)
response.WriteEntity(err)
return
}

log.Info("got metadata details successfully.")
response.WriteEntity(res.Backends)
}

// GetListMetaDataRequest * This function fetches the request parameters from the request and assigns them default values if not present.
//* It returns ListMetadataRequest for ListMetaData API call
func GetListMetaDataRequest(request *restful.Request) (listMetadataRequest mt.ListMetadataRequest, err error) {
typeOfCloudVendor := request.QueryParameter("type")
backendName := request.QueryParameter("backendName")
bucketName := request.QueryParameter("bucketName")
objectName := request.QueryParameter("objectName")
region := request.QueryParameter("region")
sizeOfObjectInBytes, err := common.GetSizeRequestParamAsInt64(request, "sizeOfObject")
if err != nil {
return mt.ListMetadataRequest{}, err
}

sizeOfBucketInBytes, err := common.GetSizeRequestParamAsInt64(request, "sizeOfBucket")
if err != nil {
return mt.ListMetadataRequest{}, err
}

bucketSizeOperator := request.QueryParameter("bucketSizeOperator")
objectSizeOperator := request.QueryParameter("objectSizeOperator")
sortOrder := request.QueryParameter("sort")
limit, offset, err := common.GetPaginationParam(request)
if err != nil {
return mt.ListMetadataRequest{}, err
}

return mt.ListMetadataRequest{
Type: typeOfCloudVendor,
BackendName: backendName,
Limit: limit,
Offset: offset,
BucketName: bucketName,
ObjectName: objectName,
SizeOfObjectInBytes: sizeOfObjectInBytes,
SizeOfBucketInBytes: sizeOfBucketInBytes,
BucketSizeOperator: bucketSizeOperator,
ObjectSizeOperator: objectSizeOperator,
Region: region,
SortOrder: sortOrder,
}, nil

}
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ services:
- /etc/localtime:/etc/localtime
- /var/log/multi-cloud:/var/log/multi-cloud
- ./examples/multi-cloud.conf:/etc/multi-cloud/multi-cloud.conf

metadata:
image: sodafoundation/multi-cloud-metadata
depends_on:
- keydb
environment:
- MICRO_REGISTRY=mdns
- DB_HOST=datastore:27017
# use container-name of keydb:container port of keydb as the value
- KEY_DB_URI=keydb:6380
volumes:
- /etc/localtime:/etc/localtime
- /var/log/multi-cloud:/var/log/multi-cloud
- ./examples/multi-cloud.conf:/etc/multi-cloud/multi-cloud.conf
restart: always

keydb:
image: eqalpha/keydb:x86_64_v6.2.2
container_name: keydb
ports:
- "6380:6380"
volumes:
- ./examples/keydb.conf:/etc/keydb/keydb.conf
restart: always

block:
image: sodafoundation/multi-cloud-block
Expand Down
Loading

0 comments on commit 2b363b5

Please sign in to comment.