def __init__(self, task_def): self.task_def = task_def self.docker_client = Client(base_url='unix://var/run/docker.sock', version='1.18') self.service_obj = service.Service(self.task_def.service_data[0]) self.service_name = self.service_obj.get_service_name() self.mysql_db_name = constants.DEFAULT_DB_NAME self.mysql_user = constants.DEFAULT_DB_USER self.mysql_password = constants.DEFAULT_DB_PASSWORD self.mysql_root_password = constants.DEFAULT_DB_PASSWORD self.mysql_version = 'mysql:5.5' self.db_info = {} self.db_info['root_user'] = '******' self.db_info['root_password'] = self.mysql_root_password self.db_info['user'] = self.mysql_user self.db_info['password'] = self.mysql_password self.db_info['db'] = self.mysql_db_name self.service_info = {} self.service_info['name'] = self.service_name self.service_info['version'] = self.service_obj.get_service_version() if self.service_obj.get_setup_file_content(): self.db_info['setup_file'] = 'setup.sh' self.app_status_file = '' if self.task_def.app_data: self.app_name = self.task_def.app_data['app_name'] self.app_status_file = constants.APP_STORE_PATH + "/" + self.app_name + "/" self.app_status_file = self.app_status_file + self.service_obj.get_service_version( ) + "/app-status.txt"
def _update_service_data(self, service_data, service_name, version): service_obj = service.Service(service_data[0]) setup_file_content = service_obj.get_setup_file_content() service_location, service_version = self._store_service_contents( service_name, setup_file_content, version) service_data[0]['service_location'] = service_location service_data[0]['service_version'] = service_version service_data[0]['service_name'] = service_name return service_data, service_version
def __init__(self, task_def): self.task_def = task_def if task_def.app_data: self.app_dir = task_def.app_data['app_location'] self.app_name = task_def.app_data['app_name'] self.app_version = task_def.app_data['app_version'] self.services = {} if task_def.service_data: self.service_obj = service.Service(task_def.service_data[0]) if self.service_obj.get_service_type() == 'mysql': self.services['mysql'] = awsh.MySQLServiceHandler(self.task_def) self.docker_handler = docker_lib.DockerLib()
def __init__(self, task_def): self.task_def = task_def if self.task_def.app_data: self.app_type = task_def.app_data['app_type'] self.app_dir = task_def.app_data['app_location'] self.app_name = task_def.app_data['app_name'] self.app_port = task_def.app_data['app_port'] if 'app_variables' in task_def.app_data: self.app_variables = task_def.app_data['app_variables'] self.services = {} if task_def.service_data: self.service_obj = service.Service(task_def.service_data[0]) if self.service_obj.get_service_type() == 'mysql': self.services['mysql'] = lh.MySQLServiceHandler(self.task_def)
def __init__(self, task_def): self.task_def = task_def if task_def.app_data: self.app_dir = task_def.app_data['app_location'] self.app_name = task_def.app_data['app_name'] self.app_version = task_def.app_data['app_version'] self.services = {} if task_def.service_data: self.service_obj = service.Service(task_def.service_data[0]) if self.service_obj.get_service_type() == 'mysql': self.services['mysql'] = gh.MySQLServiceHandler(self.task_def) self.docker_client = Client(base_url='unix://var/run/docker.sock', version='1.18') self.docker_handler = docker_lib.DockerLib()
def __init__(self, task_def): self.task_def = task_def self.instance_name = '' self.instance_version = '' self.instance_prov_workdir = '' self.connection_name = '' self.database_version = '' self.database_tier = '' self.instance_ip_address = '' self.app_status_file = '' if task_def.app_data: self.instance_prov_workdir = task_def.app_data['app_location'] self.instance_name = task_def.app_data['app_name'] self.instance_version = task_def.app_data['app_version'] self.access_token_cont_name = "google-access-token-cont-" + self.instance_name + "-" + self.instance_version self.create_db_cont_name = "google-create-db-" + self.instance_name + "-" + self.instance_version self.app_status_file = constants.APP_STORE_PATH + "/" + self.instance_name + "/" + self.instance_version + "/app-status.txt" if task_def.service_data: self.service_obj = service.Service(task_def.service_data[0]) self.instance_prov_workdir = self.service_obj.get_service_prov_work_location( ) self.instance_name = self.service_obj.get_service_name() self.instance_version = self.service_obj.get_service_version() self.access_token_cont_name = "google-access-token-cont-" + self.instance_name + "-" + self.instance_version self.create_db_cont_name = "google-create-db-" + self.instance_name + "-" + self.instance_version self.mysql_db_name = constants.DEFAULT_DB_NAME self.mysql_user = constants.DEFAULT_DB_USER # Check if we have already provisioned a db instance. If so, use that password password = self._read_password() if not password: self.mysql_password = utils.generate_google_password() else: self.mysql_password = password self.db_info = {} self.db_info['user'] = self.mysql_user self.db_info['db'] = self.mysql_db_name self.db_info['password'] = self.mysql_password self.docker_handler = docker_lib.DockerLib()
def __init__(self, task_def): self.task_def = task_def #self.logger = logging.getLogger(name=self.__class__.__name__) self.services = {} self.app_obj = '' if self.task_def.app_data: self.app_obj = app.App(self.task_def.app_data) self.app_dir = task_def.app_data['app_location'] self.app_name = task_def.app_data['app_name'] if task_def.service_data: self.service_obj = service.Service(task_def.service_data[0]) if self.service_obj.get_service_type() == 'mysql': self.services['mysql'] = awsh.MySQLServiceHandler(self.task_def) self.docker_handler = docker_lib.DockerLib() self.docker_client = Client(base_url='unix://var/run/docker.sock', version='1.18')
def __init__(self, task_def): self.task_def = task_def self.instance_name = '' self.instance_version = '' self.app_name = '' self.app_version = '' self.services = {} self.service_handler = '' self.instance_prov_workdir = '' self.app_variables = '' # Set values using service_data first if task_def.service_data: self.service_obj = service.Service(task_def.service_data[0]) self.instance_prov_workdir = self.service_obj.get_service_prov_work_location( ) self.instance_name = self.service_obj.get_service_name() self.instance_version = self.service_obj.get_service_version() if self.service_obj.get_service_type() == 'mysql': self.services['mysql'] = awsh.MySQLServiceHandler( self.task_def) # If app_data is present overwrite the previously set values if self.task_def.app_data: self.app_type = task_def.app_data['app_type'] self.app_dir = task_def.app_data['app_location'] self.app_name = task_def.app_data['app_name'] self.app_version = task_def.app_data['app_version'] self.instance_prov_workdir = task_def.app_data[ 'app_location'] + "/" + task_def.app_data['app_name'] self.entry_point = app.App( task_def.app_data).get_entrypoint_file_name() if 'app_variables' in task_def.app_data: self.app_variables = task_def.app_data['app_variables'] self.deploy_dir = self.instance_prov_workdir self.docker_handler = docker_lib.DockerLib()
def generate(self, generate_type, service_ip_dict, service_info): if generate_type == 'service': fmlogging.debug("AWS generator called for service") self.service_obj = service.Service(self.task_def.service_data[0]) # deploy_dir = self.service_obj.get_service_prov_work_location() # Copy aws-creds to the service deploy directory cp_cmd = ("cp -r {aws_creds_path} {deploy_dir}/.").format( aws_creds_path=AWS_CREDS_PATH, deploy_dir=self.deploy_dir) fmlogging.debug("Copying aws-creds directory..") fmlogging.debug(cp_cmd) os.system(cp_cmd) if self.task_def.app_data: app_obj = app.App(self.task_def.app_data) app_obj.update_app_status( "GENERATING AWS ARTIFACTS for RDS instance") for serv in self.task_def.service_data: serv_handler = self.services[serv['service']['type']] utils.update_status( self.service_obj.get_status_file_location(), "GENERATING_ARTIFACTS_FOR_PROVISIONING_SERVICE_INSTANCE") # Invoke public interface serv_handler.generate_instance_artifacts() else: fmlogging.debug("AWS generator called for app %s" % self.task_def.app_data['app_name']) app_obj = app.App(self.task_def.app_data) app_obj.update_app_status("GENERATING AWS ARTIFACTS") if self.app_type == 'python': self._generate_for_python_app(app_obj, service_ip_dict, service_info) else: print("Application of type %s not supported." % self.app_type) return 0
def __init__(self, task_def): self.task_def = task_def #self.logger = fmlogging.getLogger(name=self.__class__.__name__) #handler = lh.RotatingFileHandler(constants.LOG_FILE_NAME, # maxBytes=5000000, backupCount=0) #self.logger.addHandler(handler) if task_def.app_data: self.app_dir = task_def.app_data['app_location'] self.app_name = task_def.app_data['app_name'] self.app_version = task_def.app_data['app_version'] self.access_token_cont_name = "google-access-token-cont-" + self.app_name + "-" + self.app_version self.create_db_cont_name = "google-create-db-" + self.app_name + "-" + self.app_version self.app_obj = app.App(self.task_def.app_data) self.services = {} if task_def.service_data: self.service_obj = service.Service(task_def.service_data[0]) if self.service_obj.get_service_type() == 'mysql': self.services['mysql'] = gh.MySQLServiceHandler(self.task_def) self.docker_handler = docker_lib.DockerLib()
def __init__(self, task_def): self.task_def = task_def self.instance_name = '' self.instance_version = '' self.instance_prov_workdir = '' if task_def.app_data: self.app_type = task_def.app_data['app_type'] self.app_dir = task_def.app_data['app_location'] self.app_name = task_def.app_data['app_name'] self.entry_point = app.App(task_def.app_data).get_entrypoint_file_name() if 'app_variables' in task_def.app_data: self.app_variables = task_def.app_data['app_variables'] self.services = {} if task_def.service_data: self.service_obj = service.Service(task_def.service_data[0]) self.service_details = '' if self.service_obj.get_service_type() == 'mysql': self.services['mysql'] = gh.MySQLServiceHandler(self.task_def) self.docker_handler = docker_lib.DockerLib()
def run(self): fmlogging.debug("Starting build/deploy for %s" % self.name) if self.action == "delete": fmlogging.debug("Manager -- delete") gen.Generator(self.task_def).generate_for_delete(self.info) bld.Builder(self.task_def).build_for_delete(self.info) dep.Deployer(self.task_def).deploy_for_delete(self.info) elif self.action == "secure": fmlogging.debug("Manager -- secure") gen.Generator(self.task_def).generate_to_secure(self.info) bld.Builder(self.task_def).build_to_secure(self.info) dep.Deployer(self.task_def).deploy_to_secure(self.info) else: if self.task_def.app_data: app_obj = app.App(self.task_def.app_data) app_obj.update_app_status("name::" + self.name) app_obj.update_app_status("cloud::" + self.task_def.cloud_data['type']) app_cont_name = app_obj.get_cont_name() # Two-step protocol # Step 1: For each service build and deploy. Collect the IP address of deployed service # Step 2: Generate, build, deploy application. Pass the IP addresses of the services # Step 1: service_ip_addresses = {} services = self.task_def.service_data cloud = self.task_def.cloud_data['type'] for serv in services: service_obj = service.Service(serv) service_name = service_obj.get_service_name() service_kind = service_obj.get_service_type() utils.update_status(service_obj.get_status_file_location(), "name::" + service_name) utils.update_status(service_obj.get_status_file_location(), "cloud::" + cloud) try: gen.Generator(self.task_def).generate('service', service_ip_addresses, services) bld.Builder(self.task_def).build(build_type='service', build_name=service_name) serv_ip_addr = dep.Deployer(self.task_def).deploy(deploy_type='service', deploy_name=service_kind) fmlogging.debug("IP Address of the service:%s" % serv_ip_addr) service_ip_addresses[service_kind] = serv_ip_addr except Exception as e: fmlogging.error(e) raise e # Step 2: # - Generate, build, deploy app if self.task_def.app_data: # Allow time for service container to be deployed and started time.sleep(5) try: gen.Generator(self.task_def).generate('app', service_ip_addresses, services) bld.Builder(self.task_def).build(build_type='app', build_name=self.task_def.app_data['app_name']) result = dep.Deployer(self.task_def).deploy(deploy_type='app', deploy_name=self.task_def.app_data['app_name'] ) fmlogging.debug("Result:%s" % result) except Exception as e: fmlogging.error(e) raise e
def post(self): #args = parser.parse_args() fmlogging.debug("Received POST request.") args = request.get_json(force=True) response = jsonify() response.status_code = 201 args_dict = dict(args) try: # Handle service deployment if not 'app' in args_dict and (args_dict['service'] and args_dict['cloud']): cloud_data = args['cloud'] cloud = cloud_data['type'] service_data = args['service'] service_data[0]['lock'] = "false" # Currently supporting single service service_obj = service.Service(service_data[0]) task_name = service_name = service_obj.get_service_name() version = '' # get new version for service deployment service_data, service_version = self._update_service_data( service_data, service_name, version) task_def = task_definition.TaskDefinition( '', cloud_data, service_data) service_id = utils.get_id(SERVICE_STORE_PATH, "service_ids.txt", service_name, service_version, '', '', '', cloud, cloud_data) fmlogging.debug("Service id:%s" % service_id) response.headers['location'] = ( '/deployments/{service_id}').format(service_id=service_id) elif args['app'] and args['service'] and args[ 'cloud']: #handle app and service deployment app_data = args['app'] cloud_data = args['cloud'] service_data = args['service'] service_data[0]['lock'] = "true" task_name = app_name = app_data['app_name'] app_tar_name = app_data['app_tar_name'] content = app_data['app_content'] cloud = cloud_data['type'] app_location, app_version = self._store_app_contents( app_name, app_tar_name, content) app_data['app_location'] = app_location app_data['app_version'] = app_version service_name = service.Service( service_data[0]).get_service_type() + "-" + app_name service_data, service_version = self._update_service_data( service_data, service_name, app_version) task_def = task_definition.TaskDefinition( app_data, cloud_data, service_data) service_id = utils.get_id(SERVICE_STORE_PATH, "service_ids.txt", service_name, service_version, '', '', '', cloud, cloud_data) fmlogging.debug("Service id:%s" % service_id) app_id = utils.get_id(APP_STORE_PATH, "app_ids.txt", app_name, app_version, service_name, service_version, service_id, cloud, cloud_data) fmlogging.debug("App id:%s" % app_id) response.headers['location'] = ( '/deployments/{app_id}').format(app_id=app_id) elif 'app' in args_dict and 'cloud' in args_dict: app_data = args['app'] cloud_data = args['cloud'] task_name = app_name = app_data['app_name'] app_tar_name = app_data['app_tar_name'] content = app_data['app_content'] cloud = cloud_data['type'] app_location, app_version = self._store_app_contents( app_name, app_tar_name, content) app_data['app_location'] = app_location app_data['app_version'] = app_version task_def = task_definition.TaskDefinition( app_data, cloud_data, '') app_id = utils.get_id(APP_STORE_PATH, "app_ids.txt", app_name, app_version, '', '', '', cloud, cloud_data) fmlogging.debug("App id:%s" % app_id) response.headers['location'] = ( '/deployments/{app_id}').format(app_id=app_id) # dispatch the handler thread delegatethread = mgr.Manager(task_name, task_def) thread.start_new_thread(start_thread, (delegatethread, )) fmlogging.debug("Location header:%s" % response.headers['location']) fmlogging.debug("Response:%s" % response) except OSError as oe: fmlogging.error(oe) # Send back service unavailable status response.status_code = 503 return response