当前位置: 首页>>代码示例>>Python>>正文


Python service.ServiceController类代码示例

本文整理汇总了Python中agent.controllers.service.ServiceController的典型用法代码示例。如果您正苦于以下问题:Python ServiceController类的具体用法?Python ServiceController怎么用?Python ServiceController使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ServiceController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_post_manifest_inprogress_errorout

    def test_post_manifest_inprogress_errorout(self):
        packages = ['http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus']
        manifest = 'bar'
        service = 'foo'

        try:
            path = ServiceController.manifestPath(service)
            os.makedirs(path)
            path = ServiceController.installedPkgPath(service)
            os.makedirs(path)
            path = ServiceController.downloadedPkgPath(service)
            os.makedirs(path)
        except Exception as excep:
            LOG.warning('got an OS Exception - %s' % str(excep))


        body = json.dumps({'package' : packages})
        response = self.app.post(url(controller = 'manifest', action = 'post', service = service, manifest = manifest),
                                 headers = {'Content-Type' : 'application/json'},
                                 params = body)
        assert response.status_int == 200, 'Manifest Post assert'

        try:
            response = self.app.post(url(controller = 'manifest', action = 'post', service = service, manifest = manifest),
                                 headers = {'Content-Type' : 'application/json'},
                                 params = body)
            #should error out!
            raise Exception('Oops! Expected AppError but did not get any')
        except AppError:
            pass
开发者ID:cronuspaas,项目名称:cronusagent,代码行数:30,代码来源:test_manifest.py

示例2: cleanupOrphanedPackages

    def cleanupOrphanedPackages(checkAge = False):
        '''  API to cleanup Orphaned Packages For All Services '''
        from agent.controllers.service import ServiceController
        #services = os.listdir(service_nodes)
        from agent.controllers.manifest import ManifestController
        #import pdb;pdb.set_trace()
        services = ServiceController.getServices()
        service_nodes = ServiceController.serviceRootPath()

        linkedPaths = []
        sysServices = ['agent']
        LOG.info('Garbage collecting orphaned installed packages')
        for service in services:
            try:
                if service in sysServices:
                    LOG.debug('system services cannot be garbage collected')
                else:
                    servicePath = os.path.join(service_nodes, service)
                    installedPkgPath = os.path.join(servicePath, 'installed-packages')
                    linkedPaths.extend(ManifestController.getAllSymLinks(service))
                    linkedPaths.extend(manifestutil.getModuleSymLinks(service))
                    LOG.debug('symLinks returned %s' % linkedPaths)
                    installedPkgPaths = PackageUtil.getAllInstalledPackages(installedPkgPath)
                    LOG.debug('installedPkgPaths returned for the service %s' % installedPkgPaths)
                    if len(installedPkgPaths) > 0:
                        orphanPkgs = set(installedPkgPaths) - set(linkedPaths)
                        LOG.debug('orphanPkgs returned %s' % orphanPkgs)
                        PackageUtil.cleanupInstalledPkgs(installedPkgPath, orphanPkgs)
            except BaseException as excep:
                LOG.error('Failed to proceed with garbage collection %s' % str(excep))
                # agent-804, manifests only contains folders, need to delete if file is in manifests
                servicePath = os.path.join(service_nodes, service)
                if not os.path.isdir(servicePath):
                    utils.runsyscmd('rm -f %s' % servicePath)
        LOG.info('Garbage collecting orphaned installed packages completed')
开发者ID:anzarafaq,项目名称:cronusagent,代码行数:35,代码来源:package.py

示例3: __deleteServices

    def __deleteServices(self):
        """ delete all services except agent itself; clear all manifests in 'agent' itself except current active"""
        self._updateStatus(progress = 60)
        services = ServiceController.getServices()

        #kill all service threads
        self._threadMgr.stopServiceThread()

        #remove folder
        for service in services:
            if 'agent' == service:
                self.__delAllExceptActiveManifests(service)
                continue

            path = ServiceController.servicePath(service)
            # retry service cleanup
            for _ in range(3):
                if not os.path.exists(path):
                    break
                ServiceDelete.deleteFolderContents(path)
                # sleep here a bit to ensure delete is complete
                time.sleep(1)

            if os.path.exists(path):
                msg = 'Could not delete service %s completely even after 3 retries.' % service
                LOG.error(msg)
                raise Exception(msg)

        self._updateStatus(progress = 90)
