openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject [incubator-openwhisk-wskdeploy] branch master updated: Updating trigger creation/deletion process (#958)
Date Mon, 09 Jul 2018 22:41:10 GMT
This is an automated email from the ASF dual-hosted git repository.

pdesai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git


The following commit(s) were added to refs/heads/master by this push:
     new 829ba85  Updating trigger creation/deletion process (#958)
829ba85 is described below

commit 829ba850c25c9c5fc4f8a81ce27d4c60e089a4be
Author: Priti Desai <pdesai@us.ibm.com>
AuthorDate: Mon Jul 9 15:41:07 2018 -0700

    Updating trigger creation/deletion process (#958)
---
 deployers/servicedeployer.go | 107 ++++++++++++++++++++-----------------------
 utils/misc.go                |   2 +-
 2 files changed, 51 insertions(+), 58 deletions(-)

diff --git a/deployers/servicedeployer.go b/deployers/servicedeployer.go
index 970629a..2e266c0 100644
--- a/deployers/servicedeployer.go
+++ b/deployers/servicedeployer.go
@@ -910,38 +910,32 @@ func (deployer *ServiceDeployer) createFeedAction(trigger *whisk.Trigger,
feedNa
 
 	var err error
 	var response *http.Response
+	if err = deployer.createTrigger(t); err != nil {
+		return err
+	}
+	qName, err := utils.ParseQualifiedName(feedName, deployer.ClientConfig.Namespace)
+	if err != nil {
+		return err
+	}
+
+	namespace := deployer.Client.Namespace
+	deployer.Client.Namespace = qName.Namespace
 	err = retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
-		_, response, err = deployer.Client.Triggers.Insert(t, true)
+		_, response, err = deployer.Client.Actions.Invoke(qName.EntityName, params, true, false)
 		return err
 	})
-	if err != nil {
-		return createWhiskClientError(err.(*whisk.WskError), response, wski18n.TRIGGER_FEED, true)
-	} else {
+	deployer.Client.Namespace = namespace
 
-		qName, err := utils.ParseQualifiedName(feedName, deployer.ClientConfig.Namespace)
-		if err != nil {
-			return err
-		}
+	if err != nil {
+		// Remove the created trigger
+		deployer.Client.Triggers.Delete(trigger.Name)
 
-		namespace := deployer.Client.Namespace
-		deployer.Client.Namespace = qName.Namespace
-		err = retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
-			_, response, err = deployer.Client.Actions.Invoke(qName.EntityName, params, true, false)
+		retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
+			_, _, err := deployer.Client.Triggers.Delete(trigger.Name)
 			return err
 		})
-		deployer.Client.Namespace = namespace
-
-		if err != nil {
-			// Remove the created trigger
-			deployer.Client.Triggers.Delete(trigger.Name)
-
-			retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
-				_, _, err := deployer.Client.Triggers.Delete(trigger.Name)
-				return err
-			})
 
-			return createWhiskClientError(err.(*whisk.WskError), response, wski18n.TRIGGER_FEED, false)
-		}
+		return createWhiskClientError(err.(*whisk.WskError), response, wski18n.TRIGGER_FEED, false)
 	}
 
 	displayPostprocessingInfo(wski18n.TRIGGER_FEED, trigger.Name, true)
@@ -1203,11 +1197,10 @@ func (deployer *ServiceDeployer) UnDeployTriggers(deployment *DeploymentProject)
 			if err != nil {
 				return err
 			}
-		} else {
-			err := deployer.deleteTrigger(trigger)
-			if err != nil {
-				return err
-			}
+		}
+		err := deployer.deleteTrigger(trigger)
+		if err != nil {
+			return err
 		}
 	}
 
@@ -1262,15 +1255,17 @@ func (deployer *ServiceDeployer) deleteTrigger(trigger *whisk.Trigger)
error {
 
 	displayPreprocessingInfo(parsers.YAML_KEY_TRIGGER, trigger.Name, false)
 
-	var err error
-	var response *http.Response
-	err = retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
-		_, response, err = deployer.Client.Triggers.Delete(trigger.Name)
-		return err
-	})
+	if _, _, ok := deployer.Client.Triggers.Get(trigger.Name); ok == nil {
+		var err error
+		var response *http.Response
+		err = retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
+			_, response, err = deployer.Client.Triggers.Delete(trigger.Name)
+			return err
+		})
 
