-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f15dd2c
commit aef2eba
Showing
15 changed files
with
2,449 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// Licensed to VMware, Inc. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. VMware, Inc. licenses this file to you 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 realization_store | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/vmware-labs/multi-tenant-persistence-for-saas/pkg/datastore" | ||
"github.com/vmware-labs/multi-tenant-persistence-for-saas/pkg/protostore" | ||
) | ||
|
||
func GetRealizationStore(d datastore.DataStore, p protostore.ProtoStore, logger *logrus.Entry) IRealizationStore { | ||
log := logger.WithField("sub-comp", "realization-store") | ||
return &realizationStoreV0{ | ||
dataStore: d, | ||
protoStore: p, | ||
logger: log, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// Licensed to VMware, Inc. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. VMware, Inc. licenses this file to you 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 realization_store | ||
|
||
// Constants for logger field names & values. | ||
const ( | ||
ORG_ID = "orgId" | ||
RESOURCE_ID = "resourceId" | ||
ENFORCEMENT_POINT = "enforcementPoint" | ||
ALL = "*" | ||
) | ||
|
||
// Logging statements. | ||
const ( | ||
RESOURCE = "resource" | ||
OVERALL_STATUS = "overall status" | ||
ENFORCEMENT_STATUS = "enforcement status" | ||
ENFORCEMENT = "enforcement" | ||
INTENT = "intent" | ||
|
||
PERSISTING = "Persisting" | ||
SETTING = "Setting" | ||
RESETTING = "Resetting" | ||
SOFT_DELETING = "Soft-Deleting" | ||
DELETING = "Deleting" | ||
PURGING = "Purging" | ||
FETCHING = "Fetching" | ||
REGISTERING = "Registering" | ||
MARKING = "Marking" | ||
|
||
STARTED = "..." | ||
FAILED = "failed: " | ||
ERRORED = "errored: " | ||
FINISHED = "finished." | ||
|
||
AS_PENDING = "as pending" | ||
AS_SUCCESS = "as success" | ||
AS_ERROR = "as error" | ||
AS_DELETION_PENDING = "as deletion pending" | ||
AS_DELETION_REALIZED = "as deletion realized" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// Licensed to VMware, Inc. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. VMware, Inc. licenses this file to you 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 realization_store | ||
|
||
import ( | ||
"strings" | ||
"time" | ||
|
||
"google.golang.org/protobuf/proto" | ||
|
||
"github.com/vmware-labs/multi-tenant-persistence-for-saas/pkg/datastore" | ||
"github.com/vmware-labs/multi-tenant-persistence-for-saas/pkg/protostore" | ||
) | ||
|
||
type ProtobufWithMetadata struct { | ||
proto.Message | ||
protostore.Metadata | ||
} | ||
|
||
type OverallStatus struct { | ||
Id string `gorm:"primaryKey"` | ||
OrgId string `gorm:"primaryKey"` | ||
RealizationStatus Status | ||
AdditionalDetails string | ||
Revision int64 `gorm:"column:resource_revision"` | ||
XTableName string `gorm:"-"` | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
} | ||
|
||
func (o *OverallStatus) TableName() string { | ||
return o.XTableName | ||
} | ||
|
||
type EnforcementStatus struct { | ||
Id string `gorm:"primaryKey"` | ||
OrgId string `gorm:"primaryKey"` | ||
EnforcementPointId string `gorm:"primaryKey"` | ||
RealizationStatus Status | ||
AdditionalDetails string | ||
Revision int64 `gorm:"column:resource_revision"` | ||
XTableName string `gorm:"-"` | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
} | ||
|
||
func (e *EnforcementStatus) TableName() string { | ||
return e.XTableName | ||
} | ||
|
||
func GetOverallStatusTableName(msg proto.Message) string { | ||
return strings.Join([]string{"overall", "status", datastore.GetTableName(msg)}, "_") | ||
} | ||
|
||
func GetEnforcementStatusTableName(msg proto.Message) string { | ||
return strings.Join([]string{"enforcement", "status", datastore.GetTableName(msg)}, "_") | ||
} | ||
|
||
func GetModelEnforcementStatusRecordWithoutRevision(resource *ProtobufWithMetadata, orgId string) *EnforcementStatus { | ||
enforcementStatusRecord := EnforcementStatus{ | ||
Id: resource.Id, | ||
OrgId: orgId, | ||
XTableName: GetEnforcementStatusTableName(resource.Message), | ||
} | ||
return &enforcementStatusRecord | ||
} | ||
|
||
func GetModelEnforcementStatusRecord(resource *ProtobufWithMetadata, orgId string) *EnforcementStatus { | ||
enforcementStatusRecord := EnforcementStatus{ | ||
Id: resource.Id, | ||
OrgId: orgId, | ||
XTableName: GetEnforcementStatusTableName(resource.Message), | ||
Revision: resource.Revision, | ||
} | ||
return &enforcementStatusRecord | ||
} | ||
|
||
func GetModelOverallStatusRecord(resource *ProtobufWithMetadata, orgId string) *OverallStatus { | ||
overallStatusRecord := OverallStatus{ | ||
Id: resource.Id, | ||
OrgId: orgId, | ||
XTableName: GetOverallStatusTableName(resource.Message), | ||
Revision: resource.Revision, | ||
} | ||
return &overallStatusRecord | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// Licensed to VMware, Inc. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. VMware, Inc. licenses this file to you 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 realization_store_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gorm.io/gorm/schema" | ||
|
||
. "github.com/vmware-labs/multi-tenant-persistence-for-saas/pkg/realization_store" | ||
"github.com/vmware-labs/multi-tenant-persistence-for-saas/test/pb" | ||
) | ||
|
||
func TestStatusDbTableNames(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
cpuOverallStatusRecord := GetModelOverallStatusRecord(&ProtobufWithMetadata{Message: &pb.CPU{}}, "") | ||
memoryOverallStatusRecord := GetModelOverallStatusRecord(&ProtobufWithMetadata{Message: &pb.Memory{}}, "") | ||
assert.NotEqual(schema.Tabler(cpuOverallStatusRecord).TableName(), schema.Tabler(memoryOverallStatusRecord).TableName(), | ||
"Expected the names of overall status DB tables for 2 entities not to be the same") | ||
|
||
cpuEnforcementStatusRecord := GetModelEnforcementStatusRecord(&ProtobufWithMetadata{Message: &pb.CPU{}}, "") | ||
memoryEnforcementStatusRecord := GetModelEnforcementStatusRecord(&ProtobufWithMetadata{Message: &pb.Memory{}}, "") | ||
assert.NotEqual(schema.Tabler(cpuEnforcementStatusRecord).TableName(), schema.Tabler(memoryEnforcementStatusRecord).TableName(), | ||
"Expected the names of enforcement status DB tables for 2 entities not to be the same") | ||
} |
Oops, something went wrong.