def peer_disconnect(self, event): job_id = monitoring_utils.update_dashboard( event['message']['peer'], RESOURCE_TYPE_PEER, NS.tendrl_context.integration_id, "delete") logger.log("debug", NS.publisher_id, {"message": "Update dashboard job %s " "created" % job_id})
def peer_detach(self, event): time.sleep(self.sync_interval) job_id = monitoring_utils.update_dashboard( event['message']['host'], RESOURCE_TYPE_PEER, NS.tendrl_context.integration_id, "delete") logger.log("debug", NS.publisher_id, {"message": "Update dashboard job %s " "created" % job_id})
def volume_remove_brick_force(self, event): time.sleep(self.sync_interval) # Event returns bricks list as space separated single string bricks = event['message']['bricks'].split(" ") for brick in bricks: fetched_brick = NS.gluster.objects.Brick( fqdn=brick.split(":/")[0], brick_dir=brick.split(":/")[1].replace('/', '_')).load() try: NS._int.wclient.delete( "clusters/{0}/Bricks/all/{1}/{2}".format( NS.tendrl_context.integration_id, brick.split(":/")[0], brick.split(":/")[1].replace('/', '_')), recursive=True, ) except etcd.EtcdKeyNotFound: pass job_id = monitoring_utils.update_dashboard( "%s|%s" % (event['message']['volume'], brick), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete") logger.log( "debug", NS.publisher_id, {"message": "Update dashboard job %s " "created" % job_id}) job_id = monitoring_utils.delete_resource_from_graphite( "%s|%s" % (event['message']['volume'], brick), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete") logger.log( "debug", NS.publisher_id, { "message": "Delete resource from graphite job %s " "created" % job_id }) volume_brick_path = "clusters/{0}/Volumes/{1}/"\ "Bricks".format( NS.tendrl_context.integration_id, fetched_brick.vol_id, ) # remove all the brick infromation under volume as the # subvolume might have changed, let the next sync handle # the updation of brick info try: NS._int.wclient.delete(volume_brick_path, recursive=True) except etcd.EtcdKeyNotFound: pass _trigger_sync_key = 'clusters/%s/_sync_now' % NS.tendrl_context.integration_id etcd_utils.write(_trigger_sync_key, 'true') etcd_utils.refresh(_trigger_sync_key, self.sync_interval)
def test_update_dashboard(): setattr(__builtin__, "NS", maps.NamedDict()) NS.publisher_id = 1 NS.tendrl = maps.NamedDict() NS.tendrl.objects = maps.NamedDict() NS.tendrl_context = maps.NamedDict() NS.tendrl_context.integration_id = 0 NS.tendrl_context.cluster_name = "Test Name" NS.tendrl.objects.Job = MockJob assert update_dashboard("Test Name", "Test", 0, "push")
def peer_detach(self, event): time.sleep(self.sync_interval) job_id = monitoring_utils.update_dashboard( event['message']['host'], RESOURCE_TYPE_PEER, NS.tendrl_context.integration_id, "delete" ) logger.log( "debug", NS.publisher_id, { "message": "Update dashboard job %s " "created" % job_id } )
def volume_remove_brick_force(self, event): time.sleep(self.sync_interval) # Event returns bricks list as space separated single string bricks = event['message']['bricks'].split(" ") try: for brick in bricks: # find fqdn using ip ip = socket.gethostbyname(brick.split(":/")[0]) node_id = etcd_utils.read("indexes/ip/%s" % ip).value fqdn = NS.tendrl.objects.ClusterNodeContext( node_id=node_id).load().fqdn brick = fqdn + ":" + brick.split(":")[-1] fetched_brick = NS.tendrl.objects.GlusterBrick( NS.tendrl_context.integration_id, fqdn=brick.split(":/")[0], brick_dir=brick.split(":/")[1].replace('/', '_')).load() # delete brick etcd_utils.delete( "clusters/{0}/Bricks/all/{1}/{2}".format( NS.tendrl_context.integration_id, brick.split(":/")[0], brick.split(":/")[1].replace('/', '_')), recursive=True, ) # delete alert dashbaord job_id = monitoring_utils.update_dashboard( "%s|%s" % (event['message']['volume'], brick), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete") logger.log( "debug", NS.publisher_id, {"message": "Update dashboard job %s " "created" % job_id}) # delete brick details from graphite job_id = monitoring_utils.delete_resource_from_graphite( "%s|%s" % (event['message']['volume'], brick), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete") logger.log( "debug", NS.publisher_id, { "message": "Delete resource from graphite job %s " "created" % job_id }) volume_brick_path = "clusters/{0}/Volumes/{1}/"\ "Bricks".format( NS.tendrl_context.integration_id, fetched_brick.vol_id, ) # remove all the brick infromation under volume as the # subvolume might have changed, let the next sync handle # the updation of brick info etcd_utils.delete(volume_brick_path, recursive=True) _trigger_sync_key = 'clusters/%s/_sync_now' % \ NS.tendrl_context.integration_id etcd_utils.write(_trigger_sync_key, 'true') etcd_utils.refresh(_trigger_sync_key, self.sync_interval) except etcd.EtcdKeyNotFound: logger.log("debug", NS.publisher_id, {"message": "Unable to delete bricks %s" % bricks})
def volume_delete(self, event): time.sleep(self.sync_interval) fetched_volumes = NS.tendrl.objects.GlusterVolume( NS.tendrl_context.integration_id).load_all() for fetched_volume in fetched_volumes: if fetched_volume.name == event['message']['name']: fetched_volume.deleted = True fetched_volume.deleted_at = time_utils.now() fetched_volume.save() try: sub_volumes = etcd_utils.read( "/clusters/{0}/Volumes/{1}/Bricks".format( NS.tendrl_context.integration_id, fetched_volume.vol_id)) for sub_volume in sub_volumes.leaves: bricks = etcd_utils.read(sub_volume.key) for brick in bricks.leaves: fqdn = brick.key.split('/')[-1].split(':')[0] path = brick.key.split('/')[-1].split(':')[-1][1:] # Delete brick dashboard from grafana brick_obj = NS.tendrl.objects.GlusterBrick( NS.tendrl_context.integration_id, fqdn, path).load() # Delete brick brick_path = "clusters/{0}/Bricks/"\ "all/{1}/{2}".format( NS.tendrl_context.integration_id, fqdn, path ) etcd_utils.delete(brick_path, recursive=True) brick_full_path = fqdn + ":" + brick_obj.\ brick_path.split(":")[-1] job_id = monitoring_utils.update_dashboard( "%s|%s" % (event['message']['name'], brick_full_path), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete") logger.log( "debug", NS.publisher_id, { "message": "Update dashboard job %s" " for brick %s " "in cluster %s created" % (job_id, brick.key.split('/')[-1], NS.tendrl_context.integration_id) }) # Delete brick from graphite job_id = monitoring_utils.\ delete_resource_from_graphite( "%s|%s" % ( event['message']['name'], brick_full_path ), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete" ) logger.log( "debug", NS.publisher_id, { "message": "Delete resource " "from graphite job %s " "for brick %s in cluster %s created" % (job_id, brick.key.split('/')[-1], NS.tendrl_context.integration_id) }) except etcd.EtcdKeyNotFound: pass # Delete volume dashboard from grafana job_id = monitoring_utils.update_dashboard( event['message']['name'], RESOURCE_TYPE_VOLUME, NS.tendrl_context.integration_id, "delete") logger.log("debug", NS.publisher_id, {"message": "Update dashboard job %s " "created" % job_id}) # Delete volume details from graphite job_id = monitoring_utils.delete_resource_from_graphite( event['message']['name'], RESOURCE_TYPE_VOLUME, NS.tendrl_context.integration_id, "delete") logger.log("debug", NS.publisher_id, { "message": "Delete resource from graphite job %s " "created" % job_id })
def volume_remove_brick_force(self, event): time.sleep(self.sync_interval) # Event returns bricks list as space separated single string bricks = event['message']['bricks'].split(" ") try: for brick in bricks: # find fqdn using ip ip = socket.gethostbyname(brick.split(":/")[0]) node_id = etcd_utils.read("indexes/ip/%s" % ip).value fqdn = NS.tendrl.objects.ClusterNodeContext( node_id=node_id ).load().fqdn brick = fqdn + ":" + brick.split(":")[-1] fetched_brick = NS.tendrl.objects.GlusterBrick( NS.tendrl_context.integration_id, fqdn=brick.split(":/")[0], brick_dir=brick.split(":/")[1].replace('/', '_') ).load() # delete brick etcd_utils.delete( "clusters/{0}/Bricks/all/{1}/{2}".format( NS.tendrl_context.integration_id, brick.split(":/")[0], brick.split(":/")[1].replace('/', '_') ), recursive=True, ) # delete alert dashbaord job_id = monitoring_utils.update_dashboard( "%s|%s" % (event['message']['volume'], brick), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete" ) logger.log( "debug", NS.publisher_id, { "message": "Update dashboard job %s " "created" % job_id } ) # delete brick details from graphite job_id = monitoring_utils.delete_resource_from_graphite( "%s|%s" % (event['message']['volume'], brick), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete" ) logger.log( "debug", NS.publisher_id, { "message": "Delete resource from graphite job %s " "created" % job_id } ) volume_brick_path = "clusters/{0}/Volumes/{1}/"\ "Bricks".format( NS.tendrl_context.integration_id, fetched_brick.vol_id, ) # remove all the brick infromation under volume as the # subvolume might have changed, let the next sync handle # the updation of brick info etcd_utils.delete( volume_brick_path, recursive=True ) _trigger_sync_key = 'clusters/%s/_sync_now' % \ NS.tendrl_context.integration_id etcd_utils.write(_trigger_sync_key, 'true') etcd_utils.refresh(_trigger_sync_key, self.sync_interval) except etcd.EtcdKeyNotFound: logger.log( "debug", NS.publisher_id, { "message": "Unable to delete bricks %s" % bricks } )
def volume_delete(self, event): time.sleep(self.sync_interval) fetched_volumes = NS.tendrl.objects.GlusterVolume( NS.tendrl_context.integration_id ).load_all() for fetched_volume in fetched_volumes: if fetched_volume.name == event['message']['name']: fetched_volume.deleted = True fetched_volume.deleted_at = time_utils.now() fetched_volume.save() try: sub_volumes = etcd_utils.read( "/clusters/{0}/Volumes/{1}/Bricks".format( NS.tendrl_context.integration_id, fetched_volume.vol_id ) ) for sub_volume in sub_volumes.leaves: bricks = etcd_utils.read( sub_volume.key ) for brick in bricks.leaves: fqdn = brick.key.split('/')[-1].split(':')[0] path = brick.key.split('/')[-1].split(':')[-1][1:] # Delete brick dashboard from grafana brick_obj = NS.tendrl.objects.GlusterBrick( NS.tendrl_context.integration_id, fqdn, path ).load() # Delete brick brick_path = "clusters/{0}/Bricks/"\ "all/{1}/{2}".format( NS.tendrl_context.integration_id, fqdn, path ) etcd_utils.delete( brick_path, recursive=True ) brick_full_path = fqdn + ":" + brick_obj.\ brick_path.split(":")[-1] job_id = monitoring_utils.update_dashboard( "%s|%s" % ( event['message']['name'], brick_full_path ), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete" ) logger.log( "debug", NS.publisher_id, { "message": "Update dashboard job %s" " for brick %s " "in cluster %s created" % ( job_id, brick.key.split('/')[-1], NS.tendrl_context.integration_id ) } ) # Delete brick from graphite job_id = monitoring_utils.\ delete_resource_from_graphite( "%s|%s" % ( event['message']['name'], brick_full_path ), RESOURCE_TYPE_BRICK, NS.tendrl_context.integration_id, "delete" ) logger.log( "debug", NS.publisher_id, { "message": "Delete resource " "from graphite job %s " "for brick %s in cluster %s created" % ( job_id, brick.key.split('/')[-1], NS.tendrl_context.integration_id ) } ) except etcd.EtcdKeyNotFound: pass # Delete volume dashboard from grafana job_id = monitoring_utils.update_dashboard( event['message']['name'], RESOURCE_TYPE_VOLUME, NS.tendrl_context.integration_id, "delete" ) logger.log( "debug", NS.publisher_id, { "message": "Update dashboard job %s " "created" % job_id } ) # Delete volume details from graphite job_id = monitoring_utils.delete_resource_from_graphite( event['message']['name'], RESOURCE_TYPE_VOLUME, NS.tendrl_context.integration_id, "delete" ) logger.log( "debug", NS.publisher_id, { "message": "Delete resource from graphite job %s " "created" % job_id } )