Beispiel #1
0
def addToCustomer(mc,island,custId,corpus='/tmp/corpus'):
    print 'addToCustomer()'
    amptool = ActiveMailboxPartitionTool()
    emscmdtool = EmsCommandLineTool()

    print 'executing amp cluster-location'
    amptool.runCommand('cluster-location',array(['-r'],String))


    args = []
    args.append("-f" )
    args.append( str(island))
    args.append("-s" )
    args.append( str(island))

    args.append( "-i" )
    args.append( corpus)
    args.append( "-o" )
    args.append( "/tmp")
    args.append( "-r" )
    args.append( "equal-to-sent")
    args.append( "-c")
    args.append(str(custId))
    args.append( "-q")
    argsArr = array(args,String)

    print 'executing make-test-customer'
    result = emscmdtool.runCommand('make-test-customer',argsArr)

    if result is False:
        raise Exception('make-test-customer failed, customer already exists?')
    ManagementContainer.getInstance().getMailRoutingConfigGenerator().waitForRegenComplete()

    # ensure policy_exploded_users updates with user account info
    rpm = mc.getRetentionPolicyManager()
    rpm.notifyOfExternalPolicyChanges(int(custId))

    # move the contents of staging to sftp.drop
    src = os.path.join('/tmp',str(custId))
    dst = os.path.join('/ems/bigdisk/sftp.drop',str(custId))
    if not os.path.exists(dst):
        os.mkdir(dst)
    for f in os.listdir(src):
        if f.endswith('.gzip.enc.done.ftp'):
            shutil.copy(os.path.join(src,f),dst)
            os.remove(os.path.join(src,f))

            idxF = f.replace('.gzip.enc.done.ftp','.index.done.ftp')
            shutil.copy(os.path.join(src,idxF),dst)
            os.remove(os.path.join(src,idxF))

    shutil.rmtree(src)

    return
Beispiel #2
0
def activate( customerId, domain, makingActive=True ):
    print 'Looking up customer...'
    customer = getCustomer( customerId )
    print '  Customer State: ',customer.getState()
    if (customer.getState() == CustomerState.ACTIVE and makingActive is True) or (customer.getState() == CustomerState.READY and makingActive is False):
        print 'Customer is already '+ customer.getState().toString() +', returning OK'
        return OK

    print 'getting user'
    user = "******" + domain;
    actualUser = ManagementContainer.getInstance().getUserManager().getUser( user )
    if actualUser is None:
        return ERROR_ACTUAL_USER
    print 'User: '******'state mgr: ', stateMgr

    transitionMessage = None
    notificationMessage = None
    passPhrase = None

    print 'Changing state...'
    LOGGER.info( 'Changing state...' )
    if makingActive:
        res = stateMgr.changeCustomerState( customer, actualUser, CustomerState.ACTIVE, transitionMessage, notificationMessage, passPhrase, 'activating from activate.py', True )
        if not res is True:
            print 'Activation failed'
            LOGGER.error( 'Activation failed.' )
            return ERROR_STATE_CHANGE_FAILED
    else:
        res = stateMgr.changeCustomerState( customer, actualUser, CustomerState.RECOVERY, transitionMessage, notificationMessage, passPhrase, 'recovering from activate.py', True )
        if not res is True:
            print 'Shift to RECOVERY failed'
            LOGGER.error( 'Shift to RECOVERY failed.' )
            return ERROR_STATE_CHANGE_FAILED
        res = stateMgr.changeCustomerState( customer, actualUser, CustomerState.READY, transitionMessage, notificationMessage, passPhrase, 'making ready from activate.py', True )
        if not res is True:
            print 'Shift to READY failed'
            LOGGER.error( 'Shift to READY failed.' )
            return ERROR_STATE_CHANGE_FAILED
        # java's "boolean ? x : y" is written as "x if boolean else y" in python!
    state='ACTIVE'
    if not makingActive:
        state='READY'
    print 'State change to ' + state + ' succeeded.'
    LOGGER.info( 'State change to ' + state + ' succeeded.' )
    return OK
