func (p UpdateExportProcessor) Process() {
	printDebug("UPDATEEXPORT", p.UpdateExportMsg)
	Export := types.GetExportById(p.UpdateExportMsg.ExportId, p.GetAgent())
	Export.UpdateTags(p.UpdateExportMsg.Tags)
	var pjp PendingJobProcessor
	pjp.Appkey = Export.GetAppKey()
	pjp.GenericProcessor = processor.GetGenericProcessor()
	p.SpawnProcess(pjp)
	var uesp ExportedStateProcessor
	uesp.AppKey = Export.GetAppKey()
	uesp.GenericProcessor = processor.GetGenericProcessor()

	p.SpawnProcess(uesp)

	if !Export.GetApp().IsNode() {
		for _, node := range types.GetNodes(p.GetAgent()) {
			node.Lock()
			var smp SendMessageProcessor
			smp.App = node
			smp.Msg = p.UpdateExportMsg
			smp.GenericProcessor = processor.GetGenericProcessor()
			p.SpawnProcess(smp)
			node.Unlock()
		}
	}
}
func (p LeaveProcessor) Process() {

	app := types.GetApp(p.AppId, p.GetAgent())
	app.Lock()
	if app.Exists() {
		keys := []types.AppKey{}
		for _, e := range app.GetExports() {
			keys = append(keys, e.GetAppKey())
		}
		conn, _ := app.GetConnection()
		conn.Close()
		printDebug("LEAVE locking")
		printDebug("LEAVE unlocking")
		if !app.IsNode() {
			for _, exp := range app.GetExports() {
				printDebug("LEAVE unlocking")
				var m messages.RemoveExportMessage
				m.ExportId = exp.GetId()
				var smp SendMessageProcessor
				smp.Msg = m
				smp.GenericProcessor = processor.GetGenericProcessor()
				for _, n := range types.GetNodes(p.GetAgent()) {
					smp.App = n
					p.SpawnProcess(smp)
				}
			}
			for _, imp := range app.GetImports() {
				var m messages.RemoveImportMessage
				m.ImportId = imp.GetId()
				var smp SendMessageProcessor
				smp.Msg = m
				smp.GenericProcessor = processor.GetGenericProcessor()
				for _, n := range types.GetNodes(p.GetAgent()) {
					smp.App = n
					p.SpawnProcess(smp)
				}
			}

			printDebug("LEAVE removing")
			app.Remove()
			printDebug("LEAVE removed")

			for _, k := range keys {
				if k.Exists() {
					var esp ExportedStateProcessor
					esp.AppKey = k
					esp.GenericProcessor = processor.GetGenericProcessor()
					p.SpawnProcess(esp)
				}
			}
		}
	}

}
func (p PendingJobProcessor) Process() {
	printDebug("pendingjob")

	for _, imp := range p.Appkey.GetImporter() {
		for _, j := range imp.GetJobs() {
			if !j.IsAssigned() {
				if imp.HasExporter() {
					exp := imp.GetExporter()[0]
					app := exp.GetApp()
					app.Lock()
					if app.Exists() {
						j.Assign(exp)
						var djp DeliverJobProcessor
						djp.Job = j
						djp.GenericProcessor = processor.GetGenericProcessor()

						p.SpawnProcess(djp)
						app.Unlock()
					}

				}
			}
		}
	}

}
Example #4
0
func (da DockAgent) ProcessMsg(appid string, msgtype int64, codec string, msg []byte) {
	var p processors.ParseMessageProccesor
	p.AppId = appid
	p.Codec = codec
	p.Msg = msg
	p.Type = msgtype
	p.GenericProcessor = processor.GetGenericProcessor()
	go da.launchProcess(p)
}
func (p ResultProcessor) Process() {
	printDebug("Processing result")

	job := types.GetJobFromResult(p.Result, p.GetAgent())
	switch p.Result.CallType {
	case calltypes.ONE2ONE:
		if job.Exists() {
			imp := job.GetImport()
			var smp SendMessageProcessor
			smp.App = imp.GetApp()
			smp.Msg = p.Result
			smp.GenericProcessor = processor.GetGenericProcessor()
			p.SpawnProcess(smp)
			job.Remove()
		}
	case calltypes.ONE2MANY:
		if job.Exists() {
			imp := job.GetImport()
			var smp SendMessageProcessor
			printDebug("SENDING ONE2MANY RES", imp.GetApp())

			smp.App = imp.GetApp()
			smp.Msg = p.Result
			smp.GenericProcessor = processor.GetGenericProcessor()
			p.SpawnProcess(smp)
		}
	case calltypes.MANY2MANY, calltypes.MANY2ONE:
		exp := types.GetExportById(p.Result.ExportId, p.GetAgent())
		for _, imp := range exp.GetAppKey().GetListener(p.Result.FunctionName, exp) {
			printDebug("Sending to", imp.GetId())
			var smp SendMessageProcessor
			smp.App = imp.GetApp()
			res := p.Result
			res.ImportId = imp.GetId()
			smp.Msg = res
			smp.GenericProcessor = processor.GetGenericProcessor()
			p.SpawnProcess(smp)
			job.Remove()
		}
	}

}
Example #6
0
func (da DockAgent) InitDocking(appid string, codec string, msg []byte, connection connection.Connection) {
	debugPrint("initializing docking")
	var p processors.DockProcessor
	p.AppId = appid
	p.Codec = codec
	p.DockMessage = msg
	p.Connection = connection
	p.GenericProcessor = processor.GetGenericProcessor()

	go da.launchProcess(p)

}
func (p AddExportProcessor) Process() {
	app := types.GetApp(p.AppId, p.GetAgent())
	if !app.Exists() {
		mprint("Could not add exmport, app does not exist")
		return
	}
	app.Lock()
	Export := types.GetExport(p.AppId, p.AddExportMsg.AppKey, p.AddExportMsg.Tags, p.AddExportMsg.ExportId, p.GetAgent())
	Export.Add()

	if !app.IsNode() {
		var smp SendMessageProcessor
		smp.App = app
		smp.Msg = messages.ExportAddedMessage{Export.GetId(), p.AddExportMsg.AppKey, p.AddExportMsg.Tags}
		smp.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(smp)
	}

	var pjp PendingJobProcessor
	pjp.Appkey = Export.GetAppKey()
	pjp.GenericProcessor = processor.GetGenericProcessor()
	p.SpawnProcess(pjp)
	var uesp ExportedStateProcessor
	uesp.AppKey = Export.GetAppKey()
	uesp.GenericProcessor = processor.GetGenericProcessor()
	p.SpawnProcess(uesp)

	if !app.IsNode() {
		p.AddExportMsg.ExportId = Export.GetId()
		for _, node := range types.GetNodes(p.GetAgent()) {
			var smp SendMessageProcessor
			smp.App = node
			smp.Msg = p.AddExportMsg
			smp.GenericProcessor = processor.GetGenericProcessor()
			p.SpawnProcess(smp)
		}
	}
	app.Unlock()

}
func (p UpdateImportProcessor) Process() {

	Import := types.GetImportById(p.UpdateImportMsg.ImportId, p.GetAgent())
	Import.UpdateTags(p.UpdateImportMsg.Tags)

	if !Import.GetApp().IsNode() {
		var smp SendMessageProcessor
		smp.App = Import.GetApp()
		smp.Msg = messages.ImportUpdatedMessage{Import.GetId(), Import.HasExporter()}
		smp.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(smp)
		for _, node := range types.GetNodes(p.GetAgent()) {
			node.Lock()
			var smp SendMessageProcessor
			smp.App = node
			smp.Msg = p.UpdateImportMsg
			smp.GenericProcessor = processor.GetGenericProcessor()
			p.SpawnProcess(smp)
			node.Unlock()
		}
	}
}
func (p ExportedStateProcessor) Process() {
	for _, imp := range p.AppKey.GetImporter() {
		app := imp.GetApp()
		ok := app.Lock()
		if ok {
			if !app.IsNode() {
				var smp SendMessageProcessor
				smp.App = app
				printDebug(imp.HasExporter())
				smp.Msg = messages.ImportUpdatedMessage{imp.GetId(), imp.HasExporter()}
				smp.GenericProcessor = processor.GetGenericProcessor()
				p.SpawnProcess(smp)
			}
			app.Unlock()
		}
	}
}
func (p StopListenProcessor) Process() {

	Import := types.GetImportById(p.StopListenMsg.ImportId, p.GetAgent())

	Import.StopListenToFunction(p.StopListenMsg.FunctionName)

	if !Import.GetApp().IsNode() {
		for _, n := range types.GetNodes(p.GetAgent()) {
			var smp SendMessageProcessor
			smp.App = n
			smp.Msg = p.StopListenMsg
			smp.GenericProcessor = processor.GetGenericProcessor()
			p.SpawnProcess(smp)

		}

	}

}
func (p RequestProcessor) Process() {
	app := types.GetApp(p.AppId, p.GetAgent())
	if !app.Exists() {
		mprint("Could not add jo, app does not exist")
		return
	}
	app.Lock()
	job := types.GetJobFromRequest(p.Request, p.GetAgent())
	job.Create()
	imp := job.GetImport()
	if job.Exists() && imp.HasExporter() {

		var djp DeliverJobProcessor
		djp.Job = job
		djp.GenericProcessor = processor.GetGenericProcessor()

		p.SpawnProcess(djp)

	}
	app.Unlock()
}
func (p ParseMessageProccesor) Process() {

	decoder := util.GetCodec(p.Codec)
	if decoder == nil {
		return
	}
	printDebug("Processing message", p.Type)
	switch p.Type {
	case messages.LEAVE:
		var np LeaveProcessor
		np.AppId = p.AppId
		np.GenericProcessor = processor.GetGenericProcessor()

		p.SpawnProcess(np)

	case messages.ADD_EXPORT:
		var m messages.AddExportMessage
		decoder.Decode(p.Msg, &m)
		var np AddExportProcessor
		np.AppId = p.AppId
		np.AddExportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.UPDATE_EXPORT:
		var m messages.UpdateExportMessage
		decoder.Decode(p.Msg, &m)
		var np UpdateExportProcessor
		np.AppId = p.AppId
		np.UpdateExportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.REMOVE_EXPORT:
		var m messages.RemoveExportMessage
		decoder.Decode(p.Msg, &m)
		var np RemoveExportProcessor
		np.AppId = p.AppId
		np.RemoveExportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.REMOVE_IMPORT:
		var m messages.RemoveImportMessage
		decoder.Decode(p.Msg, &m)
		var np RemoveImportProcessor
		np.AppId = p.AppId
		np.RemoveImportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.ADD_IMPORT:
		var m messages.AddImportMessage
		decoder.Decode(p.Msg, &m)
		var np AddImportProcessor
		np.AppId = p.AppId
		np.AddImportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.UPDATE_IMPORT:
		var m messages.UpdateImportMessage
		decoder.Decode(p.Msg, &m)
		var np UpdateImportProcessor
		np.AppId = p.AppId
		np.UpdateImportMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)
	case messages.LISTEN:
		var m messages.ListenMessage
		decoder.Decode(p.Msg, &m)
		var np StartListenProcessor
		np.AppId = p.AppId
		np.StartListenMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)
	case messages.STOP_LISTEN:
		var m messages.StopListenMessage
		decoder.Decode(p.Msg, &m)
		var np StopListenProcessor
		np.AppId = p.AppId
		np.StopListenMsg = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)

	case messages.REQUEST:
		var m messages.Request
		decoder.Decode(p.Msg, &m)
		var np RequestProcessor
		np.AppId = p.AppId
		np.Request = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)
	case messages.RESULT:
		var m messages.Result
		decoder.Decode(p.Msg, &m)
		printDebug("RESZ", m)
		var np ResultProcessor
		np.AppId = p.AppId
		np.Result = m
		np.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(np)
	}

}
func (p DockProcessor) Process() {
	if p.Connection != nil {
		decoder := util.GetCodec(p.Codec)
		if decoder == nil {
			return
		}
		var dmsg messages.DockMessage
		err := decoder.Decode(p.DockMessage, &dmsg)
		if err != nil {
			return
		}
		app := types.GetApp(p.AppId, p.GetAgent())
		ok := app.Create(dmsg, p.Connection)
		if ok {
			app.Lock()
			defer app.Unlock()
			conn, _ := app.GetConnection()
			err = conn.Init()
			if err != nil {
				return
			}
			if app.IsNode() {
				var sp SendMessageProcessor
				sp.App = app
				sp.Msg = messages.DockMessage{"runtime", []string{"JSON"}, true}
				sp.GenericProcessor = processor.GetGenericProcessor()
				p.SpawnProcess(sp)
			}

		}

		var sp SendMessageProcessor
		sp.App = app
		sp.Msg = messages.DockedMessage{ok}
		sp.GenericProcessor = processor.GetGenericProcessor()
		p.SpawnProcess(sp)

		if ok && app.IsNode() {
			for _, localapp := range types.GetApps(p.GetAgent()) {
				for _, imp := range localapp.GetImports() {
					var m messages.AddImportMessage
					m.AppKey = imp.GetAppKey().GetKey()
					m.Tags = imp.GetTagNames()
					m.ImportId = imp.GetId()
					var sp SendMessageProcessor
					sp.App = app
					sp.Msg = m
					sp.GenericProcessor = processor.GetGenericProcessor()
					p.SpawnProcess(sp)
				}
				for _, exp := range localapp.GetExports() {
					var m messages.AddExportMessage
					m.AppKey = exp.GetAppKey().GetKey()
					m.Tags = exp.GetTagNames()
					m.ExportId = exp.GetId()
					var sp SendMessageProcessor
					sp.App = app
					sp.Msg = m
					sp.GenericProcessor = processor.GetGenericProcessor()
					p.SpawnProcess(sp)
				}
			}
		}
	}

}