Esempio n. 1
0
    def take_action(self, parsed_args):

        app_id = parsed_args.app_id

        #get app data from local db
        (appname,app) = db.get_app_data( app_id )
        if not (appname and app):
            raise RuntimeError('Can not find local app {0}'.format(app_id))

        self.log.debug( '==============================================================' )
        self.log.debug("> found app %s in local db" % appname)
        self.log.debug("> app_data")
        self.log.debug( json.dumps(app, indent=4) )
        self.log.debug( '==============================================================' )

        config = utils.gen_config(appname)

        if parsed_args.local:
            is_succeed = False
            try:
                #1. check app state
                state = db.get_app_state(appname)
                if not parsed_args.force and state != constant.STATE_APP_STOPPED:
                    raise RuntimeError("App current state is {0}, only support stop 'Stopped' app!".format(state))

                print 'Starting local app ...'
#                #2. update to starting
#                db.start_app(appname)
                #3. do action
                self.start_app(config, appname, app)
#                #4. update to running
#                db.start_app(appname,True)
                print 'Local app %s started!' % appname
                #save app info into local db
                stack_id = db.get_stackid_from_appid(app_id)
                db.create_app( config["appname"], config["appname"], stack_id, '', base64.b64encode(utils.dict2str(app)) )
                is_succeed = True
            except Result,e:
                print '!!!Expected error occur %s' % str(e.format())
            except Exception,e:
                print '!!!Unexpected error occur %s' % str(e)
Esempio n. 2
0
    def take_action(self, parsed_args):

        app_id = parsed_args.app_id

        #get app data from local db
        (appname,app) = db.get_app_data( app_id )
        if not (appname and app):
            raise RuntimeError('Can not find local app {0}'.format(app_id))

        self.log.debug( '==============================================================' )
        self.log.debug("> found app %s in local db" % appname)
        self.log.debug("> app_data")
        self.log.debug( json.dumps(app, indent=4) )
        self.log.debug( '==============================================================' )

        config = utils.gen_config(appname)

        if parsed_args.local:
            is_succeed = False
            try:
                #1. check app state
                state = db.get_app_state(appname)
                if state in [constant.STATE_APP_TERMINATED,constant.STATE_APP_TERMINATING]:
                    raise RuntimeError("App current state is {0}, cancel!".format(state))
                elif not parsed_args.force and not state in [constant.STATE_APP_RUNNING,constant.STATE_APP_STOPPED]:
                    raise RuntimeError("App current state is {0}, only support stop 'Running' or 'Stopped' app!".format(state))

                print 'Terminating local app ...'
                #2. update to terminating
                db.terminate_app(appname)
                #3. do action
                self.terminate_app(config, appname, app)
                #4. update to terminated
                db.terminate_app(appname,True)
                print 'Local app %s terminated!' % appname
                is_succeed = True
            except Result,e:
                print '!!!Expected error occur %s' % str(e.format())
            except Exception,e:
                print '!!!Unexpected error occur %s' % str(e)