Beispiel #3
0
def deleteDuplicate(locId,storageId,commit,type):
     mc = ManagementContainer.getInstance()
     cm = mc.getClusterManager()
     loc = cm.getClusterLocation(locId)
     if loc is None:
         print 'No cluster location for',locId,'?'
         return
     masterUrl = loc.getClusterLocationProperty(SolrClusterAdapter.SOLR_MASTER_HOST_URL_PROP) + '/%s/update' % type
     data = '<delete><query>storageid:%d</query></delete>' % storageId
     print time.asctime(),'url',masterUrl,'data',data

     if not commit:
         return 

     #
     # delete duplicates
     #
     f = None
     try:
         req = urllib2.Request(masterUrl,data,headers={'Content-type': 'text/xml'}) 
         f = urllib2.urlopen(req)
         print time.asctime(),masterUrl,data,f.read()
     finally:
         if f is not None:
             f.close()
Beispiel #4
0
def getUserDBData(partId,msgId):
    mc = ManagementContainer.getInstance()
    conn = mc.getDBConnection(ManagementContainer.AM_POOL_NAME)

    recipients = []
    sender = 0
    rs = None
    s = None

    try:
        s = conn.createStatement()
        sql = 'select user_id,is_sender from msg_users_%s where m1_message_id = %s' % (partId,msgId)
        rs = s.executeQuery(sql)
        while rs.next():
            id = rs.getInt(1)
            category = RecipientCategory.valueOf(rs.getInt(2))
            if RecipientCategory.SENDER.equals(category):
                sender = id
            else:
                recipients.append(MatchRecipient(id, category))
    finally:
        conn.rollback()
        DbUtils.safeClose(rs)
        DbUtils.safeClose(s)
        mc.safeReturnDBConnection(conn, ManagementContainer.AM_POOL_NAME)

    return (sender,recipients)
Beispiel #5
0
def test(islandId,numMessages):
    mc = ManagementContainer.getInstance()
    cm = mc.getCustomerManager()
    amsm = mc.getActiveMailboxStoreManager()
    custid = 0
    
    try:
        if not os.path.exists('/tmp/replay-custid.txt'):
            print '/tmp/replay-custid.txt does not exist'
            return(1)

        f = open('/tmp/replay-custid.txt','r')
        for line in f:
            custid = int(line.strip())
            break
        f.close()
        os.remove('/tmp/replay-custid.txt')
        print 'using customer id',custid

        msgs = findMessages(mc,custid,numMessages)

        print 'search for',msgs

        if not checkSearchStatus2(mc,msgs,custid,True):
            print 'Did not find messages'
            return(1)
        else:
            print 'Found messages'
    finally:
        if custid > 0:
            cm.deleteCustomers([custid])
    
    return(0)
Beispiel #6
0
    def changeState(self,locName,feed,update,purge,threshMsg):
        cm = ManagementContainer.getInstance().getClusterManager()
        cl = cm.findFirstMatchingClusterLocation(locName)
        changeState = False

        if feed is not None and feed == cl.isFeedEnabled():
            log('changeState: feed is already in expected state (' + str(feed) + ') for ' + cl.toString())
        elif feed is not None:
            cl.setFeedEnabled(feed)
            changeState = True

        if purge is not None and purge == cl.isPurgeEnabled():
            log('changeState: purge is already in expected state (' + str(purge) + ') for ' + cl.toString())
        elif purge is not None:
            cl.setPurgeEnabled(purge)
            changeState = True

        if update is not None and update == cl.isUpdateEnabled():
            log('changeState: update is already is expected state (' + str(update) + ') for ' + cl.toString())
        elif update is not None:
            cl.setUpdateEnabled(update)
            changeState = True

        if changeState:
            self.sendMail('cluster location policy changed for ' + cl.toString(), threshMsg + ' feed ' + str(cl.isFeedEnabled()) + ',update ' + str(cl.isUpdateEnabled()) + ',purge ' + str(cl.isPurgeEnabled()) + ' for ' + cl.toString())
            log('changeState: feed ' + str(cl.isFeedEnabled()) + ',update ' + str(cl.isUpdateEnabled()) + ',purge ' + str(cl.isPurgeEnabled()) + ' for ' + cl.toString())
            cm.updateClusterLocation(cl)
        else:
            log('changeState: feed no changes for ' + cl.toString())

        return changeState
