@@ -29,8 +29,10 @@ import (
2929 "github.com/apache/openwhisk-wskdeploy/parsers"
3030 "github.com/apache/openwhisk-wskdeploy/runtimes"
3131 "github.com/apache/openwhisk-wskdeploy/utils"
32+ "github.com/apache/openwhisk-wskdeploy/wskderrors"
3233 "github.com/apache/openwhisk-wskdeploy/wski18n"
3334 "github.com/apache/openwhisk-wskdeploy/wskprint"
35+ "github.com/davecgh/go-spew/spew"
3436 "github.com/spf13/cobra"
3537)
3638
@@ -117,9 +119,6 @@ func ExportAction(actionName string, packageName string, maniyaml *parsers.YAML,
117119
118120func exportProject (projectName string , targetManifest string ) error {
119121
120- whisk .SetVerbose (utils .Flags .Verbose )
121- whisk .SetDebug (utils .Flags .Trace )
122-
123122 maniyaml := & parsers.YAML {}
124123 maniyaml .Project .Name = projectName
125124
@@ -129,13 +128,19 @@ func exportProject(projectName string, targetManifest string) error {
129128 return err
130129 }
131130
131+ // Emit additional trace data (primarily in Travis)
132+ if utils .Flags .Trace {
133+ spew .Dump (packages )
134+ }
135+
132136 var bindings = make (map [string ]whisk.Binding )
133137
134138 // iterate over each package to find managed annotations
135139 // check if "managed" annotation is attached to a package
136140 // add to export when managed project name matches with the
137141 // specified project name
138142 for _ , pkg := range packages {
143+
139144 if a := pkg .Annotations .GetValue (utils .MANAGED ); a != nil {
140145 // decode the JSON blob and retrieve __OW_PROJECT_NAME
141146 pa := a .(map [string ]interface {})
@@ -199,59 +204,66 @@ func exportProject(projectName string, targetManifest string) error {
199204
200205 // iterate over the list of triggers to determine whether any of them part of specified managed project
201206 for _ , trg := range triggers {
202- // trigger has attached managed annotation
203- if a := trg .Annotations .GetValue (utils .MANAGED ); a != nil {
204- // decode the JSON blob and retrieve __OW_PROJECT_NAME
205- ta := a .(map [string ]interface {})
206- if ta [utils .OW_PROJECT_NAME ] == projectName {
207-
208- for pkgName := range maniyaml .Packages {
209- if maniyaml .Packages [pkgName ].Namespace == trg .Namespace {
210- if maniyaml .Packages [pkgName ].Triggers == nil {
211- pkg := maniyaml .Packages [pkgName ]
212- pkg .Triggers = make (map [string ]parsers.Trigger )
213- maniyaml .Packages [pkgName ] = pkg
214- }
215207
216- // export trigger to manifest
217-
218- if feedname , isFeed := utils . IsFeedAction ( & trg ); isFeed {
219- // check if feed name starts with namespace and workaround it
220- // the current problem is that client has user namespace and when feed specified with different namespace it will fail to invoke the feed action
221- // we need to transform the path from e.g.
222- // /api/v1/namespaces/[email protected] _uspace/actions//whisk.system/alarms/interval?blocking=true 223- // in to
224- // /api/v1/namespaces/[email protected] _uspace/actions/../../whisk.system/actions/alarms/interval?blocking=true 225- if strings . HasPrefix ( feedname , "/" ) {
226- // /whisk.system/alarms/interval -> ../../whisk.system/actions/alarms/interval
227- prts := strings . SplitN ( feedname , "/" , 3 )
228- feedname = "../../" + prts [ 1 ] + "/actions/" + prts [ 2 ]
208+ // trigger has attached managed annotation
209+ if trg . Annotations != nil {
210+ if a := trg . Annotations . GetValue ( utils . MANAGED ); a != nil {
211+ // decode the JSON blob and retrieve __OW_PROJECT_NAME
212+ ta := a .( map [ string ] interface {})
213+ if ta [ utils . OW_PROJECT_NAME ] == projectName {
214+
215+ for pkgName := range maniyaml . Packages {
216+ if maniyaml . Packages [ pkgName ]. Namespace == trg . Namespace {
217+ if maniyaml . Packages [ pkgName ]. Triggers == nil {
218+ pkg := maniyaml . Packages [ pkgName ]
219+ pkg . Triggers = make ( map [ string ]parsers. Trigger )
220+ maniyaml . Packages [ pkgName ] = pkg
229221 }
230222
231- // export feed input parameters
232- params := make (map [string ]interface {})
233- params ["authKey" ] = client .Config .AuthToken
234- params ["lifecycleEvent" ] = "READ"
235- params ["triggerName" ] = "/" + client .Namespace + "/" + trg .Name
236- res , _ , err := client .Actions .Invoke (feedname , params , true , true )
237- if err != nil {
238- return err
239- }
240- feedConfig := res ["config" ]
223+ // export trigger to manifest
224+
225+ if feedname , isFeed := utils .IsFeedAction (& trg ); isFeed {
226+ // check if feed name starts with namespace and workaround it
227+ // the current problem is that client has user namespace and when feed specified with different namespace it will fail to invoke the feed action
228+ // we need to transform the path from e.g.
229+ // /api/v1/namespaces/[email protected] _uspace/actions//whisk.system/alarms/interval?blocking=true 230+ // in to
231+ // /api/v1/namespaces/[email protected] _uspace/actions/../../whisk.system/actions/alarms/interval?blocking=true 232+ if strings .HasPrefix (feedname , "/" ) {
233+ // /whisk.system/alarms/interval -> ../../whisk.system/actions/alarms/interval
234+ prts := strings .SplitN (feedname , "/" , 3 )
235+ feedname = "../../" + prts [1 ] + "/actions/" + prts [2 ]
236+ }
237+
238+ // export feed input parameters
239+ params := make (map [string ]interface {})
240+ params ["authKey" ] = client .Config .AuthToken
241+ params ["lifecycleEvent" ] = "READ"
242+ params ["triggerName" ] = "/" + client .Namespace + "/" + trg .Name
243+ res , _ , err := client .Actions .Invoke (feedname , params , true , true )
244+ if err != nil {
245+ return err
246+ }
247+ feedConfig := res ["config" ]
241248
242- if feedConfig != nil {
243- for key , val := range feedConfig .(map [string ]interface {}) {
244- if key != "startDate" {
245- trg .Parameters = trg .Parameters .AddOrReplace (& whisk.KeyValue {Key : key , Value : val })
249+ if feedConfig != nil {
250+ for key , val := range feedConfig .(map [string ]interface {}) {
251+ if key != "startDate" {
252+ trg .Parameters = trg .Parameters .AddOrReplace (& whisk.KeyValue {Key : key , Value : val })
253+ }
246254 }
247255 }
248256 }
249- }
250257
251- maniyaml .Packages [pkgName ].Triggers [trg .Name ] = * maniyaml .ComposeParsersTrigger (trg )
258+ maniyaml .Packages [pkgName ].Triggers [trg .Name ] = * maniyaml .ComposeParsersTrigger (trg )
259+ }
252260 }
253261 }
254262 }
263+ } else {
264+ // Emit additional trace data on common Travis failures
265+ spew .Dump (trg )
266+ return wskderrors .NewCommandError ("Export" , "Trigger missing annotations." )
255267 }
256268 }
257269
@@ -263,29 +275,36 @@ func exportProject(projectName string, targetManifest string) error {
263275
264276 // iterate over the list of rules to determine whether any of them is part of the manage dproject
265277 for _ , rule := range rules {
278+
266279 // get rule from OW
267280 wskRule , _ , _ := client .Rules .Get (rule .Name )
268- // rule has attached managed annotation
269- if a := wskRule .Annotations .GetValue (utils .MANAGED ); a != nil {
270- // decode the JSON blob and retrieve __OW_PROJECT_NAME
271- ta := a .(map [string ]interface {})
272- if ta [utils .OW_PROJECT_NAME ] == projectName {
273-
274- for pkgName := range maniyaml .Packages {
275- if maniyaml .Packages [pkgName ].Namespace == wskRule .Namespace {
276- if maniyaml .Packages [pkgName ].Rules == nil {
277- pkg := maniyaml .Packages [pkgName ]
278- pkg .Rules = make (map [string ]parsers.Rule )
279- maniyaml .Packages [pkgName ] = pkg
280- }
281281
282- // export rule to manifest
283- maniyaml .Packages [pkgName ].Rules [wskRule .Name ] = * maniyaml .ComposeParsersRule (* wskRule )
282+ if wskRule .Annotations != nil {
283+ // rule has attached managed annotation
284+ if a := wskRule .Annotations .GetValue (utils .MANAGED ); a != nil {
285+ // decode the JSON blob and retrieve __OW_PROJECT_NAME
286+ ta := a .(map [string ]interface {})
287+ if ta [utils .OW_PROJECT_NAME ] == projectName {
288+
289+ for pkgName := range maniyaml .Packages {
290+ if maniyaml .Packages [pkgName ].Namespace == wskRule .Namespace {
291+ if maniyaml .Packages [pkgName ].Rules == nil {
292+ pkg := maniyaml .Packages [pkgName ]
293+ pkg .Rules = make (map [string ]parsers.Rule )
294+ maniyaml .Packages [pkgName ] = pkg
295+ }
296+
297+ // export rule to manifest
298+ maniyaml .Packages [pkgName ].Rules [wskRule .Name ] = * maniyaml .ComposeParsersRule (* wskRule )
299+ }
284300 }
285301 }
286302 }
303+ } else {
304+ // Emit additional trace data on common Travis failures
305+ spew .Dump (wskRule )
306+ return wskderrors .NewCommandError ("Export" , "Rule missing annotations." )
287307 }
288-
289308 }
290309
291310 // API Gateway is an optional component. Export APIs only when ApigwAccessToken is configured
@@ -386,7 +405,14 @@ func exportProject(projectName string, targetManifest string) error {
386405
387406 // find exported manifest parent directory
388407 manifestDir := filepath .Dir (utils .Flags .ManifestPath )
389- os .MkdirAll (manifestDir , os .ModePerm )
408+ errMkDir := os .MkdirAll (manifestDir , os .ModePerm )
409+
410+ // Exit if unable to create export dir. structure
411+ // TODO: This sometimes fails in Travis, perhaps retry?
412+ if errMkDir != nil {
413+ wskprint .PrintOpenWhiskError (errMkDir .Error ())
414+ return errMkDir
415+ }
390416
391417 // export manifest to file
392418 parsers .Write (maniyaml , targetManifest )
0 commit comments