Skip to content

Commit

Permalink
Merge branch 'develop' into feature/gh-80-google-vpc
Browse files Browse the repository at this point in the history
  • Loading branch information
loicalbertin authored Nov 15, 2018
2 parents 03ce035 + e4c5125 commit 5f86978
Show file tree
Hide file tree
Showing 56 changed files with 1,765 additions and 1,118 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### FEATURES

* Support GCE virtual private networks (VPC) ([GH-80](https://github.com/ystia/yorc/issues/80))
* Support Kubernetes Jobs. ([GH-86](https://github.com/ystia/yorc/issues/86))

### ENHANCEMENTS

Expand Down
9 changes: 9 additions & 0 deletions data/tosca/yorc-kubernetes-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ node_types:
implementation:
file: "embedded"
type: yorc.artifacts.Deployment.Kubernetes

yorc.nodes.kubernetes.api.types.JobResource:
derived_from: org.alien4cloud.kubernetes.api.types.JobResource
interfaces:
tosca.interfaces.node.lifecycle.Runnable:
run:
implementation:
file: "embedded"
type: yorc.artifacts.Deployment.Kubernetes

yorc.nodes.kubernetes.api.types.ServiceResource:
derived_from: org.alien4cloud.kubernetes.api.types.ServiceResource
Expand Down
4 changes: 2 additions & 2 deletions deployments/definition_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,9 @@ func registerImplementationTypes(ctx context.Context, kv *api.KV, deploymentID s
return errors.Errorf("Duplicate implementation artifact file extension %q found in artifact %q and %q", ext, check, t)
}
extPath := path.Join(consulutil.DeploymentKVPrefix, deploymentID, "topology", implementationArtifactsExtensionsPath, ext)
_, err = kv.Put(&api.KVPair{Key: extPath, Value: []byte(t)}, nil)
err = consulutil.StoreConsulKeyAsString(extPath, t)
if err != nil {
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
return err
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion deployments/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// SetInstanceStateStringWithContextualLogs stores the state of a given node instance and publishes a status change event
// context is used to carry contextual information for logging (see events package)
func SetInstanceStateStringWithContextualLogs(ctx context.Context, kv *api.KV, deploymentID, nodeName, instanceName, state string) error {
_, err := kv.Put(&api.KVPair{Key: path.Join(consulutil.DeploymentKVPrefix, deploymentID, "topology/instances", nodeName, instanceName, "attributes/state"), Value: []byte(state)}, nil)
err := consulutil.StoreConsulKeyAsString(path.Join(consulutil.DeploymentKVPrefix, deploymentID, "topology/instances", nodeName, instanceName, "attributes/state"), state)
if err != nil {
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
}
Expand Down
7 changes: 1 addition & 6 deletions deployments/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,7 @@ func GetNodePropertyValue(kv *api.KV, deploymentID, nodeName, propertyName strin

// SetNodeProperty sets a node property
func SetNodeProperty(kv *api.KV, deploymentID, nodeName, propertyName, propertyValue string) error {
kvp := &api.KVPair{
Key: path.Join(consulutil.DeploymentKVPrefix, deploymentID, "topology", "nodes", nodeName, "properties", propertyName),
Value: []byte(propertyValue),
}
_, err := kv.Put(kvp, nil)
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
return consulutil.StoreConsulKeyAsString(path.Join(consulutil.DeploymentKVPrefix, deploymentID, "topology", "nodes", nodeName, "properties", propertyName), propertyValue)
}

// GetStringNodeProperty returns the string value of a property.
Expand Down
12 changes: 4 additions & 8 deletions deployments/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func addOrRemoveInstanceFromTargetRelationship(kv *api.KV, deploymentID, nodeNam
if err != nil {
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
}
_, errGrp, store := consulutil.WithContext(context.Background())
for _, relInstKVPair := range relInstKVPairs {
if strings.HasSuffix(relInstKVPair.Key, "target/name") {
if string(relInstKVPair.Value) == nodeName {
Expand All @@ -239,7 +240,7 @@ func addOrRemoveInstanceFromTargetRelationship(kv *api.KV, deploymentID, nodeNam
if err != nil {
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
}
if kvp.Value == nil {
if kvp == nil || len(kvp.Value) == 0 {
return errors.Errorf("Missing key %q", instPath)
}
instances := strings.Split(string(kvp.Value), ",")
Expand All @@ -257,16 +258,11 @@ func addOrRemoveInstanceFromTargetRelationship(kv *api.KV, deploymentID, nodeNam
}
instances = newInstances
}
kvp.Value = []byte(strings.Join(instances, ","))
_, err = kv.Put(kvp, nil)
if err != nil {
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
}

store.StoreConsulKeyAsString(instPath, strings.Join(instances, ","))
}
}
}
return nil
return errGrp.Wait()
}

// DeleteRelationshipInstance deletes the instance from relationship instances stored in consul
Expand Down
3 changes: 1 addition & 2 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ func PublishAndLogWorkflowStatusChange(ctx context.Context, kv *api.KV, deployme
func storeStatusUpdateEvent(kv *api.KV, deploymentID string, eventType StatusUpdateType, data string) (string, error) {
now := time.Now().Format(time.RFC3339Nano)
eventsPrefix := path.Join(consulutil.EventsPrefix, deploymentID)
p := &api.KVPair{Key: path.Join(eventsPrefix, now), Value: []byte(data), Flags: uint64(eventType)}
_, err := kv.Put(p, nil)
err := consulutil.StoreConsulKeyAsStringWithFlags(path.Join(eventsPrefix, now), data, uint64(eventType))
if err != nil {
return "", err
}
Expand Down
11 changes: 0 additions & 11 deletions prov/ansible/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/ystia/yorc/config"
"github.com/ystia/yorc/events"
"github.com/ystia/yorc/helper/stringutil"
"github.com/ystia/yorc/log"
"github.com/ystia/yorc/prov"
"github.com/ystia/yorc/tasks"
Expand Down Expand Up @@ -57,16 +56,6 @@ func (e *defaultExecutor) ExecOperation(ctx context.Context, conf config.Configu
}
kv := consulClient.KV()

logOptFields, ok := events.FromContext(ctx)
if !ok {
return errors.New("Missing context log fields")
}
logOptFields[events.NodeID] = nodeName
logOptFields[events.ExecutionID] = taskID
logOptFields[events.OperationName] = stringutil.GetLastElement(operation.Name, ".")
logOptFields[events.InterfaceName] = stringutil.GetAllExceptLastElement(operation.Name, ".")
ctx = events.NewContext(ctx, logOptFields)

exec, err := newExecution(ctx, kv, conf, taskID, deploymentID, nodeName, operation, e.cli)
if err != nil {
if IsOperationNotImplemented(err) {
Expand Down
29 changes: 6 additions & 23 deletions prov/hostspool/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ package hostspool
import (
"context"
"encoding/json"
"strconv"
"strings"

"github.com/ystia/yorc/helper/labelsutil"

"github.com/hashicorp/go-multierror"

"github.com/dustin/go-humanize"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"

"strconv"

"github.com/dustin/go-humanize"
"github.com/ystia/yorc/config"
"github.com/ystia/yorc/deployments"
"github.com/ystia/yorc/events"
"github.com/ystia/yorc/helper/labelsutil"
"github.com/ystia/yorc/tasks"
"github.com/ystia/yorc/tosca"
)
Expand All @@ -44,16 +41,6 @@ func (e *defaultExecutor) ExecDelegate(ctx context.Context, cfg config.Configura
if err != nil {
return err
}
// Fill log optional fields for log registration
logOptFields, ok := events.FromContext(ctx)
if !ok {
return errors.New("Missing contextual log optional fields")
}
logOptFields[events.NodeID] = nodeName
logOptFields[events.ExecutionID] = taskID
logOptFields[events.OperationName] = delegateOperation
logOptFields[events.InterfaceName] = "delegate"
ctx = events.NewContext(ctx, logOptFields)

instances, err := tasks.GetInstances(cc.KV(), taskID, deploymentID, nodeName)
if err != nil {
Expand Down Expand Up @@ -133,9 +120,7 @@ func (e *defaultExecutor) hostsPoolCreate(originalCtx context.Context, cc *api.C
return err
}
for _, instance := range instances {
logOptFields, _ := events.FromContext(originalCtx)
logOptFields[events.InstanceID] = instance
ctx := events.NewContext(originalCtx, logOptFields)
ctx := events.AddLogOptionalFields(originalCtx, events.LogOptionalFields{events.InstanceID: instance})

allocation := &Allocation{NodeName: nodeName, Instance: instance, DeploymentID: deploymentID, Shareable: shareable, Resources: allocatedResources}
hostname, warnings, err := hpManager.Allocate(allocation, filters...)
Expand Down Expand Up @@ -318,9 +303,7 @@ func (e *defaultExecutor) hostsPoolDelete(originalCtx context.Context, cc *api.C
}
var errs error
for _, instance := range instances {
logOptFields, _ := events.FromContext(originalCtx)
logOptFields[events.InstanceID] = instance
ctx := events.NewContext(originalCtx, logOptFields)
ctx := events.AddLogOptionalFields(originalCtx, events.LogOptionalFields{events.InstanceID: instance})
hostname, err := deployments.GetInstanceAttributeValue(cc.KV(), deploymentID, nodeName, instance, "hostname")
if err != nil {
errs = multierror.Append(errs, err)
Expand Down
15 changes: 7 additions & 8 deletions prov/hostspool/hostspool_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package hostspool

import (
"context"
"fmt"
"path"
"reflect"
Expand Down Expand Up @@ -388,12 +389,10 @@ func (cm *consulManager) backupHostStatus(hostname string) error {
return err
}
hostPath := path.Join(consulutil.HostsPoolPrefix, hostname)
_, err = cm.cc.KV().Put(&api.KVPair{Key: path.Join(hostPath, ".statusBackup"), Value: []byte(status.String())}, nil)
if err != nil {
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
}
_, err = cm.cc.KV().Put(&api.KVPair{Key: path.Join(hostPath, ".messageBackup"), Value: []byte(message)}, nil)
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
_, errGrp, store := consulutil.WithContext(context.Background())
store.StoreConsulKeyAsString(path.Join(hostPath, ".statusBackup"), status.String())
store.StoreConsulKeyAsString(path.Join(hostPath, ".messageBackup"), message)
return errGrp.Wait()
}
func (cm *consulManager) restoreHostStatus(hostname string) error {
hostPath := path.Join(consulutil.HostsPoolPrefix, hostname)
Expand Down Expand Up @@ -441,9 +440,9 @@ func (cm *consulManager) setHostStatusWithMessage(hostname string, status HostSt
if err != nil {
return err
}
_, err = cm.cc.KV().Put(&api.KVPair{Key: path.Join(consulutil.HostsPoolPrefix, hostname, "status"), Value: []byte(status.String())}, nil)
err = consulutil.StoreConsulKeyAsString(path.Join(consulutil.HostsPoolPrefix, hostname, "status"), status.String())
if err != nil {
return errors.Wrap(err, consulutil.ConsulGenericErrMsg)
return err
}
return cm.setHostMessage(hostname, message)
}
Expand Down
Loading

0 comments on commit 5f86978

Please sign in to comment.