Esempio n. 1
0
    def updatedu(self,
                 du,
                 full_sync_flag="false",
                 directory_to_import_from=None):
        """Start Tool Update """
        dudata = du.get("du_data")
        builds = dudata.get('build')
        deployment_field = dudata.get('deployment_field')
        localDu = self.deploymentunitDB.GetDeploymentUnitByName(dudata["name"])
        du_id = str(localDu.get("_id"))
        try:
            if dudata.get("operation").lower() == "update":
                DuHelperService.add_update_du(dudata, du_id, self.logo_path,
                                              directory_to_import_from,
                                              self.full_logo_path, False)
                # HANLDE BUILD
                if builds is not None and len(builds) > 0:
                    builds_handled = [
                    ]  # WE need to deactivate all other builds
                    builds_not_to_process = []
                    for build in builds:
                        if build.get("to_process", "true").lower() == "true":
                            if build.get("to_process"): build.pop("to_process")
                            if build.get("to_process_reason"):
                                build.pop("to_process_reason")
                            BuildHelperService.add_update_build(
                                build, du_id,
                                join(
                                    directory_to_import_from,
                                    os.path.join("artifacts",
                                                 dudata["repository_to_use"])))
                            builds_handled.append(build["build_number"])
                        else:
                            builds_not_to_process.append(build["build_number"])
                    # SUPPOSE THE ACCOUNT SENDS 2 BUILDS THAT ARE  ACTIVE THEY WILL BE HANDLED
                    # BUT ALL OTHER BUILDS SHOULD BE MADE INACTIVE IN LOCAL
                    for build in self.buildsDB.get_all_builds(du_id):
                        if build["build_number"] not in builds_handled and build[
                                "build_number"] not in builds_not_to_process:
                            build_id = build.get("_id")
                            build["_id"] = {}
                            build["_id"]["oid"] = str(build_id)
                            build["status"] = "0"
                            self.buildsDB.update_build(build)

                # HANLDE DEPLOYMENT FIELDS
                if deployment_field is not None \
                        and len(deployment_field) > 0:
                    HelperServices.add_update_deployment_fields(
                        deployment_field['fields'], du_id)
            return {
                "result": "success",
                "message": dudata["name"] + " was updated"
            }
        except Exception as e_value:  # catch *all* exceptions
            traceback.print_exc()
            return {"result": "failed", "message": str(e_value)}
Esempio n. 2
0
 def put(self):
     deploymentUnitSet = request.get_json()
     if deploymentUnitSet.get("_id"):
         if type(deploymentUnitSet.get("_id")) is not dict:
             raise Exception("The type of _id is invalid")
         if not deploymentUnitSet.get("_id").get("oid"):
             raise Exception("oid was not found in _id")
     else:
         raise Exception("_id was not found in input request ")
     DuHelperService.add_update_du_set(deploymentUnitSet,
                                       deploymentUnitSet["_id"]["oid"],
                                       logo_path, logo_full_path)
     return {
         "result": "success",
         "message": "The DeploymentUnit Set is updated successfully"
     }, 200
Esempio n. 3
0
def deleteDeploymentUnitSet(id):
    isDeleted = DuHelperService.delete_du_set(id)
    return jsonify(
        json.loads(
            dumps({
                "result": "success",
                "message": "DeploymentUnit Set was deleted",
                "data": isDeleted
            }))), 200
