Skip to content

Commit

Permalink
add specific legacy stuff to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
stefbenoist committed Nov 21, 2019
1 parent 5827a68 commit 7592333
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 89 deletions.
6 changes: 3 additions & 3 deletions deployments/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func TestRunConsulDeploymentsPackageTests(t *testing.T) {
t.Run("TestNotifyAttributeOnValueChange", func(t *testing.T) {
testNotifyAttributeOnValueChange(t, deploymentID)
})
//t.Run("TestImportTopologyTemplate", func(t *testing.T) {
// testImportTopologyTemplate(t, deploymentID)
//})
t.Run("TestImportTopologyTemplate", func(t *testing.T) {
testImportTopologyTemplateNodeMetadata(t, deploymentID)
})
t.Run("TestTopologyTemplateMetadata", func(t *testing.T) {
testTopologyTemplateMetadata(t, deploymentID)
})
Expand Down
24 changes: 8 additions & 16 deletions deployments/definition_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,23 +978,15 @@ func testCheckCycleInNestedWorkflows(t *testing.T) {

// Testing a Deployment Definition where one of the imports
// contains a topology template
func testImportTopologyTemplate(t *testing.T, deploymentID string) {
// t.Parallel()

// Check the stored compute node and network have the expected type
expectedKeyValuePairs := map[string]string{
"topology/nodes/TestCompute/type": "yorc.nodes.openstack.Compute",
"topology/nodes/TestCompute/metadata/monitoring_time_interval": "30",
"topology/nodes/Network/type": "yorc.nodes.openstack.Network",
}
func testImportTopologyTemplateNodeMetadata(t *testing.T, deploymentID string) {
t.Parallel()

for key, expectedValue := range expectedKeyValuePairs {
consulKey := path.Join(consulutil.DeploymentKVPrefix, deploymentID, key)
exist, value, err := consulutil.GetStringValue(consulKey)
require.NoError(t, err, "Error getting value for key %s", consulKey)
require.True(t, exist, "Unexpected null value for key %s", consulKey)
assert.Equal(t, value, expectedValue, "Wrong value for key %s", key)
}
node, err := getNodeTemplateStruct(context.Background(), deploymentID, "TestCompute")
require.NoError(t, err, "Error getting node template")
require.NotNil(t, node, "node TestCompute should not be nil")
require.NotNil(t, node.Metadata, "node TestCompute should not be nil")
require.Len(t, node.Metadata, 1, "a metadata entry is expected")
require.Equal(t, "30", node.Metadata["monitoring_time_interval"], "monitoring time interval is expected in metadata")
}

// Testing topology template metadata
Expand Down
14 changes: 14 additions & 0 deletions deployments/internal/store_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,31 @@ package internal
import (
"context"
"github.com/pkg/errors"
"github.com/ystia/yorc/v4/log"
"github.com/ystia/yorc/v4/storage"
"github.com/ystia/yorc/v4/storage/types"
"github.com/ystia/yorc/v4/tosca"
"os"
"path"
"path/filepath"
)

// storeNodes stores topology nodes
func storeNodes(ctx context.Context, topology tosca.Topology, topologyPrefix, importPath, rootDefPath string) error {
nodesPrefix := path.Join(topologyPrefix, "nodes")
for nodeName, node := range topology.TopologyTemplate.NodeTemplates {
nodePrefix := nodesPrefix + "/" + nodeName

for artName, artDef := range node.Artifacts {
artFile := filepath.Join(rootDefPath, filepath.FromSlash(path.Join(importPath, artDef.File)))
log.Debugf("Looking if artifact %q exists on filesystem", artFile)
if _, err := os.Stat(artFile); os.IsNotExist(err) {
log.Printf("Warning: Artifact %q for node %q with computed path %q doesn't exists on filesystem, ignoring it.", artName, nodeName, artFile)
continue
}
delete(node.Artifacts, artName)
}

err := storage.GetStore(types.StoreTypeDeployment).Set(nodePrefix, node)
if err != nil {
return errors.Wrapf(err, "failed to store node with name:%q and value:%+v", nodeName, node)
Expand Down
4 changes: 4 additions & 0 deletions deployments/internal/store_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func StoreRepositories(ctx context.Context, consulStore consulutil.ConsulStore,
repositoriesPrefix := path.Join(topologyPrefix, "repositories")
for repositoryName, repo := range topology.Repositories {
repoPrefix := path.Join(repositoriesPrefix, repositoryName)
// Default repository token is password
if repo.Credit.TokenType == "" {
repo.Credit.TokenType = "password"
}
err := storage.GetStore(types.StoreTypeDeployment).Set(repoPrefix, repo)
if err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions deployments/internal/store_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ import (
"github.com/ystia/yorc/v4/tosca"
)

// TypeExistsFlagName is the name of a Consul key that is used to prove the existence of a TOSCA type
//
// This key doesn't contain any value and allow to detect types even if there is no other values stored for them into consul
const TypeExistsFlagName = ".existFlag"

// StoreAllTypes stores all types of a given topology
func StoreAllTypes(ctx context.Context, consulStore consulutil.ConsulStore, topology tosca.Topology, topologyPrefix, importPath string) error {
storeDataTypes(ctx, consulStore, topology, topologyPrefix, importPath)
Expand Down
17 changes: 16 additions & 1 deletion deployments/internal/store_workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@ package internal

import (
"context"
"path"
"strings"

"github.com/pkg/errors"

"github.com/ystia/yorc/v4/helper/collections"
"github.com/ystia/yorc/v4/helper/consulutil"
"github.com/ystia/yorc/v4/storage"
"github.com/ystia/yorc/v4/storage/types"
"github.com/ystia/yorc/v4/tosca"
"path"
)

// StoreWorkflow stores a workflow
func StoreWorkflow(ctx context.Context, deploymentID, workflowName string, workflow *tosca.Workflow) error {
wfPrefix := path.Join(consulutil.DeploymentKVPrefix, deploymentID, "workflows", workflowName)

for _, step := range workflow.Steps {
for _, activity := range step.Activities {
if activity.CallOperation != "" {
// Preserve case for requirement and target node name in case of relationship operation
opSlice := strings.SplitN(activity.CallOperation, "/", 2)
opSlice[0] = strings.ToLower(opSlice[0])
activity.CallOperation = strings.Join(opSlice, "/")
}
}
}

return storage.GetStore(types.StoreTypeDeployment).Set(wfPrefix, workflow)
}

Expand Down
Loading

0 comments on commit 7592333

Please sign in to comment.