Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/spring/azext_spring/migration/converter/conversion_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,35 @@ def set_params_for_converter(self, converter_type, params):
converter.set_params(params)

def run_converters(self, source):
converted_contents = []
converted_contents = {}
source_wrapper = SourceDataWrapper(source)
# converted_contents.append(self.get_converter(MainConverter).convert(None))
converted_contents.append(
self.get_converter(EnvironmentConverter).convert(
source_wrapper.get_resources_by_type('Microsoft.AppPlatform/Spring')[0]
)
converted_contents[self.get_converter(MainConverter).get_template_name()] = self.get_converter(MainConverter).convert(
source_wrapper.get_resources_by_type('Microsoft.AppPlatform/Spring/apps')
)
converted_contents[self.get_converter(EnvironmentConverter).get_template_name()] = self.get_converter(EnvironmentConverter).convert(
source_wrapper.get_resources_by_type('Microsoft.AppPlatform/Spring')[0]
)
# converted_contents.append(
# self.get_converter(AppConverter).convert(
# source_wrapper.get_resources_by_type('Microsoft.AppPlatform/apps')
# source_wrapper.get_resources_by_type('Microsoft.AppPlatform/Spring/apps')
# )
# )
# converted_contents.append(
# self.get_converter(RevisionConverter).convert(
# source_wrapper.get_resources_by_type('Microsoft.AppPlatform/apps/deployments')
# source_wrapper.get_resources_by_type('Microsoft.AppPlatform/Spring/apps/deployments')
# )
# )
converted_contents.append(self.get_converter(ReadMeConverter).convert(None))
converted_contents[self.get_converter(ReadMeConverter).get_template_name()] = self.get_converter(ReadMeConverter).convert(None)
return converted_contents

def save_to_files(self, converted_contents, output_path):
print("Start to save the converted content to files ...")
os.makedirs(os.path.dirname(output_path), exist_ok=True)
for i, content in enumerate(converted_contents):
filename = f"{output_path}/export_script_{i+1}.bicep"
with open(filename, 'w', encoding='utf-8') as output_file:
print("Start to generate the {filename} file ...")

for filename, content in converted_contents.items():
output_filename = f"{output_path}/{filename}"
with open(output_filename, 'w', encoding='utf-8') as output_file:
print(f"Start to generate the {output_filename} file ...")
output_file.write(content)

class SourceDataWrapper:
Expand Down
13 changes: 11 additions & 2 deletions src/spring/azext_spring/migration/converter/main_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
# Concrete Converter Subclass for Read Me
class MainConverter(ConverterTemplate):
def load_source(self, source):
pass
self.source = []
for resource in source:
print("resource: ", resource)
self.source.append(resource)

def calculate_data(self):
pass
self.data.setdefault("apps", [])
for app in self.source:
self.data["apps"].append({
"name": app["name"],
})
print("app: ", app)
print(self.data["apps"])

def get_template_name(self):
return "main.bicep"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Env
param containerAppEnvName string
param location string
param apps array

param workloadProfileName string
param workloadProfileType string

Expand All @@ -15,10 +15,11 @@ module containerAppEnv 'environment.bicep' = {
}
}

module appModule 'app.bicep' = [for app in apps: {
name: '${app.name}'
dependsOn: [containerAppEnv]
{% for app in data.apps %}
module {{ app.name }} 'app-{{ app.name }}.bicep' = {
name: '{{ app.name }}'
params: {
containerAppEnvId: containerAppEnv.outputs.containerAppEnvId
}
}]
}
{% endfor %}
4 changes: 3 additions & 1 deletion src/spring/azext_spring/migration/migration_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
from .converter.revision_converter import RevisionConverter
from .converter.gateway_converter import GatewayConverter
from .converter.readme_converter import ReadMeConverter
from .converter.main_converter import MainConverter

logger = get_logger(__name__)


def migration_aca_start(cmd, client, resource_group, service):
# API calls
print("Start API calls to get ASA service, apps and deployments...")
print("Start export ARM template for ASA service...")
asa_arm = export_asa_arm_template(cmd, resource_group, service)

# Create context and add converters
context = ConversionContext()
context.add_converter(MainConverter())
context.add_converter(EnvironmentConverter())
context.add_converter(AppConverter())
context.add_converter(RevisionConverter())
Expand Down