Ejemplo n.º 1
0
def update(id, solution):
    """
    This function updates an existing solutions in the solutions list

    :param key:    key of the solutions to update in the solutions list
    :param solutions:   solutions to update
    :return:       updated solutions
    """

    app.logger.debug(solution)

    # Does the solutions exist in solutions list?
    existing_solution = Solution.query.filter(Solution.id == id).one_or_none()

    # Does solutions exist?

    if existing_solution is not None:
        schema = SolutionSchema()
        update_solution = schema.load(solution, session=db.session)
        update_solution.key = solution['id']
        update_solution.lastUpdated = ModelTools.get_utc_timestamp()

        db.session.merge(update_solution)
        db.session.commit()

        # return the updted solutions in the response
        data = schema.dump(update_solution)
        return data, 200

    # otherwise, nope, deployment doesn't exist, so that's an error
    else:
        abort(404, f"Solution not found")
Ejemplo n.º 2
0
def deployment_update(oid, solutionDeploymentDetails):
    """
    Updates an existing solutions in the solutions list with the deployed status.

    :param key:    id of the solution
    :param solutionDetails:   solution details to update
    :return:       updated solution
    """

    app.logger.debug(solutionDeploymentDetails)

    # Does the solutions exist in solutions list?
    existing_solution = Solution.query.filter(Solution.id == oid).one_or_none()

    # Does solutions exist?

    if existing_solution is not None:
        schema = SolutionSchema()
        update_solution = schema.load(solutionDeploymentDetails,
                                      session=db.session)
        update_solution.key = solutionDeploymentDetails['id']
        update_solution.lastUpdated = ModelTools.get_utc_timestamp()
        update_solution.deployed = solutionDeploymentDetails['deployed']

        db.session.merge(update_solution)
        db.session.commit()

        # return the updted solutions in the response
        data = schema.dump(update_solution)
        return data, 200

    # otherwise, nope, deployment doesn't exist, so that's an error
    else:
        abort(404, f"Solution {oid} not found")
Ejemplo n.º 3
0
def deployment_update(oid, solutionDeploymentDetails):
    """
    Updates an existing solutions in the solutions list with the deployed status.

    :param key:    id of the solution
    :param solutionDetails:   solution details to update
    :return:       updated solution
    """
    logger.debug(solutionDeploymentDetails)

    # Does the solutions exist in solutions list?
    existing_solution = (db.session.query(Solution).filter(
        Solution.id == oid).one_or_none())

    # Does solutions exist?

    if existing_solution is not None:
        schema = SolutionSchema(many=False)
        update_solution = schema.load(solutionDeploymentDetails,
                                      session=db.session)
        update_solution.id = oid
        update_solution.lastUpdated = ModelTools.get_utc_timestamp()
        update_solution.deployed = solutionDeploymentDetails.get(
            "deployed", existing_solution.deployed)
        update_solution.deploymentState = solutionDeploymentDetails.get(
            "deploymentState", existing_solution.deploymentState)
        update_solution.statusId = solutionDeploymentDetails.get(
            "statusId", existing_solution.statusId)
        update_solution.statusCode = solutionDeploymentDetails.get(
            "statusCode", existing_solution.statusCode)
        update_solution.statusMessage = solutionDeploymentDetails.get(
            "statusMessage", existing_solution.statusMessage)
        update_solution.taskId = solutionDeploymentDetails.get(
            "taskId", existing_solution.taskId)
        update_solution.deploymentFolderId = solutionDeploymentDetails.get(
            "deploymentFolderId", existing_solution.deploymentFolderId)
        update_solution.isSandbox = solutionDeploymentDetails.get(
            "isSandbox", existing_solution.isSandbox)

        db.session.merge(update_solution)
        db.session.commit()

        # return the updted solutions in the response
        schema = SolutionDeploymentSchema(many=False)
        data = schema.dump(update_solution)
        return data, 200

    # otherwise, nope, deployment doesn't exist, so that's an error
    else:
        abort(404, f"Solution {oid} not found")