开发者ID:cronuspaas,项目名称:cronusagent,代码行数:29,代码来源:services_cleanup.py

示例4: test_multiple_manifest_create

    def test_multiple_manifest_create(self):
        """ when a manifest creation is in progress for a service, another creation should block """
        packages = ["http://www.stackscaling.com/agentrepo/pkgA-1.2.0.unix.cronus"]
        service = 'foo'
        manifest1 = 'bar'
        manifest2 = 'car'
        try:
            for pkg in packages:
                mockDownloadPkg(pkg)
                
            path = ServiceController.manifestPath(service)
            os.makedirs(path)
            path = ServiceController.installedPkgPath(service)
            os.makedirs(path)
        except Exception as excep:
            LOG.warning('got an OS Exception - %s' % str(excep))

        body = json.dumps({'package' : packages})
        response1 = self.app.post(url(controller = 'manifest', action = 'post', service = service, manifest = manifest1),
                                 headers = {'Content-Type' : 'application/json'},
                                 params = body)
        self.assertEquals(response1.status_int, 200, 'Manifest1 Post assert - should go through')

        try:
            response2 = self.app.post(url(controller = 'manifest', action = 'post', service = service, manifest = manifest2),
                                 headers = {'Content-Type' : 'application/json'},
                                 params = body)
            self.assertFalse(True, 'Expected an exception but did not get one!')
        except AppError:
            pass

        checkStatus(self, 'create manifest bar', response1, timeout = 25)
        self.assertTrue(islink(os.path.join(manifestutil.manifestPath('foo', 'bar'), 'pkgA')))
        self.assertFalse(islink(os.path.join(manifestutil.manifestPath('foo', 'car'), 'pkgA')))
开发者ID:cronuspaas,项目名称:cronusagent,代码行数:34,代码来源:test_manifest.py

示例5: test_post_manifest_inprogress_ok

    def test_post_manifest_inprogress_ok(self):
        service = 'foo'
        manifest = 'blahblah'
        try:
            path = ServiceController.servicePath(service)
            if os.path.exists(path):
                if os.name == 'nt':
                    cmd = 'rm -r %s' % path
                    LOG.debug("running command %s" % cmd)
                    os.system(cmd)
                else:
                    shutil.rmtree(path)
            path = ServiceController.manifestPath(service)
            os.makedirs(path)
            path = ServiceController.installedPkgPath(service)
            os.makedirs(path)
            inProgressPath = ManifestCreate.inProgress(ManifestController.manifestPath(service, manifest))
            os.makedirs(inProgressPath)
            path = ServiceController.downloadedPkgPath(service)
            os.makedirs(path)
        except Exception as excep:
            LOG.warning('got an OS Exception - %s' % str(excep))

        createManifest(self, ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus"], manifest = 'blahblah', createDirs = False)
        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'blahblah'), 'pkgA')))
开发者ID:anzarafaq,项目名称:cronusagent,代码行数:25,代码来源:test_manifest.py

示例6: createManifest

def createManifest(testController,
                   packages = ['http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus'],
                   manifest = 'bar', service = 'foo', createDirs = True):
    try:
        path = ServiceController.servicePath(service)
        os.makedirs(os.path.join(path, 'manifests'))
        os.makedirs(os.path.join(path, 'modules'))
        os.makedirs(os.path.join(path, '.appdata'))
        os.makedirs(os.path.join(path, '.data'))
        
        path = ServiceController.installedPkgPath(service)
        os.makedirs(path)
    except Exception as excep:
        LOG.warning('got an OS Exception - %s' % str(excep))


    try:
        for pkgUri in packages:
            mockDownloadPkg(pkgUri)
