func Migrate_0_9_1_to_15_04_03(session *gocql.Session) error { // Perform all migration queries. for _, query := range migrationQueries_0_9_1_to_15_04_03 { canolog.Info(query) if err := session.Query(query).Exec(); err != nil { // Ignore errors (just print them). canolog.Warn(query, ": ", err) } } return nil }
func (dl *CassDatalayer) PrepDb(keyspace string) error { cluster := gocql.NewCluster("127.0.0.1") session, err := cluster.CreateSession() if err != nil { canolog.Error("Error creating DB session: ", err) return err } // Create keyspace. err = session.Query(` CREATE KEYSPACE ` + keyspace + ` WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1} `).Exec() if err != nil { // Ignore errors (just log them). canolog.Warn("(IGNORED) ", err) } // Create a new session connecting to that keyspace. cluster = gocql.NewCluster("127.0.0.1") cluster.Keyspace = keyspace cluster.Consistency = gocql.Quorum session, err = cluster.CreateSession() if err != nil { canolog.Error("Error creating DB session: ", err) return err } // Perform all creation queries. for _, query := range creationQueries { if err := session.Query(query).Exec(); err != nil { // Ignore errors (just print them). // This allows PrepDB to be used to add new tables. Eventually, we // should come up with a proper migration strategy. canolog.Warn("(IGNORED) ", query, ": ", err) } } return nil }
func (client *CanopySGClient) Send(m MailMessage) error { mail, ok := m.(*CanopySGMail) if !ok { return errors.New("Message was not constructed with CanopySGClient") } canolog.Info("Sending email: " + fmt.Sprint(mail.sgmail)) err := client.sg.Send(mail.sgmail) if err != nil { canolog.Warn("Error sending email: " + err.Error()) } return err }
func POST__api__device__id(info *RestRequestInfo, sideEffect *RestSideEffects) (map[string]interface{}, RestError) { var err error device, restErr := getDeviceByIdString(info) if device == nil { return nil, restErr } // Check for SDDL doc. If it doesn't exist, then create it. // TODO: should this only be done if the device is reporting? doc := device.SDDLDocument() if doc == nil { // Create SDDL for the device if it doesn't exist. // TODO: should this be automatically done by device.SDDLClass()? newDoc := sddl.Sys.NewEmptyDocument() err := device.SetSDDLDocument(newDoc) if err != nil { return nil, InternalServerError("Setting new SDDL document").Log() } doc = newDoc } // Parse payload for fieldName, value := range info.BodyObj { switch fieldName { case "friendly_name": friendlyName, ok := value.(string) if !ok { continue } device.SetName(friendlyName) case "location_note": locationNote, ok := value.(string) if !ok { continue } device.SetLocationNote(locationNote) case "var_decls": sddlJsonObj, ok := value.(map[string]interface{}) if !ok { return nil, BadInputError("Expected object \"var_decls\"") } err = device.ExtendSDDL(sddlJsonObj) if err != nil { return nil, BadInputError(err.Error()) } } } // Handle vars last for fieldName, value := range info.BodyObj { switch fieldName { case "vars": varsJsonObj, ok := value.(map[string]interface{}) if !ok { return nil, BadInputError("Expected object \"vars\"") } for varName, valueJsonObj := range varsJsonObj { varDef, err := device.LookupVarDef(varName) if err != nil { canolog.Warn("Cloud variable not found: ", varName) /* TODO: Report warning in response*/ continue } varVal, err := cloudvar.JsonToCloudVarValue(varDef, valueJsonObj) if err != nil { canolog.Warn("Cloud variable value parsing problem: ", varName, err) /* TODO: Report warning in response*/ continue } device.InsertSample(varDef, time.Now(), varVal) } } } timestamps := info.Query["timestamps"] timestamp_type := "epoch_us" if timestamps != nil && timestamps[0] == "rfc3339" { timestamp_type = "rfc3339" } out, err := deviceToJsonObj(device, timestamp_type) if err != nil { return nil, InternalServerError("Generating JSON") } out["result"] = "ok" return out, nil }