if (not active):
    print NAMESPACE+" : namespace inactive"

# Get the active disk list
A_DISKS = cache_disk_lib.get_active_disks()


logger.info('------------------------------------------------------------')
logger.info('Starting background listing...')
logger.info("Starting mgmt build list with (%s, %s, %s)", NAMESPACE, NS_UID, PATTERN)
#NICE_VAL_0=os.nice(-10)
#logger.info("nice val is %d", NICE_VAL_0)

# If lock file exists then it means the task is already in progress
# Hence, nothing to do
if mgmt_lib.is_lock_valid(LOCK_FILE):
    print "Object list generation is already in progress. Please retry after few minutes"
    logger.info('Bailing on retry since task is running.')
    sys.exit()
else:
    # Check if the list file exists
    if os.path.exists(OBJECT_LIST_FILE):
	# If the number of objects in the old list is above 10K 
	# we would like to create a 2 min pause between subsequent
	# requests
	old_list_count=len(OBJECT_LIST_FILE)
        if old_list_count > 10000 :
	    # Now find the time since that last update 
	    # to the object list file
            file_change_time=os.path.getmtime(OBJECT_LIST_FILE)
	    curr_time=time.time()
                print "Object queued for deletion"
                print "Please run the object list command for the URI"
            else:
                print "Object not found"

            sys.exit()

    # Convert the PATTERN that is grep friendly
    # first made . as literal and then made the normal grep friendly pattern
    #[!!fix for bug 1737]

    #Setup the signal handler here,
    # at paths which take object listing
    signal.signal(signal.SIGCHLD, handleSIGCHLD)

    if mgmt_lib.is_lock_valid(SLOW_DEL_LOCK_FILE):
        print NAMESPACE + " : Object deletion is already in progress.Please try after sometime."
        sys.exit()

    if mgmt_lib.is_lock_valid(OBJ_BUILD_LOCK_FILE):
        print NAMESPACE + " : Object list generation is already in progress.Please try after sometime."
        sys.exit()

    # Check if a delete is already in progress
    #Moved this check here as files are created only for a pattern or delete all
    if mgmt_lib.is_lock_valid(LOCK_FILE):
        print NAMESPACE+" : Deletion of objects for this namespace already"+ \
        " in progress"
        print "Issue this command only after the earlier one has completed"
        print "Check log for status of deletion"
        sys.exit()
LOG_DIR = "/var/log/nkn/cache"

LOCK_FILE = LOG_DIR + "/ns_objects_" + NAMESPACE + ".slow.del.lck"

if (NS_DOMAIN == "all"):
    NS_DOMAIN = "any"

# Sanity check
if (not os.path.isfile(LIST_FILE)):
    syslog.syslog(syslog.LOG_NOTICE, "file doesnot exists :  " + LIST_FILE)
    syslog.syslog(
        syslog.LOG_NOTICE,
        "[Cache Deletion] Error: List file missing for Domain : " + NS_DOMAIN)
    sys.exit()

if mgmt_lib.is_lock_valid(LOCK_FILE):
    print "Object deletion is already in progress. Please retry after few minutes"
    sys.exit()
else:
    mgmt_lib.acquire_lock(LOCK_FILE)

if not NAMESPACE == "":
    syslog.syslog(syslog.LOG_NOTICE,
                  "[Cache Deletion] Starting for Namespace: " + NAMESPACE)

syslog.syslog(syslog.LOG_NOTICE,
              "[Cache Deletion] Starting for Domain : " + NS_DOMAIN)

