// 2017 Rackspace, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. package ebi import ( "strconv" "strings" "github.com/sirupsen/logrus" "github.rackspace.com/DCM/migration/pkg/collection" "github.rackspace.com/gorax/tools/util" ) // DMartDevices method will gather all device information that is housed in GDCI-EBI's instance of // data-warehouse. func (c *Client) DMartDevices(params QueryParams) (deviceList []Device, err error) { params.DC = strings.ToUpper(params.DC) logrus.Infof("querying DMart for Device SKU information for %s...", params.DC) skus, err := c.DMartSKUs(params) if err != nil { return } logrus.Infof("querying DMart for Device/Account/Location information for %s...", params.DC) qry, err := QueryString(params, "DMART_Collect_Device_Info.sql") if err != nil { return } devices, err := c.sql.QueryInterface(qry) if err != nil { return } for _, item := range devices { var d Device // Do some checks to make sure the device number can be found if _, ok := item["Device_Number"]; !ok { continue } if item["Device_Number"] == "" { continue } n, err := strconv.Atoi(item["Device_Number"]) if err != nil { continue } d.ID = n if val, ok := item["Account_BDC"]; ok { d.Account.BDC = val } if val, ok := item["Account_Geographic_Location"]; ok { d.Account.GeographicLocation = val } if val, ok := item["Account_Lead_Tech"]; ok { d.Account.LeadTech = val } if val, ok := item["Account_Manager"]; ok { d.Account.AM = val } if val, ok := item["MRRTotal"]; ok { d.Account.CMRR = val } if val, ok := item["Account_Name"]; ok { d.Account.Name = val } if val, ok := item["Account_Number"]; ok { d.Account.Number = util.Atoi(val) } if val, ok := item["Account_Primary_Contact"]; ok { d.Account.PrimaryContact = val } if val, ok := item["Account_Status"]; ok { d.Account.Status = val } if val, ok := item["Account_Team_Name"]; ok { d.Account.TeamName = val } if val, ok := item["Account_Service_Level"]; ok { d.Account.Type = val } if val, ok := item["Device_CMRR"]; ok { d.Device.CMRR = val } if val, ok := item["component_configuration_type_name"]; ok { d.Device.ComponentConfigType = val } if val, ok := item["Device_Datacenter_Abbr"]; ok { d.Device.DataCenter = val } if val, ok := item["Device_Host_Name"]; ok { d.Device.HostName = val } if val, ok := item["Device_Make_Model"]; ok { d.Device.MakeModel = val } if val, ok := item["Device_Online_Status"]; ok { d.Device.OnlineStatus = val } if val, ok := item["Device_OS"]; ok { d.Device.OS = val } if val, ok := item["Device_OS_Name"]; ok { d.Device.OSName = val } if val, ok := item["Device_Status"]; ok { d.Device.Status = val } if val, ok := item["Device_Type"]; ok { d.Device.Type = val } if val, ok := item["component_configuration_type_u_height"]; ok { d.Device.UHeight = val } if val, ok := item["component_container_label"]; ok { d.Environment.Current.Container = val } if val, ok := item["Environment"]; ok { d.Environment.Number = val } if val, ok := item["Device_Type_Icon"]; ok { d.IconURL = iconPrefix + val } // TODO: has_das missing d.Device.SLA = func() string { if val, ok := hasSKUMap(skus[item["Device_Number"]], collection.SKUsServiceLevels); ok { return val } return d.Account.Type }() d.Device.CustomerManaged = hasSKU(skus[item["Device_Number"]], collection.SKUsCustomerManaged) d.RCv2 = hasSKU(skus[item["Device_Number"]], collection.SKUsRackConnectV2) d.RCv3 = hasSKU(skus[item["Device_Number"]], collection.SKUsRackConnectV3) if d.RCv2 || d.RCv3 { d.RackConnect = true } d.SAN = hasSKU(skus[item["Device_Number"]], collection.SKUsSANHBAs) d.MBU = hasSKU(skus[item["Device_Number"]], collection.SKUsMBU) d.DEX = hasSKU(skus[item["Device_Number"]], collection.SKUsDEX) d.DoubleTake = hasSKU(skus[item["Device_Number"]], collection.SKUsDoubleTake) d.MSSQLSupport = hasSKU(skus[item["Device_Number"]], collection.SKUsMSSQLSupport) d.MySQLSupport = hasSKU(skus[item["Device_Number"]], collection.SKUsMySQLSupport) d.OracleSupport = hasSKU(skus[item["Device_Number"]], collection.SKUsOracle) d.SharePoint = hasSKU(skus[item["Device_Number"]], collection.SKUsSharePoint) d.Skype = hasSKU(skus[item["Device_Number"]], collection.SKUsSkypeForBusiness) // SKU 110339: Flagged-Integration is used by legacy Datapipe to reference the account number and // device number that this device is linked to in admin.mydatapipe.net. if exist := setFlaggedIntegrationSKU(&d, skus[item["Device_Number"]]); exist { d.Linked.Type = LinkedByIntegration } // SKU 110132: Device-Details is used by Tricore/RAS to show the linked account that the device ID // is associated with. Since we need to represent this as the actual customer account, instead of the // parent account, we override the account name and put the actual account info in the linked sub-doc. if exist := setDeviceDetailsSKU(&d, skus[item["Device_Number"]]); exist { d.Linked.Type = LinkedByDetails } deviceList = append(deviceList, d) } logrus.Infof("found a total of %d devices in %s", len(deviceList), params.DC) return } // DMartSKUs method will gather the MRR for all devices specified or for an entire DC. func (c *Client) DMartSKUs(params QueryParams) (deviceSKUs map[string]SKUData, err error) { deviceSKUs = make(map[string]SKUData) qry, err := QueryString(params, "DMART_SKUs_By_DC.sql") if err != nil { return } r, err := c.sql.QueryInterface(qry) if err != nil { return } for _, item := range r { if _, ok := item["Device_Number"]; !ok { continue } if _, ok := item["sku_number"]; !ok { continue } id := item["Device_Number"] if _, ok := deviceSKUs[id]; !ok { deviceSKUs[id] = make(SKUData) } skuID := item["sku_number"] if _, ok := deviceSKUs[id][skuID]; !ok { deviceSKUs[id][skuID] = SKUUnit{ Name: item["sku_name"], Attr: make([]SKUAttr, 0), } } attrSku := deviceSKUs[id][skuID] attrSku.Attr = append(attrSku.Attr, SKUAttr{ Name: item["sku_attribute_name"], AttrValue: item["sku_parts_attribute_value"], Label: item["sku_skunit_label"], }) deviceSKUs[id][skuID] = attrSku } logrus.Infof("ebi.DMartSKUs: found %d sku devices for %s", len(deviceSKUs), params.DC) return } // DMartMRR method will gather the MRR for all devices specified or for an entire DC. func (c *Client) DMartMRR(dc string) (deviceMrr map[string]DeviceMRR, err error) { deviceMrr = make(map[string]DeviceMRR) qry, err := QueryString(QueryParams{DC: dc}, "DMART_MRR_By_DC.sql") if err != nil { return } r, err := c.sql.QueryInterface(qry) if err != nil { return } for _, item := range r { d := DeviceMRR{} if val, ok := item["ACCOUNT_AccountNumber"]; ok { d.Account = val } if val, ok := item["SERVER_datacenter"]; ok { d.Datacenter = val } if val, ok := item["Dollar_AMount"]; ok { d.USD = val } if val, ok := item["SERVER_computer_number"]; ok { deviceMrr[val] = d } } logrus.Infof("ebi.DMartMRR: found %d mrr results for %s", len(deviceMrr), dc) return }