Example #1
0
    def createFeed(self, args, props, putResponse):
        ns = props['namespace']
        triggerName = getQName(args.name, ns)

        parameters = args.param
        if parameters is None:
            parameters = []
        parameters.append([ 'lifecycleEvent', 'CREATE' ])
        parameters.append([ 'triggerName', triggerName ])
        parameters.append([ 'authKey', args.auth ])

        feedArgs = {
            'verbose': args.verbose,
            'name' : args.feed,
            'param': parameters,
            'blocking': True,
            'auth': args.auth
        }

        feedResponse = Action().doInvoke(dict2obj(feedArgs), props)
        if feedResponse.status == httplib.OK:
            print 'ok: created %s feed %s' % (self.name, args.name)
        else:
            print 'error: failed to create %s feed %s' % (self.name, args.name)
            # clean up by deleting trigger
            self.httpDelete(args, props)
            return responseError(feedResponse, None)
Example #2
0
 def formatListEntity(self, e):
     ns = e['namespace']
     name = getQName(e['name'], ns)
     return '{:<65} {:<8}{:<7}'.format(
             name,
             'shared' if (e['publish'] or e['publish'] == 'true') else 'private',
             'binding' if e['binding'] else '')
Example #3
0
    def create(self, args, props, update):
        exe = self.getExec(args, props)
        if args.sequence:
            if args.param is None:
                args.param = []
            ns = props['namespace']
            actions = self.csvToList(args.artifact)
            actions = [getQName(a, ns) for a in actions]
            args.param.append(['_actions', json.dumps(actions)])

        validExe = exe is not None and 'kind' in exe
        if update or validExe:  # if create action, then exe must be valid
            payload = {}
            if args.annotation:
                payload['annotations'] = getAnnotations(args)
            if args.param:
                payload['parameters'] = getParams(args)
            # API will accept limits == {} as limits not specified on an update
            if args.timeout or args.memory:
                payload['limits'] = self.getLimits(args)
            if validExe:
                payload['exec'] = exe
            if args.shared:
                self.addPublish(payload, args)
            return self.put(args, props, update, json.dumps(payload))
        else:
            if not args.copy:
                print 'the artifact "%s" is not a valid file. If this is a docker image, use --docker.' % args.artifact
            else:
                print 'the action "%s" does not exit, is malformed, or your are not entitled to it.' % args.artifact
            return 2
Example #4
0
    def deleteFeed(self, args, props, res):
        trigger = json.loads(res.read())
        hasFeed = [a['value'] for a in  trigger['annotations'] if a['key'] == 'feed']
        feedName = hasFeed[0] if hasFeed else None

        if feedName:
            ns = props['namespace']
            triggerName = getQName(args.name, ns)

            parameters = []
            parameters.append([ 'lifecycleEvent', 'DELETE' ])
            parameters.append([ 'triggerName', triggerName ])
            parameters.append([ 'authKey', args.auth ])

            feedArgs = {
                'verbose': args.verbose,
                'name' : feedName,
                'param': parameters,
                'blocking': True,
                'auth': args.auth
            }

            feedResponse = Action().doInvoke(dict2obj(feedArgs), props)
            if feedResponse.status == httplib.OK:
                return self.deleteResponse(args, res)
            else:
                print 'error: failed to delete %s feed %s but did delete the trigger' % (self.name, args.name)
                return responseError(feedResponse, None)
Example #5
0
    def deleteFeed(self, args, props, res):
        trigger = json.loads(res.read())
        hasFeed = [a['value'] for a in  trigger['annotations'] if a['key'] == 'feed']
        feedName = hasFeed[0] if hasFeed else None

        if feedName:
            ns = props['namespace']
            triggerName = getQName(args.name, ns)

            parameters = []
            parameters.append([ 'lifecycleEvent', 'DELETE' ])
            parameters.append([ 'triggerName', triggerName ])
            parameters.append([ 'authKey', args.auth ])

            feedArgs = {
                'verbose': args.verbose,
                'name' : feedName,
                'param': parameters,
                'blocking': True,
                'auth': args.auth
            }

            feedResponse = Action().doInvoke(dict2obj(feedArgs), props)
            if feedResponse.status == httplib.OK:
                return self.deleteResponse(args, res)
            else:
                print 'error: failed to delete %s feed %s but did delete the trigger' % (self.name, args.name)
                return responseError(feedResponse, None)
