Ejemplo n.º 1
0
        public async Task <IActionResult> CreateProjectAsync([FromBody] Project projectEntity)
        {
            var existingModel = await _dao.FindBySpecificationAsync <Project>(p => p.Name == projectEntity.Name);

            if (existingModel.FirstOrDefault() != null)
            {
                return(Conflict($"Project '{projectEntity.Name}' already exists."));
            }

            projectEntity.DateCreated = DateTime.UtcNow;

            await _dao.AddAsync(projectEntity);

            return(CreatedAtAction(nameof(GetProjectByIdAsync), new { id = projectEntity.Id }, projectEntity.Id));
        }
        public void Setup()
        {
            var mockCluster1 = new Mock <ICluster>();

            mockCluster1.Setup(x => x.Id).Returns(_cluster1Guid);
            mockCluster1.Setup(x => x.Name).Returns("cluster1");
            mockCluster1.Setup(x => x.Type).Returns("cluster");

            var mockCluster2 = new Mock <ICluster>();

            mockCluster2.Setup(x => x.Id).Returns(_cluster2Guid);
            mockCluster2.Setup(x => x.Name).Returns("cluster2");
            mockCluster2.Setup(x => x.Type).Returns("cluster");

            _clusters = new ClusterCollection
            {
                mockCluster1.Object,
                mockCluster2.Object
            };

            _dao = new InMemoryDataAccessObject();
            _dao.AddAsync(new ClusterConnectionEntity
            {
                Id          = _clusterConnection1Guid,
                ClusterType = "cluster",
                Description = "fake cluster connection",
                Name        = "FakeClusterConnection",
            });

            _controller = new ClusterConnectionsController(_logger, _clusters, _dao);
        }
        public async Task AddAsync <TObject>(TObject entity) where TObject : IEntity
        {
            await _wrappedDao.AddAsync(entity);

            var key = entity.Id.ToString();
            var val = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(entity));
            await _cache.SetAsync(key, val);
        }
Ejemplo n.º 4
0
        public override async Task <bool> HandleAsync(CustomerCreatedEvent @event, CancellationToken cancellationToken = default)
        {
            var customer = new Model.Customer(@event.CustomerId, @event.CustomerName, @event.Email);
            await dao.AddAsync(customer);

            this.logger.LogInformation($"客户信息创建成功。");

            return(true);
        }
Ejemplo n.º 5
0
        public async Task Execute(IJobExecutionContext context)
        {
            var jobName = context?.JobDetail?.Key?.Name;

            if (string.IsNullOrEmpty(jobName))
            {
                _logger.LogError("No name defined on the JobDetail.");
                return;
            }

            if (!context?.MergedJobDataMap.ContainsKey("clusterType") ?? true)
            {
                _logger.LogError($"Failed to start the job, the clusterType is not specified in the job data. Execution ID: {jobName}");
                return;
            }

            try
            {
                var clusterType = context?.MergedJobDataMap["clusterType"].ToString() !;
                IDictionary <string, object> properties;
                if (context?.MergedJobDataMap.ContainsKey("properties") ?? false)
                {
                    properties = context.MergedJobDataMap["properties"] as IDictionary <string, object> ?? new Dictionary <string, object>();
                }
                else
                {
                    properties = new Dictionary <string, object>();
                }

                _logger.LogInformation($"Submitting job, Execution ID: {jobName}, Cluster Type: {clusterType}");

                var jobEntity = await _clusterService.SubmitJobAsync(clusterType, properties, context?.CancellationToken ?? default);

                if (jobEntity.State == JobState.Created)
                {
                    _logger.LogInformation($"Job {jobName} has been successfully submitted to the cluster whose type is {clusterType}");
                }
                else
                {
                    _logger.LogError($"Job {jobName} created failed, check log for more information.");
                    _logger.LogError(string.Join(Environment.NewLine, jobEntity.Logs.ToArray()));
                }

                jobEntity.SubmissionName = jobName;
                await _dao.AddAsync(jobEntity);

                _logger.LogInformation($"Job {jobName} has been saved successfully, Job ID: {jobEntity.Id}");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Failed to submit the job to the cluster, Execution ID: {jobName}");
            }
        }