private async Async.Task <HttpResponseData> Post(HttpRequestData req) { var request = await RequestHandling.ParseRequest <NodeStateEnvelope>(req); if (!request.IsOk) { return(await _context.RequestHandling.NotOk(req, request.ErrorV, context : "node event")); } var envelope = request.OkV; _log.Info($"node event: machine_id: {envelope.MachineId} event: {EntityConverter.ToJsonString(envelope)}"); var error = envelope.Event switch { NodeStateUpdate updateEvent => await OnStateUpdate(envelope.MachineId, updateEvent), WorkerEvent workerEvent => await OnWorkerEvent(envelope.MachineId, workerEvent), NodeEvent nodeEvent => await OnNodeEvent(envelope.MachineId, nodeEvent), _ => new Error(ErrorCode.INVALID_REQUEST, new string[] { $"invalid node event: {envelope.Event.GetType().Name}" }), }; if (error is Error e) { return(await _context.RequestHandling.NotOk(req, e, context : "node event")); } else { return(await RequestHandling.Ok(req, new BoolResult(true))); } }
private async Async.Task <HttpResponseData> Post(HttpRequestData req) { var request = await RequestHandling.ParseRequest <NodeAddSshKeyPost>(req); if (!request.IsOk) { return(await _context.RequestHandling.NotOk( req, request.ErrorV, "NodeAddSshKey")); } var node = await _context.NodeOperations.GetByMachineId(request.OkV.MachineId); if (node == null) { return(await _context.RequestHandling.NotOk( req, new Error(ErrorCode.UNABLE_TO_FIND, new[] { "unable to find node" }), $"{request.OkV.MachineId}")); } var result = await _context.NodeOperations.AddSshPublicKey(node, request.OkV.PublicKey); if (!result.IsOk) { return(await _context.RequestHandling.NotOk(req, result.ErrorV, "NodeAddSshKey")); } var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new BoolResult(true)); return(response); }
private async Async.Task <HttpResponseData> Get(HttpRequestData req) { _log.Info("Notification search"); var request = await RequestHandling.ParseUri <NotificationSearch>(req); if (!request.IsOk) { return(await _context.RequestHandling.NotOk(req, request.ErrorV, "notification search")); } var entries = request.OkV switch { { Container : null } => _context.NotificationOperations.SearchAll(), { Container : var c } => _context.NotificationOperations.SearchByRowKeys(c.Select(x => x.ContainerName)) };
public async Async.Task <HttpResponseData> Run([HttpTrigger] HttpRequestData req) { var request = await RequestHandling.ParseRequest <CanScheduleRequest>(req); if (!request.IsOk || request.OkV == null) { return(await RequestHandling.NotOk(req, request.ErrorV, typeof(CanScheduleRequest).ToString(), _log)); } var canScheduleRequest = request.OkV; var node = await _nodeOperations.GetByMachineId(canScheduleRequest.MachineId); if (node == null) { return(await RequestHandling.NotOk( req, new Error( ErrorCode.UNABLE_TO_FIND, new string[] { "unable to find node" } ), canScheduleRequest.MachineId.ToString(), _log )); } var allowed = true; var workStopped = false; if (!await _nodeOperations.CanProcessNewWork(node)) { allowed = false; } var task = await _taskOperations.GetByTaskId(canScheduleRequest.TaskId); workStopped = task == null || TaskStateHelper.ShuttingDown.Contains(task.State); if (allowed) { allowed = (await _nodeOperations.AcquireScaleInProtection(node)).IsOk; } return(await RequestHandling.Ok( req, new BaseResponse[] { new CanSchedule(allowed, workStopped) })); }
private async Async.Task <HttpResponseData> Post(HttpRequestData req) { var request = await RequestHandling.ParseRequest <CanScheduleRequest>(req); if (!request.IsOk) { return(await _context.RequestHandling.NotOk(req, request.ErrorV, typeof(CanScheduleRequest).ToString())); } var canScheduleRequest = request.OkV; var node = await _context.NodeOperations.GetByMachineId(canScheduleRequest.MachineId); if (node == null) { return(await _context.RequestHandling.NotOk( req, new Error( ErrorCode.UNABLE_TO_FIND, new string[] { "unable to find node" }), canScheduleRequest.MachineId.ToString())); } var allowed = true; if (!await _context.NodeOperations.CanProcessNewWork(node)) { allowed = false; } var task = await _context.TaskOperations.GetByTaskId(canScheduleRequest.TaskId); var workStopped = task == null || task.State.ShuttingDown(); if (workStopped) { allowed = false; } if (allowed) { allowed = (await _context.NodeOperations.AcquireScaleInProtection(node)).IsOk; } return(await RequestHandling.Ok(req, new CanSchedule(Allowed : allowed, WorkStopped : workStopped))); }
private void SetRevitValue() { //What could go wrong? //1. The Value is already set and we go into circular reference - that should be resolved in the Revit value (skip if we are == value) //2. The UIValue is already set and we go into circular reference ... Value = Utils.GetDutValueTo(StorageType, DisplayUnitType, RevitValue); UIValue = ValueConvertUtils.StringFromDoubleConvert(DisplayUnitType, Precision, Value); if (!_suppres) { RequestHandling.MakeRequest(RequestId.ChangeParam, new Tuple <string, double>(Name, RevitValue)); // Suppres request in case of Shuffle, or mass request (can only make 1 single bulk request at a time) } else { _suppres = false; } }
public TestContext(ILogTracer logTracer, IStorage storage, ICreds creds, string storagePrefix) { EntityConverter = new EntityConverter(); ServiceConfiguration = new TestServiceConfiguration(storagePrefix); Storage = storage; Creds = creds; Containers = new Containers(logTracer, Storage, Creds, ServiceConfiguration); Queue = new Queue(Storage, logTracer); RequestHandling = new RequestHandling(logTracer); TaskOperations = new TaskOperations(logTracer, this); NodeOperations = new NodeOperations(logTracer, this); JobOperations = new JobOperations(logTracer, this); NodeTasksOperations = new NodeTasksOperations(logTracer, this); TaskEventOperations = new TaskEventOperations(logTracer, this); NodeMessageOperations = new NodeMessageOperations(logTracer, this); ConfigOperations = new ConfigOperations(logTracer, this); PoolOperations = new PoolOperations(logTracer, this); ScalesetOperations = new ScalesetOperations(logTracer, this); UserCredentials = new UserCredentials(logTracer, ConfigOperations); }
private async Async.Task <HttpResponseData> Get(HttpRequestData req) { var query = HttpUtility.ParseQueryString(req.Url.Query); var container = query["container"]; if (container is null) { return(await _context.RequestHandling.NotOk( req, new Error( ErrorCode.INVALID_REQUEST, new string[] { "'container' query parameter must be provided" }), "download")); } var filename = query["filename"]; if (filename is null) { return(await _context.RequestHandling.NotOk( req, new Error( ErrorCode.INVALID_REQUEST, new string[] { "'filename' query parameter must be provided" }), "download")); } var sasUri = await _context.Containers.GetFileSasUrl( new Container(container), filename, StorageType.Corpus, BlobSasPermissions.Read, TimeSpan.FromMinutes(5)); return(RequestHandling.Redirect(req, sasUri)); }
//Makes a TypeToInstance request to Toggle between the two private void TypeToInstance(object sender) { TypeOrInstance = TypeOrInstance.Equals("Instance") ? "Type" : "Instance"; RequestHandling.MakeRequest(RequestId.TypeToInstance, Name, Type); }
//Makes a Delete Request to Delete the Parameter private void Delete(object sender) { RequestHandling.MakeRequest(RequestId.DeleteId, Name); }
//Changes the Name of the Parameter private void ChangeName() { RequestHandling.MakeRequest(RequestId.ChangeParamName, new Tuple <string, string>(OldName, Name)); }