#             pkgDict = PackageUtil.parseUri(pkgUri)
#             pkgName = pkgDict['package']
#             localPkgRoot = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'packages')
#             src = os.path.join(localPkgRoot, pkgName)
#             shutil.copy(src, pkgDict['packagePath'])
#             propPkgName = pkgDict['propName']
#             propSrc = os.path.join(localPkgRoot, propPkgName)
#             shutil.copy(propSrc, pkgDict['propPath'])
    except Exception as excep:
        LOG.warning('got an OS Exception - %s' % str(excep))
        
    body = json.dumps({'package' : packages})
    response = testController.app.post(url(controller = 'manifest', action = 'post', service = service, manifest = manifest),
                             headers = {'Content-Type' : 'application/json'},
                             params = body)
    assert response.status_int == 200, 'Manifest Post assert'

    LOG.debug('response body = %s' % response.body)

    body = json.loads(response.body)

    # wait until the status is done
    tm = time.time()
    now = tm
    while (tm + 120 > now):
        response = testController.app.get(body['status'])
        body = json.loads(response.body)

        LOG.debug("createManifest  ********** progress = %s" % body['progress'])
        if (int(body['progress']) == 100):
            break
        time.sleep(0.1)
        now = time.time()

    assert tm + 120 >= now, 'Create manifest timed out'
    LOG.debug('status = ' + str(response.status_int))
    assert response.status_int == 200, "HTTP response != 200"
    LOG.debug ('Status response body = %s' % str(body))
    assert int(body['progress']) == 100
开发者ID:cronuspaas,项目名称:cronusagent,代码行数:58,代码来源:test_util.py

示例7: stopServiceThread

    def stopServiceThread(self):
        """ stop all service threads """
        from agent.controllers.service import ServiceController

        LOG.info("Stopping service thread")
        with self.__lock:
            services = ServiceController.getServices()
            for service in services:
                threads = self.getThreadByCat(ServiceController.serviceCat(service), fastbreak=False)
                for thread in threads:
                    thread.stop()
开发者ID:arunkumar-m,项目名称:cronus-agent,代码行数:11,代码来源:threadmgr.py

示例8: getManifests

    def getManifests(service):
        """ return the list of manifests under a specific service """
        from agent.lib.agent_thread.manifest_create import ManifestCreate

        manifests = []

        dirContent = os.listdir(ServiceController.manifestPath(service))

        for item in dirContent:
            path = os.path.join(ServiceController.manifestPath(service), item)
            if (os.path.isdir(path) and not ManifestCreate.isInProgress(path)):
                if (not islink(path)):
                    manifests.append(item)

        return sorted(manifests)
开发者ID:anzarafaq,项目名称:cronusagent,代码行数:15,代码来源:manifest.py

示例9: test_getAllSymLinks

    def test_getAllSymLinks(self):
        #import pdb;
        #pdb.set_trace()
        serviceName = '.sbe.appService.SI1'
        manifestName = 'manifestA'
        try:
            createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                                  "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)
        except Exception as ex:
            print 'exception thrown during mf'

        symLinks = manifestutil.getAllSymLinks(serviceName)
        """ return all the symlinks from manifests to packages for a given service"""
        LOG.debug('calling getAllSymLinks')
        linkedPaths = []
        installedPkgPath = os.path.join(ServiceController.servicePath(serviceName), 'installed-packages')
        pathToPkgA = os.path.join(installedPkgPath, 'pkgA')
        pathToPkgA120 = os.path.join(pathToPkgA, '1.2.0.unix')
        pathToPkgB = os.path.join(installedPkgPath, 'pkgB')
        pathToPkgB060 = os.path.join(pathToPkgB, '0.6.0.unix')

        bitmap = 0
        for path in symLinks:
            if path.find(pathToPkgA120) >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 1
            elif path.find(pathToPkgB060) >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 2
        self.assertEquals(3, bitmap)
开发者ID:cronuspaas,项目名称:cronusagent,代码行数:31,代码来源:test_manifest.py

示例10: test_delete_active_manifest

    def test_delete_active_manifest(self):
        createManifest(self)

        self.assertTrue(os.path.isdir(ServiceController.manifestPath('foo')))
        currentPath = os.getcwd()
        os.chdir(ServiceController.manifestPath('foo'))
        manifestPath = 'bar' #ManifestController.manifestPath('foo', 'bar'); use short manifest name instead of full path
        symlink(manifestPath, 'active')
        os.chdir(currentPath)

        response = self.app.delete(url(controller = 'manifest', action = 'delete', service = "foo", manifest = "bar"),
                                   expect_errors = True)
        self.assertEquals(500, response.status_int)

        body = json.loads(response.body)
        self.assertEquals(Errors.MANIFEST_DELETING_ACTIVE_MANIFEST, body['error'])
