Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23,187 changes: 23,187 additions & 0 deletions api/coverage.html

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion api/pkg/apis/v1alpha1/managers/jobs/jobs-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ func (s *JobsManager) HandleJobEvent(ctx context.Context, event v1alpha2.Event)
})
var err error = nil
defer observ_utils.CloseSpanWithError(span, &err)
log.Info(" M (Job): handling %v event, event body %v, %v", event.Metadata["objectType"], "job", event.Body)

namespace := model.ReadProperty(event.Metadata, "namespace", nil)
if namespace == "" {
Expand All @@ -377,7 +378,7 @@ func (s *JobsManager) HandleJobEvent(ctx context.Context, event v1alpha2.Event)

switch objectType {
case "instance":
log.Debugf(" M (Job): handling instance job %s", job.Id)
log.Debugf(" M (Job): handling instance job >>>>>>>>>>>>>>>>>>>>>>>>>>>> %s, %s", job.Id, namespace)
instanceName := job.Id
var instance model.InstanceState
//get intance
Expand All @@ -387,9 +388,13 @@ func (s *JobsManager) HandleJobEvent(ctx context.Context, event v1alpha2.Event)
return err //TODO: instance is gone
}

log.Debugf(" M (Job): handling instance job solution name >>>>>>>>>>>>>>>>>>>>>>>>>>>> %s", instance.Spec.Solution)

//get solution
var solution model.SolutionState
solution, err = s.apiClient.GetSolution(ctx, instance.Spec.Solution, namespace)
log.Debugf(" M (Job): handling instance job solution after GetSolution >>>>>>>>>>>>>>>>>>>>>>>>>>>> %s", solution.ObjectMeta.Name)

if err != nil {
solution = model.SolutionState{
ObjectMeta: model.ObjectMeta{
Expand Down
104 changes: 93 additions & 11 deletions api/pkg/apis/v1alpha1/managers/solutions/solutions-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/eclipse-symphony/symphony/api/pkg/apis/v1alpha1/model"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/contexts"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/managers"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/providers"
"github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/providers/states"
"github.com/eclipse-symphony/symphony/coa/pkg/logger"

observability "github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/observability"
observ_utils "github.com/eclipse-symphony/symphony/coa/pkg/apis/v1alpha2/observability/utils"
)

var sLog = logger.NewLogger("coa.runtime")

type SolutionsManager struct {
managers.Manager
StateProvider states.IStateProvider
Expand All @@ -48,14 +53,28 @@ func (t *SolutionsManager) DeleteState(ctx context.Context, name string, namespa
var err error = nil
defer observ_utils.CloseSpanWithError(span, &err)

var rootResource string
var version string
parts := strings.Split(name, ":")
if len(parts) == 2 {
rootResource = parts[0]
version = parts[1]
} else {
return v1alpha2.NewCOAError(nil, fmt.Sprintf("Solution name is invalid in the request (%s)", name), v1alpha2.BadRequest)
}

sLog.Info(" M (Solution manager): delete state >>>>>>>>>>>>>>>>>>>>parts %v, %v", rootResource, version)

id := rootResource + "-" + version
err = t.StateProvider.Delete(ctx, states.DeleteRequest{
ID: name,
ID: id,
Metadata: map[string]interface{}{
"namespace": namespace,
"group": model.SolutionGroup,
"version": "v1",
"resource": "solutions",
"kind": "Solution",
"namespace": namespace,
"group": model.SolutionGroup,
"version": "v1",
"resource": "solutions",
"kind": "Solution",
"rootResource": rootResource,
},
})
return err
Expand All @@ -68,28 +87,58 @@ func (t *SolutionsManager) UpsertState(ctx context.Context, name string, state m
var err error = nil
defer observ_utils.CloseSpanWithError(span, &err)

sLog.Info(" M (Solution manager): debug upsert state >>>>>>>>>>>>>>>>>>>> %v, %v, %v", state.Spec.Version, state.Spec.RootResource, name)
if state.ObjectMeta.Name != "" && state.ObjectMeta.Name != name {
return v1alpha2.NewCOAError(nil, fmt.Sprintf("Name in metadata (%s) does not match name in request (%s)", state.ObjectMeta.Name, name), v1alpha2.BadRequest)
}
state.ObjectMeta.FixNames(name)

var rootResource string
version := state.Spec.Version
if state.Spec.RootResource == "" && version != "" {
suffix := "-" + version
rootResource = strings.TrimSuffix(name, suffix)
} else {
rootResource = state.Spec.RootResource
}

if state.ObjectMeta.Labels == nil {
state.ObjectMeta.Labels = make(map[string]string)
}

_, versionLabelExists := state.ObjectMeta.Labels["version"]
_, rootLabelExists := state.ObjectMeta.Labels["rootResource"]
refreshLabels := false
if !versionLabelExists || !rootLabelExists {
sLog.Info(" M (Solution manager): update labels to true >>>>>>>>>>>>>>>>>>>> %v, %v", rootResource, version)

state.ObjectMeta.Labels["rootResource"] = rootResource
state.ObjectMeta.Labels["version"] = version
refreshLabels = true
}

sLog.Info(" M (Solution manager): debug refresh >>>>>>>>>>>>>>>>>>>> %v, %v, %v", refreshLabels, versionLabelExists, rootLabelExists)

body := map[string]interface{}{
"apiVersion": model.SolutionGroup + "/v1",
"kind": "Solution",
"metadata": state.ObjectMeta,
"spec": state.Spec,
}

upsertRequest := states.UpsertRequest{
Value: states.StateEntry{
ID: name,
Body: body,
},
Metadata: map[string]interface{}{
"namespace": state.ObjectMeta.Namespace,
"group": model.SolutionGroup,
"version": "v1",
"resource": "solutions",
"kind": "Solution",
"namespace": state.ObjectMeta.Namespace,
"group": model.SolutionGroup,
"version": "v1",
"resource": "solutions",
"kind": "Solution",
"rootResource": rootResource,
"refreshLabels": strconv.FormatBool(refreshLabels),
},
}

Expand Down Expand Up @@ -150,6 +199,8 @@ func (t *SolutionsManager) GetState(ctx context.Context, id string, namespace st
var err error = nil
defer observ_utils.CloseSpanWithError(span, &err)

sLog.Info(" M (Solution manager): debug get state >>>>>>>>>>>>>>>>>>>> %v, %v", id, namespace)

getRequest := states.GetRequest{
ID: id,
Metadata: map[string]interface{}{
Expand All @@ -172,3 +223,34 @@ func (t *SolutionsManager) GetState(ctx context.Context, id string, namespace st
}
return ret, nil
}

func (t *SolutionsManager) GetLatestState(ctx context.Context, id string, namespace string) (model.SolutionState, error) {
ctx, span := observability.StartSpan("Solutions Manager", ctx, &map[string]string{
"method": "GetLatest",
})
var err error = nil
defer observ_utils.CloseSpanWithError(span, &err)

sLog.Info(" M (Solution manager): debug get latest state >>>>>>>>>>>>>>>>>>>> %v, %v", id, namespace)

getRequest := states.GetRequest{
ID: id,
Metadata: map[string]interface{}{
"version": "v1",
"group": model.SolutionGroup,
"resource": "solutions",
"namespace": namespace,
"kind": "Solution",
},
}
target, err := t.StateProvider.GetLatest(ctx, getRequest)
if err != nil {
return model.SolutionState{}, err
}

ret, err := getSolutionState(target.Body)
if err != nil {
return model.SolutionState{}, err
}
return ret, nil
}
8 changes: 5 additions & 3 deletions api/pkg/apis/v1alpha1/model/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ type (
}

SolutionSpec struct {
DisplayName string `json:"displayName,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Components []ComponentSpec `json:"components,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Components []ComponentSpec `json:"components,omitempty"`
Version string `json:"version,omitempty"`
RootResource string `json:"rootResource,omitempty"`
}
)

Expand Down
52 changes: 52 additions & 0 deletions api/pkg/apis/v1alpha1/model/versionedcampaign.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
* SPDX-License-Identifier: MIT
*/

package model

import (
"errors"
)

type VersionedCampaignState struct {
ObjectMeta ObjectMeta `json:"metadata,omitempty"`
Spec *VersionedCampaignSpec `json:"spec,omitempty"`
}

type VersionedCampaignSpec struct {
Name string `json:"name,omitempty"`
}

func (c VersionedCampaignSpec) DeepEquals(other IDeepEquals) (bool, error) {
otherC, ok := other.(VersionedCampaignSpec)
if !ok {
return false, errors.New("parameter is not a VersionedCampaignSpec type")
}

if c.Name != otherC.Name {
return false, nil
}

return true, nil
}

func (c VersionedCampaignState) DeepEquals(other IDeepEquals) (bool, error) {
otherC, ok := other.(VersionedCampaignState)
if !ok {
return false, errors.New("parameter is not a VersionedCampaignState type")
}

equal, err := c.ObjectMeta.DeepEquals(otherC.ObjectMeta)
if err != nil || !equal {
return equal, err
}

equal, err = c.Spec.DeepEquals(*otherC.Spec)
if err != nil || !equal {
return equal, err
}

return true, nil
}
62 changes: 62 additions & 0 deletions api/pkg/apis/v1alpha1/model/versionedcatalog
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
* SPDX-License-Identifier: MIT
*/

package model

import (
"errors"
"reflect"
)

// TODO: all state objects should converge to this paradigm: id, spec and status
type VersionedCatalogState struct {
ObjectMeta ObjectMeta `json:"metadata,omitempty"`
Spec *VersionedCatalogSpec `json:"spec,omitempty"`
}

type VersionedCatalogSpec struct {
Name string `json:"name"`
}

func (c VersionedCatalogSpec) DeepEquals(other IDeepEquals) (bool, error) {
otherC, ok := other.(VersionedCatalogSpec)
if !ok {
return false, errors.New("parameter is not a VersionedCatalogSpec type")
}

if c.Name != otherC.Name {
return false, nil
}

if c.Generation != otherC.Generation {
return false, nil
}

if !reflect.DeepEqual(c.Properties, otherC.Properties) {
return false, nil
}

return true, nil
}

func (c VersionedCatalogState) DeepEquals(other IDeepEquals) (bool, error) {
otherC, ok := other.(VersionedCatalogState)
if !ok {
return false, errors.New("parameter is not a VersionedCatalogState type")
}

equal, err := c.ObjectMeta.DeepEquals(otherC.ObjectMeta)
if err != nil || !equal {
return equal, err
}

equal, err = c.Spec.DeepEquals(*otherC.Spec)
if err != nil || !equal {
return equal, err
}

return true, nil
}
59 changes: 59 additions & 0 deletions api/pkg/apis/v1alpha1/model/versionedsolution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
* SPDX-License-Identifier: MIT
*/

package model

import (
"errors"
)

type (
VersionedSolutionState struct {
ObjectMeta ObjectMeta `json:"metadata,omitempty"`
Spec *VersionedSolutionSpec `json:"spec,omitempty"`
}

VersionedSolutionSpec struct {
DisplayName string `json:"displayName,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
)

func (c VersionedSolutionSpec) DeepEquals(other IDeepEquals) (bool, error) {
otherC, ok := other.(VersionedSolutionSpec)
if !ok {
return false, errors.New("parameter is not a VersionedSolutionSpec type")
}

if c.DisplayName != otherC.DisplayName {
return false, nil
}

if !StringMapsEqual(c.Metadata, otherC.Metadata, nil) {
return false, nil
}

return true, nil
}

func (c VersionedSolutionState) DeepEquals(other IDeepEquals) (bool, error) {
otherC, ok := other.(VersionedSolutionState)
if !ok {
return false, errors.New("parameter is not a VersionedSolutionState type")
}

equal, err := c.ObjectMeta.DeepEquals(otherC.ObjectMeta)
if err != nil || !equal {
return equal, err
}

equal, err = c.Spec.DeepEquals(*otherC.Spec)
if err != nil || !equal {
return equal, err
}

return true, nil
}
Loading