Esempio n. 4
0
 def adddu(self, du, full_sync_flag="false", directory_to_import_from=None):
     """Start Tool Addition"""
     # MAINTAINING ARRAY TO MEMORISE INSERTED IDS
     inserted_du_list = []
     inserted_build_list = []
     inserted_deployment_fields_list = []
     dudata = du.get("du_data")
     deployment_field = dudata.get("deployment_field")
     builds = dudata.get("build")
     DuHelperService.check_if_du_exists(dudata)
     try:
         du_inserted = DuHelperService.add_update_du(
             dudata, None, self.logo_path, directory_to_import_from,
             self.full_logo_path, False)
         inserted_du_list.append(du_inserted)
         if deployment_field is not None and len(deployment_field) > 0:
             inserted_deployment_fields_list.append(
                 HelperServices.add_update_deployment_fields(
                     deployment_field["fields"], du_inserted))
         # preparing Build data
         if builds is not None and len(builds) > 0:
             for build in builds:
                 if build.get("to_process", "true").lower() == "true":
                     inserted_build_list.append(
                         BuildHelperService.add_update_build(
                             build, du_inserted,
                             join(
                                 directory_to_import_from,
                                 os.path.join(
                                     "artifacts",
                                     dudata["repository_to_use"]))))
         return {
             "result": "success",
             "message": dudata["name"] + " was inserted"
         }
     except Exception as e_value:  # catch *all* exceptions
         traceback.print_exc()
         for rec in inserted_deployment_fields_list:
             self.deploymentFieldsDB.DeleteDeploymentFields(rec)
         for rec in inserted_du_list:
             self.deploymentunitDB.DeleteDeploymentUnit(rec)
         for rec in inserted_build_list:
             self.buildsDB.delete_build(rec)
         return {"result": "failed", "message": str(e_value)}
Esempio n. 5
0
 def put(self):
     deploymentUnitData = request.get_json()
     if deploymentUnitData.get("_id"):
         if type(deploymentUnitData.get("_id")) is not dict:
             raise Exception("The type of _id is invalid")
         if not deploymentUnitData.get("_id").get("oid"):
             raise Exception("oid was not found in _id")
     else:
         raise Exception("_id was not found in input request ")
     DuHelperService.add_update_du(deploymentUnitData,
                                   deploymentUnitData["_id"]["oid"],
                                   logo_path, None, logo_full_path)
     return {
         "result": "success",
         "message": "The deploymentUnit is updated successfully",
         "data": {
             "_id": str(deploymentUnitData.get("_id").get("oid"))
         }
     }, 200
Esempio n. 6
0
 def handle_delete_operation(self, record, full_sync_flag,
                             directory_to_import_from):
     if full_sync_flag.lower() == "true":
         if record.get("tool_data"):
             return ToolHelperService.delete_tool(
                 record.get("tool_data").get("_id"), False)
         if record.get("du_data"):
             return DuHelperService.delete_du(
                 record.get("du_data").get("_id"), False)
         elif record.get("duset_data"):
             return DuHelperService.delete_du_set(
                 record.get("duset_data").get("_id"), False)
         elif record.get("state_data"):
             return StateHelperService.delete_state(
                 record.get("state_data").get("_id"), False)
     elif full_sync_flag.lower() == "false":
         return {
             "result": "success",
             "message": "Skipping as full_sync_flag is not true"
         }
     raise Exception("Processing:Conditions to process were not found")
Esempio n. 7
0
 def handle_extra_validations(self, record):
     # VALIDATE THE TOOL DETAILS
     if record.get("tool_data"):
         ToolHelperService.validate_tool_data(record.get("tool_data"))
         # Update tool Dependency
         tooldata = record.get("tool_data")
         if tooldata and tooldata.get("versions"):
             versions_list = []
             versions = tooldata.get("versions")
             if versions and len(versions) > 0:
                 for VersionsData in versions:
                     versions_list.append(
                         ToolHelperService.set_dependend_tools(
                             VersionsData, True))
                 record["tool_data"]["versions"] = versions_list
     elif record.get("du_data"):
         DuHelperService.validate_du_data(record.get("du_data"))
     elif record.get("duset_data"):
         DuHelperService.validate_duset_data(record.get("duset_data"))
     elif record.get("state_data"):
         StateHelperService.check_state_mandate_fields(
             record.get("state_data"))
     else:
         raise Exception("Validations:Conditions to process were not found")
