Esempio n. 1
0
def proxy_reconvert_map (request, **kwargs):
	"""
	Reconverts an existing map from the mirror dir (already in geojson format) to the gj directory. Used to implement updates to the conversion table in the ng version of the proxy
	:param request:
	:param kwargs:
	:return:
	"""

	proxy_id =  kwargs['proxy_id']
	meta_id =  kwargs['meta_id']
	map_id = kwargs['map_id']

	response_reconversion = {
	'success': True,
	'report': ''
	}

	try:
		gjdata = proxy_core.rebuildShape(proxy_id, meta_id, map_id, False)
		proxy_core.replicateShapeData(gjdata, proxy_id, meta_id, map_id, False)
	except Exception as ex:
		response_reconversion['success'] = False
		response_reconversion['report'] = ex


	return HttpResponse(json.dumps(response_reconversion), mimetype="application/json")
Esempio n. 2
0
def handleFileEvent (eventpath):
	"""
	Acts as controller during the whole process of update (and eventual send in case of write/full
	:param eventpath: path to the changed/added/deleted file on the filesystem
	:return:
	"""

	# our upload dir structure is:
	# $upload / $proxy_instance / $meta_id / $shape_id.zip

	# we detect what has actually changed.
	# It MUST be a zip file or somebody is messing with the dir structure and we must exit and warn about it



	proxy_id, meta_id, shape_id = proxy_core.verifyUpdateStructure(eventpath)


	print "Working on file event @ %s/%s/%s" % (proxy_id, meta_id, shape_id)
	print "w.eventpath %s" % eventpath

	locker = proxy_lock.ProxyLocker (retries=3, wait=5)

	upsert = None
	# Determining if the event is an upsert or a delete
	if not os.path.exists(eventpath):
		# delete
		#proxy_core.handleDelete (proxy_id, meta_id, shape_id)
		print "Deleting %s/%s/%s" % (proxy_id, meta_id, shape_id)
		locker.performLocked(proxy_core.handleDelete, proxy_id, meta_id, shape_id)
	elif zipfile.is_zipfile(eventpath):
		# upsert
		# proxy_core.handleUpsert (proxy_id, meta_id, shape_id)
		print "Updating/Adding %s/%s/%s" % (proxy_id, meta_id, shape_id)
		locker.performLocked(proxy_core.handleUpsert, proxy_id, meta_id, shape_id)
		upsert = shape_id
	else:
		# wrong file type or directory creation
		print "Unexpected file type or operation on path %s" % eventpath
		raise InvalidFSOperationException ("Unexpected file type or operation on path %s" % eventpath)

	if upsert is not None:
		shapedata = proxy_core.rebuildShape(proxy_id, meta_id, shape_id, modified=True)
		#proxy_core.replicateShapeData (shapedata, proxy_id, meta_id, shape_id, modified=True)
		locker.performLocked(proxy_core.replicateShapeData, shapedata, proxy_id, meta_id, shape_id, modified=True)
	else:
		# this is a delete
		#proxy_core.replicateDelete (proxy_id, meta_id, shape_id)
		locker.performLocked(proxy_core.replicateDelete, proxy_id, meta_id, shape_id)

	#no need of locking for this, since it simply adds/updates a file to the /next dir
	proxy_core.queueForSend(proxy_id, meta_id)


	#if the server is a write/full server, we launch the server update process

	proxymanifest = proxy_core.getManifest(proxy_id)
	if proxymanifest['operations']['write'] == u'full':
		try:
			sentok, details = sendUpdatesWrite(proxy_id)
			if sentok is True:
				logEvent ("Sent update for proxy %s" % proxy_id)
			else:
				logEvent ("Error while sending update for proxy %s: %s" % (proxy_id, details))
		except Exception as e:
			logEvent (e.message, True)
Esempio n. 3
0
def saveVisMap (request, **kwargs):
	"""
	Saves a map from the Vis tool to the requested meta
	:param request:
	:param kwargs:
	:return:
	"""

	try:
		proxy_id = kwargs['proxy_id']
		meta_id = kwargs['meta_id']
		map_id = kwargs['map_id']
		#map_id = request.POST['mapname']

		mapdata = request.POST['jsondata']

		print "Changes submitted for map %s to standalone tool %s in meta %s" % (map_id, proxy_id, meta_id)
		print "format %s" % (type(mapdata))
		#print "DATA: %s" % mapdata

		if meta_id == ".st":
			deploypath = os.path.join(proxyconf.baseproxypath, proxy_id, proxyconf.path_standalone)
			path_tool = os.path.join(deploypath, map_id)
		else:

			deploypath = os.path.join(proxyconf.baseproxypath, proxy_id, proxyconf.path_mirror, meta_id, map_id)
			if not os.path.exists (deploypath):
				os.makedirs(deploypath)
			path_tool = os.path.join(deploypath, map_id+".geojson")



		dest_fp = open(path_tool, 'w+')

		json.dump(json.loads(mapdata), dest_fp, encoding="latin-1")

		dest_fp.close()

		if meta_id != ".st":

			print "Rebuilding data locally"
			proxy_core.replicateShapeData(proxy_core.rebuildShape(proxy_id, meta_id, map_id, False), proxy_id, meta_id, map_id, False)


			print "Rebuilding data on linker"
			destproxy = proxy_core.findLinkedBy(proxy_id)
			if destproxy is not None:
				print "Rebuilding map data on linker proxy %s" % destproxy
				try:
					proxy_core.replicateShapeData(proxy_core.rebuildShape(destproxy, meta_id, map_id, False), destproxy, meta_id, map_id, False)
				except Exception as ex:
					print "Error while rebuilding shape on linker proxy: %s" % ex
			else:
				print "No destination proxy for this instance %s" % proxy_id

		feedback = {
			'success': True,
			'report': "Mappa salvata correttamente."
		}

	except Exception as ex:

		print "Save fail due to:\n%s" % ex

		feedback = {

			'success': False,
			'report': "Errore: %s" % ex

		}


	return HttpResponse(json.dumps(feedback), mimetype="application/json")