Beispiel #7
0
def retrieve_an_archive(cust_id, archive_name, user_id, chunk_hint, file_name, output_ids):
    print "\nretrieve_a_chunk routine:: output file_name is :", file_name

    try:
        outfile_stream = FileOutputStream(file_name)
    except:
        print "retrieve_a_chunk routine:: Failed to open output stream on file : ", file_name, "..returning"
        return None

    # retrieve data
    mc = ManagementContainer.getInstance()
    rm = mc.getRecoveryManager()

    l_cust_id = Integer.parseInt(cust_id);
    l_user_id = Integer.parseInt(user_id);
    sosw = IRecoveryManager.SimpleOutputStreamWrapper(outfile_stream)

    try:
        rm.createPerUserActiveRecoveryArchiveFile(l_cust_id, archive_name, l_user_id, sosw, chunk_hint)
    except:
        print "retrieve_a_chunk routine:: `Exception while creating active recovery archive..returning"
        sys.exc_info()[1].printStackTrace()

        print("*** print_exc:")
        traceback.print_exc(file=sys.stdout)
        outfile_stream.close()
        raise

    outfile_stream.close()
    return get_chunk_hint(file_name, output_ids)
Beispiel #8
0
def enableIslandEDiscovery( islandId, enabled ):

    file = File('/tmp/cluster_tmp.out')
    ampout = PrintStream(FileOutputStream(file))
    amptool = ActiveMailboxPartitionTool()
    amptool.setOutputStream(ampout)

    mc = ManagementContainer.getInstance()
    island = mc.getIslandManager().getIsland( islandId )
    edMode = island.isEdiscoveryEnabled()
    if edMode != enabled:
        island.setEdiscoveryEnabled( enabled )
        mc.getIslandManager().updateIsland(island)

    result = amptool.runCommand('cluster',array(['-l'],String))
    cmdline = 'cat /tmp/cluster_tmp.out | grep -v FeedOn | grep -E \" .*' + str( islandId ) + ' .*\" > /tmp/cluster.out'
    os.system(cmdline)
    if result is False:
        return ERROR_CLUSTER_FAILED
    linedata = open( '/tmp/cluster.out', 'r' ).read()
    items = linedata.split()
    enderServiceName = items[5]

    if island.getPlatformVersion().endswith( '-solr' ):
        enderServiceName = 'solrproxy-' + enderServiceName
    else:
        enderServiceName = 'fastproxy-' + enderServiceName
    proxyHost = items[10]
    print 'restarting proxy \"' + enderServiceName + '\" on \"' + proxyHost + '\" to ensure that island capability cache is in synch'

    proxy = Service( enderServiceName )
    proxy.invoke( 'restart', proxyHost )
    print 'proxy restarted'

    return edMode
def retrieve_an_archive(cust_id, archive_name, user_id, chunk_hint, file_name, output_ids):
    print "\nretrieve_a_chunk routine:: output file_name is :", file_name

    try:
        outfile_stream = FileOutputStream(file_name)
    except:
        print "retrieve_a_chunk routine:: Failed to open output stream on file : ", file_name, "..returning"
        return None

    # retrieve data
    mc = ManagementContainer.getInstance()
    rm = mc.getRecoveryManager()

    l_cust_id = Integer.parseInt(cust_id);
    l_user_id = Integer.parseInt(user_id);
    sosw = IRecoveryManager.SimpleOutputStreamWrapper(outfile_stream)

    try:
        rm.createPerUserActiveRecoveryArchiveFile(l_cust_id, archive_name, l_user_id, sosw, chunk_hint)
    except:
        print "retrieve_a_chunk routine:: `Exception while creating active recovery archive..returning"
        sys.exc_info()[1].printStackTrace()

        print("*** print_exc:")
        traceback.print_exc(file=sys.stdout)
        outfile_stream.close()
        raise

    outfile_stream.close()
    return get_chunk_hint(file_name, output_ids)
