def add(self, rights): if rights: try: rights = rights.split(',') except AttributeError: pass for right in rights: set.add(self, right)
def restartService(self, service, components=None, wait=True): if components == None: components = self.listServiceComponents(service) tasks = MySet() for component in components: debug("Restarting component {}".format(component)) body = { "RequestInfo": { "command": "RESTART", "context": "Ansible: Restart {}/{}".format(service, component), "operation_level": "host_component" }, "Requests/resource_filters": [{ "service_name": service, "component_name": component, "hosts_predicate": "HostRoles/component_name=" + component }] } code, responseText = self.post( CLUSTER_REQUESTS_URL.format(self.cluster), body) if code == 202: tasks.add(json.loads(responseText)[REQUESTS][ID]) else: error( "Invalid return code {} ({}) on service operation. Check ambari-server.log on the ambari node" .format(code, responseText)) allTasks = list(tasks) # Preserve for return if wait: while len(tasks) > 0: time.sleep(2) debug("Task to wait: {}".format(tasks)) tasks2 = list(tasks) # Better to copy, as we may remove items. for task in tasks2: result = self.get( CLUSTER_REQUEST_URL.format(self.cluster, task)) status = result[REQUESTS][REQUEST_STATUS] debug("task:{} status:{}".format(task, status)) if status == "COMPLETED": tasks.remove(task) return allTasks
def updateStatus(self, status): body = self.get("/ws/v1/cluster/apps?states=NEW,NEW_SAVING,SUBMITTED,ACCEPTED,RUNNING") activeYarnApps = XSet() if "apps" in body and body["apps"] != None and "app" in body["apps"]: for yarnApp in body["apps"]["app"]: activeYarnApps.add(yarnApp["name"]) if yarnApp["name"] in status: app = status[yarnApp["name"]] if yarnApp["state"] in startingSet: # Found an instance in "starting" state. if app["state"] == State.NONEXISTENT: app["state"] = State.STARTING app["ids"][yarnApp["id"]] = yarnApp["state"] elif yarnApp["state"] == YarnState.RUNNING: app["state"] = State.RUNNING app["ids"][yarnApp["id"]] = yarnApp["state"] else: error("Unknown Yarn State:{}".format(yarnApp["state"])) for appName in status: if appName not in activeYarnApps: if status[appName]["state"] != State.NONEXISTENT: status[appName]["state"] = State.KILLED status[appName]["ids"] = {} return status
def add(self, thing): print '%s ok' % thing Set.add(self, thing)
def add(self, *args): print "adding %s" % args return Set.add(self, *args)