示例#1
0
 public Task <InvokeResult> AddInstanceAsync([FromBody] DeploymentInstance instance)
 {
     return(_instanceManager.AddInstanceAsync(instance, OrgEntityHeader, UserEntityHeader));
 }
示例#2
0
        public async Task <DeploymentInstance> CreateInstanceAsync(Subscription subscription, Solution solution, DeviceRepository repo, string name, string key,
                                                                   string environmentName, EntityHeader org, EntityHeader user, DateTime createTimestamp)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException(nameof(subscription));
            }
            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }
            if (repo == null)
            {
                throw new ArgumentNullException(nameof(repo));
            }

            var userOrg = await _orgRepo.GetOrganizationAsync(org.Id);

            await _storageUtils.DeleteIfExistsAsync <DeploymentInstance>(key, org);

            await _storageUtils.DeleteIfExistsAsync <DeploymentHost>(key, org);

            var instance = new DeploymentInstance()
            {
                Name = name,
                Key  = key,
            };

            var freeVMInstance = await _productManager.GetProductByKeyAsync("vms", "freetrial", org, user);

            if (freeVMInstance == null)
            {
                throw new ArgumentNullException(nameof(freeVMInstance));
            }

            this.AddId(instance);
            this.AddAuditProperties(instance, createTimestamp, org, user);
            this.AddOwnedProperties(instance, org);

            var containerRepo = await _storageUtils.FindWithKeyAsync <ContainerRepository>("consoleruntime");

            if (containerRepo == null)
            {
                throw new ArgumentNullException(nameof(containerRepo));
            }

            if (EntityHeader.IsNullOrEmpty(containerRepo.PreferredTag))
            {
                throw new ArgumentNullException(nameof(containerRepo.PreferredTag));
            }

            instance.DeviceRepository = new EntityHeader <DeviceRepository>()
            {
                Id = repo.Id, Text = repo.Name
            };
            instance.Subscription = new EntityHeader()
            {
                Id = subscription.Id.ToString(), Text = subscription.Name
            };
            instance.DeploymentConfiguration = EntityHeader <DeploymentConfigurations> .Create(DeploymentConfigurations.SingleInstance);

            instance.DeploymentType = EntityHeader <DeploymentTypes> .Create(DeploymentTypes.Managed);

            instance.QueueType = EntityHeader <QueueTypes> .Create(QueueTypes.InMemory);

            instance.LogStorage = EntityHeader <LogStorage> .Create(LogStorage.Cloud);

            instance.PrimaryCacheType = EntityHeader <CacheTypes> .Create(CacheTypes.LocalInMemory);

            instance.SharedAccessKey1 = _instanceMgr.GenerateAccessKey();
            instance.SharedAccessKey2 = _instanceMgr.GenerateAccessKey();
            instance.NuvIoTEdition    = EntityHeader <NuvIoTEditions> .Create(NuvIoTEditions.Container);

            instance.LogStorage = EntityHeader <LogStorage> .Create(LogStorage.Cloud);

            instance.WorkingStorage = EntityHeader <WorkingStorage> .Create(WorkingStorage.Cloud);

            instance.IsDeployed = false;
            instance.Solution   = new EntityHeader <Solution>()
            {
                Id = solution.Id, Text = solution.Name
            };
            instance.ContainerRepository = new EntityHeader()
            {
                Id = containerRepo.Id, Text = containerRepo.Name
            };
            instance.ContainerTag = containerRepo.PreferredTag;
            instance.Size         = EntityHeader.Create(freeVMInstance.Id.ToString(), freeVMInstance.Name);

            var topLevel = key;

            instance.DnsHostName = environmentName == "production" ? $"{topLevel}.{userOrg.Namespace}.iothost.net" : $"{topLevel}.{userOrg.Namespace}.{environmentName}.iothost.net";

            await _instanceMgr.AddInstanceAsync(instance, org, user);

            return(instance);
        }