Beispiel #10
0
    def runPurge(self,partition,purgeId,workDir):
        mc = ManagementContainer.getInstance()
        amsm = mc.getActiveMailboxStoreManager()
        spoolDir = PurgeController(partition,None).getSpoolDirectory().getCanonicalPath()
        start = int(time.time())
        success = ps_SUCCESS

        try:
            # bring the remote job to the local directory where purge does its work
            self.importJobDirectory(spoolDir,workDir)

            # get expected size and report
            items = self.getNumItemsInJob(purgeId, workDir)
            log('Purge partition =',partition.getId(),'purgeId =',purgeId,'Expected Deletions =',items)

            # execute the purge
            if amsm.purgeExpiredMessagesV2(partition,PurgeController.getConfiguredPurgeStages(),purgeId,False):
                mc.getStatManager().logStat("purge-client-run-time-succeeded-" + str(partition.getId()), int(time.time()) - start)
                success = ps_SUCCESS
            # handles generic failure (including EMSDEV-10100) in purgeExpiredMessagesV2()
            else: 
                mc.getStatManager().logStat("purge-client-run-time-failed-" + str(partition.getId()), int(time.time()) - start)
                log('Purge reported failure. Cleaning',workDir,'in preparation for redispatch...')
                success = ps_SHOULDDELETE
        # handles EMSDEV-10100 failure before purgeExpiredMessagesV2()
        except IllegalStateException, FileNotFoundException:
            mc.getStatManager().logStat("purge-client-run-time-failed-" + str(partition.getId()), int(time.time()) - start)
            log('Purge reported failure. Cleaning',workDir,'in preparation for redispatch...')
            success = ps_SHOULDDELETE            
Beispiel #11
0
def setup(islandId):
    sor = SOR()
    hosts = sor.getHosts("purge-dispatcherV2")
    if hosts is None or len(hosts) != 1:
        print "Did not find expected host for purge-dispatcherV2", hosts
        return 1
    purgeHost = hosts.pop()

    mc = ManagementContainer.getInstance()
    purgeDispatcher = Service("purge-dispatcherV2")
    preCalcSvc = Service("purge-precalc-service")

    try:
        purgeDispatcher.invoke("stop", purgeHost)
        preCalcSvc.invoke("stop", purgeHost)

        os.system(
            "cd /tmp; /bin/rm -rf /tmp/corpus /tmp/purge-1; tar -xf endtoend-test-corpus.tar; mv /tmp/corpus /tmp/purge-1"
        )
        os.system("sed -i 's/@enron.com/@purge1.com/g' /tmp/purge-1/*")

        setupCustomer(mc, islandId, corpus="/tmp/purge-1", name="purge1", domain="purge1.com", recvDate="now")

        return 0
    finally:
        purgeDispatcher.invoke("start", purgeHost)
        preCalcSvc.invoke("start", purgeHost)
Beispiel #12
0
    def checkForJob(self,workDir):
        jobFile = os.path.join(workDir,'sentinel')

        if os.path.exists(jobFile):
            partId = int(os.path.basename(workDir))
            mc = ManagementContainer.getInstance()
            pm = mc.getPartitionManager()
            partition = pm.getPartition(partId)
            log('Found a purge job for partition',partId)
            if self.processJob(partition,workDir,jobFile):
                log('Purge succeeded. Clearing jobs directory (',workDir,')to signal dispatcher that a partition is completed')
                self.clearJobDirectory(workDir)
                pm.refreshFreeSpaceInfo(Collections.singletonList(partition))
            else:
                log('Purge failed. Not clearing job directory(',workDir,'). Will retry with current batch later')
                count = 1
                if partId in self.failuresByPartId:
                    count = self.failuresByPartId[partId]
                    count = count + 1
                    if count >= self.maxFailures:
                        log('Purge: failed purge',count,'times for partition',partId,'. Clearing job')
                        self.clearJobDirectory(workDir)
                        count = 0
                self.failuresByPartId[partId] = count

            return True

        return False
