示例#1
0
def get_project_info(project_name):
    """
    Makes a REST call to hopsworks to get all metadata of a project for the provided project.

    Args:
        :project_name: the name of the project

    Returns:
        JSON response

    Raises:
        :RestAPIError: if there was an error in the REST call to Hopsworks
    """
    return util.http(constants.DELIMITERS.SLASH_DELIMITER +
                     constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER +
                     constants.REST_CONFIG.HOPSWORKS_PROJECT_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER +
                     constants.REST_CONFIG.HOPSWORKS_PROJECT_INFO_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER +
                     project_name)
示例#2
0
def _get_credentials(project_id):
    """
    Makes a REST call to hopsworks for getting the project user certificates needed to connect to services such as Hive

    Args:
        :project_name: id of the project

    Returns:
        JSON response

    Raises:
        :RestAPIError: if there was an error in the REST call to Hopsworks
    """
    return util.http(
        constants.DELIMITERS.SLASH_DELIMITER +
        constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE +
        constants.DELIMITERS.SLASH_DELIMITER +
        constants.REST_CONFIG.HOPSWORKS_PROJECT_RESOURCE +
        constants.DELIMITERS.SLASH_DELIMITER + project_id +
        constants.DELIMITERS.SLASH_DELIMITER +
        constants.REST_CONFIG.HOPSWORKS_PROJECT_CREDENTIALS_RESOURCE)
示例#3
0
def get_project_info(project_name):
    """
    Makes a REST call to hopsworks to get all metadata of a project for the provided project.

    Args:
        :project_name: the name of the project

    Returns:
        JSON response
        See https://github.com/logicalclocks/hopsworks-ee/blob/master/hopsworks-common/src/main/java/io/hops/hopsworks/common/project/ProjectDTO.java

    Raises:
        :RestAPIError: if there was an error in the REST call to Hopsworks
    """
    return util.http(constants.DELIMITERS.SLASH_DELIMITER +
                     constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE +
                     constants.DELIMITERS.SLASH_DELIMITER +
                     constants.REST_CONFIG.HOPSWORKS_PROJECT_RESOURCE +
                     constants.DELIMITERS.SLASH_DELIMITER +
                     constants.REST_CONFIG.HOPSWORKS_PROJECT_INFO_RESOURCE +
                     constants.DELIMITERS.SLASH_DELIMITER + project_name)
示例#4
0
def create(new_project, owner=None):
    """
    Creates a project in Hopsworks.

    >>> from hops import util, project
    >>> new_project = {"projectName": "MyProject4", "description": "", "retentionPeriod": "", "status": 0,
    >>>                "services": ["JOBS", "KAFKA", "JUPYTER", "HIVE", "SERVING", "FEATURESTORE", "AIRFLOW"]}
    >>>
    >>> util.connect("localhost", api_key="api_key_file")
    >>> project.create(new_project)

    Args:
        :new_project: A dictionary with the new project attributes.
        :owner: Create a project for another user (owner). Only admin user can use this option.

    Returns:
        JSON response

    Raises:
        :RestAPIError: if there was an error in the REST call to Hopsworks
    """
    if owner is None:
        project_endpoint = constants.REST_CONFIG.HOPSWORKS_PROJECT_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                           "?projectName=" + new_project['projectName']
    else:
        project_endpoint = constants.REST_CONFIG.HOPSWORKS_ADMIN_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                           constants.REST_CONFIG.HOPSWORKS_PROJECT_RESOURCE + "s" + \
                           constants.DELIMITERS.SLASH_DELIMITER + "createas"
        new_project["owner"] = owner

    headers = {
        constants.HTTP_CONFIG.HTTP_CONTENT_TYPE:
        constants.HTTP_CONFIG.HTTP_APPLICATION_JSON
    }
    return util.http(constants.DELIMITERS.SLASH_DELIMITER +
                     constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE +
                     constants.DELIMITERS.SLASH_DELIMITER + project_endpoint,
                     headers=headers,
                     method=constants.HTTP_CONFIG.HTTP_POST,
                     data=json.dumps(new_project))
