def _restore_inter_deployment_dependencies(self): # managers older than 4.6.0 didn't have the support get_capability. # manager newer than 5.0.5 have the inter deployment dependencies as # part of the database dump if (self._snapshot_version < V_4_6_0 or self._snapshot_version > V_5_0_5): return ctx.logger.info('Restoring inter deployment dependencies') update_service_composition = (self._snapshot_version == V_5_0_5) deployment_contexts = utils.get_dep_contexts(self._snapshot_version) deployments_queue = queue.Queue() failed_deployments_queue = queue.Queue() for tenant_name, deployments in deployment_contexts: for dep_id in deployments: deployments_queue.put((tenant_name, dep_id)) wf_context = current_workflow_ctx.get_ctx() context_params = current_workflow_ctx.get_parameters() threads = [] for i in range( min(self._config.snapshot_restore_threads, deployments_queue.qsize())): t = threading.Thread( target=self._create_inter_deployment_dependencies, args=(deployments_queue, failed_deployments_queue, wf_context, context_params, update_service_composition)) threads.append(t) t.start() for t in threads: t.join() if not failed_deployments_queue.empty(): deployments = list(failed_deployments_queue.queue) raise NonRecoverableError('Failed to restore snapshot, could not ' 'create the inter deployment ' 'dependencies from the following ' 'deployments {0}. See exception ' 'tracebacks logged above for more ' 'details'.format(deployments)) ctx.logger.info('Successfully restored inter deployment dependencies.')
def _restore_deployment_envs(self, postgres): deps = utils.get_dep_contexts(self._snapshot_version) token_info = postgres.get_deployment_creator_ids_and_tokens() deps_with_failed_plugins = Queue.Queue() failed_deployments = Queue.Queue() threads = list() for tenant, deployments in deps: ctx.logger.info( 'Restoring deployment environments for {tenant}'.format( tenant=tenant, ) ) tenant_client = get_rest_client(tenant=tenant) for deployment_id, dep_ctx in deployments.iteritems(): # Task graph is created and executed by threads to # shorten restore time significantly wf_ctx = current_workflow_ctx.get_ctx() wf_parameters = current_workflow_ctx.get_parameters() self._semaphore.acquire() t = threading.Thread(target=self._get_and_execute_task_graph, args=(token_info, deployment_id, dep_ctx, tenant, tenant_client, wf_ctx, wf_parameters, deps_with_failed_plugins, failed_deployments) ) t.setDaemon(True) threads.append(t) t.start() for t in threads: t.join() if not failed_deployments.empty(): deployments = list(failed_deployments.queue) raise NonRecoverableError('Failed to restore snapshot, the ' 'following deployment environments were' ' not restored: {0}. See exception' ' tracebacks logged above for more' ' details.'.format(deployments)) self._log_final_information(deps_with_failed_plugins)