开发者ID:cronuspaas,项目名称:cronusagent,代码行数:16,代码来源:test_manifest.py

示例11: __init__

    def __init__(self, threadMgr, service, manifest):
        """ Constructor """
        from agent.controllers.service import ServiceController

        AgentThread.__init__(self, threadMgr, cat = [ServiceController.serviceCat(service)], name = 'delete_manifest')
        self.service = service
        self.manifest = manifest
开发者ID:anzarafaq,项目名称:cronusagent,代码行数:7,代码来源:manifest_delete.py

示例12: activateManifest

def activateManifest(testController, manifest = 'bar', service = 'foo'):

    body = json.dumps({'manifest':manifest})

    response = testController.app.post(url(controller = 'manifest', action = 'activate', service = service, manifest = manifest),
                                       headers = {'Content-Type' : 'application/json'},
                                       params = body)

    assert response.status_int == 200, 'Action get assert'

    body = json.loads(response.body)

    tm = time.time()
    while (tm + 120 > time.time()):
        response = testController.app.get(body['status'])
        body = json.loads(response.body)

        LOG.debug("activateManifest ********** progress = %s" % body['progress'])
        if (int(body['progress']) == 100):
            break
        time.sleep(0.1)

    LOG.debug('status = ' + str(response.status_int))
    assert response.status_int == 200, "HTTP response != 200"
    LOG.debug ('Status response body = %s' % str(body))
    assert body['progress'] == 100

    # let's make sure the link is there correctly
    activePath = os.path.join(ServiceController.manifestPath(service), 'active')
    LOG.debug ('active path = ' + activePath)
    assert islink(activePath)

    link = readlink(activePath)
    LOG.debug ('link = ' + link)
    assert link == manifest
开发者ID:cronuspaas,项目名称:cronusagent,代码行数:35,代码来源:test_util.py

示例13: delete

    def delete(self, service, manifest):
        """ Delete a new service object """
        try:
            path = ManifestController.manifestPath(service, manifest)
            if (not os.path.isdir(path)):
                return errorResult(request, response, Errors.MANIFEST_NOT_FOUND,
                                   'manifest (%s/%s) missing service' % (service, manifest),
                                   controller = self)

            # first check that this isn't the active manifest
            path = os.path.join(ServiceController.manifestPath(service), 'active')
            if (os.path.exists(path)):
                activePath = os.path.basename(readlink(path))
                deletePath = os.path.basename(ManifestController.manifestPath(service, manifest))

                if (activePath == deletePath):
                    return errorResult(request, response, Errors.MANIFEST_DELETING_ACTIVE_MANIFEST,
                                       'Manifest(%s, %s) attempting to delete active manifest'
                                       % (service, manifest),
                                       controller = self)

            # now try to delete the manifest directory
            appGlobal = config['pylons.app_globals']
            manThread = ManifestDelete(appGlobal.threadMgr, service, manifest)
            self.injectJobCtx(manThread)
            manThread.start()
            manThread.threadMgrEvent.wait()

            return statusResult(request, response, manThread, controller = self)

        except Exception as excep:
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                               errorMsg = 'Unknown error for delete manifest(%s/%s) - %s - %s' %
                               (service, manifest, str(excep), traceback.format_exc(2)),
                               controller = self)
开发者ID:anzarafaq,项目名称:cronusagent,代码行数:35,代码来源:manifest.py

示例14: manifestPath

 def manifestPath(service, manifest):
     """
     compute the path to this manifest
     @param service:    name of the service
     @param manifest:   name of the manifest
     """
     return os.path.join(ServiceController.manifestPath(service), manifest)
开发者ID:anzarafaq,项目名称:cronusagent,代码行数:7,代码来源:manifest.py

示例15: test_post2

    def test_post2(self):
        # successful post
        createManifest(self)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(ServiceController.installedPkgPath('foo'), 'perlserver', '1.0.0.unix',
                                           'cronus', 'scripts', 'activate')))
        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'bar'), 'perlserver')))
开发者ID:anzarafaq,项目名称:cronusagent,代码行数:8,代码来源:test_manifest.py


注:本文中的agent.controllers.service.ServiceController类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。