Package Products :: Package Zuul :: Package routers :: Module application
[hide private]
[frames] | no frames]

Source Code for Module Products.Zuul.routers.application

  1  ############################################################################## 
  2  # 
  3  # Copyright (C) Zenoss, Inc. 2013, all rights reserved. 
  4  # 
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  # 
  8  ############################################################################## 
  9   
 10   
 11  import logging 
 12  from urllib2 import URLError 
 13   
 14  from Products import Zuul 
 15  from Products.ZenMessaging.audit import audit 
 16  from Products.Zuul.routers import TreeRouter 
 17  from Products.ZenUtils.Ext import DirectResponse 
 18  from Products.Zuul.form.interfaces import IFormBuilder 
 19  from Products.Zuul.interfaces import IInfo, ITreeNode 
 20   
 21  log = logging.getLogger('zen.ApplicationRouter') 
 22   
 23   
24 -class ApplicationRouter(TreeRouter):
25 """ 26 """ 27
28 - def _getFacade(self):
29 return Zuul.getFacade('applications', self.context)
30
31 - def _monitorFacade(self):
32 return Zuul.getFacade('monitors', self.context)
33
34 - def getTree(self, id):
35 """ 36 Returns the tree structure of the application and collector 37 hierarchy. 38 39 @type id: string 40 @param id: Id of the root node of the tree to be returned 41 @rtype: [dictionary] 42 @return: Object representing the tree 43 """ 44 try: 45 appfacade = self._getFacade() 46 monitorfacade = Zuul.getFacade("monitors", self.context) 47 nodes = [ITreeNode(m) for m in monitorfacade.query()] 48 for monitor in nodes: 49 apps = appfacade.queryMonitorDaemons(monitor.name) 50 for app in apps: 51 monitor.addChild(IInfo(app)) 52 apps = appfacade.queryMasterDaemons() 53 for app in apps: 54 nodes.append(IInfo(app)) 55 return Zuul.marshal(nodes) 56 except URLError as e: 57 log.exception(e) 58 return DirectResponse.fail( 59 "Error fetching daemons list: " + str(e.reason) 60 )
61
62 - def getForm(self, uid):
63 """ 64 Given an object identifier, this returns all of the editable fields 65 on that object as well as their ExtJs xtype that one would 66 use on a client side form. 67 68 @type uid: string 69 @param uid: Unique identifier of an object 70 @rtype: DirectResponse 71 @return: B{Properties} 72 - form: (dictionary) form fields for the object 73 """ 74 app = self._getFacade().get(uid) 75 form = IFormBuilder(IInfo(app)).render(fieldsets=False) 76 form = Zuul.marshal(form) 77 return DirectResponse(form=form)
78
79 - def start(self, uids):
80 """ 81 Will issue the command to start the selected ids 82 @type uids: Array[Strings] 83 @param uids: List of valid daemon ids that will need to started 84 @rtype: DirectResposne 85 @return: DirectReponse of success if no errors are encountered 86 """ 87 facade = self._getFacade() 88 for uid in uids: 89 facade.start(uid) 90 audit('UI.Applications.Start', id) 91 if len(uids) > 1: 92 return DirectResponse.succeed("Started %s daemons" % len(uids)) 93 return DirectResponse.succeed()
94
95 - def stop(self, uids):
96 """ 97 Will issue the command to stop the selected ids 98 @type uids: Array[Strings] 99 @param uids: List of valid daemon ids that will need to stopped 100 @rtype: DirectResposne 101 @return: DirectReponse of success if no errors are encountered 102 """ 103 facade = self._getFacade() 104 for uid in uids: 105 facade.stop(uid) 106 audit('UI.Applications.Stop', id) 107 if len(uids) > 1: 108 return DirectResponse.succeed("Stopped %s daemons" % len(uids)) 109 return DirectResponse.succeed()
110
111 - def restart(self, uids):
112 """ 113 Will issue the command to restart the selected ids 114 @type uids: Array[Strings] 115 @param uids: List of valid daemon ids that will need to restarted 116 @rtype: DirectResposne 117 @return: DirectReponse of success if no errors are encountered 118 """ 119 facade = self._getFacade() 120 for uid in uids: 121 facade.restart(uid) 122 audit('UI.Applications.Restart', id) 123 if len(uids) > 1: 124 return DirectResponse.succeed("Restarted %s daemons" % len(uids)) 125 return DirectResponse.succeed()
126
127 - def setAutoStart(self, uids, enabled):
128 """ 129 Enables or disables autostart on all applications passed into uids. 130 If it is already in that state it is a noop. 131 @type uids: Array[Strings] 132 @param uids: List of valid daemon ids that will need to enabled 133 @type enabled: boolean 134 @param uids: true for enabled or false for disabled 135 @rtype: DirectResposne 136 @return: DirectReponse of success if no errors are encountered 137 """ 138 facade = self._getFacade() 139 applications = facade.query() 140 for app in applications: 141 if app.id in uids: 142 app.autostart = enabled 143 audit('UI.Applications.AutoStart', id, {'autostart': enabled}) 144 return DirectResponse.succeed()
145
146 - def getInfo(self, id):
147 """ 148 Returns the serialized info object for the given id 149 @type: id: String 150 @param id: Valid id of a application 151 @rtype: DirectResponse 152 @return: DirectResponse with data of the application 153 """ 154 facade = self._getFacade() 155 app = facade.get(id) 156 data = Zuul.marshal(IInfo(app)) 157 return DirectResponse.succeed(data=data)
158
159 - def getAllResourcePools(self, query=None):
160 """ 161 Returns a list of resource pool identifiers. 162 @rtype: DirectResponse 163 @return: B{Properties}: 164 - data: ([String]) List of resource pool identifiers 165 """ 166 pools = self._monitorFacade().queryPools() 167 ids = (dict(name=p.id) for p in pools) 168 return DirectResponse.succeed(data=Zuul.marshal(ids))
169
170 - def getApplicationConfigFiles(self, id):
171 """ 172 Returns all the configuration files for an application 173 """ 174 facade = self._getFacade() 175 info = IInfo(facade.get(id)) 176 files = info.configFiles 177 return DirectResponse.succeed(data=Zuul.marshal(files))
178
179 - def updateConfigFiles(self, id, configFiles):
180 """ 181 Updates the configuration files for an application specified by id. 182 The configFiles parameters is an array of dictionaries of the form: 183 { 184 filename: "blah", 185 contents: "line 1\nline 2\n..." 186 } 187 The filename parameter serves as the "id" of each configFile 188 passed in. 189 """ 190 facade = self._getFacade() 191 info = IInfo(facade.get(id)) 192 for f in configFiles: 193 configFile = info.getConfigFileByFilename(f['filename']) 194 if configFile: 195 configFile.content = f['content'] 196 facade.updateService(id) # save the updated config files to elastic 197 return DirectResponse.succeed()
198