diff --git a/epm/cmd/epm/app/server.go b/epm/cmd/epm/app/server.go index 0d75e98cfe5223a2c0428cd692343ae5b75e94ad..b1811fcd470445d11ed90272224f24d121e3cd30 100644 --- a/epm/cmd/epm/app/server.go +++ b/epm/cmd/epm/app/server.go @@ -42,32 +42,32 @@ func runServer(opts *options.Options) error { return fmt.Errorf("create metadata server failed. %++v", err) } - server := epm.CachePoolManagerServer{} + server := epm.EnclavePoolManagerServer{} - bundleCache0 := occlum.Cach0Manager{ - DefaultCachePoolManager: epm.DefaultCachePoolManager{ + bundleCache0 := occlum.BundleCach0Manager{ + DefaultEnclavePool: epm.DefaultEnclavePool{ Root: cfg.Root, CacheMetadata: metadata, }} - bundleCache1 := occlum.Cach1Manager{ - DefaultCachePoolManager: epm.DefaultCachePoolManager{ + bundleCache1 := occlum.BundleCach1Manager{ + DefaultEnclavePool: epm.DefaultEnclavePool{ Root: cfg.Root, CacheMetadata: metadata, }} - bundleCache2 := occlum.Cach2Manager{ - DefaultCachePoolManager: epm.DefaultCachePoolManager{ + bundleCache2 := occlum.BundleCach2Manager{ + DefaultEnclavePool: epm.DefaultEnclavePool{ Root: cfg.Root, CacheMetadata: metadata, }} - // registry the bundle cache pool managers to the manager server - server.RegistryCachePoolManager(&bundleCache0) - server.RegistryCachePoolManager(&bundleCache1) - server.RegistryCachePoolManager(&bundleCache2) + // register the bundle cache pool managers to the manager server + server.RegisterCachePoolManager(&bundleCache0) + server.RegisterCachePoolManager(&bundleCache1) + server.RegisterCachePoolManager(&bundleCache2) // start the grpc server with the server options s := grpc.NewServer(serverOpts...) // registry and start the cache pool manager server - v1alpha1.RegisterCachePoolManagerServer(s, &server) + v1alpha1.RegisterEnclavePoolManagerServer(s, &server) // listen and serve lis, err := net.Listen("udp", cfg.GRPC.Address) if err != nil { diff --git a/epm/cmd/epm/app/start.go b/epm/cmd/epm/app/start.go index a6ca05e006664cedd00c8c86dc8e40532a96af8b..8375016e5b3576b50e6de6530c5e9879ee9499ec 100644 --- a/epm/cmd/epm/app/start.go +++ b/epm/cmd/epm/app/start.go @@ -5,8 +5,8 @@ import ( "github.com/spf13/cobra" ) -// NewCachePoolManagerServer creat and start the cache pool manager server -func NewCachePoolManagerServer() *cobra.Command { +// NewEnclavePoolManagerServer creat and start the enclave pool manager server +func NewEnclavePoolManagerServer() *cobra.Command { opts := &options.Options{} cmd := &cobra.Command{ Short: "Launch signature server", diff --git a/epm/cmd/epm/main.go b/epm/cmd/epm/main.go index b3fb38763c7b5333f9fed87b9192aa1f22ddfc7f..a834784152b7a1330c7f77ca04852b600aa26e4d 100644 --- a/epm/cmd/epm/main.go +++ b/epm/cmd/epm/main.go @@ -14,7 +14,7 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) } - cmd := app.NewCachePoolManagerServer() + cmd := app.NewEnclavePoolManagerServer() cmd.Flags().AddGoFlagSet(flag.CommandLine) if err := cmd.Execute(); err != nil { diff --git a/epm/conf/config.toml b/epm/conf/config.toml index 999cbbd05e342bfc5a6efd41c210f6fdb989a8e2..56c48e10a5a1fcb213013a47d04aca2090065bca 100644 --- a/epm/conf/config.toml +++ b/epm/conf/config.toml @@ -1,4 +1,6 @@ root = "/var/local/epm" +db_path = "/var/local/epm/epm.db" +db_timeout = 10 [grpc] address = "/var/run/containerd/containerd.sock" @@ -7,10 +9,10 @@ root = "/var/local/epm" max_recv_message_size = 16777216 max_send_message_size = 16777216 -[caches] - [caches.bundle-cache-pool_occlum_cache0] - type = "bundle-cache-pool.occlum.cache0" - [caches.bundle-cache-pool_occlum_cache1] - type = "bundle-cache-pool.occlum.cache1" - [caches.bundle-cache-pool_occlum_cache2] - type = "bundle-cache-pool.occlum.cache2" \ No newline at end of file +[pools] + [pools."bundle-cache.occlum.cache0"] + type = "bundle-cache.occlum.cache0" + [pools."bundle-cache.occlum.cache1"] + type = "bundle-cache.occlum.cache1" + [pools."bundle-cache.occlum.cache2"] + type = "bundle-cache.occlum.cache2" \ No newline at end of file diff --git a/epm/config/config.go b/epm/config/config.go index 36756ee4aff555a682f6614b95c4ee100d46eaa8..ff99372e537dbf77750d89557ca536a52b7be452 100644 --- a/epm/config/config.go +++ b/epm/config/config.go @@ -9,8 +9,8 @@ type Config struct { DBPath string `toml:"db_path"` // DBTimeout is the amount of time to wait to obtain a database file lock. DBTimeout int `toml:"db_timeout"` - // CachePools stores the configurations of cache pool managers - CachePools map[string]CachePool `toml:"cache_pools"` + // EnclavePools stores the configurations of enclave pool + EnclavePools map[string]EnclavePoolConfiguration `toml:"pools"` } // GRPCConfig provides GRPC configuration for the socket @@ -25,7 +25,7 @@ type GRPCConfig struct { MaxSendMsgSize int `toml:"max_send_message_size"` } -// CachePool provides the configuration for the cache pool -type CachePool struct { +// EnclavePoolConfiguration provides the configuration for the enclave pool +type EnclavePoolConfiguration struct { Type string `toml:"type"` } diff --git a/epm/config/config_test.go b/epm/config/config_test.go index 7485508fceb4e9c576bf5802f2b2ad3e5aef1838..ad33f658c2d2d635d431127b8f46e22e4440af0e 100644 --- a/epm/config/config_test.go +++ b/epm/config/config_test.go @@ -10,6 +10,8 @@ import ( func TestDecodeConfig(t *testing.T) { text := ` root = "/var/local/epm" +db_path = "/var/local/epm/epm.db" +db_timeout = 10 [grpc] address = "/var/run/containerd/containerd.sock" @@ -18,13 +20,13 @@ root = "/var/local/epm" max_recv_message_size = 16777216 max_send_message_size = 16777216 -[cache_pools] - [cache_pools.bundle-cache-pool_occlum_cache0] - type = "bundle-cache-pool.occlum.cache0" - [cache_pools.bundle-cache-pool_occlum_cache1] - type = "bundle-cache-pool.occlum.cache1" - [cache_pools.bundle-cache-pool_occlum_cache2] - type = "bundle-cache-pool.occlum.cache2" +[pools] + [pools."bundle-cache.occlum.cache0"] + type = "bundle-cache.occlum.cache0" + [pools."bundle-cache.occlum.cache1"] + type = "bundle-cache.occlum.cache1" + [pools."bundle-cache.occlum.cache2"] + type = "bundle-cache.occlum.cache2" ` var cfg Config @@ -32,7 +34,7 @@ root = "/var/local/epm" t.Fatal(err) } - for k, v := range cfg.CachePools { + for k, v := range cfg.EnclavePools { fmt.Println(k) fmt.Println(v.Type) } diff --git a/epm/pkg/epm-api/v1alpha1/api.pb.go b/epm/pkg/epm-api/v1alpha1/api.pb.go index 0f6c4bbae2eba2c7b1631125575e8126b59c9c0c..78ed96d95b95e82e5e00912ae26029abe18c418a 100644 --- a/epm/pkg/epm-api/v1alpha1/api.pb.go +++ b/epm/pkg/epm-api/v1alpha1/api.pb.go @@ -7,12 +7,11 @@ package v1alpha1 import ( - reflect "reflect" - sync "sync" - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) const ( @@ -26,15 +25,15 @@ const ( // of the legacy proto package is being used. const _ = proto.ProtoPackageIsVersion4 -// Cache represents the metadata of a cache managed by cache pool manager. +// Cache represents the metadata of a cache managed by enclave pool. type Cache struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Type represents the type of cache pool manager + // Type represents the type of enclave pool Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` - // ID represents the id of the cache and the id is unique in the same type of cache + // ID represents the id of the cache and the id is unique in the same type of enclave pool ID string `protobuf:"bytes,2,opt,name=ID,proto3" json:"ID,omitempty"` // SavePath represents the absolute path to store the cache SavePath string `protobuf:"bytes,3,opt,name=savePath,proto3" json:"savePath,omitempty"` @@ -126,7 +125,7 @@ type GetCacheRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Type represents the type of cache pool manager + // Type represents the type of enclave pool Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` // ID represents the id of the cache ID string `protobuf:"bytes,2,opt,name=ID,proto3" json:"ID,omitempty"` @@ -336,7 +335,7 @@ type ListCacheRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Type represents the type of cache pool manager + // Type represents the type of enclave pool Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` // LastCacheID represents the id of the last cache metadata in the most recent query list, // if the value is "", query the cache metadata from the starting point of DB, @@ -404,7 +403,7 @@ type ListCacheResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // CachePools represents the list of response caches + // Caches represents the list of response caches Caches []*Cache `protobuf:"bytes,1,rep,name=caches,proto3" json:"caches,omitempty"` } @@ -452,7 +451,7 @@ type DeleteCacheRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Type represents the type of cache pool manager + // Type represents the type of enclave pool Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` // ID represents the id of the cache ID string `protobuf:"bytes,2,opt,name=ID,proto3" json:"ID,omitempty"` @@ -557,7 +556,7 @@ type LoadCacheRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Type represents the type of cache pool manager + // Type represents the type of enclave pool Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` // ID represents the id of the cache ID string `protobuf:"bytes,3,opt,name=ID,proto3" json:"ID,omitempty"` @@ -719,31 +718,31 @@ var file_api_proto_rawDesc = []byte{ 0x01, 0x28, 0x09, 0x52, 0x0a, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x50, 0x61, 0x74, 0x68, 0x22, 0x23, 0x0a, 0x11, 0x4c, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x02, 0x6f, 0x6b, 0x32, 0xfd, 0x02, 0x0a, 0x10, 0x43, 0x61, 0x63, 0x68, 0x65, 0x50, 0x6f, - 0x6f, 0x6c, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x12, 0x43, 0x0a, 0x08, 0x47, 0x65, 0x74, - 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x19, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, - 0x2e, 0x47, 0x65, 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1a, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x43, + 0x52, 0x02, 0x6f, 0x6b, 0x32, 0xff, 0x02, 0x0a, 0x12, 0x45, 0x6e, 0x63, 0x6c, 0x61, 0x76, 0x65, + 0x50, 0x6f, 0x6f, 0x6c, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x12, 0x43, 0x0a, 0x08, 0x47, + 0x65, 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x19, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, + 0x61, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x47, 0x65, + 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x46, 0x0a, 0x09, 0x53, 0x61, 0x76, 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x1a, 0x2e, + 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x43, 0x61, 0x63, + 0x68, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x76, 0x31, 0x61, 0x6c, + 0x70, 0x68, 0x61, 0x31, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, + 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x1a, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, + 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x1b, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x4c, 0x69, 0x73, + 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x12, 0x4c, 0x0a, 0x0b, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, + 0x1c, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, + 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, - 0x0a, 0x09, 0x53, 0x61, 0x76, 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x1a, 0x2e, 0x76, 0x31, - 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, + 0x0a, 0x09, 0x4c, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x1a, 0x2e, 0x76, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x4c, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, - 0x61, 0x31, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x61, - 0x63, 0x68, 0x65, 0x12, 0x1a, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x4c, - 0x69, 0x73, 0x74, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1b, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x43, - 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4c, - 0x0a, 0x0b, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x1c, 0x2e, - 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, - 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x76, 0x31, - 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x43, 0x61, 0x63, - 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x09, - 0x4c, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x1a, 0x2e, 0x76, 0x31, 0x61, 0x6c, - 0x70, 0x68, 0x61, 0x31, 0x2e, 0x4c, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, - 0x2e, 0x4c, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x31, 0x2e, 0x4c, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x63, 0x68, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -777,16 +776,16 @@ var file_api_proto_depIdxs = []int32{ 0, // 1: v1alpha1.GetCacheResponse.cache:type_name -> v1alpha1.Cache 0, // 2: v1alpha1.SaveCacheRequest.cache:type_name -> v1alpha1.Cache 0, // 3: v1alpha1.ListCacheResponse.caches:type_name -> v1alpha1.Cache - 1, // 4: v1alpha1.CachePoolManager.GetCache:input_type -> v1alpha1.GetCacheRequest - 3, // 5: v1alpha1.CachePoolManager.SaveCache:input_type -> v1alpha1.SaveCacheRequest - 5, // 6: v1alpha1.CachePoolManager.ListCache:input_type -> v1alpha1.ListCacheRequest - 7, // 7: v1alpha1.CachePoolManager.DeleteCache:input_type -> v1alpha1.DeleteCacheRequest - 9, // 8: v1alpha1.CachePoolManager.LoadCache:input_type -> v1alpha1.LoadCacheRequest - 2, // 9: v1alpha1.CachePoolManager.GetCache:output_type -> v1alpha1.GetCacheResponse - 4, // 10: v1alpha1.CachePoolManager.SaveCache:output_type -> v1alpha1.SaveCacheResponse - 6, // 11: v1alpha1.CachePoolManager.ListCache:output_type -> v1alpha1.ListCacheResponse - 8, // 12: v1alpha1.CachePoolManager.DeleteCache:output_type -> v1alpha1.DeleteCacheResponse - 10, // 13: v1alpha1.CachePoolManager.LoadCache:output_type -> v1alpha1.LoadCacheResponse + 1, // 4: v1alpha1.EnclavePoolManager.GetCache:input_type -> v1alpha1.GetCacheRequest + 3, // 5: v1alpha1.EnclavePoolManager.SaveCache:input_type -> v1alpha1.SaveCacheRequest + 5, // 6: v1alpha1.EnclavePoolManager.ListCache:input_type -> v1alpha1.ListCacheRequest + 7, // 7: v1alpha1.EnclavePoolManager.DeleteCache:input_type -> v1alpha1.DeleteCacheRequest + 9, // 8: v1alpha1.EnclavePoolManager.LoadCache:input_type -> v1alpha1.LoadCacheRequest + 2, // 9: v1alpha1.EnclavePoolManager.GetCache:output_type -> v1alpha1.GetCacheResponse + 4, // 10: v1alpha1.EnclavePoolManager.SaveCache:output_type -> v1alpha1.SaveCacheResponse + 6, // 11: v1alpha1.EnclavePoolManager.ListCache:output_type -> v1alpha1.ListCacheResponse + 8, // 12: v1alpha1.EnclavePoolManager.DeleteCache:output_type -> v1alpha1.DeleteCacheResponse + 10, // 13: v1alpha1.EnclavePoolManager.LoadCache:output_type -> v1alpha1.LoadCacheResponse 9, // [9:14] is the sub-list for method output_type 4, // [4:9] is the sub-list for method input_type 4, // [4:4] is the sub-list for extension type_name diff --git a/epm/pkg/epm-api/v1alpha1/api.proto b/epm/pkg/epm-api/v1alpha1/api.proto index e9dcb44e0acafa85367061302da7821d45b2abbe..2f6b205c9d2e4eee8d151ee5701bf77a82d09bf0 100644 --- a/epm/pkg/epm-api/v1alpha1/api.proto +++ b/epm/pkg/epm-api/v1alpha1/api.proto @@ -2,11 +2,11 @@ syntax = 'proto3'; package v1alpha1; -// Cache represents the metadata of a cache managed by cache pool manager. +// Cache represents the metadata of a cache managed by enclave pool. message Cache { - // Type represents the type of cache pool manager + // Type represents the type of enclave pool string type = 1; - // ID represents the id of the cache and the id is unique in the same type of cache + // ID represents the id of the cache and the id is unique in the same type of enclave pool string ID = 2; // SavePath represents the absolute path to store the cache string savePath = 3; @@ -18,8 +18,8 @@ message Cache { int64 created = 6; } -// CachePoolManager represents a cache pool manager. -service CachePoolManager { +// EnclavePoolManager represents an enclave pool +service EnclavePoolManager { // GetCache represents get the specified cache metadata rpc GetCache(GetCacheRequest) returns (GetCacheResponse) {} // SaveCache represents save the data to a cache directory and record the cache metadata @@ -34,7 +34,7 @@ service CachePoolManager { // GetCacheRequest message GetCacheRequest { - // Type represents the type of cache pool manager + // Type represents the type of enclave pool string type = 1; // ID represents the id of the cache string ID = 2; @@ -58,7 +58,7 @@ message SaveCacheResponse { } message ListCacheRequest { - // Type represents the type of cache pool manager + // Type represents the type of enclave pool string type = 1; // LastCacheID represents the id of the last cache metadata in the most recent query list, // if the value is "", query the cache metadata from the starting point of DB, @@ -73,7 +73,7 @@ message ListCacheResponse { } message DeleteCacheRequest { - // Type represents the type of cache pool manager + // Type represents the type of enclave pool string type = 1; // ID represents the id of the cache string ID = 2; @@ -84,7 +84,7 @@ message DeleteCacheResponse { } message LoadCacheRequest { - // Type represents the type of cache pool manager + // Type represents the type of enclave pool string type = 1; // ID represents the id of the cache string ID = 3; diff --git a/epm/pkg/epm-api/v1alpha1/api_grpc.pb.go b/epm/pkg/epm-api/v1alpha1/api_grpc.pb.go index 347d8d56483eab5b16947746e75695bf5dd5459e..887468f374b3fdc1a20a5c9492c3c1fda4116401 100644 --- a/epm/pkg/epm-api/v1alpha1/api_grpc.pb.go +++ b/epm/pkg/epm-api/v1alpha1/api_grpc.pb.go @@ -13,10 +13,10 @@ import ( // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion6 -// CachePoolManagerClient is the client API for CachePoolManager service. +// EnclavePoolManagerClient is the client API for EnclavePoolManager service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type CachePoolManagerClient interface { +type EnclavePoolManagerClient interface { // GetCache represents get the specified cache metadata GetCache(ctx context.Context, in *GetCacheRequest, opts ...grpc.CallOption) (*GetCacheResponse, error) // SaveCache represents save the data to a cache directory and record the cache metadata @@ -29,63 +29,63 @@ type CachePoolManagerClient interface { LoadCache(ctx context.Context, in *LoadCacheRequest, opts ...grpc.CallOption) (*LoadCacheResponse, error) } -type cachePoolManagerClient struct { +type enclavePoolManagerClient struct { cc grpc.ClientConnInterface } -func NewCachePoolManagerClient(cc grpc.ClientConnInterface) CachePoolManagerClient { - return &cachePoolManagerClient{cc} +func NewEnclavePoolManagerClient(cc grpc.ClientConnInterface) EnclavePoolManagerClient { + return &enclavePoolManagerClient{cc} } -func (c *cachePoolManagerClient) GetCache(ctx context.Context, in *GetCacheRequest, opts ...grpc.CallOption) (*GetCacheResponse, error) { +func (c *enclavePoolManagerClient) GetCache(ctx context.Context, in *GetCacheRequest, opts ...grpc.CallOption) (*GetCacheResponse, error) { out := new(GetCacheResponse) - err := c.cc.Invoke(ctx, "/v1alpha1.CachePoolManager/GetCache", in, out, opts...) + err := c.cc.Invoke(ctx, "/v1alpha1.EnclavePoolManager/GetCache", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *cachePoolManagerClient) SaveCache(ctx context.Context, in *SaveCacheRequest, opts ...grpc.CallOption) (*SaveCacheResponse, error) { +func (c *enclavePoolManagerClient) SaveCache(ctx context.Context, in *SaveCacheRequest, opts ...grpc.CallOption) (*SaveCacheResponse, error) { out := new(SaveCacheResponse) - err := c.cc.Invoke(ctx, "/v1alpha1.CachePoolManager/SaveCache", in, out, opts...) + err := c.cc.Invoke(ctx, "/v1alpha1.EnclavePoolManager/SaveCache", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *cachePoolManagerClient) ListCache(ctx context.Context, in *ListCacheRequest, opts ...grpc.CallOption) (*ListCacheResponse, error) { +func (c *enclavePoolManagerClient) ListCache(ctx context.Context, in *ListCacheRequest, opts ...grpc.CallOption) (*ListCacheResponse, error) { out := new(ListCacheResponse) - err := c.cc.Invoke(ctx, "/v1alpha1.CachePoolManager/ListCache", in, out, opts...) + err := c.cc.Invoke(ctx, "/v1alpha1.EnclavePoolManager/ListCache", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *cachePoolManagerClient) DeleteCache(ctx context.Context, in *DeleteCacheRequest, opts ...grpc.CallOption) (*DeleteCacheResponse, error) { +func (c *enclavePoolManagerClient) DeleteCache(ctx context.Context, in *DeleteCacheRequest, opts ...grpc.CallOption) (*DeleteCacheResponse, error) { out := new(DeleteCacheResponse) - err := c.cc.Invoke(ctx, "/v1alpha1.CachePoolManager/DeleteCache", in, out, opts...) + err := c.cc.Invoke(ctx, "/v1alpha1.EnclavePoolManager/DeleteCache", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *cachePoolManagerClient) LoadCache(ctx context.Context, in *LoadCacheRequest, opts ...grpc.CallOption) (*LoadCacheResponse, error) { +func (c *enclavePoolManagerClient) LoadCache(ctx context.Context, in *LoadCacheRequest, opts ...grpc.CallOption) (*LoadCacheResponse, error) { out := new(LoadCacheResponse) - err := c.cc.Invoke(ctx, "/v1alpha1.CachePoolManager/LoadCache", in, out, opts...) + err := c.cc.Invoke(ctx, "/v1alpha1.EnclavePoolManager/LoadCache", in, out, opts...) if err != nil { return nil, err } return out, nil } -// CachePoolManagerServer is the server API for CachePoolManager service. -// All implementations must embed UnimplementedCachePoolManagerServer +// EnclavePoolManagerServer is the server API for EnclavePoolManager service. +// All implementations must embed UnimplementedEnclavePoolManagerServer // for forward compatibility -type CachePoolManagerServer interface { +type EnclavePoolManagerServer interface { // GetCache represents get the specified cache metadata GetCache(context.Context, *GetCacheRequest) (*GetCacheResponse, error) // SaveCache represents save the data to a cache directory and record the cache metadata @@ -96,147 +96,147 @@ type CachePoolManagerServer interface { DeleteCache(context.Context, *DeleteCacheRequest) (*DeleteCacheResponse, error) // LoadCache represents load the specified cache data to work directory LoadCache(context.Context, *LoadCacheRequest) (*LoadCacheResponse, error) - mustEmbedUnimplementedCachePoolManagerServer() + mustEmbedUnimplementedEnclavePoolManagerServer() } -// UnimplementedCachePoolManagerServer must be embedded to have forward compatible implementations. -type UnimplementedCachePoolManagerServer struct { +// UnimplementedEnclavePoolManagerServer must be embedded to have forward compatible implementations. +type UnimplementedEnclavePoolManagerServer struct { } -func (*UnimplementedCachePoolManagerServer) GetCache(context.Context, *GetCacheRequest) (*GetCacheResponse, error) { +func (*UnimplementedEnclavePoolManagerServer) GetCache(context.Context, *GetCacheRequest) (*GetCacheResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetCache not implemented") } -func (*UnimplementedCachePoolManagerServer) SaveCache(context.Context, *SaveCacheRequest) (*SaveCacheResponse, error) { +func (*UnimplementedEnclavePoolManagerServer) SaveCache(context.Context, *SaveCacheRequest) (*SaveCacheResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SaveCache not implemented") } -func (*UnimplementedCachePoolManagerServer) ListCache(context.Context, *ListCacheRequest) (*ListCacheResponse, error) { +func (*UnimplementedEnclavePoolManagerServer) ListCache(context.Context, *ListCacheRequest) (*ListCacheResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListCache not implemented") } -func (*UnimplementedCachePoolManagerServer) DeleteCache(context.Context, *DeleteCacheRequest) (*DeleteCacheResponse, error) { +func (*UnimplementedEnclavePoolManagerServer) DeleteCache(context.Context, *DeleteCacheRequest) (*DeleteCacheResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteCache not implemented") } -func (*UnimplementedCachePoolManagerServer) LoadCache(context.Context, *LoadCacheRequest) (*LoadCacheResponse, error) { +func (*UnimplementedEnclavePoolManagerServer) LoadCache(context.Context, *LoadCacheRequest) (*LoadCacheResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method LoadCache not implemented") } -func (*UnimplementedCachePoolManagerServer) mustEmbedUnimplementedCachePoolManagerServer() {} +func (*UnimplementedEnclavePoolManagerServer) mustEmbedUnimplementedEnclavePoolManagerServer() {} -func RegisterCachePoolManagerServer(s *grpc.Server, srv CachePoolManagerServer) { - s.RegisterService(&_CachePoolManager_serviceDesc, srv) +func RegisterEnclavePoolManagerServer(s *grpc.Server, srv EnclavePoolManagerServer) { + s.RegisterService(&_EnclavePoolManager_serviceDesc, srv) } -func _CachePoolManager_GetCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _EnclavePoolManager_GetCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(GetCacheRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CachePoolManagerServer).GetCache(ctx, in) + return srv.(EnclavePoolManagerServer).GetCache(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1alpha1.CachePoolManager/GetCache", + FullMethod: "/v1alpha1.EnclavePoolManager/GetCache", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CachePoolManagerServer).GetCache(ctx, req.(*GetCacheRequest)) + return srv.(EnclavePoolManagerServer).GetCache(ctx, req.(*GetCacheRequest)) } return interceptor(ctx, in, info, handler) } -func _CachePoolManager_SaveCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _EnclavePoolManager_SaveCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SaveCacheRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CachePoolManagerServer).SaveCache(ctx, in) + return srv.(EnclavePoolManagerServer).SaveCache(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1alpha1.CachePoolManager/SaveCache", + FullMethod: "/v1alpha1.EnclavePoolManager/SaveCache", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CachePoolManagerServer).SaveCache(ctx, req.(*SaveCacheRequest)) + return srv.(EnclavePoolManagerServer).SaveCache(ctx, req.(*SaveCacheRequest)) } return interceptor(ctx, in, info, handler) } -func _CachePoolManager_ListCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _EnclavePoolManager_ListCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ListCacheRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CachePoolManagerServer).ListCache(ctx, in) + return srv.(EnclavePoolManagerServer).ListCache(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1alpha1.CachePoolManager/ListCache", + FullMethod: "/v1alpha1.EnclavePoolManager/ListCache", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CachePoolManagerServer).ListCache(ctx, req.(*ListCacheRequest)) + return srv.(EnclavePoolManagerServer).ListCache(ctx, req.(*ListCacheRequest)) } return interceptor(ctx, in, info, handler) } -func _CachePoolManager_DeleteCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _EnclavePoolManager_DeleteCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(DeleteCacheRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CachePoolManagerServer).DeleteCache(ctx, in) + return srv.(EnclavePoolManagerServer).DeleteCache(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1alpha1.CachePoolManager/DeleteCache", + FullMethod: "/v1alpha1.EnclavePoolManager/DeleteCache", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CachePoolManagerServer).DeleteCache(ctx, req.(*DeleteCacheRequest)) + return srv.(EnclavePoolManagerServer).DeleteCache(ctx, req.(*DeleteCacheRequest)) } return interceptor(ctx, in, info, handler) } -func _CachePoolManager_LoadCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _EnclavePoolManager_LoadCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(LoadCacheRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CachePoolManagerServer).LoadCache(ctx, in) + return srv.(EnclavePoolManagerServer).LoadCache(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1alpha1.CachePoolManager/LoadCache", + FullMethod: "/v1alpha1.EnclavePoolManager/LoadCache", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CachePoolManagerServer).LoadCache(ctx, req.(*LoadCacheRequest)) + return srv.(EnclavePoolManagerServer).LoadCache(ctx, req.(*LoadCacheRequest)) } return interceptor(ctx, in, info, handler) } -var _CachePoolManager_serviceDesc = grpc.ServiceDesc{ - ServiceName: "v1alpha1.CachePoolManager", - HandlerType: (*CachePoolManagerServer)(nil), +var _EnclavePoolManager_serviceDesc = grpc.ServiceDesc{ + ServiceName: "v1alpha1.EnclavePoolManager", + HandlerType: (*EnclavePoolManagerServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "GetCache", - Handler: _CachePoolManager_GetCache_Handler, + Handler: _EnclavePoolManager_GetCache_Handler, }, { MethodName: "SaveCache", - Handler: _CachePoolManager_SaveCache_Handler, + Handler: _EnclavePoolManager_SaveCache_Handler, }, { MethodName: "ListCache", - Handler: _CachePoolManager_ListCache_Handler, + Handler: _EnclavePoolManager_ListCache_Handler, }, { MethodName: "DeleteCache", - Handler: _CachePoolManager_DeleteCache_Handler, + Handler: _EnclavePoolManager_DeleteCache_Handler, }, { MethodName: "LoadCache", - Handler: _CachePoolManager_LoadCache_Handler, + Handler: _EnclavePoolManager_LoadCache_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/epm/pkg/epm/bundle-cache-pool/occlum/cach-manager.go b/epm/pkg/epm/bundle-cache-pool/occlum/cach-manager.go index 0d1446264eeca682b4691d12b1860d8800b4ee99..f9734b6782f020d7dbc30bd5dc33e1216c8c351b 100644 --- a/epm/pkg/epm/bundle-cache-pool/occlum/cach-manager.go +++ b/epm/pkg/epm/bundle-cache-pool/occlum/cach-manager.go @@ -4,26 +4,26 @@ import ( cache_manager "github.com/alibaba/inclavare-containers/epm/pkg/epm" ) -type Cach0Manager struct { - cache_manager.DefaultCachePoolManager +type BundleCach0Manager struct { + cache_manager.DefaultEnclavePool } -func (d *Cach0Manager) GetCacheType() string { - return "bundle-cache-pool.occlum.cache0" +func (d *BundleCach0Manager) GetPoolType() string { + return "bundle-cache.occlum.cache0" } -type Cach1Manager struct { - cache_manager.DefaultCachePoolManager +type BundleCach1Manager struct { + cache_manager.DefaultEnclavePool } -func (d *Cach1Manager) GetCacheType() string { - return "bundle-cache-pool.occlum.cache1" +func (d *BundleCach1Manager) GetPoolType() string { + return "bundle-cache.occlum.cache1" } -type Cach2Manager struct { - cache_manager.DefaultCachePoolManager +type BundleCach2Manager struct { + cache_manager.DefaultEnclavePool } -func (d *Cach2Manager) GetCacheType() string { - return "bundle-cache-pool.occlum.cache2" +func (d *BundleCach2Manager) GetPoolType() string { + return "bundle-cache.occlum.cache2" } diff --git a/epm/pkg/epm/emp-server.go b/epm/pkg/epm/emp.go similarity index 62% rename from epm/pkg/epm/emp-server.go rename to epm/pkg/epm/emp.go index b6440517c8ab3045fcf8dd34fcfb715428fc2e32..ace48e0c1ab2493466098b3b364b4d986c95bd80 100644 --- a/epm/pkg/epm/emp-server.go +++ b/epm/pkg/epm/emp.go @@ -9,15 +9,15 @@ import ( "google.golang.org/grpc/status" ) -// CachePoolManagerServer represents the service that manages the cache pool managers -type CachePoolManagerServer struct { - v1alpha1.UnimplementedCachePoolManagerServer - // cachePoolManagers containers the mapping of the cache type and cache pool manager - cachePoolManagers map[string]CachePoolManager +// EnclavePoolManagerServer represents the service that manages the enclave pools +type EnclavePoolManagerServer struct { + v1alpha1.UnimplementedEnclavePoolManagerServer + // cachePools containers the mapping of the cache type and enclave pool + cachePools map[string]EnclavePool } // GetCache gets the specified cache metadata -func (s *CachePoolManagerServer) GetCache(ctx context.Context, req *v1alpha1.GetCacheRequest) (*v1alpha1.GetCacheResponse, error) { +func (s *EnclavePoolManagerServer) GetCache(ctx context.Context, req *v1alpha1.GetCacheRequest) (*v1alpha1.GetCacheResponse, error) { manager, err := s.getCachePoolManager(req.Type) if err != nil { return nil, status.Errorf(codes.InvalidArgument, err.Error()) @@ -30,7 +30,7 @@ func (s *CachePoolManagerServer) GetCache(ctx context.Context, req *v1alpha1.Get } // SaveCache saves the data to a cache directory and record the cache metadata -func (s *CachePoolManagerServer) SaveCache(ctx context.Context, req *v1alpha1.SaveCacheRequest) (*v1alpha1.SaveCacheResponse, error) { +func (s *EnclavePoolManagerServer) SaveCache(ctx context.Context, req *v1alpha1.SaveCacheRequest) (*v1alpha1.SaveCacheResponse, error) { cache := req.Cache manager, err := s.getCachePoolManager(cache.Type) if err != nil { @@ -43,7 +43,7 @@ func (s *CachePoolManagerServer) SaveCache(ctx context.Context, req *v1alpha1.Sa } // ListCache lists part of or all of the cache metadata -func (s *CachePoolManagerServer) ListCache(ctx context.Context, req *v1alpha1.ListCacheRequest) (*v1alpha1.ListCacheResponse, error) { +func (s *EnclavePoolManagerServer) ListCache(ctx context.Context, req *v1alpha1.ListCacheRequest) (*v1alpha1.ListCacheResponse, error) { manager, err := s.getCachePoolManager(req.Type) if err != nil { return nil, status.Errorf(codes.InvalidArgument, err.Error()) @@ -56,7 +56,7 @@ func (s *CachePoolManagerServer) ListCache(ctx context.Context, req *v1alpha1.Li } // DeleteCache deletes the specified cached data and remove the corresponding cache metadata -func (s *CachePoolManagerServer) DeleteCache(ctx context.Context, req *v1alpha1.DeleteCacheRequest) (*v1alpha1.DeleteCacheResponse, error) { +func (s *EnclavePoolManagerServer) DeleteCache(ctx context.Context, req *v1alpha1.DeleteCacheRequest) (*v1alpha1.DeleteCacheResponse, error) { manager, err := s.getCachePoolManager(req.Type) if err != nil { return nil, status.Errorf(codes.InvalidArgument, err.Error()) @@ -68,7 +68,7 @@ func (s *CachePoolManagerServer) DeleteCache(ctx context.Context, req *v1alpha1. } // LoadCache loads the specified cache data to work directory -func (s *CachePoolManagerServer) LoadCache(ctx context.Context, req *v1alpha1.LoadCacheRequest) (*v1alpha1.LoadCacheResponse, error) { +func (s *EnclavePoolManagerServer) LoadCache(ctx context.Context, req *v1alpha1.LoadCacheRequest) (*v1alpha1.LoadCacheResponse, error) { manager, err := s.getCachePoolManager(req.Type) if err != nil { return nil, status.Errorf(codes.InvalidArgument, err.Error()) @@ -79,17 +79,17 @@ func (s *CachePoolManagerServer) LoadCache(ctx context.Context, req *v1alpha1.Lo return &v1alpha1.LoadCacheResponse{Ok: true}, nil } -// RegistryCachePoolManager registry the cache pool manager to the cache pool manager server -func (s *CachePoolManagerServer) RegistryCachePoolManager(m CachePoolManager) { - if s.cachePoolManagers == nil { - s.cachePoolManagers = make(map[string]CachePoolManager) +// RegisterCachePoolManager register the cache pool manager to the cache pool manager server +func (s *EnclavePoolManagerServer) RegisterCachePoolManager(m EnclavePool) { + if s.cachePools == nil { + s.cachePools = make(map[string]EnclavePool) } - s.cachePoolManagers[m.GetCacheType()] = m + s.cachePools[m.GetPoolType()] = m } // getCachePoolManager gets the cache pool manager by the cache type -func (s *CachePoolManagerServer) getCachePoolManager(cacheType string) (CachePoolManager, error) { - manager, ok := s.cachePoolManagers[cacheType] +func (s *EnclavePoolManagerServer) getCachePoolManager(cacheType string) (EnclavePool, error) { + manager, ok := s.cachePools[cacheType] if ok && manager != nil { return manager, nil } diff --git a/epm/pkg/epm/interface.go b/epm/pkg/epm/interface.go index 17d78e1f0d1b9500206b36006cdcd521b359b945..7c7a38c81d55ef660318e2d95440a0f4669a3188 100644 --- a/epm/pkg/epm/interface.go +++ b/epm/pkg/epm/interface.go @@ -13,8 +13,8 @@ import ( cache_metadata "github.com/alibaba/inclavare-containers/epm/pkg/metadata" ) -// CachePoolManager represents a cache manager -type CachePoolManager interface { +// EnclavePool represents a kind of enclave pool +type EnclavePool interface { // GetCache gets the cache by ID GetCache(ID string) (*v1alpha1.Cache, error) // SaveCache saves the data to a cache directory and record the cache metadata @@ -25,21 +25,21 @@ type CachePoolManager interface { DeleteCache(ID string) error // LoadCache loads the specified cache data to work directory LoadCache(ID, targetPath string) error - // GetCacheType gets the cache type of current cache pool manager - GetCacheType() string + // GetPoolType gets the pool type of current pool + GetPoolType() string } -// DefaultCachePoolManager is the default implementation of CachePoolManager -type DefaultCachePoolManager struct { +// DefaultEnclavePool is the default implementation of EnclavePool +type DefaultEnclavePool struct { Root string CacheMetadata *cache_metadata.Metadata } -func (d *DefaultCachePoolManager) GetCache(ID string) (*v1alpha1.Cache, error) { - return d.CacheMetadata.GetCache(d.GetCacheType(), ID) +func (d *DefaultEnclavePool) GetCache(ID string) (*v1alpha1.Cache, error) { + return d.CacheMetadata.GetCache(d.GetPoolType(), ID) } -func (d *DefaultCachePoolManager) SaveCache(sourcePath string, cache *v1alpha1.Cache) error { +func (d *DefaultEnclavePool) SaveCache(sourcePath string, cache *v1alpha1.Cache) error { savePath, err := d.BuildCacheSavePath(d.Root, cache) if err != nil { return err @@ -64,14 +64,14 @@ func (d *DefaultCachePoolManager) SaveCache(sourcePath string, cache *v1alpha1.C cache.SavePath = savePath cache.Size = size cache.Created = time.Now().Unix() - return d.CacheMetadata.SaveCache(d.GetCacheType(), cache.ID, cache) + return d.CacheMetadata.SaveCache(d.GetPoolType(), cache.ID, cache) } -func (d *DefaultCachePoolManager) ListCache(lastCacheID string, limit int32) ([]*v1alpha1.Cache, error) { - return d.CacheMetadata.ListCache(d.GetCacheType(), lastCacheID, limit) +func (d *DefaultEnclavePool) ListCache(lastCacheID string, limit int32) ([]*v1alpha1.Cache, error) { + return d.CacheMetadata.ListCache(d.GetPoolType(), lastCacheID, limit) } -func (d *DefaultCachePoolManager) DeleteCache(ID string) error { +func (d *DefaultEnclavePool) DeleteCache(ID string) error { cache, err := d.GetCache(ID) if err != nil { return err @@ -79,10 +79,10 @@ func (d *DefaultCachePoolManager) DeleteCache(ID string) error { if err := os.RemoveAll(cache.SavePath); err != nil { return err } - return d.CacheMetadata.DeleteCache(d.GetCacheType(), ID) + return d.CacheMetadata.DeleteCache(d.GetPoolType(), ID) } -func (d *DefaultCachePoolManager) LoadCache(ID, targetPath string) error { +func (d *DefaultEnclavePool) LoadCache(ID, targetPath string) error { cache, err := d.GetCache(ID) if err != nil { return err @@ -96,11 +96,11 @@ func (d *DefaultCachePoolManager) LoadCache(ID, targetPath string) error { return nil } -func (d *DefaultCachePoolManager) GetCacheType() string { +func (d *DefaultEnclavePool) GetPoolType() string { return "default" } -func (d *DefaultCachePoolManager) BuildCacheSavePath(rootDir string, cache *v1alpha1.Cache) (string, error) { +func (d *DefaultEnclavePool) BuildCacheSavePath(rootDir string, cache *v1alpha1.Cache) (string, error) { caches, err := d.CacheMetadata.GetAncestorCaches(cache) if err != nil { return "", err