Ejemplo n.º 1
0
def download_build_files(build,parent_entity_id,directory_to_export_to, download_build_after,external_artifacts, **keyargs):
    """Download Build Files"""
    try:
        if not os.path.exists(directory_to_export_to):
            os.makedirs(directory_to_export_to) 
        if download_build_after and "none" not in str(download_build_after).lower():
            if build.get("build_date") and \
                    datetime.strptime(
                    (str(str(build['build_date']).split(".")[0])), "%Y-%m-%d %H:%M:%S") < datetime.strptime(
                    (str(str(download_build_after).split(".")[0])), "%Y-%m-%d %H:%M:%S"):
                return  # SKIP DOWNLOADING THIS BUILD
        
        parent_details = HelperServices.get_details_of_parent_entity_id(parent_entity_id)
        if not parent_details.get("repository_to_use") : raise Exception("Missing key: repository_to_use in parent details")
        repo_details = repositoryDB.get_repository_by_name(parent_details.get("repository_to_use"), False)
        deployer_module="Plugins.repositoryPlugins."+repo_details.get("handler")
        class_obj=CustomClassLoaderService.get_class(deployer_module)
        method = getattr(class_obj(repo_details),"trnx_handler") # MEDHOD NAME
        keyargs.update({"transaction_type":"download","build_details":build,"directory_to_export_to":directory_to_export_to})
        method(**keyargs)
        
        if  external_artifacts and build.get("additional_artifacts"):
            ExternalRepoDownloadHelper.handle_request("download",build.get("additional_artifacts"),directory_to_export_to)        
    
    except Exception:
        print "Unable to execute download_build_files : build:"+str(build)+" directory: "+directory_to_export_to
        traceback.print_exc()        
Ejemplo n.º 2
0
def verify_deployment_request(req):
    # CHECK IF parent_entity_id is valid
    parent_entity = HelperServices.get_details_of_parent_entity_id(req.get("parent_entity_id"))
    deployer_module="Plugins.deploymentPlugins."+parent_entity.get("deployer_to_use")
    class_obj=CustomClassLoaderService.get_class(deployer_module)
    if "verify_deployment_request" in dir(class_obj):       
        method = getattr(class_obj(None),"verify_deployment_request") # MEDHOD NAME
        keyargs={"input_dep_request_dict":req}
        method(**keyargs)
Ejemplo n.º 3
0
def verify_group_deployment_request(group_request):
    # CHECK IF parent_entity_id is valid
    parent_entity = HelperServices.get_details_of_parent_entity_id(group_request[0].get("parent_entity_id"))
    deployer_module="Plugins.deploymentPlugins."+parent_entity.get("deployer_to_use")
    class_obj=CustomClassLoaderService.get_class(deployer_module)
    if "verify_group_deployment_request" in dir(class_obj):
        method = getattr(class_obj(None),"verify_group_deployment_request") # MEDHOD NAME
        keyargs={"input_group_dep_request_dict":group_request}
        method(**keyargs)
    else:
        print "Skipping step : verify group deployment request as method doesn't exists in "+parent_entity.get("deployer_to_use")
Ejemplo n.º 4
0
def validate_build_structure(build):
    parent_details = None
    keys_to_validate=["build_number","status","package_type"]
    keys_to_pop=["state_details","create_state_ind","operation"]
    validate_keys_exists(build, "build", keys_to_validate)
    for key in keys_to_pop:
        if build.get(key): build.pop(key) 
    if build.get("parent_entity_id"): 
        parent_details = HelperServices.get_details_of_parent_entity_id(build.get("parent_entity_id"))   
    if build.get("build_date"):
        build["build_date"] = datetime.strptime(
            (str(build["build_date"]).split(".")[0]), "%Y-%m-%d %H:%M:%S")
    validate_by_repository_to_use(build,parent_details.get("repository_to_use"))    
Ejemplo n.º 5
0
def add_request(requests_list):
    ids_list=[]
    group_status_details = []
    try:
        #Check while adding new group deployment req to database    
        verify_group_deployment_request(requests_list)
        for req in requests_list:            
            for rec in ["requested_by","parent_entity_id","deployment_type",\
                        "scheduled_date" ,"request_type"]:
                if not rec in req.keys(): raise ValueError("Mandatory key: "+rec+" was not found in request")
            finalData = handle_dependent_and_order(req) #ADD MMISSING DEPLOYMENT ORDER
            #CHECK if build_id is valid or assign new build
            get_build_for_parent(finalData)            
            #Check while adding new deployment req to database    
            verify_deployment_request(req)
            
            
        #START ADDING
        for req in requests_list:   
            try:
                dep_id=str(deploymentRequestDB.AddDeploymentRequest(req))
            except Exception as ex:
                if req.get("parent_entity_id"): 
                    parent_details = HelperServices.get_details_of_parent_entity_id(req.get("parent_entity_id"))
                    if parent_details:
                        raise Exception("For entity "+str(parent_details.get("name","Unknown"))+" :"+str(ex))
                raise ex        
       
            ids_list.append(dep_id)
            group_status_details.append({"deployment_id": dep_id, "machine_id": req.get(
                                "machine_id"), "status": "New", "status_message": "The request is accepted",\
                                "deployment_order": int(req.get("deployment_order")), "dependent": req.get("dependent")})
        newGroupDeploymentRequest = {
            "deployment_type": str(req.get("deployment_type")).lower(), "details": group_status_details,\
             "requested_by": req.get("requested_by"), "name": "Deployment Group " + CounterDB.get_counter(),\
              "scheduled_date": req.get("scheduled_date"),"request_type":str(req.get("request_type"))}
        
        if req.get("callback_url"):
            newGroupDeploymentRequest["callback"]= { "callback_url": str(req.get("callback_url")) }
        # ADD ADDITIONAL KEYS    
        for key_to_add in ["parent_entity_set_id","package_state_id","machine_group_id"]:
            if key_to_add in req.keys(): newGroupDeploymentRequest[key_to_add]=str(req.get(key_to_add))
        return deploymentRequestGroupDB.add_new_grp_depreq(newGroupDeploymentRequest)
    except Exception as e:  # catch *all* exceptions
        print "Error :" + str(e)
        traceback.print_exc()
        # REMOVE ALREADY ADDED REQUESTS
        for rec in ids_list:
            deploymentRequestDB.CancelDeploymentRequest(rec)
        raise e       
