public SingleResult <CmpInterfaceModel.Models.VmMigrationRequest> GetVmMigrationRequest([FromODataUri] int key) { try { using (CmpServiceLib.CmpService CMP = new CmpServiceLib.CmpService(_EventLog, _CmpDbConnectionString, _AftsDbConnectionString)) { CmpServiceLib.Models.VmMigrationRequest vmMigrationRequest = CMP.FetchMigrationRequest(key); if (null == vmMigrationRequest) { return(null); } var vmr = new List <CmpInterfaceModel.Models.VmMigrationRequest>(); vmr.Add(ServToInt(vmMigrationRequest)); return(SingleResult.Create(vmr.AsQueryable())); } } catch (Exception ex) { LogThis(ex, EventLogEntryType.Error, "Exception in GetVmMigrationRequest()", 100, 100); throw; } //return SingleResult.Create(db.VmMigrationRequests.Where(vmmigrationrequest => vmmigrationrequest.ID == key)); }
private void OpsQueueTest() { var vmOp = new VmOp() { Config = "", Id = 0, Name = null, Opcode = CmpInterfaceModel.Constants.VmOpcodeEnum.STOP.ToString(), StatusCode = CmpInterfaceModel.Constants.StatusEnum.Submitted.ToString(), StatusMessage = CmpInterfaceModel.Constants.StatusEnum.Submitted.ToString(), VmId = 3, Vmsize = "", disks = null, iData = 0, sData = null }; var opSpec = VmOpsController.Translate(vmOp); opSpec.Requestor = ""; //opSpec = new CmpInterface(null).SubmitOpToQueue(opSpec); var cmp = new CmpServiceLib.CmpService(eLog, ConfigurationManager.ConnectionStrings["CMPContext"].ConnectionString, null); opSpec = cmp.SubmitOpToQueue(opSpec); }
//********************************************************************* /// /// <summary> /// PUT odata/VmMigrations(5) /// </summary> /// <param name="key"></param> /// <param name="vmmigrationrequest"></param> /// <returns></returns> /// //********************************************************************* //[Authorize] public async Task <IHttpActionResult> Put([FromODataUri] int key, CmpInterfaceModel.Models.VmMigrationRequest vmmigrationrequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (key != vmmigrationrequest.ID) { return(BadRequest()); } /*db.Entry(vmmigrationrequest).State = EntityState.Modified; * * try * { * await db.SaveChangesAsync(); * } * catch (DbUpdateConcurrencyException) * { * if (!VmMigrationRequestExists(key)) * { * return NotFound(); * } * else * { * throw; * } * } * * return Updated(vmmigrationrequest);*/ ////////////////////// try { DateTime Now = DateTime.UtcNow; vmmigrationrequest.LastStatusUpdate = DateTime.UtcNow; CmpServiceLib.Models.VmMigrationRequest vmMigReq = IntToServ(vmmigrationrequest); CmpServiceLib.CmpService CMP = new CmpServiceLib.CmpService(_EventLog, _CmpDbConnectionString, _AftsDbConnectionString); CMP.UpdateVmMigrationRequest(vmMigReq, null, true, null); return(Updated(vmmigrationrequest)); } catch (Exception ex) { LogThis(ex, EventLogEntryType.Error, "Exception in Put()", 100, 100); throw ex; } }
//********************************************************************* /// /// <summary> /// POST odata/VmMigrations /// </summary> /// <param name="vmmigrationrequest"></param> /// <returns></returns> /// //********************************************************************* //[Authorize] public async Task <IHttpActionResult> Post(CmpInterfaceModel.Models.VmMigrationRequest vmmigrationrequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var cmp = new CmpServiceLib.CmpService(_EventLog, _CmpDbConnectionString, _AftsDbConnectionString); var vmMigReq = IntToServ(vmmigrationrequest); if (0 == vmmigrationrequest.ID) { vmmigrationrequest = ServToInt(cmp.InsertVmMigrationRequest(vmMigReq)); } else { cmp.UpdateVmMigrationRequest(vmMigReq, null, true, null); } return(Created(vmmigrationrequest)); }
public IQueryable <CmpInterfaceModel.Models.VmMigrationRequest> GetVmMigrations(ODataQueryOptions queryString) { string filterText = null; string reqStatus = null; string reqAgentRegion = null; string VmDeploymentRequestID = null; string reqAgentName = null; if (null != queryString.Filter) { filterText = queryString.Filter.RawValue; reqStatus = ExtractQsValue(filterText, "StatusCode"); reqAgentRegion = ExtractQsValue(filterText, "AgentRegion"); reqAgentName = ExtractQsValue(filterText, "AgentName"); VmDeploymentRequestID = ExtractQsValueByKey(filterText, "VmDeploymentRequestID"); reqAgentName = ExtractQsValueByAgent(filterText, "AgentName"); } var vmrOutList = new List <CmpInterfaceModel.Models.VmMigrationRequest>(); try { using (CmpServiceLib.CmpService CMP = new CmpServiceLib.CmpService(_EventLog, _CmpDbConnectionString, _AftsDbConnectionString)) { List <CmpServiceLib.Models.VmMigrationRequest> vmMigrationRequestList = null; if (null == VmDeploymentRequestID) { vmMigrationRequestList = CMP.FetchMigrationRequestsByAgent(reqAgentName); var filteredMigrationRequest = vmMigrationRequestList.DistinctBy(o => o.ID); vmMigrationRequestList = filteredMigrationRequest.ToList(); } else { vmMigrationRequestList = new List <VmMigrationRequest>(); var migrationRequest = CMP.FetchMigrationRequest(Convert.ToInt32(VmDeploymentRequestID), CmpDb.FetchMigrationRequestKeyTypeEnum.DepReqId); if (null != migrationRequest) { vmMigrationRequestList.Add(migrationRequest); } } if (null == vmMigrationRequestList) { return(null); } foreach (CmpServiceLib.Models.VmMigrationRequest vmMigrationRequest in vmMigrationRequestList) { vmrOutList.Add(ServToInt(vmMigrationRequest)); } } } catch (Exception ex) { LogThis(ex, EventLogEntryType.Error, "Exception in GetVmMigrationRequests()", 100, 100); throw; } return(vmrOutList.AsQueryable()); }