-	if err != nil {
-		return createWhiskClientError(err.(*whisk.WskError), response, parsers.YAML_KEY_TRIGGER,
false)
+		if err != nil {
+			return createWhiskClientError(err.(*whisk.WskError), response, parsers.YAML_KEY_TRIGGER,
false)
+		}
 	}
 
 	displayPostprocessingInfo(parsers.YAML_KEY_TRIGGER, trigger.Name, false)
@@ -1279,6 +1274,8 @@ func (deployer *ServiceDeployer) deleteTrigger(trigger *whisk.Trigger)
error {
 
 func (deployer *ServiceDeployer) deleteFeedAction(trigger *whisk.Trigger, feedName string)
error {
 
+	displayPreprocessingInfo(parsers.YAML_KEY_FEED, trigger.Name, false)
+
 	params := make(whisk.KeyValueArr, 0)
 	// TODO() define keys and operations as const
 	params = append(params, whisk.KeyValue{Key: "authKey", Value: deployer.ClientConfig.AuthToken})
@@ -1295,6 +1292,11 @@ func (deployer *ServiceDeployer) deleteFeedAction(trigger *whisk.Trigger,
feedNa
 		return err
 	}
 
+	if _, _, ok := deployer.Client.Triggers.Get(trigger.Name); ok != nil {
+		displayPostprocessingInfo(parsers.YAML_KEY_FEED, trigger.Name, false)
+		return nil
+	}
+
 	namespace := deployer.Client.Namespace
 	deployer.Client.Namespace = qName.Namespace
 	var response *http.Response
@@ -1312,19 +1314,8 @@ func (deployer *ServiceDeployer) deleteFeedAction(trigger *whisk.Trigger,
feedNa
 		whisk.Debug(whisk.DbgError, errString)
 		return wskderrors.NewWhiskClientError(wskErr.Error(), wskErr.ExitCode, response)
 
-	} else {
-		trigger.Parameters = nil
-		var err error
-		err = retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
-			_, response, err = deployer.Client.Triggers.Delete(trigger.Name)
-			return err
-		})
-
-		if err != nil {
-			return createWhiskClientError(err.(*whisk.WskError), response, parsers.YAML_KEY_TRIGGER,
false)
-		}
 	}
-
+	displayPostprocessingInfo(parsers.YAML_KEY_FEED, trigger.Name, false)
 	return nil
 }
 
@@ -1332,15 +1323,17 @@ func (deployer *ServiceDeployer) deleteRule(rule *whisk.Rule) error
{
 
 	displayPreprocessingInfo(parsers.YAML_KEY_RULE, rule.Name, false)
 
-	var err error
-	var response *http.Response
-	err = retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
-		response, err = deployer.Client.Rules.Delete(rule.Name)
-		return err
-	})
+	if _, _, ok := deployer.Client.Rules.Get(rule.Name); ok == nil {
+		var err error
+		var response *http.Response
+		err = retry(DEFAULT_ATTEMPTS, DEFAULT_INTERVAL, func() error {
+			response, err = deployer.Client.Rules.Delete(rule.Name)
+			return err
+		})
 
-	if err != nil {
-		return createWhiskClientError(err.(*whisk.WskError), response, parsers.YAML_KEY_RULE, false)
+		if err != nil {
+			return createWhiskClientError(err.(*whisk.WskError), response, parsers.YAML_KEY_RULE,
false)
+		}
 	}
 	displayPostprocessingInfo(parsers.YAML_KEY_RULE, rule.Name, false)
 	return nil
diff --git a/utils/misc.go b/utils/misc.go
index 177fe10..81ea403 100644
--- a/utils/misc.go
+++ b/utils/misc.go
@@ -34,7 +34,7 @@ import (
 )
 
 const (
-	DEFAULT_HTTP_TIMEOUT = 30
+	DEFAULT_HTTP_TIMEOUT = 60
 	DEFAULT_PROJECT_PATH = "."
 	HTTP_FILE_EXTENSION  = "http"
 	// name of manifest and deployment files


Mime
View raw message