Пример #1
0
def _generate_data(request,
                   output_view_provider,
                   experiment_output,
                   experiment,
                   **kwargs):
    # TODO: handle URI_COLLECTION also
    logger.debug("getting data product for {}".format(experiment_output.value))
    output_file = None
    test_output_file = getattr(output_view_provider,
                               'test_output_file',
                               None)
    if (experiment_output.value and
        experiment_output.type in (DataType.URI,
                                   DataType.STDOUT,
                                   DataType.STDERR) and
            experiment_output.value.startswith("airavata-dp")):
        data_product = request.airavata_client.getDataProduct(
            request.authz_token, experiment_output.value)
        if user_storage.exists(request, data_product):
            output_file = user_storage.open_file(request, data_product)
        elif settings.DEBUG and test_output_file is not None:
            output_file = open(test_output_file, 'rb')
    # TODO: change interface to provide output_file as a path
    # TODO: convert experiment and experiment_output to dict/JSON
    data = output_view_provider.generate_data(request,
                                              experiment_output,
                                              experiment,
                                              output_file=output_file,
                                              **kwargs)
    _process_interactive_params(data)
    return data
 def get_downloadURL(self, data_product):
     """Getter for downloadURL field."""
     request = self.context['request']
     if user_storage.exists(request, data_product):
         return (request.build_absolute_uri(
             reverse('django_airavata_api:download_file')) + '?' +
                 urlencode({'data-product-uri': data_product.productUri}))
     return None
def _generate_data(request,
                   output_view_provider,
                   experiment_output,
                   experiment,
                   test_mode=False,
                   **kwargs):
    output_files = []
    # test_mode can only be used in DEBUG=True mode
    if test_mode and settings.DEBUG:
        test_output_file = getattr(output_view_provider,
                                   'test_output_file',
                                   None)
        if test_output_file is None:
            raise Exception(f"test_output_file is not set on {output_view_provider}")
        logger.info(f"Using {test_output_file} instead of regular output file")
        output_file = open(test_output_file, 'rb')
        output_files.append(output_file)

    elif (experiment_output.value and
          experiment_output.type in (DataType.URI,
                                     DataType.URI_COLLECTION,
                                     DataType.STDOUT,
                                     DataType.STDERR) and
            experiment_output.value.startswith("airavata-dp")):
        data_product_uris = experiment_output.value.split(",")
        data_products = map(lambda dpid:
                            request.airavata_client.getDataProduct(request.authz_token,
                                                                   dpid),
                            data_product_uris)
        for data_product in data_products:
            if user_storage.exists(request, data_product):
                output_file = user_storage.open_file(request, data_product)
                output_files.append(output_file)

    generate_data_func = output_view_provider.generate_data
    method_sig = inspect.signature(generate_data_func)
    if 'output_files' in method_sig.parameters:
        generate_data_func = partial(generate_data_func, output_files=output_files)
    # TODO: convert experiment and experiment_output to dict/JSON
    data = generate_data_func(request,
                              experiment_output,
                              experiment,
                              output_file=output_files[0] if len(output_files) > 0 else None,
                              **kwargs)
    _process_interactive_params(data)
    return data
Пример #4
0
def create_experiment(request, app_module_id):
    request.active_nav_item = 'dashboard'

    # User input files can be passed as query parameters
    # <input name>=<path/to/user_file>
    # and also as data product URIs
    # <input name>=<data product URI>
    app_interface = ApplicationModuleViewSet.as_view(
        {'get': 'application_interface'})(request, app_module_id=app_module_id)
    if app_interface.status_code != 200:
        raise Exception("Failed to load application module data: {}".format(
            app_interface.data['detail']))
    user_input_values = {}
    for app_input in app_interface.data['applicationInputs']:
        if (app_input['type'] == DataType.URI
                and app_input['name'] in request.GET):
            user_file_value = request.GET[app_input['name']]
            try:
                user_file_url = urlparse(user_file_value)
                if user_file_url.scheme == 'airavata-dp':
                    dp_uri = user_file_value
                    try:
                        data_product = request.airavata_client.getDataProduct(
                            request.authz_token, dp_uri)
                        if user_storage_sdk.exists(request, data_product):
                            user_input_values[app_input['name']] = dp_uri
                    except Exception:
                        logger.exception(
                            f"Failed checking data product uri: {dp_uri}")
            except ValueError:
                logger.exception(f"Invalid user file value: {user_file_value}")
        elif (app_input['type'] == DataType.STRING
              and app_input['name'] in request.GET):
            name = app_input['name']
            user_input_values[name] = request.GET[name]
    context = {
        'bundle_name': 'create-experiment',
        'app_module_id': app_module_id,
        'user_input_values': json.dumps(user_input_values)
    }
    if 'experiment-data-dir' in request.GET:
        context['experiment_data_dir'] = request.GET['experiment-data-dir']

    return render(request, 'django_airavata_workspace/create_experiment.html',
                  context)