Ejemplo n.º 6
0
def update_build():
    request_build_details = request.get_json()
    if not request_build_details.get("_id"):
        build_details = buildDB.get_build_by_number(
            str(request_build_details.get("parent_entity_id")),
            request_build_details.get("build_number"), True)
        if build_details is not None:
            if build_details.get("_id"):
                request_build_details["_id"] = {
                    "oid": str(build_details.get("_id"))
                }
            else:
                raise Exception(
                    "Unable to find a build id for parent_entity_id" +
                    str(request_build_details.get("parent_entity_id")))
        else:
            raise Exception(
                "Unable to find a build details for build number " +
                str(request_build_details.get("build_number")) +
                " and parent_entity_id " +
                str(request_build_details.get("parent_entity_id")))
    else:
        if request_build_details.get("parent_entity_id"):
            HelperServices.get_details_of_parent_entity_id(
                request_build_details.get("parent_entity_id"))
    result = BuildHelperService.add_update_build(
        request_build_details, request_build_details.get("parent_entity_id"),
        None)
    return jsonify(
        json.loads(
            dumps({
                "result": "success",
                "message": "Build updated successfully",
                "data": {
                    "id": result
                }
            }))), 200
Ejemplo n.º 7
0
 def remove_artifact(self, build_details):
     parent_details = HelperServices.get_details_of_parent_entity_id(
         build_details.get("parent_entity_id"))
     repository_to_use = parent_details.get("repository_to_use")
     if not repository_to_use:
         raise Exception("Missing key: repository_to_use in parent details")
     repo_details = self.repositoryDB.get_repository_by_name(
         repository_to_use, False)
     deployer_module = "Plugins.repositoryPlugins." + repo_details.get(
         "handler")
     class_obj = CustomClassLoaderService.get_class(deployer_module)
     method = getattr(class_obj(repo_details),
                      "trnx_handler")  # MEDHOD NAME
     keyargs = {
         "transaction_type": "delete",
         "build_details": build_details
     }
     method(**keyargs)
Ejemplo n.º 8
0
def add_update_build(build, parent_entity_id, directory_to_import_from=None):
    """Add Update a Build"""
    if build.get("to_process"):build.pop("to_process")
    if build.get("to_process_reason"):build.pop("to_process_reason")
    build["parent_entity_id"] = parent_entity_id
    validate_build_structure(build)
    parent_details = HelperServices.get_details_of_parent_entity_id(parent_entity_id)
    if not parent_details.get("repository_to_use") : raise Exception("Missing key: repository_to_use in parent details")
    repo_details = repositoryDB.get_repository_by_name(parent_details.get("repository_to_use"), False)
    deployer_module="Plugins.repositoryPlugins."+repo_details.get("handler")
    class_obj=CustomClassLoaderService.get_class(deployer_module)
    method = getattr(class_obj(repo_details),"trnx_handler") # MEDHOD NAME
    if build["status"] == "1" and directory_to_import_from:
        keyargs={"transaction_type":"upload","build_details":build,"directory_to_import_from":directory_to_import_from}
        method(**keyargs)            

        # UPLOAD ADDITIONAL ARTIFACTS
        additional_artifacts_upload=str(repo_details.get("additional_artifacts_upload","false")).lower() == "true"
        if additional_artifacts_upload and build.get("additional_artifacts"):
            ExternalRepoDownloadHelper.handle_request("upload",build.get("additional_artifacts"),\
                                                          directory_to_import_from,config=repo_details)
    
    if build["status"] == "1" :
        keyargs={"transaction_type":"validate_if_file_is_present_in_repository","build_details":build}
        method(**keyargs)
    
    BuildRecord = buildsDB.get_build_by_number(
        parent_entity_id, build["build_number"], False)
    if BuildRecord:
        build["_id"] = {}
        build["_id"]["oid"] = str(BuildRecord.get("_id"))
        Buildresult = buildsDB.update_build(build)
    else:
        Buildresult = buildsDB.add_build(build)
    if Buildresult is None:
        raise Exception("Unable to add new Build in DB")

    return str(Buildresult)
Ejemplo n.º 9
0
 def get(self, parent_entity_id):
     return repository_by_name().get(
         HelperServices.get_details_of_parent_entity_id(
             parent_entity_id).get("repository_to_use"))