Ejemplo n.º 4
0
def create(solution):
    """
    This function creates a new solution in the solutions list
    based on the passed in solutions data

    :param solution:  solution to create in solutions list
    :return:        201 on success, 406 on solutions exists
    """

    app.logger.debug("Before")
    app.logger.debug(pformat(solution))

    lastUpdated = ModelTools.get_utc_timestamp()

    # Defaults
    if (solution.get('active') == None):
        solution['active'] = True

    if (solution.get('favourite') == None):
        solution['favourite'] = True

    if (solution.get('teams') == None):
        solution['teams'] = 0

    # Remove applications because Solutions don't have
    # any applications when they are first created
    if ('applications' in solution):
        del solution['applications']

    # we don't need the id, the is generated automatically on the database
    if ('id' in solution):
        del solution["id"]

    solution['lastUpdated'] = ModelTools.get_utc_timestamp()

    app.logger.debug("After")
    app.logger.debug(pformat(solution))

    schema = SolutionSchema()
    new_solution = schema.load(solution, session=db.session)
    db.session.add(new_solution)
    db.session.commit()

    # Serialize and return the newly created solution
    # in the response
    data = schema.dump(new_solution)
    return data, 201
Ejemplo n.º 5
0
def update(oid, solutionDetails):
    """
    Updates an existing solutions in the solutions list.

    :param key:    key of the solutions to update in the solutions list
    :param solutions:   solutions to update
    :return:       updated solutions
    """
    logger.debug("update::solutionDetails: %s", solutionDetails)
    with db_session() as dbs:
        # Does the solutions exist in solutions list?
        existing_solution = dbs.query(Solution).filter(
            Solution.id == oid).one_or_none()

        # Does solutions exist?

        if existing_solution is not None:
            solutionDetails["id"] = oid

            envs = solutionDetails.get("environments")
            # Remove envs as it's processed separately, but in the same transaction.
            if "environments" in solutionDetails:
                del solutionDetails["environments"]
                solution_extension.create_solution_environments(oid,
                                                                envs,
                                                                dbsession=dbs)
            schema = SolutionSchema(many=False)
            new_solution = schema.load(solutionDetails, session=dbs)
            new_solution.lastUpdated = ModelTools.get_utc_timestamp()
            dbs.merge(new_solution)
            dbs.commit()

            new_solution = solution_extension.expand_solution(new_solution,
                                                              dbsession=dbs)
            # return the updted solutions in the response
            schema = ExtendedSolutionSchema(many=False)
            data = schema.dump(new_solution)
            logger.debug("data: %s", data)
            return data, 200
            # otherwise, nope, deployment doesn't exist, so that's an error
        else:
            abort(404, f"Solution {oid} not found")
Ejemplo n.º 6
0
def deployment_create(solutionDeploymentDetails):
    """
    This function queries a solution forwards the request to the DaC

    :param solution:  id
    :return:        201 on success
    :               404 if solution not found
    :               500 if other failure
    """
    logger.debug(pformat(solutionDeploymentDetails))

    oid = solutionDeploymentDetails["id"]
    sol = db.session.query(Solution).filter(Solution.id == oid).one_or_none()

    if sol is None:
        abort(404, f"Solution with id {oid} not found".format(id=oid))

    if sol.deploymentState == DeploymentStatus.SUCCESS:
        resp_json = {"id": oid, "deploymentState": sol.deploymentState}
    else:
        schema = SolutionSchema(many=False)
        update_solution = schema.load(solutionDeploymentDetails,
                                      session=db.session)
        update_solution.id = oid
        update_solution.lastUpdated = ModelTools.get_utc_timestamp()
        update_solution.deployed = False
        update_solution.deploymentState = DeploymentStatus.PENDING
        update_solution.taskId = None
        db.session.merge(update_solution)
        db.session.commit()
        resp_json = {
            "id": oid,
            "deploymentState": update_solution.deploymentState
        }
        # This step is in a separate thread.
        db.session.close()
        executor.submit(start_deployment, sol.id)

    return make_response(resp_json, 200)
Ejemplo n.º 7
0
def update(oid, solutionDetails):
    """
    Updates an existing solutions in the solutions list.

    :param key:    key of the solutions to update in the solutions list
    :param solutions:   solutions to update
    :return:       updated solutions
    """

    app.logger.debug(solutionDetails)

    # Does the solutions exist in solutions list?
    existing_solution = Solution.query.filter(Solution.id == oid).one_or_none()

    # Does solutions exist?

    if existing_solution is not None:
        solutionDetails['environments'] = json.dumps(
            solutionDetails.get('environments')
            or existing_solution.environments)
        schema = SolutionSchema()
        update_solution = schema.load(solutionDetails, session=db.session)
        update_solution.key = solutionDetails.get('id', oid)
        update_solution.lastUpdated = ModelTools.get_utc_timestamp()

        db.session.merge(update_solution)
        db.session.commit()

        # return the updted solutions in the response
        schema = ExtendedSolutionSchema(many=False)
        print(">>>>>  " + pformat(solutionDetails))
        solutionDetails['environments'] = json.loads(
            solutionDetails['environments'])
        data = schema.dump(solutionDetails)
        return data, 200

    # otherwise, nope, deployment doesn't exist, so that's an error
    else:
        abort(404, f"Solution not found")
