Exemplo n.º 1
0
        /// <summary>
        /// Create a volume
        /// </summary>
        /// <param name="createVolumeRequest">Parameters for create</param>
        /// <param name="userId">User id</param>
        /// <exception cref="VolumeException">If cannot create a volume</exception>
        /// <returns>gRPC reply with volume id</returns>
        public async Task <VolumeReply> Create(CreateVolumeRequest createVolumeRequest, string userId)
        {
            logger.LogInformation("Requested for creaton of a volume"); // english

            string      volumeId = IdentityFabric.GenVolumeId();
            VolumeModel volume   = VolumeAdapter.Volume(volumeId, createVolumeRequest);

            logger.LogInformation($"Created the VolumeModel with Id {volumeId}");

            using IConnectionMultiplexer redis = redisService.Connect();
            IDatabase db = redis.GetDatabase();

            logger.LogInformation($"Connected to the Redis servier");

            ITransaction transaction = db.CreateTransaction();

            logger.LogInformation($"Bigin transaction");

            string redisKey = GetVolumeKey(userId, volumeId);

            foreach (PropertyInfo propInfo in volume.GetType().GetProperties())
            {
                _ = transaction.HashSetAsync(redisKey, propInfo.Name, propInfo.GetValue(volume).ToString());
            }

            if (await transaction.ExecuteAsync() == false)
            {
                logger.LogError("Cannot create a volume. Transaction failed");
                throw new VolumeException("Cannot create a volume");
            }
            logger.LogInformation($"Creansaction completed successfully");
            return(VolumeAdapter.Volume(volume));
        }
Exemplo n.º 2
0
        public Instance Transform(LaunchInstanceRequest request)
        {
            List <Volume> dataVolumes = request.DataVolumes
                                        .ToList()
                                        .ConvertAll(id => new Volume()
            {
                Id = id
            });

            return(new Instance()
            {
                Id = IdentityFabric.GenInstanceId(),
                Name = request.Name,
                SystemVolume = new Volume()
                {
                    Id = request.SystemVolume
                },
                DataVolumes = dataVolumes,
                InstanceType = request.InstanceType,
                InstanceState = InstanceState.PENDING
            });
        }