Example #1
0
class ChangeManager(object):
    def __init__(self, model):
        ''' Constructor '''
        self.model = model
        self.curl_manager = CurlManager()

    def run(self, operation):
        uri = self.model.get_uri(operation)
        data_contract = self.create_curl_data(uri)
        self.curl_manager.create_agent(data_contract)
        result, output = self.curl_manager.execute_agent()

        self.model.update(MessageType.JSON, output)
        self.model.update(MessageType.STATUS_CODE, result)

        return int(result)

    def create_curl_data(self, uri):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + uri
        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
        data_contract.set_empty_postfield()

        return data_contract
Example #2
0
class ShowManager(object):
    
    def __init__(self, model):
        ''' Constructor '''
        self.model = model
        self.curl_manager = CurlManager()
        
    def run(self, operation):
        
        target = self.model.data_storage.target
        
        uri = self.model.get_uri(operation, target)
        data_contract = self.create_curl_data(uri)
        self.curl_manager.create_agent(data_contract)
        result, output = self.curl_manager.execute_agent()  
        
        self.model.update(MessageType.JSON, output)
        self.model.update(MessageType.STATUS_CODE, result)
        
        return int(result)
            
    def create_curl_data(self, uri):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + uri
        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
Example #3
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
     }
Example #4
0
class ServerService(object):
    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
        }

    def run(self, operation, target):
        uri = self.model.get_uri(operation, target)
        uri = self.modify_uri(uri)
        data_contract = self.curl_data_dispatcher[operation](uri)
        self.curl_manager.create_agent(data_contract)
        result, output = self.curl_manager.execute_agent()
        self.model.update(MessageType.JSON, output)
        return int(result)

    def create_curl_data(self, uri):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + uri
        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 self.model.data_storage.test else False
        return data_contract

    def create_curl_POST_data(self, uri):
        data_contract = self.create_curl_data(uri)
        data_contract.set_empty_postfield()
        return data_contract

    def modify_uri(self, uri):
        modified_uri = uri
        data_storage = self.model.data_storage

        if data_storage.forceOperation:
            modified_uri += "?force=true"

        return modified_uri
Example #5
0
class ServerService(object):
    
    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}
    
    def run(self, operation, target):
        uri = self.model.get_uri(operation, target)
        uri = self.modify_uri(uri)
        data_contract = self.curl_data_dispatcher[operation](uri)
        self.curl_manager.create_agent(data_contract)
        result, output = self.curl_manager.execute_agent()  
        self.model.update(MessageType.JSON, output)
        return int(result)
            
    def create_curl_data(self, uri):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + uri
        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 self.model.data_storage.test else False
        return data_contract
    
    def create_curl_POST_data(self, uri):
        data_contract = self.create_curl_data(uri)
        data_contract.set_empty_postfield()    
        return data_contract
    
    def modify_uri(self, uri):
        modified_uri = uri
        data_storage = self.model.data_storage
        
        if data_storage.forceOperation:
            modified_uri += "?force=true"
        
        return modified_uri
Example #6
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}
Example #7
0
class LogsManager(object):
    def __init__(self, model):
        ''' Constructor '''
        self.model = model
        self.curl_manager = CurlManager()

    def run(self, operation):

        target = self.model.data_storage.target

        uri = self.model.get_uri(operation, target)
        uri = self.modify_uri(uri)
        data_contract = self.create_curl_data(uri)
        self.curl_manager.create_agent(data_contract)
        result, output = self.curl_manager.execute_agent()

        self.model.update(MessageType.JSON, output)
        self.model.update(MessageType.STATUS_CODE, result)

        return int(result)

    def create_curl_data(self, uri):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + uri
        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 modify_uri(self, uri):
        modified_uri = uri
        data_storage = self.model.data_storage

        if data_storage.maxResults:
            modified_uri += "?maxResults=" + str(data_storage.maxResults)

        return modified_uri
Example #8
0
class ClusterDataService(object):
    def __init__(self, model):
        ''' Constructor '''
        self.model = model
        self.curl_manager = CurlManager()

    def run(self):
        self.model.update(MessageType.INFO, "Retrieving clusters data")
        uri = "/management/tenant-monitoring/clusters"
        data_contract = self.create_curl_data(uri)
        self.curl_manager.create_agent(data_contract)
        result, json_data = self.curl_manager.execute_agent()
        self.model.data_storage.clusters = self.map_cluster_data_from_REST(
            json_data)
        self.model.update(MessageType.INFO,
                          "Retrieved clusters data - SUCCESS")
        return int(result)

    def create_curl_data(self, uri):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + uri
        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 map_cluster_data_from_REST(self, json_data):
        ''' Interpreting the data from the request - servers and clusters data. '''
        clusters = dict()

        for cluster_data in json_data["body"]["items"]:
            cluster = list()
            for server in cluster_data["servers"]:
                cluster.append(server["name"])
            clusters[cluster_data["name"]] = cluster

        return clusters
