1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 from aria.orchestrator import context
20 from aria.storage import (
26 from ..storage import init_inmemory_model_storage
27 from .topology import create_simple_topology_two_nodes
30 def simple(tmpdir, inmemory=False, context_kwargs=None, topology=None):
31 initiator = init_inmemory_model_storage if inmemory else None
32 initiator_kwargs = {} if inmemory else dict(base_dir=tmpdir)
33 topology = topology or create_simple_topology_two_nodes
35 model_storage = aria.application_model_storage(
36 sql_mapi.SQLAlchemyModelAPI, initiator=initiator, initiator_kwargs=initiator_kwargs)
37 resource_storage = aria.application_resource_storage(
38 filesystem_rapi.FileSystemResourceAPI,
39 api_kwargs=dict(directory=os.path.join(tmpdir, 'resources'))
42 service_id = topology(model_storage)
43 execution = models.create_execution(model_storage.service.get(service_id))
44 model_storage.execution.put(execution)
47 name='simple_context',
48 model_storage=model_storage,
49 resource_storage=resource_storage,
50 service_id=service_id,
51 workflow_name=models.WORKFLOW_NAME,
52 execution_id=execution.id,
53 task_max_attempts=models.TASK_MAX_ATTEMPTS,
54 task_retry_interval=models.TASK_RETRY_INTERVAL
56 final_kwargs.update(context_kwargs or {})
57 return context.workflow.WorkflowContext(**final_kwargs)