示例#1
0
 def __init__(self, model):
     ''' Constructor '''
     self.model = model
     self.curl_manager = CurlManager()
     self.nm_manager = NMManager()
     self.curl_data_dispatcher = {
         Operation.Server.START: self.create_curl_POST_data,
         Operation.Server.STOP: self.create_curl_POST_data,
         Operation.Server.STATUS: self.create_curl_data,
         Operation.Server.RESTART: self.create_curl_POST_data,
         Operation.Server.SUSPEND: self.create_curl_POST_data,
         Operation.Server.RESUME: self.create_curl_POST_data
     }
示例#2
0
文件: server.py 项目: cerndb/wls-cli
 def __init__(self, model):
     ''' Constructor '''
     self.model = model
     self.nm_manager = NMManager()
     self.curl_manager = CurlManager()
示例#3
0
文件: server.py 项目: cerndb/wls-cli
class AdminServerService(object):
    
    def __init__(self, model):
        ''' Constructor '''
        self.model = model
        self.nm_manager = NMManager()
        self.curl_manager = CurlManager()
    
    def run(self, operation):
        data_contract = self.create_nm_data(operation)
        self.nm_manager.create_agent(data_contract)
        result = -1
        output = ""
        
        if operation == Operation.Server.START:
            p = multiprocessing.Process(target = self.ping_admin)
            p.start()
            
            t = threading.Thread(target = self.print_dots, args = (p,))
            t.start()
            
            try:
                result, output = self.nm_manager.execute_agent()  
                p.join(timeout = 3)
            except TypeError as exception: 
                p.terminate()
                raise Exception(exception)
            
            #print "PRZED"
            #p.join(timeout = 3)
            #print "PO"
        
            # If thread is still active
            if p.is_alive():
                # Terminate
                p.terminate()
                p.join()

        else:
            result, output = self.nm_manager.execute_agent()  
        self.model.update(MessageType.INFO, output)
        return int(result)
    
    def create_nm_data(self, operation):
        data_contract = NMDataContract()
        data_storage = self.model.data_storage
        data_contract.target = Constans.ADMINSERVER_NAME
        data_contract.operation = "START" if operation == Operation.Server.START else "KILL"
        data_contract.wls_dir = data_storage.wls_dir
        data_contract.domain_name = data_storage.domain_name
        data_contract.domain_dir = data_storage.domain_dir
        return data_contract
    
    def create_curl_data(self):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + \
             "/management/wls/latest"
        data_contract.certs = data_storage.curl_certs
        data_contract.user_pwd = data_storage.user_pwd
        data_contract.cookie_file = data_storage.cookie_path
        data_contract.cookie_jar = data_storage.cookie_path
        data_contract.netrc = data_storage.netrc
        data_contract.ssl_verifypeer = True if not data_storage.test else False
        return data_contract

    def print_dots(self, p):
        
        while p.is_alive():
            sys.stdout.write("."),
            sys.stdout.flush()
            time.sleep(1)

    def ping_admin(self):
        data_contract = self.create_curl_data()
        self.curl_manager.create_agent(data_contract)
        result = -1
        
        while result !=0:
            try:
                result, output = self.curl_manager.execute_agent()
            except Exception: 
                time.sleep(3)
示例#4
0
 def __init__(self, model):
     ''' Constructor '''
     self.model = model
     self.nm_manager = NMManager()
     self.curl_manager = CurlManager()
示例#5
0
class AdminServerService(object):
    def __init__(self, model):
        ''' Constructor '''
        self.model = model
        self.nm_manager = NMManager()
        self.curl_manager = CurlManager()

    def run(self, operation):
        data_contract = self.create_nm_data(operation)
        self.nm_manager.create_agent(data_contract)
        result = -1
        output = ""

        if operation == Operation.Server.START:
            p = multiprocessing.Process(target=self.ping_admin)
            p.start()

            t = threading.Thread(target=self.print_dots, args=(p, ))
            t.start()

            try:
                result, output = self.nm_manager.execute_agent()
                p.join(timeout=3)
            except TypeError as exception:
                p.terminate()
                raise Exception(exception)

            #print "PRZED"
            #p.join(timeout = 3)
            #print "PO"

            # If thread is still active
            if p.is_alive():
                # Terminate
                p.terminate()
                p.join()

        else:
            result, output = self.nm_manager.execute_agent()
        self.model.update(MessageType.INFO, output)
        return int(result)

    def create_nm_data(self, operation):
        data_contract = NMDataContract()
        data_storage = self.model.data_storage
        data_contract.target = Constans.ADMINSERVER_NAME
        data_contract.operation = "START" if operation == Operation.Server.START else "KILL"
        data_contract.wls_dir = data_storage.wls_dir
        data_contract.domain_name = data_storage.domain_name
        data_contract.domain_dir = data_storage.domain_dir
        return data_contract

    def create_curl_data(self):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + \
             "/management/wls/latest"
        data_contract.certs = data_storage.curl_certs
        data_contract.user_pwd = data_storage.user_pwd
        data_contract.cookie_file = data_storage.cookie_path
        data_contract.cookie_jar = data_storage.cookie_path
        data_contract.netrc = data_storage.netrc
        data_contract.ssl_verifypeer = True if not data_storage.test else False
        return data_contract

    def print_dots(self, p):

        while p.is_alive():
            sys.stdout.write("."),
            sys.stdout.flush()
            time.sleep(1)

    def ping_admin(self):
        data_contract = self.create_curl_data()
        self.curl_manager.create_agent(data_contract)
        result = -1

        while result != 0:
            try:
                result, output = self.curl_manager.execute_agent()
            except Exception:
                time.sleep(3)