Example #9
0
class ClusterDataService(object):
    
    def __init__(self, model):
        ''' Constructor '''
        self.model = model
        self.curl_manager = CurlManager()
    
    def run(self):
        self.model.update(MessageType.INFO, "Retrieving clusters data")
        uri = "/management/tenant-monitoring/clusters"
        data_contract = self.create_curl_data(uri)
        self.curl_manager.create_agent(data_contract)
        result, json_data = self.curl_manager.execute_agent()
        self.model.data_storage.clusters = self.map_cluster_data_from_REST(json_data)
        self.model.update(MessageType.INFO, "Retrieved clusters data - SUCCESS")
        return int(result)
            
    def create_curl_data(self, uri):
        data_contract = CurlDataContract()
        data_storage = self.model.data_storage
        data_contract.url = data_storage.adminserver_url + uri
        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 map_cluster_data_from_REST(self, json_data):
        ''' Interpreting the data from the request - servers and clusters data. '''
        clusters = dict() 
        
        for cluster_data in json_data["body"]["items"]:
            cluster = list()
            for server in cluster_data["servers"]:
                cluster.append(server["name"])
            clusters[cluster_data["name"]] = cluster
            
        return clusters
Example #10
0
class SecurityValidator(object):
    def __init__(self, data_storage):
        self.data_storage = data_storage
        self.curl_manager = CurlManager()

    def validate_security_data(self):
        data_contract = self.create_curl_data()
        self.curl_manager.create_agent(data_contract)
        self.curl_manager.execute_agent()

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

        return data_contract
Example #11
0
class SecurityValidator(object):
    
    def __init__(self, data_storage):
        self.data_storage = data_storage
        self.curl_manager = CurlManager()
    
    def validate_security_data(self):
        data_contract = self.create_curl_data()
        self.curl_manager.create_agent(data_contract)
        self.curl_manager.execute_agent()
            
    def create_curl_data(self):
        data_contract = CurlDataContract()
        data_contract.url = self.data_storage.adminserver_url + \
             "/management/wls/latest"
        data_contract.certs = self.data_storage.curl_certs
        data_contract.user_pwd = self.data_storage.user_pwd
        data_contract.cookie_file = self.data_storage.cookie_path
        data_contract.cookie_jar = self.data_storage.cookie_path
        data_contract.netrc = self.data_storage.netrc
        data_contract.ssl_verifypeer = True if not self.data_storage.test else False
        
        return data_contract
Example #12
0
 def __init__(self, model):
     ''' Constructor '''
     self.model = model
     self.curl_manager = CurlManager()
Example #13
0
 def __init__(self, data_storage):
     self.data_storage = data_storage
     self.curl_manager = CurlManager()
Example #14
0
 def __init__(self, model):
     """ Constructor """
     self.model = model
     self.curl_manager = CurlManager()
Example #15
0
 def __init__(self, data_storage):
     self.data_storage = data_storage
     self.curl_manager = CurlManager()
Example #16
0
class DeploymentManager(object):
    def __init__(self, model):
        """ Constructor """
        self.model = model
        self.curl_manager = CurlManager()

    def run(self, operation):
        deployment_name = self.model.data_storage.deployment_name
        # uri = self.model.get_uri(operation, deployment_name)

        if (
            operation == Operation.Deployment.DEPLOY_LOCAL_APP
            or operation == Operation.Deployment.DEPLOY_LOCAL_LIB
            or operation == Operation.Deployment.DEPLOY_UPLOADED_APP
            or operation == Operation.Deployment.DEPLOY_UPLOADED_LIB
        ):
            uri = self.model.get_uri(operation)

        elif (
            operation == Operation.Deployment.REDEPLOY_UPLOADED_APP
            or operation == Operation.Deployment.REDEPLOY_UPLOADED_LIB
            or operation == Operation.Deployment.REDEPLOY_LOCAL_APP
            or operation == Operation.Deployment.REDEPLOY_LOCAL_LIB
        ):
            uri = self.model.get_uri(operation, deployment_name) + "redeploy"

        else:
            uri = self.model.get_uri(operation, deployment_name)
        data_contract = self.create_curl_data(uri, operation)
        self.curl_manager.create_agent(data_contract)
        result, output = self.curl_manager.execute_agent()

        self.model.update(MessageType.JSON, output)
        self.model.update(MessageType.STATUS_CODE, result)

        return int(result)

    def create_curl_data(self, uri, operation):
        data_storage = self.model.data_storage

        data_contract = CurlDataContract()
        data_contract.url = data_storage.adminserver_url + uri
        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

        # POST Accepting "application/json"
        if (
            operation == Operation.Deployment.DEPLOY_UPLOADED_APP
            or operation == Operation.Deployment.DEPLOY_UPLOADED_LIB
        ):
            data_contract.set_postfield(data_storage.deployment_name, data_storage.source, data_storage.target)

        # POST Accepting "multipart/form-data"
        elif operation == Operation.Deployment.DEPLOY_LOCAL_APP or operation == Operation.Deployment.DEPLOY_LOCAL_LIB:
            data_contract.set_form_file(
                data_storage.deployment_name, self.model.data_storage.source, data_storage.target
            )

        # POST Accepting "multipart/form-data"
        elif (
            operation == Operation.Deployment.REDEPLOY_LOCAL_APP or operation == Operation.Deployment.REDEPLOY_LOCAL_LIB
        ):
            data_contract.set_form_file(None, self.model.data_storage.source, None)

        # POST Accepting "application/json"
        elif (
            operation == Operation.Deployment.REDEPLOY_UPLOADED_APP
            or operation == Operation.Deployment.REDEPLOY_UPLOADED_LIB
        ):
            data_contract.set_empty_postfield()

        # DELETE
        elif operation == Operation.Deployment.UNDEPLOY_APP or operation == Operation.Deployment.UNDEPLOY_LIB:
            data_contract.set_delete()

        return data_contract