Esempio n. 8
0
 def post(self):
     deploymentUnitData = request.get_json()
     if deploymentUnitDB.GetDeploymentUnitByName(
             deploymentUnitData.get("name")) is not None:
         raise Exception("DeploymentUnit with name " +
                         deploymentUnitData.get("name") + " already exists")
     du_id = DuHelperService.add_update_du(deploymentUnitData, None,
                                           logo_path, None, logo_full_path)
     return {
         "result": "success",
         "message": "DeploymentUnit was created successfully",
         "data": {
             "_id": du_id
         }
     }, 200
Esempio n. 9
0
 def post(self):
     newDeploymentUnitSet = request.get_json()
     if deploymentUnitSetDB.GetDeploymentUnitSetByName(
             newDeploymentUnitSet.get("name"), False) is not None:
         raise Exception("Deployment Set with name " +
                         newDeploymentUnitSet.get("name") +
                         " already exists")
     newDeploymentUnitSet["id"] = id_generator()  # ADD UNIQUE ID
     deployment_unit_set_id = DuHelperService.add_update_du_set(
         newDeploymentUnitSet, None, logo_path, logo_full_path)
     return {
         "result": "success",
         "message": "The DeploymentUnit Set is added successfully",
         "data": {
             "_id": deployment_unit_set_id
         }
     }, 200
Esempio n. 10
0
 def post(self):
     """
     Creates or updates requested DU set.
     """
     bulk_du_set_response = []
     du_set_details = request.get_json()
     if type(du_set_details.get("data")) is list and len(
             du_set_details.get("data")) > 0:
         for set in du_set_details.get("data"):
             rec = {
                 "_id": "",
                 "name": set.get("name"),
                 "result": "success",
                 "message": "DU set was created"
             }
             try:
                 keys_to_validate_in_set = ["name", "du_set"]
                 #                     keys_to_validate_in_du_details = ["du_id", "dependent", "order"]
                 for key in keys_to_validate_in_set:
                     if not set.get(key):
                         raise Exception("mandatory key: " + key +
                                         " is missing in du set details")
                 if set.get("_id"):
                     if type(set.get("_id")) is not dict:
                         raise Exception(
                             "invalid type was found for key: _id")
                     if not set.get("_id").get("oid"):
                         raise Exception("oid was not found in _id")
                     rec["_id"] = set["_id"]["oid"]
                     result = DuHelperService.add_update_du_set(
                         set, str(rec["_id"]), logo_path, None,
                         logo_full_path)
                     if result == "1":
                         rec["message"] = "DU Set was updated"
                     else:
                         rec["message"] = "no changes found"
                 elif deploymentUnitSetDB.GetDeploymentUnitSetByName(
                         set.get("name")):
                     existing_du_set = deploymentUnitSetDB.GetDeploymentUnitSetByName(
                         set.get("name"))
                     rec["_id"] = str(existing_du_set.get("_id"))
                     result = DuHelperService.add_update_du_set(
                         set, str(rec["_id"]), logo_path, None,
                         logo_full_path)
                     if result == "1":
                         rec["message"] = "DU Set was updated"
                     else:
                         rec["message"] = "no changes found"
                 else:
                     rec["_id"] = DuHelperService.add_update_du_set(
                         set, None, logo_path, None, logo_full_path)
             except Exception as e:  # catch *all* exceptions
                 rec["result"] = "failed"
                 rec["message"] = str(e)
                 traceback.print_exc()
             bulk_du_set_response.append(rec)
     else:
         raise Exception(
             "expected input type is list with atleast one record")
     return {
         "result": "success",
         "message": "DU Set's has been processed for uploading",
         "data": bulk_du_set_response
     }, 200
Esempio n. 11
0
def deleteDeploymentUnit(id):
    result = DuHelperService.delete_du(id)
    if result.get("result") == "failed":
        raise Exception(result)
    else:
        return jsonify(result), 200