示例#5
0
def stop_job(name):
    """
    Stop the current execution of the job.
    Returns:
        The job status.
    """
    method = constants.HTTP_CONFIG.HTTP_PUT
    headers = {
        constants.HTTP_CONFIG.HTTP_CONTENT_TYPE:
        constants.HTTP_CONFIG.HTTP_APPLICATION_JSON
    }
    resource_url = constants.DELIMITERS.SLASH_DELIMITER + \
                   constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                   constants.REST_CONFIG.HOPSWORKS_PROJECT_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                   hdfs.project_id() + constants.DELIMITERS.SLASH_DELIMITER + \
                   constants.REST_CONFIG.HOPSWORKS_JOBS_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                   name + constants.DELIMITERS.SLASH_DELIMITER + \
                   constants.REST_CONFIG.HOPSWORKS_EXECUTIONS_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                   "{EXECUTION_ID}" + constants.DELIMITERS.SLASH_DELIMITER + \
                   "status"

    status = {"status": "stopped"}
    # If no execution_id was provided, stop all active executions
    # Get all active execution IDs
    executions = get_executions(
        name,
        "?filter_by=state:INITIALIZING,RUNNING,ACCEPTED,NEW,NEW_SAVING,SUBMITTED,"
        "STARTING_APP_MASTER")
    responses = []
    if executions['count'] > 0:
        for execution in executions['items']:
            responses.append(
                util.http(
                    resource_url.replace("{EXECUTION_ID}",
                                         str(execution['id'])), headers,
                    method, json.dumps(status)))
    return responses
示例#6
0
def create_user(new_user):
    """
    Create a user in Hopsworks. Registers and activates a user with role HOPS_USER.

    Example usage:

    >>> from hops import util, user
    >>> new_user = {"firstName":"Joe","lastName":"Doe","email":"*****@*****.**","telephoneNum":"",
    >>>             "chosenPassword":"******","repeatedPassword":"******",
    >>>             "securityQuestion":"What is your oldest sibling's middle name?","securityAnswer":"Admin123",
    >>>             "tos":"true","authType":"Mobile","twoFactor":"false","toursEnabled":"true","orgName":"","dep":"",
    >>>             "street":"","city":"","postCode":"","country":"","testUser":"******"}
    >>> util.connect("localhost", api_key="api_key_file")
    >>> user.create(new_user)

    Args:
        :new_user: Dict with the new user attributes

    Returns:
        None
    """
    headers = {
        constants.HTTP_CONFIG.HTTP_CONTENT_TYPE:
        constants.HTTP_CONFIG.HTTP_APPLICATION_JSON
    }
    # Register user
    util.http(constants.DELIMITERS.SLASH_DELIMITER + \
              constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
              constants.REST_CONFIG.HOPSWORKS_AUTH_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
              constants.REST_CONFIG.HOPSWORKS_AUTH_RESOURCE_REGISTER,
              headers=headers,
              method=constants.HTTP_CONFIG.HTTP_POST,
              data=json.dumps(new_user))

    # Get user id
    response = util.http(constants.DELIMITERS.SLASH_DELIMITER + \
                         constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                         constants.REST_CONFIG.HOPSWORKS_ADMIN_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                         constants.REST_CONFIG.HOPSWORKS_USERS_RESOURCE + "?filter_by=user_email:" + new_user["email"],
                         headers=headers,
                         method=constants.HTTP_CONFIG.HTTP_GET)
    user_profile = response['items'][0]
    user_profile["status"] = "VERIFIED_ACCOUNT"
    # Verify user
    util.http(constants.DELIMITERS.SLASH_DELIMITER + \
              constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
              constants.REST_CONFIG.HOPSWORKS_ADMIN_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
              constants.REST_CONFIG.HOPSWORKS_USERS_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
              str(user_profile['id']) + constants.DELIMITERS.SLASH_DELIMITER,
              headers=headers,
              method=constants.HTTP_CONFIG.HTTP_PUT,
              data=json.dumps(user_profile))
    # Accept user
    response = util.http(constants.DELIMITERS.SLASH_DELIMITER + \
                         constants.REST_CONFIG.HOPSWORKS_REST_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                         constants.REST_CONFIG.HOPSWORKS_ADMIN_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                         constants.REST_CONFIG.HOPSWORKS_USERS_RESOURCE + constants.DELIMITERS.SLASH_DELIMITER + \
                         str(user_profile['id']) + constants.DELIMITERS.SLASH_DELIMITER + "accepted",
                         headers=headers,
                         method=constants.HTTP_CONFIG.HTTP_PUT,
                         data=json.dumps(user_profile))
    print(response)