Example #17
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)
Example #18
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)
Example #19
0
 def __init__(self, model):
     ''' Constructor '''
     self.model = model
     self.curl_manager = CurlManager()
Example #20
0
class DeploymentManager(object):
        
    def __init__(self, model):
        ''' Constructor '''
        self.model = model
        self.curl_manager = CurlManager()
    
    def run(self, operation):
        deployment_name = self.model.data_storage.deployment_name
        #uri = self.model.get_uri(operation, deployment_name)
        
        if operation == Operation.Deployment.DEPLOY_LOCAL_APP or \
            operation == Operation.Deployment.DEPLOY_LOCAL_LIB or \
            operation == Operation.Deployment.DEPLOY_UPLOADED_APP or \
            operation == Operation.Deployment.DEPLOY_UPLOADED_LIB:
            uri = self.model.get_uri(operation)
            
        elif operation == Operation.Deployment.REDEPLOY_UPLOADED_APP or \
            operation == Operation.Deployment.REDEPLOY_UPLOADED_LIB or \
            operation == Operation.Deployment.REDEPLOY_LOCAL_APP or \
            operation == Operation.Deployment.REDEPLOY_LOCAL_LIB:
            uri = self.model.get_uri(operation, deployment_name) + "redeploy"
            
        else:
            uri = self.model.get_uri(operation, deployment_name)
        data_contract = self.create_curl_data(uri, operation)
        self.curl_manager.create_agent(data_contract)
        result, output = self.curl_manager.execute_agent()  
        
        self.model.update(MessageType.JSON, output)
        self.model.update(MessageType.STATUS_CODE, result)
        
        return int(result)
            
    def create_curl_data(self, uri, operation):
        data_storage = self.model.data_storage
        
        data_contract = CurlDataContract()
        data_contract.url = data_storage.adminserver_url + uri
        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
        
        # POST Accepting "application/json"
        if operation == Operation.Deployment.DEPLOY_UPLOADED_APP or \
            operation == Operation.Deployment.DEPLOY_UPLOADED_LIB:
            data_contract.set_postfield(data_storage.deployment_name, \
                                        data_storage.source, data_storage.target)
                                 
        # POST Accepting "multipart/form-data"
        elif operation == Operation.Deployment.DEPLOY_LOCAL_APP or \
            operation == Operation.Deployment.DEPLOY_LOCAL_LIB:
            data_contract.set_form_file(data_storage.deployment_name, \
                self.model.data_storage.source, data_storage.target)
            
        # POST Accepting "multipart/form-data"
        elif operation == Operation.Deployment.REDEPLOY_LOCAL_APP or \
            operation == Operation.Deployment.REDEPLOY_LOCAL_LIB:
            data_contract.set_form_file(None, \
                self.model.data_storage.source, None)
        
        # POST Accepting "application/json"
        elif operation == Operation.Deployment.REDEPLOY_UPLOADED_APP or \
            operation == Operation.Deployment.REDEPLOY_UPLOADED_LIB:
            data_contract.set_empty_postfield()
            
        # DELETE
        elif operation == Operation.Deployment.UNDEPLOY_APP or \
            operation == Operation.Deployment.UNDEPLOY_LIB:
            data_contract.set_delete()
        
        return data_contract