bundle.get('group_permissions', []))

    if 'children' in include_set:
        for bundle in bundles:
            json_api_include(document, BundleSchema(),
                             bundle.get('children', []))

    if 'host_worksheets' in include_set:
        for bundle in bundles:
            json_api_include(document, WorksheetSchema(),
                             bundle.get('host_worksheets', []))

    return document


@post('/bundles', apply=AuthenticatedProtectedPlugin())
def _create_bundles():
    """
    Bulk create bundles.

    Query parameters:
    - `worksheet`: UUID of the parent worksheet of the new bundle, add to
      this worksheet if not detached or shadowing another bundle. The new
      bundle also inherits permissions from this worksheet.
    - `shadow`: UUID of the bundle to "shadow" (the new bundle will be added
      as an item immediately after this bundle in its parent worksheet).
    - `detached`: 1 if should not add new bundle to any worksheet,
      or 0 otherwise. Default is 0.
    - `wait_for_upload`: 1 if the bundle state should be initialized to
      "uploading" regardless of the bundle type, or 0 otherwise. Used when
      copying bundles from another CodaLab instance, this prevents these new
Example #2
0
"""
Worksheets REST API Groups Views.
"""
import http.client

from bottle import abort, get, delete, post, request, local

from codalab.common import UsageError
from codalab.lib.server_util import json_api_include
from codalab.rest.schemas import GroupSchema, UserSchema
from codalab.rest.util import ensure_unused_group_name, get_group_info, get_resource_ids
from codalab.server.authenticated_plugin import AuthenticatedProtectedPlugin


@get('/groups/<group_spec>', apply=AuthenticatedProtectedPlugin())
def fetch_group(group_spec):
    """Fetch a single group."""
    group = get_group_info(group_spec, need_admin=False, access_all_groups=True)
    load_group_members(group)
    document = GroupSchema().dump(group).data
    include_group_relationships(document, [group])
    return document


@get('/groups', apply=AuthenticatedProtectedPlugin())
def fetch_groups():
    """Fetch list of groups readable by the authenticated user."""
    if request.user.user_id == local.model.root_user_id:
        groups = local.model.batch_get_all_groups(None, {'user_defined': True}, None)
    else:
        groups = local.model.batch_get_all_groups(
)  # Without this line "from worker.worker import VERSION" doesn't work.
from contextlib import closing
import http.client
import json
from datetime import datetime

from bottle import abort, get, local, post, request, response

from codalab.lib import spec_util
from codalab.objects.permission import check_bundle_have_run_permission
from codalab.server.authenticated_plugin import AuthenticatedProtectedPlugin
from codalab.worker.bundle_state import BundleCheckinState
from codalab.worker.main import DEFAULT_EXIT_AFTER_NUM_RUNS


@post("/workers/<worker_id>/checkin", name="worker_checkin", apply=AuthenticatedProtectedPlugin())
def checkin(worker_id):
    """
    Checks in with the bundle service, storing information about the worker.
    Waits for a message for the worker for WAIT_TIME_SECS seconds. Returns the
    message or None if there isn't one.
    """
    WAIT_TIME_SECS = 3.0

    # Old workers might not have all the fields, so allow subsets to be missing.
    socket_id = local.worker_model.worker_checkin(
        request.user.user_id,
        worker_id,
        request.json.get("tag"),
        request.json.get("group_name"),
        request.json.get("cpus"),
"""
Worksheets REST API Groups Views.
"""
import http.client

from bottle import abort, get, delete, post, request, local

from codalab.common import UsageError
from codalab.lib.server_util import json_api_include
from codalab.rest.schemas import GroupSchema, UserSchema
from codalab.rest.util import ensure_unused_group_name, get_group_info, get_resource_ids
from codalab.server.authenticated_plugin import AuthenticatedProtectedPlugin


@get('/groups/<group_spec>', apply=AuthenticatedProtectedPlugin())
def fetch_group(group_spec):
    """Fetch a single group."""
    group = get_group_info(group_spec,
                           need_admin=False,
                           access_all_groups=True)
    load_group_members(group)
    document = GroupSchema().dump(group).data
    include_group_relationships(document, [group])
    return document


@get('/groups', apply=AuthenticatedProtectedPlugin())
def fetch_groups():
    """Fetch list of groups readable by the authenticated user."""
    if request.user.user_id == local.model.root_user_id:
        groups = local.model.batch_get_all_groups(None, {'user_defined': True},
Example #5
0
import http.client
import json
from datetime import datetime

from bottle import abort, get, local, post, request, response

from codalab.lib import spec_util
from codalab.objects.permission import check_bundle_have_run_permission
from codalab.server.authenticated_plugin import AuthenticatedProtectedPlugin
from codalab.worker.bundle_state import BundleCheckinState
from codalab.worker.main import DEFAULT_EXIT_AFTER_NUM_RUNS


@post("/workers/<worker_id>/checkin",
      name="worker_checkin",
      apply=AuthenticatedProtectedPlugin())
def checkin(worker_id):
    """
    Checks in with the bundle service, storing information about the worker.
    Waits for a message for the worker for WAIT_TIME_SECS seconds. Returns the
    message or None if there isn't one.
    """
    WAIT_TIME_SECS = 3.0

    # Old workers might not have all the fields, so allow subsets to be missing.
    socket_id = local.worker_model.worker_checkin(
        request.user.user_id,
        worker_id,
        request.json.get("tag"),
        request.json.get("group_name"),
        request.json.get("cpus"),
from bottle import local, post, request

from codalab.common import UsageError, precondition
from codalab.lib.bundle_action import BundleAction
from codalab.objects.permission import check_bundles_have_all_permission
from codalab.rest.schemas import BundleActionSchema
from codalab.server.authenticated_plugin import AuthenticatedProtectedPlugin
from codalab.worker.bundle_state import State


@post('/bundle-actions', apply=AuthenticatedProtectedPlugin())
def create_bundle_actions():
    """
    Sends the message to the worker to do the bundle action, and adds the
    action string to the bundle metadata.
    """
    actions = BundleActionSchema(strict=True, many=True).load(request.json).data

    check_bundles_have_all_permission(local.model, request.user, [a['uuid'] for a in actions])
    for action in actions:
        bundle = local.model.get_bundle(action['uuid'])
        if bundle.state in [State.READY, State.FAILED, State.KILLED]:
            raise UsageError(
                'Cannot execute this action on a bundle that is in the following states: ready, failed, killed. '
                'Kill action can be executed on bundles in created, uploading, staged, making, starting, '
                'running, preparing, or finalizing state.'
            )

        worker = local.model.get_bundle_worker(action['uuid'])
        new_actions = getattr(bundle.metadata, 'actions', []) + [BundleAction.as_string(action)]
        if owner_ids:
            json_api_include(
                document, UserSchema(),
                local.model.get_users(user_ids=owner_ids)['results'])

    # Include permissions
    if 'group_permissions' in include_set:
        for w in worksheets:
            if 'group_permissions' in w:
                json_api_include(document, WorksheetPermissionSchema(),
                                 w['group_permissions'])

    return document


@post('/worksheets', apply=AuthenticatedProtectedPlugin())
def create_worksheets():
    # TODO: support more attributes
    worksheets = (
        WorksheetSchema(strict=True, many=True).load(
            request.json).data  # only allow name for now
    )

    for w in worksheets:
        w['uuid'] = new_worksheet(w['name'])

    return WorksheetSchema(many=True).dump(worksheets).data


@put('/worksheets/<uuid:re:%s>/raw' % spec_util.UUID_STR,
     apply=ProtectedPlugin())