Beispiel #13
0
def enableIslandEDiscovery( islandId, enabled ):

    mc = ManagementContainer.getInstance()
    island = mc.getIslandManager().getIsland( islandId )
    edMode = island.isEdiscoveryEnabled()
    if edMode != enabled:
        island.setEdiscoveryEnabled( enabled )
        mc.getIslandManager().updateIsland(island)

    res = os.system( '/opt/ems/bin/amp cluster -l | grep -v FeedOn | grep -E \" .*' + str( islandId ) + ' .*\" > /tmp/cluster.out')
    if res != 0:
        return ERROR_CLUSTER_FAILED
    linedata = open( '/tmp/cluster.out', 'r' ).read()
    items = linedata.split()
    enderServiceName = items[5]

    if island.getPlatformVersion().endswith( '-solr' ):
        enderServiceName = 'solrproxy-' + enderServiceName
    else:
        enderServiceName = 'fastproxy-' + enderServiceName
    proxyHost = items[10]
    print 'restarting proxy \"' + enderServiceName + '\" on \"' + proxyHost + '\" to ensure that island capability cache is in synch'

    proxy = Service( enderServiceName )
    proxy.invoke( 'restart', proxyHost )
    print 'proxy restarted'

    return edMode
Beispiel #14
0
def testRemote(islandId,numMessages):
    mc = ManagementContainer.getInstance()
    pm = mc.getPartitionManager()
    custId = None

    custId = findCustomer("rgm-remote")
    print 'Found customer id',custId
    
    if custId < 0:
        print 'Unable to locate test customer named rgm1'
        return 1
        
    msgs = findMessages(mc,custId,numMessages)
    for msg in msgs:
        pp = pm.getContentProxy(msg.getPartitionId())
        print 'Get message',msg.getMessageId(),"from partition",msg.getPartitionId()
        inputStream = pp.getRawMessage(custId,-1,msg.getMessageId())
        if inputStream is None:
            print >>sys.stderr,"Got null stream for message",msg.getMessageId(),"from partition",msg.getPartitionId()
            return 1
        createPurgeOrphan(mc,msg)
        print 'Get message',msg.getMessageId(),"from partition",msg.getPartitionId()
        try:
            inputStream = pp.getRawMessage(custId,-1,msg.getMessageId())
            print >>sys.stderr,"Got unexpected stream for message",msg.getMessageId(),"from partition",msg.getPartitionId()
            return 1
        except MessageNotFoundIOException, e:
            print >>sys.stderr,"Got expected MessageNotFoundIOException"
        except:
Beispiel #15
0
def addDomains( customerId, domains ):
    print 'Clearing any .lock files...'
    os.system('find /ems/sysconf/postfix -type f -name ".lock" -exec rm -f {} \;')

    print 'Looking up customer...'
    customer = getCustomer( customerId )

    customerDomains = customer.getDomains()
    updatedDomains = list()
    for d in customerDomains:
        updatedDomains.append( d )

    count = 0
    for d in domains:
        if not d in updatedDomains:
            updatedDomains.append( d )
            count += 1

    if count == 0:
        print 'No new domains to add to customer.'
        return OK

    print 'Updating customer to have domains ', updatedDomains
    customer.setDomains( updatedDomains )
    customerList = list()
    customerList.append( customer )
    res = ManagementContainer.getInstance().getCustomerManager().updateCustomers( customerList )
    if res != 1:
        return ERROR_CUSTOMER_NOT_UPDATED
    return OK
Beispiel #16
0
def setup(islandId):
    sor = SOR()
    hosts = sor.getHosts('purge-dispatcherV2')
    if hosts is None or len(hosts) != 1:
        print 'Did not find expected host for purge-dispatcherV2',hosts
        return 1
    purgeHost = hosts.pop()

    mc = ManagementContainer.getInstance()
    purgeDispatcher = Service('purge-dispatcherV2')
    preCalcSvc = Service('purge-precalc-service')
    
    try:
        purgeDispatcher.invoke('stop',purgeHost)
        preCalcSvc.invoke('stop',purgeHost)

        os.system("cd /tmp; /bin/rm -rf /tmp/corpus /tmp/policystats-1; tar -xf endtoend-test-corpus.tar; mv /tmp/corpus /tmp/policystats-1");
        os.system("sed -i 's/@enron.com/@policystats.com/g' /tmp/policystats-1/*");
        
        setupCustomer(mc,islandId,corpus='/tmp/policystats-1',name='PolicyStatsTest',domain='policystats.com',recvDate='now')
        
        return 0
    finally:
        purgeDispatcher.invoke('start',purgeHost)
        preCalcSvc.invoke('start',purgeHost)