Example #6
0
    def createFeed(self, args, props, putResponse):
        ns = props['namespace']
        triggerName = getQName(args.name, ns)

        parameters = args.param
        if parameters is None:
            parameters = []
        parameters.append([ 'lifecycleEvent', 'CREATE' ])
        parameters.append([ 'triggerName', triggerName ])
        parameters.append([ 'authKey', args.auth ])

        feedArgs = {
            'verbose': args.verbose,
            'name' : args.feed,
            'param': parameters,
            'blocking': True,
            'auth': args.auth
        }

        feedResponse = Action().doInvoke(dict2obj(feedArgs), props)
        if feedResponse.status == httplib.OK:
            print 'ok: created %s feed %s' % (self.name, args.name)
        else:
            print 'error: failed to create %s feed %s' % (self.name, args.name)
            # clean up by deleting trigger
            self.httpDelete(args, props)
            return responseError(feedResponse, None)
Example #7
0
    def create(self, args, props, update):
        exe = self.getExec(args, props)
        if args.sequence:
            if args.param is None:
                args.param = []
            ns = props['namespace']
            actions = self.csvToList(args.artifact)
            actions = [ getQName(a, ns) for a in actions ]
            args.param.append([ '_actions', json.dumps(actions)])

        validExe = exe is not None and 'kind' in exe
        if update or validExe: # if create action, then exe must be valid
            payload = {}
            if args.annotation:
                payload['annotations'] = getAnnotations(args)
            if args.param:
                payload['parameters'] = getParams(args)
            # API will accept limits == {} as limits not specified on an update
            if args.timeout or args.memory:
                payload['limits'] = self.getLimits(args)
            if validExe:
                payload['exec'] = exe
            if args.shared:
                self.addPublish(payload, args)
            return self.put(args, props, update, json.dumps(payload))
        else:
            if not args.copy:
                print 'the artifact "%s" is not a valid file. If this is a docker image, use --docker.' % args.artifact
            else:
                print 'the action "%s" does not exit, is malformed, or your are not entitled to it.' % args.artifact
            return 2
Example #8
0
 def formatListEntity(self, e):
     ns = e['namespace']
     name = getQName(e['name'], ns)
     return '{:<65} {:<8}{:<7}'.format(
             name,
             'shared' if (e['publish'] or e['publish'] == 'true') else 'private',
             'binding' if e['binding'] else '')
Example #9
0
 def getEntitySummary(self,
                      entity,
                      includeParams=True,
                      kind=None,
                      namespace=None):
     kind = self.name if kind is None else kind
     namespace = entity['namespace'] if 'namespace' in entity else namespace
     fullName = getQName(entity['name'], namespace)
     annotations = entity['annotations']
     description = getDescriptionFromAnnotations(annotations)
     summary = '%s %s' % (bold(kind), fullName)
     if description:
         summary += ': %s' % (description)
     if includeParams:
         parameterNames = getParameterNamesFromAnnotations(annotations)
         if parameterNames:
             summary += '\n   (%s: %s)' % (bold('params'),
                                           ' '.join(parameterNames))
     if 'actions' in entity:
         for a in entity['actions']:
             actionSummary = self.getEntitySummary(a, False, 'action',
                                                   fullName)
             summary += '\n %s' % (actionSummary)
     if 'feeds' in entity:
         for a in entity['feeds']:
             actionSummary = self.getEntitySummary(a, False, 'feed  ',
                                                   fullName)
             summary += '\n %s' % (actionSummary)
     return summary
Example #10
0
 def poll(self, args, props):
     name = args.name if args.name else '/_'
     args.name = getQName(name, '_') # kludge: use default namespace unless explicitly specified
     print 'Hit Ctrl-C to exit.'
     try:
         self.console(args, props)
     except KeyboardInterrupt:
         print ''
