Exemplo n.º 1
0
    def _prepare_and_process_doc(self, data_id, blueprint_url,
                                 application_file_name):
        # Put a temporary blueprint entry in DB
        rm = get_resource_manager()
        now = get_formatted_timestamp()
        temp_blueprint = rm.sm.put(
            Blueprint(plan=None,
                      id=data_id,
                      description=None,
                      created_at=now,
                      updated_at=now,
                      main_file_name=None,
                      visibility=None,
                      state=BlueprintUploadState.VALIDATING))

        if not blueprint_url:
            self.upload_archive_to_file_server(data_id)

        try:
            temp_blueprint.upload_execution = rm.upload_blueprint(
                data_id,
                application_file_name,
                blueprint_url,
                config.instance.file_server_root,  # for the import resolver
                validate_only=True,
            )
        except manager_exceptions.ExistingRunningExecutionError:
            rm.sm.delete(temp_blueprint)
            self.cleanup_blueprint_archive_from_file_server(
                data_id, current_tenant.name)
            raise
Exemplo n.º 2
0
def _get_or_create_blueprint(storage_manager, blueprint_id):
    try:
        return storage_manager.get(Blueprint, blueprint_id)
    except manager_exceptions.NotFoundError:
        blueprint = Blueprint(id=blueprint_id,
                              created_at=datetime.now(),
                              main_file_name='',
                              plan={})
        return storage_manager.put(blueprint)
Exemplo n.º 3
0
 def _add_blueprint_if_not_exists(sm, blueprint_id):
     try:
         sm.get_blueprint(blueprint_id)
     except manager_exceptions.NotFoundError:
         sm.put_blueprint(
             Blueprint(id=blueprint_id,
                       created_at=datetime.now(),
                       main_file_name='',
                       plan={}))
Exemplo n.º 4
0
    def _prepare_and_process_doc(self,
                                 data_id,
                                 visibility,
                                 blueprint_url,
                                 application_file_name,
                                 override_failed_blueprint,
                                 labels=None):
        # Put a new blueprint entry in DB
        now = get_formatted_timestamp()
        rm = get_resource_manager()
        if override_failed_blueprint:
            new_blueprint = rm.sm.get(Blueprint, data_id)
            new_blueprint.plan = None
            new_blueprint.description = None
            new_blueprint.created_at = now
            new_blueprint.updated_at = now
            new_blueprint.main_file_name = None
            new_blueprint.visibility = visibility
            new_blueprint.state = BlueprintUploadState.PENDING
            rm.sm.update(new_blueprint)
        else:
            new_blueprint = rm.sm.put(
                Blueprint(plan=None,
                          id=data_id,
                          description=None,
                          created_at=now,
                          updated_at=now,
                          main_file_name=None,
                          visibility=visibility,
                          state=BlueprintUploadState.PENDING))

        if not blueprint_url:
            new_blueprint.state = BlueprintUploadState.UPLOADING
            rm.sm.update(new_blueprint)
            self.upload_archive_to_file_server(data_id)

        try:
            new_blueprint.upload_execution = rm.upload_blueprint(
                data_id,
                application_file_name,
                blueprint_url,
                config.instance.file_server_root,  # for the import resolver
                labels=labels)
            rm.sm.update(new_blueprint)
        except manager_exceptions.ExistingRunningExecutionError as e:
            new_blueprint.state = BlueprintUploadState.FAILED_UPLOADING
            new_blueprint.error = str(e)
            new_blueprint.error_traceback = traceback.format_exc()
            rm.sm.update(new_blueprint)
            self.cleanup_blueprint_archive_from_file_server(
                data_id, current_tenant.name)
            raise
        return new_blueprint