Beispiel #17
0
def setupCustomer(mc,island,domain,isCloud,isOnPremises,userAccounts,loadCorpus=False):
    deleteCustomer(mc)
    amptool = ActiveMailboxPartitionTool()
    emscmdtool = EmsCommandLineTool()
    print 'creating customer...'
    cm = mc.getCustomerManager()
    print 'executing amp cluster-location'
    amptool.runCommand('cluster-location',array(['-r'],String))



    args = []
    args.append("-f" )
    args.append( str(island))
    args.append("-s" )
    args.append( str(island))
    args.append("-d" )
    args.append( domain)
    args.append( "-n" )
    args.append("systest_journaling_customer" )
    args.append("-e" )
    args.append( "nobody@" + domain)
    args.append("-q")
    if loadCorpus:
        args.append( "-i" )
        args.append( "/tmp/corpus")
        args.append( "-o" )
        args.append( "/ems/bigdisk/sftp.drop")

    if isCloud:
        args.append("--guid")
    if isOnPremises:
        args.append( "--bcc" )

    if userAccounts is not None:
        for address in userAccounts:
            args.append("--user-account" )
            args.append( address + "@" + domain )
    print "creating journal-enabled customer "
    Logger.getLogger( "cloud.py" ).info( "Creating systest_journaling_customer..." )
    result = emscmdtool.runCommand('make-test-customer',args)

    if result is False:
        raise Exception('make-test-customer failed, customer already exists?')
    ManagementContainer.getInstance().getMailRoutingConfigGenerator().waitForRegenComplete()
    cust = cm.findCustomers([SearchConstraint(ICustomerManager.PROP_NAME, SearchConstraintOperator.CONSTRAINT_EQUALS, 'systest_journaling_customer')])
    return cust[0]
Beispiel #18
0
def validateData(data):
    rows = 0
    custId = -1
    partId = -1
    msgId = -1
    for k,v in data.items():
        if rows == 0:
            rows = len(v)
        elif rows != len(v):
            raise Exception('Message has different number of documents on different shards:' + str(rows) + ' and ' + str(len(v)))

        for doc in v.values():
            if custId == -1:
                # when getting the first document, pull the comparison values of customer, message, and partition
                custId = doc.getCustomerID()
                msgId = doc.getStorageID()
                partId = doc.getPartitionID()
            elif custId != doc.getCustomerID():
                raise Exception('Message has different customers on documents:' + str(custId) + ' and ' + str(doc.getCustomerID()))
            elif partId != doc.getPartitionID():
                raise Exception('Message has different partition on documents:' + str(partId) + ' and ' + str(doc.getPartitionID()))
            else:
                pass # all ok

        
    if custId < 0:
        raise Exception('Did not find any valid customer ID in the data set')
    if partId < 0:
        raise Exception('Did not find any valid partition ID in the data set')
    if msgId < 0:
        raise Exception('Did not find any valid message ID in the data set')

    mc = ManagementContainer.getInstance()
    pm = mc.getPartitionManager()
    amsm = mc.getActiveMailboxStoreManager()

    idxStatus = getIndexStatus(amsm, partId, msgId, custId)
    if idxStatus <= 0:
        raise Exception('Message ' + str(msgId) + ' on partition ' + str(partId) + ' says this message is not indexed: ' + str(idxStatus))
    
    if idxStatus not in data.keys():
        raise Exception('DB index status of ' + str(idxStatus) + ' does not match any search results for message locations: ' + str(data.keys))

    # pop one arbitrary set of data from the map 
    (k1,v1) = data.popitem()

    # use the set above and compare documents to rest of the duplicates
    for k2,v2 in data.items():
        for docId,doc in v.items():
            doc2 = v2[docId]
            if compareDocs(custId,doc,doc2) != 0:
                raise Exception('Documents in the sets do not compare as the same ' + str(docId))

    results = []
    for k,v in data.items():
        if k != idxStatus:
            print 'Should delete duplicates for',msgId,'on location',k,'the copy at location',idxStatus,'should be preserved'
            results.append((msgId,k))
    return results
