Example #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)}
Example #2
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
Example #3
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
Example #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)}
Example #5
0
 def post(self):
     """
     Creates or updates requested DUs.
     """
     bulk_du_response = []
     du_details = request.get_json()
     if type(du_details.get("data")) is list and len(
             du_details.get("data")) > 0:
         for du in du_details.get("data"):
             rec = {
                 "_id": "",
                 "name": du.get("name"),
                 "result": "success",
                 "message": "DU was created"
             }
             try:
                 keys_to_validate = ["name"]
                 for key in keys_to_validate:
                     if not du.get(key):
                         raise Exception("mandatory key: " + key +
                                         " is missing in du details")
                 if du.get("_id"):
                     if type(du.get("_id")) is not dict:
                         raise Exception(
                             "invalid type was found for key: _id")
                     if not du.get("_id").get("oid"):
                         raise Exception("oid was not found in _id")
                     rec["_id"] = du["_id"]["oid"]
                     result = DuHelperService.add_update_du(
                         du, str(rec["_id"]), logo_path, None,
                         logo_full_path)
                     if result == "1":
                         rec["message"] = "DU was updated"
                     else:
                         rec["message"] = "no changes found"
                 elif deploymentUnitDB.GetDeploymentUnitByName(
                         du.get("name")):
                     existing_du = deploymentUnitDB.GetDeploymentUnitByName(
                         du.get("name"))
                     rec["_id"] = str(existing_du.get("_id"))
                     result = DuHelperService.add_update_du(
                         du, str(rec["_id"]), logo_path, None,
                         logo_full_path)
                     if result == "1":
                         rec["message"] = "DU was updated"
                     else:
                         rec["message"] = "no changes found"
                 else:
                     rec["_id"] = DuHelperService.add_update_du(
                         du, 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_response.append(rec)
     else:
         raise Exception(
             "expected input type is list with atleast one record")
     return {
         "result": "success",
         "message": "DU's has been processed for uploading",
         "data": bulk_du_response
     }, 200