def updateSpecificModelObject(object_id: text, content: hugJson, request, response): """Update model containing the specified object_id, with the provided JSON.""" try: if hasRequiredData(request, response, content, ['source']): dbTable = archiveSchema.Model dataHandle = request.context['dbSession'].query(dbTable).filter( dbTable.object_id == object_id).first() if dataHandle is None: request.context['payload']['errors'].append( 'No archived model exists with ID {}, in order to update. Use POST on ./archive/model to create.' .format(object_id)) response.status = HTTP_404 else: source = mergeUserAndSource(content, request) content['object_created_by'] = source if 'data' in content.keys(): ## Override the model data to the current result setattr(dataHandle, 'data', content['data']) if 'meta_data' in content.keys(): ## Override the model metadata to the current result setattr(dataHandle, 'meta_data', content['meta_data']) ## Update the model dataHandle = request.context['dbSession'].merge(dataHandle) request.context['dbSession'].commit() request.context['payload'][ 'Response'] = 'Updated archived model {}'.format(object_id) request.context['logger'].debug( 'Updated archived model {}'.format(object_id)) except: errorMessage(request, response) ## end updateSpecificConfigGroups return cleanPayload(request)
def queryThisContent(content:hugJson, request, response): """Query OCP for results matching the provided JSON.""" try: countResult = content.pop('count', False) queryThisContentHelper(request, response, content) ## Flat and Nested formats return a dictionary, but Nested-Simple ## returns a list, so we can't mutate the payload... overwrite. payload = request.context['payload'].copy() request.context['logger'].info('this payload: {}'.format(payload)) request.context['logger'].info('payload type: {}'.format(type(payload))) if countResult: request.context['payload'] = {} ## If we are just returning a count, need to determine what type ## of thing to count... dict vs list structure, object in Flat ## layout, or result set in Nested or Nested-Simple format... if isinstance(payload, list): request.context['payload']['Result Count'] = len(payload) elif isinstance(payload, dict): if 'objects' in payload: request.context['payload']['Result Count'] = len(payload.get('objects')) else: request.context['payload']['Result Count'] = len(payload.keys()) except: errorMessage(request, response) ## end queryThisContent return cleanPayload(request)
def deleteJobResultListFilter(service: text, content: hugJson, request, response): """Delete job runtime results for service, matching the provided filter. Note: this is the runtime meta data for the job, not the CIs. """ try: if hasRequiredData(request, response, content, ['filter']): filterConditions = content.get('filter') countResult = content.get('count', False) getJobResultsFilterHelper(request, response, filterConditions, countResult, True, service) except: errorMessage(request, response) ## end deleteJobResultListFilter return cleanPayload(request)
def updateSpecificEndpointQuery(queryName:text, content:hugJson, request, response): """Update named query with the provided JSON""" try: if hasRequiredData(request, response, content, ['source', 'json_query']): dataHandle = request.context['dbSession'].query(platformSchema.EndpointQuery).filter(platformSchema.EndpointQuery.name==queryName).first() if dataHandle is None: request.context['payload']['errors'].append('No query exists with name {queryName!r}'.format(queryName=queryName)) response.status = HTTP_404 else: tempObjectId = dataHandle.object_id ## Set the source source = mergeUserAndSource(content, request) content['object_updated_by'] = source definedColumns = [col for col in inspect(platformSchema.EndpointQuery).mapper.c.keys() if col not in ['name', 'object_id', 'time_created', 'object_created_by', 'time_updated', 'object_updated_by']] request.context['logger'].debug('Printing the required column {}'.format(definedColumns)) if any(col in content.keys() for col in definedColumns): content['object_id']= tempObjectId content['name'] = queryName dataHandle = platformSchema.EndpointQuery(**content) try: apiQueryPath = request.context['envApiQueryPath'] if not os.path.exists(apiQueryPath): os.makedirs(apiQueryPath) dataHandle = request.context['dbSession'].merge(dataHandle) fileToRemove = os.path.join(apiQueryPath, queryName + '.json') request.context['dbSession'].commit() if 'json_query' in content.keys(): if os.path.isfile(fileToRemove): os.remove(fileToRemove) with open(os.path.join(fileToRemove),'w') as fh: json.dump(content['json_query'], fh) request.context['payload']['Response'] = 'Updated the query : {name}'.format(name=queryName) except KeyError: request.context['payload']['errors'].append('Invalid data, key does not exist for {queryName!r} 1'.format(queryName=queryName)) response.status = HTTP_400 else: request.context['payload']['errors'].append('Invalid data, key does not exist for {queryName!r}'.format(queryName=queryName)) response.status = HTTP_400 except: errorMessage(request, response) ## end updateSpecificEndpointQuery return cleanPayload(request)
def deleteJobReviewFilter(service: text, content: hugJson, request, response): """Delete job runtime results for service, matching the provided filter. Note: this is the runtime meta data for the job, not the CIs. """ try: dbTable = getReviewServiceTable(service, request, response) if dbTable is not None: if hasRequiredData(request, response, content, ['filter']): filterConditions = content.get('filter') countResult = content.get('count', False) searchThisContentHelper(request, response, filterConditions, dbTable, countResult, True) except: errorMessage(request, response) ## end deleteJobReviewFilter return cleanPayload(request)
def executeJobResultListFilter(service: text, content: hugJson, request, response): """Return job runtime results for service, matching the provided filter.""" try: if hasRequiredData(request, response, content, ['filter']): filterConditions = content.get('filter') countResult = content.get('count', False) getJobResultsFilterHelper(request, response, filterConditions, countResult, False, service) ## Standard conversions of dates and Decimal types to string request.context['payload'] = json.loads( json.dumps(request.context['payload'], default=customJsonDumpsConverter)) except: errorMessage(request, response) ## end executeJobResultListFilter return cleanPayload(request)
def createJobConfigServiceList(service: text, content: hugJson, request, response): """Insert a new job in the specified service.""" try: if hasRequiredData(request, response, content, ['source', 'package', 'content']): dbClass = getConfigServiceTable(service, request, response) if dbClass is not None: packageName = content.get('package') jobDescriptor = content.get('content') jobShortName = jobDescriptor.get('jobName') jobName = '{}.{}'.format(packageName, jobShortName) dataHandle = request.context['dbSession'].query( dbClass).filter(dbClass.name == jobName).first() if dataHandle is not None: request.context['payload']['errors'].append( 'Job already exists: {name!r}'.format(name=jobName)) response.status = HTTP_404 else: attributes = {} attributes['name'] = jobName attributes['package'] = packageName attributes['realm'] = jobDescriptor.get('realm', 'default') attributes['active'] = not jobDescriptor.get( 'isDisabled', True) attributes['content'] = jobDescriptor ## Update the source source = mergeUserAndSource(content, request) attributes['object_created_by'] = source thisEntry = dbClass(**attributes) request.context['dbSession'].add(thisEntry) request.context['dbSession'].commit() request.context['payload'][ 'Response'] = 'Inserted job: {name}'.format( name=jobName) except: errorMessage(request, response) ## end createJobConfigServiceList return cleanPayload(request)
def executeJobReviewFilter(service: text, content: hugJson, request, response): """Return requested job summary results, matching the provided filter.""" try: dbTable = getReviewServiceTable(service, request, response) if dbTable is not None: if hasRequiredData(request, response, content, ['filter']): filterConditions = content.get('filter') countResult = content.get('count', False) searchThisContentHelper(request, response, filterConditions, dbTable, countResult, False) ## Standard conversions of dates and Decimal types to string request.context['payload'] = json.loads( json.dumps(request.context['payload'], default=customJsonDumpsConverter)) except: errorMessage(request, response) ## end executeJobReviewFilter return cleanPayload(request)