Beispiel #19
0
def getSearchParams():
    result = ''
    mc = ManagementContainer.getInstance()
    island = mc.getIslandManager().getIsland(101)
    if island is not None:
      result = island.getSearchParms()

    return result
Beispiel #20
0
def setUserPurgeDate(usersToPurge, markPurgeDaysBeforeCurrent):
    mc = ManagementContainer.getInstance()
    connection = mc.getDBConnection(ManagementContainer.POOL_NAME)
    s = connection.createStatement()
    s.executeUpdate("update dat_user_account set purge_date = current_timestamp - '"+str(markPurgeDaysBeforeCurrent)+" days'::interval where object_id in "+QueryUtils.literal(usersToPurge))
    s.close()
    connection.commit()
    mc.safeReturnDBConnection(connection, ManagementContainer.POOL_NAME)
    DbUtils.safeClose(s)
Beispiel #21
0
 def setColumnState(self, feed, update, purge):
     if self.config.allowColumnStateChange > 0:
         log('set state for ' + self.clusterLocationName + ' feed: ' + str(feed) + ' update: ' + str(update) + ' purge: ' + str(purge))
         mc = ManagementContainer.getInstance()
         cm = mc.getClusterManager()
         self.clusterLocation.setFeedEnabled(feed)
         self.clusterLocation.setUpdateEnabled(update)
         self.clusterLocation.setPurgeEnabled(purge)
         cm.updateClusterLocation(self.clusterLocation)
Beispiel #22
0
def show(islandId):
    mc = ManagementContainer.getInstance()

    island = mc.getIslandManager().getIsland(islandId)

    print island


    sys.exit(0)
Beispiel #23
0
def findCustomer(name):
    mc = ManagementContainer.getInstance()
    cm = mc.getCustomerManager()
    sc = SearchConstraint(ICustomerService.PROP_NAME,SearchConstraintOperator.CONSTRAINT_EQUALS,name)
    customers = cm.findCustomers([sc])
    if customers.size() != 1:
        print 'Did not find customer named',name
        return -1
    return customers.iterator().next().getCustID()
Beispiel #24
0
def updatePassword(email, hashedPassword):
    mc = ManagementContainer.getInstance()
    connection = mc.getDBConnection(ManagementContainer.POOL_NAME)
    s = connection.createStatement()
    command = "update dat_user_account set hashed_password = \'" + str(hashedPassword) + "\' where primary_email = \'" + email + "\'"
    print "EXEC: " + command
    s.executeUpdate(command)
    connection.commit()
    mc.safeReturnDBConnection(connection, ManagementContainer.POOL_NAME)
    DbUtils.safeClose(s)
Beispiel #25
0
def updateContentId(oldMessageId, replacementId, partitionId):
    mc = ManagementContainer.getInstance()
    connection = mc.getDBConnection(ManagementContainer.AM_POOL_NAME)
    s = connection.createStatement()
    command = "update dat_repl_messages_" + str(partitionId) + " set content_replacement_id= " + str(replacementId) + " where m1_message_id= " + str(oldMessageId)
    print "sql: " + command
    s.executeUpdate(command)
    connection.commit()
    mc.safeReturnDBConnection(connection, ManagementContainer.AM_POOL_NAME)
    DbUtils.safeClose(s)
Beispiel #26
0
def getEnronCustomer():
    print 'getEnronCustomer()'
    mc = ManagementContainer.getInstance();
    customers = mc.getCustomerManager().findCustomers([SearchConstraint(ICustomerManager.PROP_DOMAINS, SearchConstraintOperator.CONSTRAINT_EQUALS, "enron.com")]);
    if customers is None or len( customers ) == 0:
        print 'No customer was found with enron.com domain.'
        return -1
    cust=customers[0]
    id=cust.getCustID();
    print 'enron.com customerId:',id
    return id;