Example #11
0
 def getEntitySummary(self, entity):
     kind = self.name
     fullName = getQName(entity['name'], entity['namespace'])
     end = datetime.fromtimestamp(entity['end'] / 1000)
     status = entity['response']['status']
     result = getPrettyJson(entity['response']['result'])
     summary = '%s result for %s (%s at %s):\n%s' % (kind, fullName, status, end, result)
     return summary
Example #12
0
 def list(self, args, props):
     name = args.name if args.name else '/_'
     args.name = getQName(name, '_') # kludge: use default namespace unless explicitly specified
     res = self.listCmd(args, props)
     if res.status == httplib.OK:
         result = json.loads(res.read())
         print bold('activations')
         for a in result:
             if args.full:
                 print getPrettyJson(a)
             else:
                 print '{:<45}{:<40}'.format(a['activationId'], a['name'])
         return 0
     else:
         return responseError(res)
Example #13
0
    def result(self, args, props):
        fqid = getQName(args.id, '_') # kludge: use default namespace unless explicitly specified
        namespace, aid = parseQName(fqid, props)
        url = '%(apibase)s/namespaces/%(namespace)s/activations/%(id)s/result' % {
           'apibase': apiBase(props),
           'namespace': urllib.quote(namespace),
           'id': aid
        }

        res = request('GET', url, auth=args.auth, verbose=args.verbose)

        if res.status == httplib.OK:
            response = json.loads(res.read())
            if 'result' in response:
                result = response['result']
                print getPrettyJson(result)
            return 0
        else:
            return responseError(res)
Example #14
0
    def logs(self, args, props):
        fqid = getQName(args.id, '_') # kludge: use default namespace unless explicitly specified
        namespace, aid = parseQName(fqid, props)
        url = '%(apibase)s/namespaces/%(namespace)s/activations/%(id)s/logs' % {
           'apibase': apiBase(props),
           'namespace': urllib.quote(namespace),
           'id': aid
        }

        res = request('GET', url, auth=args.auth, verbose=args.verbose)

        if res.status == httplib.OK:
            result = json.loads(res.read())
            logs = result['logs']
            if args.strip:
                logs = map(stripTimeStampAndString, logs)
            print '\n'.join(logs)
            return 0
        else:
            return responseError(res)
Example #15
0
 def getEntitySummary(self, entity, includeParams = True, kind = None, namespace = None):
     kind = self.name if kind is None else kind
     namespace = entity['namespace'] if 'namespace' in entity else namespace
     fullName = getQName(entity['name'], namespace)
     annotations = entity['annotations']
     description = getDescriptionFromAnnotations(annotations)
     summary = '%s %s' % (bold(kind), fullName)
     if description:
         summary += ': %s' % (description)
     if includeParams:
         parameterNames = getParameterNamesFromAnnotations(annotations)
         if parameterNames:
             summary += '\n   (%s: %s)' % (bold('params'), ' '.join(parameterNames))
     if 'actions' in entity:
         for a in entity['actions']:
             actionSummary = self.getEntitySummary(a, False, 'action', fullName)
             summary += '\n %s' % (actionSummary)
     if 'feeds' in entity:
         for a in entity['feeds']:
             actionSummary = self.getEntitySummary(a, False, 'feed  ', fullName)
             summary += '\n %s' % (actionSummary)
     return summary
Example #16
0
 def csvToQualifiedActions(self, props, csv):
     ns = props['namespace']
     actions = self.csvToList(csv)
     return [getQName(a, ns) for a in actions]
 def get(self, args, props):
     args.name = getQName(
         args.name,
         '_')  # kludge: use default namespace unless explicitly specified
     return Item.get(self, args, props)
Example #18
0
 def get(self, args, props):
     args.name = getQName(args.name, '_') # kludge: use default namespace unless explicitly specified
     return Item.get(self, args, props)
Example #19
0
 def csvToQualifiedActions(self, props, csv):
     ns = props['namespace']
     actions = self.csvToList(csv)
     return [ getQName(a, ns) for a in actions ]