Ejemplo n.º 8
0
def create(solutionDetails):
    """
    This function creates a new solution in the solutions list
    based on the passed in solutions data

    :param solution:  solution to create in solutions list
    :return:        201 on success, 406 on solutions exists
    """

    # Defaults
    if (solutionDetails.get('active') == None):
        solutionDetails['active'] = True

    if (solutionDetails.get('favourite') == None):
        solutionDetails['favourite'] = True

    if (solutionDetails.get('teams') == None):
        solutionDetails['teams'] = 0

    if (solutionDetails.get('deployed') == None):
        solutionDetails['deployed'] = False

    if (solutionDetails.get('deploymentState') == None):
        solutionDetails['deploymentState'] = ""

    if (solutionDetails.get('statusId') == None):
        solutionDetails['statusId'] = 0

    if (solutionDetails.get('statusCode') == None):
        solutionDetails['statusCode'] = ""

    if (solutionDetails.get('statusMessage') == None):
        solutionDetails['statusMessage'] = ""

    # Remove applications because Solutions don't have
    # any applications when they are first created
    if ('applications' in solutionDetails):
        del solutionDetails['applications']

    # we don't need the id, the is generated automatically on the database
    if ('id' in solutionDetails):
        del solutionDetails["id"]

    solutionDetails['lastUpdated'] = ModelTools.get_utc_timestamp()
    solutionDetails['environments'] = json.dumps(
        solutionDetails.get('environments') or [])

    print("Create name 2: " + solutionDetails['name'])

    schema = SolutionSchema(many=False)
    new_solution = schema.load(solutionDetails, session=db.session)
    db.session.add(new_solution)
    db.session.commit()

    print("Create name 3: " + new_solution.name)

    # Serialize and return the newly created solution
    # in the response

    print(pformat(solutionDetails['environments']))

    print("create solution")
    print(pformat(new_solution))
    print(pformat(new_solution.environments))

    schema = ExtendedSolutionSchema()
    data = schema.dump(new_solution)
    return data, 201
Ejemplo n.º 9
0
def create(solutionDetails):
    """
    This function creates a new solution in the solutions list
    based on the passed in solutions data

    :param solution:  solution to create in solutions list
    :return:        201 on success, 406 on solutions exists
    """
    data = None
    with db_session() as dbs:
        # Defaults
        if solutionDetails.get("isActive") is None:
            solutionDetails["isActive"] = True

        if solutionDetails.get("isFavourite") is None:
            solutionDetails["isFavourite"] = False

        if solutionDetails.get("deployed") is None:
            solutionDetails["deployed"] = False

        if solutionDetails.get("deploymentState") is None:
            solutionDetails["deploymentState"] = ""

        if solutionDetails.get("statusId") is None:
            solutionDetails["statusId"] = 0

        if solutionDetails.get("statusCode") is None:
            solutionDetails["statusCode"] = ""

        if solutionDetails.get("statusMessage") is None:
            solutionDetails["statusMessage"] = ""

        if solutionDetails.get("isSandbox") is None:
            solutionDetails["isSandbox"] = False

        # Remove applications because Solutions don't have
        # any applications when they are first created
        if "applications" in solutionDetails:
            del solutionDetails["applications"]

        # we don't need the id, the is generated automatically on the database
        if "id" in solutionDetails:
            del solutionDetails["id"]

        solutionDetails["lastUpdated"] = ModelTools.get_utc_timestamp()
        envs = solutionDetails.get("environments")

        # Removing this as the below schema is not expecting this field.
        if "environments" in solutionDetails:
            del solutionDetails["environments"]

        schema = SolutionSchema(many=False)

        new_solution = schema.load(solutionDetails, session=dbs)
        new_solution.lastUpdated = ModelTools.get_utc_timestamp()
        dbs.add(new_solution)
        dbs.flush()
        if envs:
            solution_extension.create_solution_environments(new_solution.id,
                                                            envs,
                                                            dbsession=dbs)
        new_solution = solution_extension.expand_solution(new_solution,
                                                          dbsession=dbs)
        schema = ExtendedSolutionSchema()
        data = schema.dump(new_solution)

    # Serialize and return the newly created solution
    # in the response

    return data, 201