func (r *Record) GetDependantReferenceMaps(connection *database.Connection) []ReferenceMap {

	endpoint_id := r.EndpointId
	application_id := r.ApplicationId

	endpoint := r.GetEndpointFromCache()

	var results []ReferenceMap

	if endpoint.CachedSourceReferenceMaps {
		logger.Debug("[Cache][Reference Maps][Source] Hit: ", r.EndpointId.Hex())
		results = endpoint.SourceReferencedMaps
	} else {
		logger.Debug("[Cache][Reference Maps][Source] Miss: ", r.EndpointId.Hex())
		query := map[string]bson.ObjectId{"source_id": endpoint_id}

		// Get the collection name
		collection := application_id.Hex() + "_maps"

		// Query the database
		database.Query(connection, collection, query).All(&results)

		if endpoint.Id != bson.ObjectId("") {
			key := r.ApplicationId.Hex() + ".endpoints." + endpoint_id.Hex()
			endpoint.SourceReferencedMaps = results
			endpoint.CachedSourceReferenceMaps = true
			b, _ := json.Marshal(endpoint)
			cache.Set(key, string(b), 5*time.Minute)

			logger.Debug("[Cache][Reference Maps][Source] Set: ", r.EndpointId.Hex())
		}
	}

	return results
}
func (object *File) Delete() {

	connection := database.GetConnection()
	defer connection.Release()
	logger.Debug("[Database] Deleting File")

	collection := connection.C(object.Collection())
	collection.RemoveId(object.Id)
}
func (object *User) Delete() {
	connection := database.GetConnection()
	defer connection.Release()
	logger.Debug("[Database] Deleting User")

	collection := connection.C(object.Collection())
	collection.RemoveId(object.Id)
	key := object.ApplicationId.Hex() + ".users." + object.Id.Hex()
	cache.Clear(key)
}
func (object *Record) DeleteAndTrigger(endpoint string, trigger bool) {
	connection := database.GetConnection()
	defer connection.Release()
	logger.Debug("[Database] Deleting Record")

	collection := connection.C(object.Collection())
	collection.RemoveId(object.Id)
	if trigger {
		go object.FindAndExecuteTriggerForEvent(endpoint + ":destroy")
	}
}
func (object *Group) Save() {
	connection := database.GetConnection()
	defer connection.Release()
	logger.Debug("[Database] Saving Group")

	collection := connection.C(object.Collection())
	if object.Id == bson.ObjectId("") {
		object.Id = bson.NewObjectId()
		collection.Insert(object)
	} else {
		collection.UpdateId(object.Id, object)
	}
}
func (object *Session) Save() {

	connection := database.GetConnection()
	defer connection.Release()
	logger.Debug("[Database] Saving Session")

	collection := connection.C(object.Collection())
	if object.Id == bson.ObjectId("") {
		object.Id = bson.NewObjectId()
		collection.Insert(object)
	} else {
		collection.UpdateId(object.Id, object)
	}

	b, _ := json.Marshal(object)
	key := object.ApplicationId.Hex() + ".sessions." + object.Id.Hex()
	cache.Set(key, string(b), 5*time.Minute)
}
func (object *Endpoint) Save() {

	connection := database.GetConnection()
	defer connection.Release()
	logger.Debug("[Database] Saving Endpoint")

	collection := connection.C(object.Collection())

	if object.Id == bson.ObjectId("") {
		object.Id = bson.NewObjectId()
		collection.Insert(object)
	} else {
		collection.UpdateId(object.Id, object)
	}

	key := object.ApplicationId.Hex() + ".endpoints." + object.Id.Hex()
	cache.Clear(key)

}
示例#8
0
func (job Job) ExecuteWithOutput() map[string]interface{} {
	getJob(job.ApplicationId)

	job.CachePath = config.SharedConfig.JobCachePath
	job.Port = config.SharedConfig.ServerPort

	application_id := bson.ObjectIdHex(job.ApplicationId)
	application := model.FindApplicationById(application_id)
	user := application.GetSuperUser()

	user.NewTriggerSession()

	job.SuperUser = user

	input_bytes, _ := json.Marshal(job)

	process := Process{}
	process.Start(config.SharedConfig.ScriptDirectory + "/runner.js")

	logger.Debug(string(input_bytes))

	process.Write(input_bytes)
	return <-process.ResultChan
}
func (object *User) Save() bool {

	connection := database.GetConnection()
	defer connection.Release()
	logger.Debug("[Database] Saving User")

	collection := connection.C(object.Collection())

	if object.Id == bson.ObjectId("") {
		object.Id = bson.NewObjectId()
		err := collection.Insert(object)
		if err != nil {
			return mgo.IsDup(err)
		}
	} else {
		collection.UpdateId(object.Id, object)
	}

	key := object.ApplicationId.Hex() + ".users." + object.Id.Hex()
	b, _ := json.Marshal(object)
	cache.SetSync(key, string(b), 5*time.Minute)

	return false
}
示例#10
0
func (connection *Connection) Release() {
	logger.Debug("[Database] Queried", connection.QueriedCollection, time.Now().Sub(connection.start_time).String())
}