#Queue the delete request
#arglist = "-s "+NS_DOMAIN+" -N del_uri_file:"+LIST_FILE+" -r /tmp/ignore -q /tmp/FMGR.queue"
#fq_arglist = "/opt/nkn/bin/nknfqueue "+_arglist
		    print "Please run the object list command for the URI"
	    else:
		    print "Object not found"
		    
	    sys.exit()

    # Convert the PATTERN that is grep friendly
    # first made . as literal and then made the normal grep friendly pattern 
    #[!!fix for bug 1737]


    #Setup the signal handler here,
    # at paths which take object listing
    signal.signal(signal.SIGCHLD, handleSIGCHLD)

    if mgmt_lib.is_lock_valid(SLOW_DEL_LOCK_FILE):
	print NAMESPACE+" : Object deletion is already in progress.Please try after sometime."
	sys.exit()


    if mgmt_lib.is_lock_valid(OBJ_BUILD_LOCK_FILE):
	print NAMESPACE+" : Object list generation is already in progress.Please try after sometime."
	sys.exit()


    # Check if a delete is already in progress
    #Moved this check here as files are created only for a pattern or delete all
    if mgmt_lib.is_lock_valid(LOCK_FILE):
	print NAMESPACE+" : Deletion of objects for this namespace already"+ \
	" in progress"
	print "Issue this command only after the earlier one has completed"
	    OBJ_PATTERN = OBJ_PATTERN.replace("^", "\^")
	    OBJ_PATTERN = OBJ_PATTERN.replace("?", "\?")
	    OBJ_PATTERN = OBJ_PATTERN.replace(".", "\.")

	    # Get the active disk list
	    A_DISKS = cache_disk_lib.get_active_disks()
			    
	    #Get the object path alone
	    OBJ_DIR_PATH = os.path.dirname(OBJ_PATTERN)
	    #Canonicalize the path
	    OBJ_DIR = os.path.abspath(OBJ_DIR_PATH) 
    #lock start
    #Lock for single object display. This set of commands call the ramcache action directly, display
    #the output and delete the temp files.Don't allow two commands to call this set of commands immediately.
    #If lock is present, display the error message for the command trying to acquire the lock.
	    if mgmt_lib.is_lock_valid(SINGLE_LOCK_FILE):
		print "The task is already in progress. Please retry after few minutes"
		sys.exit()
	    else:
		mgmt_lib.acquire_lock(SINGLE_LOCK_FILE)
		#BUG FIX:10727.
		#If file  for single object exists remove this and then open a new one.
		#This is to handle the case where in the previous listing  had script error due to some invalid exp
		#The cleanup is handled here to ensure only the object  is listed only once.
		#Issue: The single object file was not getting cleanedup and the new query was appending the new list to old list
		#resulting in multiple entry display.
		if os.path.exists(GREPED_SINGLE_OBJECT_LIST_FILE):
		    os.remove(GREPED_SINGLE_OBJECT_LIST_FILE)
		
		if os.path.exists(SINGLE_OBJECT_LIST_FILE):
		    os.remove(SINGLE_OBJECT_LIST_FILE)
Exemplo n.º 6
0
            OBJ_PATTERN = OBJ_PATTERN.replace("^", "\^")
            OBJ_PATTERN = OBJ_PATTERN.replace("?", "\?")
            OBJ_PATTERN = OBJ_PATTERN.replace(".", "\.")

            # Get the active disk list
            A_DISKS = cache_disk_lib.get_active_disks()

            #Get the object path alone
            OBJ_DIR_PATH = os.path.dirname(OBJ_PATTERN)
            #Canonicalize the path
            OBJ_DIR = os.path.abspath(OBJ_DIR_PATH)
            #lock start
            #Lock for single object display. This set of commands call the ramcache action directly, display
            #the output and delete the temp files.Don't allow two commands to call this set of commands immediately.
            #If lock is present, display the error message for the command trying to acquire the lock.
            if mgmt_lib.is_lock_valid(SINGLE_LOCK_FILE):
                print "The task is already in progress. Please retry after few minutes"
                sys.exit()
            else:
                mgmt_lib.acquire_lock(SINGLE_LOCK_FILE)
                #BUG FIX:10727.
                #If file  for single object exists remove this and then open a new one.
                #This is to handle the case where in the previous listing  had script error due to some invalid exp
                #The cleanup is handled here to ensure only the object  is listed only once.
                #Issue: The single object file was not getting cleanedup and the new query was appending the new list to old list
                #resulting in multiple entry display.
                if os.path.exists(GREPED_SINGLE_OBJECT_LIST_FILE):
                    os.remove(GREPED_SINGLE_OBJECT_LIST_FILE)

                if os.path.exists(SINGLE_OBJECT_LIST_FILE):
                    os.remove(SINGLE_OBJECT_LIST_FILE)