Beispiel #27
0
def getCustomerByDomain( domain ):
    print 'getCustomerByDomain()'
    mc = ManagementContainer.getInstance()
    customers = mc.getCustomerManager().findCustomers([SearchConstraint(ICustomerManager.PROP_DOMAINS, SearchConstraintOperator.CONSTRAINT_EQUALS, domain)])
    if customers is None or len( customers ) == 0:
        print 'No customer was found with domain ',domain
        return -1
    cust=customers[0]
    id=cust.getCustID()
    print domain,' customerId:',id
    return id
Beispiel #28
0
 def __init__(self,config):
     self.mc = ManagementContainer.getInstance()
     self.fcm = None
     self.fsm = None
     self.configDir = config['configDir']
     self.config = config
     self.datFile = 'ApiQController.dat'
     self.stats = None
     self.feedThreshold = float(config['feedThresholdPercent'])
     self.fupThreshold = float(config['fupThresholdPercent'])
     self.monitorSoftErrorCount = 0
Beispiel #29
0
def test(islandId,numMessages):
    mc = ManagementContainer.getInstance()
    if testRemote(islandId,numMessages) != 0:
        print >>sys.stderr,"testRemote() failed"
        return 1
    print 'testRemote success'
    if testLocal(islandId,numMessages) != 0:
        print >>sys.stderr,"testLocal() failed"
        return 1
    print 'testLocal success'
    return 0
Beispiel #30
0
def deleteUser(userId,custId):
    mc = ManagementContainer.getInstance()
    um = mc.getUserManager()
    print "Preparing to delete userId " + userId + " with customerId: " + custId
    userInt = int(userId)
    custInt = int(custId)
    res = um.deleteUsers([userInt],custInt)
    print "Deleted ",res," users"
    if res == 0:
        print "Didn't successfully delete user"
        return 1
    return 0
Beispiel #31
0
def determineLocationId():
    global locationId
    clm = ManagementContainer.getInstance().getClusterManager()
    locs = clm.enumClusterLocations()
    print 'locs',locs
    for loc in locs:
        print 'loc',loc
        murl = loc.getClusterLocationProperty('solr_slave_url')
        print 'murl',murl
        if murl is not None and murl.find(ARCHIVE6) > 0 :
            locationId = loc.getId()
            break
    for opt, arg in options:
        if opt == '-u':
            user_id = arg
        elif opt == '-p':
            password = arg
        elif opt == '-r':
            role = arg
        elif opt == '-o':
            originator = 'GetUserArchiveAction'
        elif opt == '-?':
            show_usage_and_exit()

    if (len(remainder) != 0):
        print "\nInvalid arguments passed."
        show_usage_and_exit()

    if (user_id == None or password == None):
        print "\n User_id, Password is must to validate the Login."
        show_usage_and_exit()

    try:
        print "Getting Login Authentication for the User ", user_id
        loginRoles = EMSRegistrationService.ROLES_CAN_GET_PRIVATE_KEY
        resp = ManagementContainer.getInstance().getAuthenticationManager(
        ).loginUserOverrideRolesIfReviewer(user_id, password,
                                           "GetUserArchiveAction", loginRoles)
        print "Authentication status of User for Downloading the Archive ", resp.getStatus(
        )
    except:
        print 'Exception', sys.exc_info(), traceback.print_exc(file=sys.stderr)
from com.m1.ems.mgmt import ManagementContainer
from com.m1.util.db import DbUtils


if __name__ == '__main__':

    if len(sys.argv) != 2:
        print 'Usage:', sys.argv[2], 'Please provide Message Id file'
        sys.exit(1)

    else:
        file_name = sys.argv[1]
        f = open(file_name)
        out = f.readlines()

        mc = ManagementContainer.getInstance()
        conn = mc.getDBConnection(ManagementContainer.AM_POOL_NAME)
        pm = mc.getPartitionManager()
        s = None
        rs = None
        #partIdList = []
        data = dict()
        try:
            s = conn.createStatement()
            done = False
            id = -1
            for msg_id in out:
                sql = 'select partition_id from dat_repl_message_key_map where m1_message_id=' + msg_id
                rs = s.executeQuery(sql)
                if rs.next():
                    id = rs.getInt(1)