Example #1
0
        public async Task <HttpResponseMessage> Put(int id, string deployId, [FromBody] DeploymentInstance detail)
        {
            var deployment = await this.repository.GetDeployment(id);

            repository.UpdateInstanceDiagnostics(detail.Configuration, deployId, deployment.RoleName, detail.Id);
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public async Task <InvokeResult> AddInstanceAsync(DeploymentInstance instance, EntityHeader org, EntityHeader user)
        {
            var host = CreateHost(instance);

            instance.PrimaryHost = new EntityHeader <DeploymentHost>()
            {
                Id = host.Id, Text = host.Name
            };

            ValidationCheck(host, Actions.Create);
            ValidationCheck(instance, Actions.Create);

            await AuthorizeAsync(instance, AuthorizeResult.AuthorizeActions.Create, user, org);

            if (!EntityHeader.IsNullOrEmpty(instance.DeviceRepository))
            {
                var repo = await _deviceManagerRepo.GetDeviceRepositoryAsync(instance.DeviceRepository.Id, org, user);

                if (EntityHeader.IsNullOrEmpty(repo.Instance))
                {
                    repo.Instance = EntityHeader.Create(instance.Id, instance.Name);
                    await _deviceManagerRepo.UpdateDeviceRepositoryAsync(repo, org, user);
                }
                else
                {
                    throw new ValidationException("Can not reassign repo", new ErrorMessage($"Repository is already assigned to the instance {repo.Instance.Text}.  A Device Repository can only be assigned to one Instance at a time."));
                }
            }

            await _instanceRepo.AddInstanceAsync(instance);

            await _deploymentHostManager.AddDeploymentHostAsync(host, org, user);

            return(InvokeResult.Success);
        }
        private DeploymentHost CreateHost(DeploymentInstance instance)
        {
            var host = new DeploymentHost
            {
                Id                = Guid.NewGuid().ToId(),
                HostType          = EntityHeader <HostTypes> .Create(HostTypes.Dedicated),
                CreatedBy         = instance.CreatedBy,
                Name              = $"{instance.Name} Host",
                LastUpdatedBy     = instance.LastUpdatedBy,
                OwnerOrganization = instance.OwnerOrganization,
                OwnerUser         = instance.OwnerUser,
                CreationDate      = instance.CreationDate,
                LastUpdatedDate   = instance.LastUpdatedDate,
                DedicatedInstance = new EntityHeader()
                {
                    Id = instance.Id, Text = instance.Name
                },
                Key                 = instance.Key,
                IsPublic            = false,
                Status              = EntityHeader <HostStatus> .Create(HostStatus.Offline),
                Size                = instance.Size,
                CloudProvider       = instance.CloudProvider,
                Subscription        = instance.Subscription,
                ContainerRepository = instance.ContainerRepository,
                ContainerTag        = instance.ContainerTag,
                DnsHostName         = instance.DnsHostName,
            };

            return(host);
        }
Example #4
0
        private DeploymentInstance GetInstance()
        {
            var instance = new DeploymentInstance();

            instance.Id              = DEVICE_INSTANCE_ID;
            instance.CreatedBy       = EntityHeader.Create(Guid.NewGuid().ToId(), "username");
            instance.LastUpdatedBy   = instance.CreatedBy;
            instance.CreationDate    = DateTime.Now.ToJSONString();
            instance.LastUpdatedDate = DateTime.Now.ToJSONString();
            instance.Key             = "abc123";
            instance.Name            = "myinstance";
            instance.PrimaryHost     = new EntityHeader <DeploymentHost>()
            {
                Id = "123", Text = "abc"
            };
            instance.Subscription        = EntityHeader.Create("id", "text");
            instance.ContainerRepository = EntityHeader.Create("id", "text");
            instance.ContainerTag        = EntityHeader.Create("id", "text");
            instance.Solution            = new EntityHeader <Solution>()
            {
                Id = "id", Text = "text"
            };
            instance.Size             = EntityHeader.Create("id", "text");
            instance.DeviceRepository = new EntityHeader <DeviceRepository>()
            {
                Id = NEW_DEVICE_REPO_ID, Text = "Don't Care"
            };

            return(instance);
        }
        public async Task <InvokeResult> UpdateInstanceAsync(DeploymentInstance instance, EntityHeader org, EntityHeader user)
        {
            ValidationCheck(instance, Actions.Update);
            await AuthorizeAsync(instance, AuthorizeResult.AuthorizeActions.Update, user, org);

            var existingInstance = await _instanceRepo.GetInstanceAsync(instance.Id);

            if (existingInstance.DeviceRepository.Id != instance.DeviceRepository.Id)
            {
                var newlyAssginedRepo = await _deviceManagerRepo.GetDeviceRepositoryAsync(instance.DeviceRepository.Id, org, user);

                if (!EntityHeader.IsNullOrEmpty(newlyAssginedRepo.Instance))
                {
                    throw new ValidationException("Device Repository In Use", new ErrorMessage($"Repository is already assigned to the instance {newlyAssginedRepo.Instance.Text}.  A Device Repository can only be assigned to one Instance at a time."));
                }

                newlyAssginedRepo.Instance = EntityHeader.Create(instance.Id, instance.Name);
                await _deviceManagerRepo.UpdateDeviceRepositoryAsync(newlyAssginedRepo, org, user);

                var oldRepo = await _deviceManagerRepo.GetDeviceRepositoryAsync(existingInstance.DeviceRepository.Id, org, user);

                oldRepo.Instance = null;
                await _deviceManagerRepo.UpdateDeviceRepositoryAsync(oldRepo, org, user);
            }

            if (existingInstance.Status.Value != instance.Status.Value ||
                existingInstance.IsDeployed != instance.IsDeployed)
            {
                await UpdateInstanceStatusAsync(instance.Id, instance.Status.Value, instance.IsDeployed, instance.ContainerTag.Text.Replace("v", string.Empty), org, user);
            }

            var solution = instance.Solution.Value;

            instance.Solution.Value = null;
            await _instanceRepo.UpdateInstanceAsync(instance);

            instance.Solution.Value = solution;

            if (!EntityHeader.IsNullOrEmpty(instance.PrimaryHost))
            {
                var host = await _deploymentHostManager.GetDeploymentHostAsync(instance.PrimaryHost.Id, org, user);

                if (host.Size.Id != instance.Size.Id ||
                    host.CloudProvider.Id != instance.CloudProvider.Id ||
                    host.Subscription.Id != instance.Subscription.Id ||
                    host.ContainerRepository.Id != instance.ContainerRepository.Id ||
                    host.ContainerTag.Id != instance.ContainerTag.Id)
                {
                    host.Size                = instance.Size;
                    host.Subscription        = instance.Subscription;
                    host.CloudProvider       = instance.CloudProvider;
                    host.ContainerRepository = instance.ContainerRepository;
                    host.ContainerTag        = instance.ContainerTag;
                    await _deploymentHostManager.UpdateDeploymentHostAsync(host, org, user);
                }
            }

            return(InvokeResult.Success);
        }
Example #6
0
        public ValidationResult ValidateInstance(DeploymentInstance intance)
        {
            var result = new ValidationResult();

            /* TODO Need to do a full sweep of the instance, make sure everything is populated that needs to be */



            return(result);
        }
Example #7
0
        private async Task <InvokeResult> PerformActionAsync(DeploymentInstance instance, EntityHeader org, EntityHeader user, DeploymentActivityTaskTypes activityType, int timeoutSeconds = 120)
        {
            var timeout = DateTime.UtcNow.Add(TimeSpan.FromSeconds(timeoutSeconds));

            await AuthorizeAsync(instance, AuthorizeResult.AuthorizeActions.Perform, user, org, $"{activityType}Instance");

            await _deploymentActivityQueueManager.Enqueue(new DeploymentActivity(DeploymentActivityResourceTypes.Instance, instance.Id, activityType)
            {
                RequestedByUserId           = user.Id,
                RequestedByUserName         = user.Text,
                RequestedByOrganizationId   = org.Id,
                RequestedByOrganizationName = org.Text,
                TimeoutTimeStamp            = timeout.ToJSONString()
            });

            return(InvokeResult.Success);
        }
Example #8
0
        private DeploymentInstance GetInstance()
        {
            var instance = new DeploymentInstance();

            instance.Id              = DEVICE_INSTANCE_ID;
            instance.CreatedBy       = EntityHeader.Create(Guid.NewGuid().ToId(), "username");
            instance.LastUpdatedBy   = instance.CreatedBy;
            instance.CreationDate    = DateTime.Now.ToJSONString();
            instance.LastUpdatedDate = DateTime.Now.ToJSONString();
            instance.Key             = "abc123";
            instance.Name            = "myinstance";
            instance.PrimaryHost     = new EntityHeader <DeploymentHost>()
            {
                Id = "123", Text = "abc"
            };
            instance.Subscription        = EntityHeader.Create("id", "text");
            instance.ContainerRepository = EntityHeader.Create("id", "text");
            instance.ContainerTag        = EntityHeader.Create("id", "text");
            instance.Solution            = new EntityHeader <Solution>()
            {
                Id = "id", Text = "text"
            };
            instance.Size          = EntityHeader.Create("id", "text");
            instance.NuvIoTEdition = EntityHeader <NuvIoTEditions> .Create(NuvIoTEditions.App);

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

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

            instance.DeviceRepository = new EntityHeader <DeviceRepository>()
            {
                Id = NEW_DEVICE_REPO_ID, Text = "Don't Care"
            };
            instance.DeploymentConfiguration = EntityHeader <DeploymentConfigurations> .Create(DeploymentConfigurations.SingleInstance);

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

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

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

            instance.SharedAccessKey1 = "ABC123";
            instance.SharedAccessKey2 = "ABC123";
            return(instance);
        }
Example #9
0
        public DeploymentInstance CreateInstance(Solution solution, DeviceRepository deviceRepo, EntityHeader org, EntityHeader user, DateTime creationTimeStamp)
        {
            var instance = new DeploymentInstance()
            {
                Name             = "Sample Deployment",
                Key              = "sample",
                DeviceRepository = new EntityHeader <DeviceRepository>()
                {
                    Id = deviceRepo.Id, Text = deviceRepo.Name
                },
                Solution = new EntityHeader <Solution>()
                {
                    Id = solution.Id, Text = solution.Name
                },
            };

            AddId(instance);
            AddOwnedProperties(instance, org);
            AddAuditProperties(instance, creationTimeStamp, org, user);
            return(instance);
        }
Example #10
0
 public Task <InvokeResult> UpdateInstanceAsync([FromBody] DeploymentInstance instance)
 {
     SetUpdatedProperties(instance);
     return(_instanceManager.UpdateInstanceAsync(instance, OrgEntityHeader, UserEntityHeader));
 }
Example #11
0
 public Task <InvokeResult> AddInstanceAsync([FromBody] DeploymentInstance instance)
 {
     return(_instanceManager.AddInstanceAsync(instance, OrgEntityHeader, UserEntityHeader));
 }
Example #12
0
        public async Task <LagoVista.IoT.Simulator.Admin.Models.Simulator> CreateSimulator(DeploymentInstance instance, Device device, string name, string key,
                                                                                           EntityHeader org, EntityHeader user, DateTime createTimestamp)
        {
            await _storageUtils.DeleteIfExistsAsync <LagoVista.IoT.Simulator.Admin.Models.Simulator>(key, org);

            var sim = new LagoVista.IoT.Simulator.Admin.Models.Simulator()
            {
                Name = name,
                Key  = key,
            };

            AddId(sim);
            AddOwnedProperties(sim, org);
            AddAuditProperties(sim, createTimestamp, org, user);

            sim.DefaultEndPoint    = instance.DnsHostName;
            sim.DefaultPort        = 80;
            sim.Anonymous          = true;
            sim.BasicAuth          = false;
            sim.DefaultPayloadType = EntityHeader <PaylodTypes> .Create(PaylodTypes.String);

            sim.DefaultTransport = EntityHeader <Simulator.Admin.Models.TransportTypes> .Create(Simulator.Admin.Models.TransportTypes.RestHttp);

            sim.DeviceId    = device.DeviceId;
            sim.Description = "This simulator is created as part of the Motion Tutorial, it will demonstrate how to send two messages, one that indicates motion has been seen and one that motion is no longer active.";

            var motionMessage = new MessageTemplate()
            {
                ContentType        = "application/json",
                HttpVerb           = "POST",
                PayloadType        = EntityHeader <PaylodTypes> .Create(PaylodTypes.String),
                Name               = "Motion Detected",
                Key                = "motiondetected",
                Id                 = Guid.NewGuid().ToId(),
                TextPayload        = "{'motion':true}",
                PathAndQueryString = "/api/motion/~deviceid~",
                EndPoint           = sim.DefaultEndPoint,
                Transport          = EntityHeader <TransportTypes> .Create(TransportTypes.RestHttp),
            };

            var motionClearedMessage = new MessageTemplate()
            {
                ContentType        = "application/json",
                HttpVerb           = "POST",
                PayloadType        = EntityHeader <PaylodTypes> .Create(PaylodTypes.String),
                Name               = "Motion Cleared",
                Key                = "motioncleared",
                Id                 = Guid.NewGuid().ToId(),
                TextPayload        = "{'motion':false}",
                EndPoint           = sim.DefaultEndPoint,
                PathAndQueryString = "/api/motion/~deviceid~",
                Transport          = EntityHeader <TransportTypes> .Create(TransportTypes.RestHttp),
            };

            sim.MessageTemplates.Add(motionMessage);
            sim.MessageTemplates.Add(motionClearedMessage);

            await this._simulatorMgr.AddSimulatorAsync(sim, org, user);

            return(sim);
        }
Example #13
0
 private InvokeResult CanTransitionToState(DeploymentHost host, DeploymentInstance instance, DeploymentActivityTaskTypes taskType, EntityHeader org, EntityHeader user)
 {
     return(InvokeResult.Success);
 }
Example #14
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);
        }
        public async Task <InvokeResult> UpdateInstanceAsync(DeploymentInstance instance, EntityHeader org, EntityHeader user)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("Null Reference Provided for instance.");
            }
            if (org == null)
            {
                throw new ArgumentNullException("Null Reference Provided for org.");
            }
            if (user == null)
            {
                throw new ArgumentNullException("Null Reference Provided for user.");
            }

            ValidationCheck(instance, Actions.Update);
            await AuthorizeAsync(instance, AuthorizeResult.AuthorizeActions.Update, user, org);

            var existingInstance = await _instanceRepo.GetInstanceAsync(instance.Id);

            if (existingInstance == null)
            {
                throw new RecordNotFoundException(typeof(DeploymentInstance).Name, instance.Id);
            }

            if (existingInstance.DeviceRepository.Id != instance.DeviceRepository.Id)
            {
                var newlyAssginedRepo = await _deviceManagerRepo.GetDeviceRepositoryAsync(instance.DeviceRepository.Id, org, user);

                if (!EntityHeader.IsNullOrEmpty(newlyAssginedRepo.Instance))
                {
                    throw new ValidationException("Device Repository In Use", new ErrorMessage($"Repository is already assigned to the instance {newlyAssginedRepo.Instance.Text}.  A Device Repository can only be assigned to one Instance at a time."));
                }

                newlyAssginedRepo.Instance = EntityHeader.Create(instance.Id, instance.Name);
                await _deviceManagerRepo.UpdateDeviceRepositoryAsync(newlyAssginedRepo, org, user);

                var oldRepo = await _deviceManagerRepo.GetDeviceRepositoryAsync(existingInstance.DeviceRepository.Id, org, user);

                oldRepo.Instance = null;
                await _deviceManagerRepo.UpdateDeviceRepositoryAsync(oldRepo, org, user);
            }

            if (!String.IsNullOrEmpty(instance.SharedAccessKey1))
            {
                var addResult = await _secureStorage.AddSecretAsync(org, instance.SharedAccessKey1);

                if (!addResult.Successful)
                {
                    return(addResult.ToInvokeResult());
                }

                if (!String.IsNullOrEmpty(instance.SharedAccessKeySecureId1))
                {
                    var removeResult = await _secureStorage.RemoveSecretAsync(org, instance.SharedAccessKeySecureId1);

                    if (!removeResult.Successful)
                    {
                        return(removeResult);
                    }
                }

                instance.SharedAccessKey1         = null;
                instance.SharedAccessKeySecureId1 = addResult.Result;
            }

            if (!String.IsNullOrEmpty(instance.SharedAccessKey2))
            {
                var addResult = await _secureStorage.AddSecretAsync(org, instance.SharedAccessKey2);

                if (!addResult.Successful)
                {
                    return(addResult.ToInvokeResult());
                }

                if (!String.IsNullOrEmpty(instance.SharedAccessKeySecureId2))
                {
                    var removeResult = await _secureStorage.RemoveSecretAsync(org, instance.SharedAccessKeySecureId2);

                    if (!removeResult.Successful)
                    {
                        return(removeResult);
                    }
                }

                instance.SharedAccessKey2         = null;
                instance.SharedAccessKeySecureId2 = addResult.Result;
            }

            if (existingInstance.Status.Value != instance.Status.Value ||
                existingInstance.IsDeployed != instance.IsDeployed)
            {
                await UpdateInstanceStatusAsync(instance.Id, instance.Status.Value, instance.IsDeployed, instance.ContainerTag.Text.Replace("v", string.Empty), org, user);
            }

            var solution = instance.Solution.Value;

            instance.Solution.Value = null;
            await _instanceRepo.UpdateInstanceAsync(instance);

            instance.Solution.Value = solution;

            if (!EntityHeader.IsNullOrEmpty(instance.PrimaryHost))
            {
                var host = await _deploymentHostManager.GetDeploymentHostAsync(instance.PrimaryHost.Id, org, user);

                if (host.Size?.Id != instance.Size?.Id ||
                    host.CloudProvider.Id != instance.CloudProvider.Id ||
                    host.Subscription.Id != instance.Subscription.Id ||
                    host.ContainerRepository?.Id != instance.ContainerRepository?.Id ||
                    host.ContainerTag?.Id != instance.ContainerTag?.Id)
                {
                    host.Size                = instance.Size;
                    host.Subscription        = instance.Subscription;
                    host.CloudProvider       = instance.CloudProvider;
                    host.ContainerRepository = instance.ContainerRepository;
                    host.ContainerTag        = instance.ContainerTag;
                    await _deploymentHostManager.UpdateDeploymentHostAsync(host, org, user);
                }
            }

            return(InvokeResult.Success);
        }
        protected void MapInstanceProperties(DeploymentInstance instance)
        {
            if (EntityHeader <NuvIoTEditions> .IsNullOrEmpty(instance.NuvIoTEdition))
            {
                switch (instance.DeploymentConfiguration.Value)
                {
                case DeploymentConfigurations.DockerSwarm:
                    instance.NuvIoTEdition = EntityHeader <NuvIoTEditions> .Create(NuvIoTEditions.Container);

                    break;

                case DeploymentConfigurations.Kubernetes:
                    instance.NuvIoTEdition = EntityHeader <NuvIoTEditions> .Create(NuvIoTEditions.Cluster);

                    break;

                case DeploymentConfigurations.SingleInstance:
                    instance.NuvIoTEdition = EntityHeader <NuvIoTEditions> .Create(NuvIoTEditions.Container);

                    break;

                case DeploymentConfigurations.UWP:
                    instance.NuvIoTEdition = EntityHeader <NuvIoTEditions> .Create(NuvIoTEditions.App);

                    break;
                }

                instance.NuvIoTEdition = EntityHeader <NuvIoTEditions> .Create(NuvIoTEditions.Container);
            }

            if (EntityHeader <WorkingStorage> .IsNullOrEmpty(instance.WorkingStorage))
            {
                if (instance.NuvIoTEdition.Value == NuvIoTEditions.App)
                {
                    instance.WorkingStorage = EntityHeader <WorkingStorage> .Create(WorkingStorage.Local);
                }
                else
                {
                    instance.WorkingStorage = EntityHeader <WorkingStorage> .Create(WorkingStorage.Cloud);
                }
            }

            if (EntityHeader <DeploymentTypes> .IsNullOrEmpty(instance.DeploymentType))
            {
                if (instance.NuvIoTEdition.Value == NuvIoTEditions.App)
                {
                    instance.DeploymentType = EntityHeader <DeploymentTypes> .Create(DeploymentTypes.OnPremise);
                }
                else if (instance.NuvIoTEdition.Value == NuvIoTEditions.Container)
                {
                    instance.DeploymentType = EntityHeader <DeploymentTypes> .Create(DeploymentTypes.Managed);
                }
                else
                {
                    instance.DeploymentType = EntityHeader <DeploymentTypes> .Create(DeploymentTypes.Cloud);
                }
            }

            if (EntityHeader <QueueTypes> .IsNullOrEmpty(instance.QueueType))
            {
                if (instance.NuvIoTEdition.Value == NuvIoTEditions.Cluster)
                {
                    instance.QueueType = EntityHeader <QueueTypes> .Create(QueueTypes.RabbitMQ);
                }
                else
                {
                    instance.QueueType = EntityHeader <QueueTypes> .Create(QueueTypes.InMemory);
                }
            }
        }
Example #17
0
 protected virtual Task <InvokeResult> PerformActionAsync(DeploymentInstance instance, EntityHeader org, EntityHeader user, DeploymentActivityTaskTypes activityType, int timeoutSeconds = 120)
 {
     return(Task.FromResult <InvokeResult>(InvokeResult.Success));
 }
Example #18
0
        public Simulator.Admin.Models.Simulator CreateSimulator(DeploymentInstance instance, EntityHeader org, EntityHeader user, DateTime creationTimeStamp)
        {
            var simulator = new Simulator.Admin.Models.Simulator()
            {
                Id               = "Simulator for Sample App",
                Key              = "sampleappsimulator",
                DefaultEndPoint  = instance.DnsHostName,
                TLSSSL           = false,
                DefaultTransport = EntityHeader <Simulator.Admin.Models.TransportTypes> .Create(Simulator.Admin.Models.TransportTypes.RestHttp),
                MessageTemplates = new List <Simulator.Admin.Models.MessageTemplate>()
                {
                    new Simulator.Admin.Models.MessageTemplate()
                    {
                        Name               = "Motion Message",
                        Key                = "motionmsg",
                        Id                 = Guid.NewGuid().ToId(),
                        TextPayload        = "{'motion':'~motionvalue~','level':~motionlevel~}",
                        PathAndQueryString = "/smplmot001/~deviceid~",
                        DynamicAttributes  = new List <Simulator.Admin.Models.MessageDynamicAttribute>()
                        {
                            new Simulator.Admin.Models.MessageDynamicAttribute()
                            {
                                Id            = Guid.NewGuid().ToId(),
                                Key           = "motionvalue",
                                DefaultValue  = "on",
                                Name          = "Motion On/Off",
                                ParameterType = EntityHeader <ParameterTypes> .Create(ParameterTypes.String),
                                Description   = "Provide a value of 'on' or 'off' to simulate motion detected"
                            },
                            new Simulator.Admin.Models.MessageDynamicAttribute()
                            {
                                Id            = Guid.NewGuid().ToId(),
                                Key           = "motionlevel",
                                DefaultValue  = "100",
                                Name          = "Motion Level",
                                ParameterType = EntityHeader <ParameterTypes> .Create(ParameterTypes.Integer),
                                Description   = "Provide a value between 0 and 100 as to the level of motion detected"
                            }
                        }
                    },
                    new Simulator.Admin.Models.MessageTemplate()
                    {
                        Name           = "Temperature Message",
                        Key            = "tempmsg",
                        Id             = Guid.NewGuid().ToId(),
                        TextPayload    = "~temperaturevalue~,~humidityvalue~",
                        PayloadType    = EntityHeader <Simulator.Admin.Models.PaylodTypes> .Create(Simulator.Admin.Models.PaylodTypes.String),
                        ContentType    = "text/csv",
                        HttpVerb       = "POST",
                        MessageHeaders = new List <Simulator.Admin.Models.MessageHeader>()
                        {
                            new Simulator.Admin.Models.MessageHeader()
                            {
                                HeaderName = "x-messageid", Value = "smpltmp001", Id = Guid.NewGuid().ToId(), Key = "xmessageid", Name = "x-messageid"
                            },
                            new Simulator.Admin.Models.MessageHeader()
                            {
                                HeaderName = "x-deviceid", Value = "~deviceid~", Id = Guid.NewGuid().ToId(), Key = "xdeviceid", Name = "x-deviceid"
                            },
                        },
                        DynamicAttributes = new List <Simulator.Admin.Models.MessageDynamicAttribute>()
                        {
                            new Simulator.Admin.Models.MessageDynamicAttribute()
                            {
                                Id            = Guid.NewGuid().ToId(),
                                Key           = "temperaturevalue",
                                DefaultValue  = "98.6",
                                Name          = "Temperature",
                                ParameterType = EntityHeader <ParameterTypes> .Create(ParameterTypes.Decimal),
                                Description   = "Provide a value of 'on' or 'off' to simulate motion detected"
                            },
                            new Simulator.Admin.Models.MessageDynamicAttribute()
                            {
                                Id            = Guid.NewGuid().ToId(),
                                Key           = "humidityvalue",
                                DefaultValue  = "65",
                                Name          = "Humidity",
                                ParameterType = EntityHeader <ParameterTypes> .Create(ParameterTypes.Decimal),
                                Description   = "Provide a value between 0 and 100 as to the level of motion detected"
                            }
                        }
                    },
                }
            };

            AddId(simulator);
            AddOwnedProperties(simulator, org);
            AddAuditProperties(simulator, creationTimeStamp, org, user);

            return(simulator);
        }
Example #19
0
        public void InstanceValidation_ListenerUniquePorts_Valid()
        {
            var instance = new DeploymentInstance()
            {
                Id                  = Guid.NewGuid().ToId(),
                CreationDate        = DateTime.UtcNow.ToJSONString(),
                LastUpdatedDate     = DateTime.UtcNow.ToJSONString(),
                LastUpdatedBy       = EntityHeader.Create("6DA61E6EA91448618F2248C97C354F1C", "USER"),
                CreatedBy           = EntityHeader.Create("6DA61E6EA91448618F2248C97C354F1C", "CREATED"),
                OwnerOrganization   = EntityHeader.Create("1112403B28644ED180465C0393F0CA14", "USER"),
                Key                 = "instancekey",
                Name                = "MyInstance",
                ContainerRepository = new EntityHeader()
                {
                    Id = "2212403B28644ED180465C0393F0CA14", Text = "Container"
                },
                ContainerTag = new EntityHeader()
                {
                    Id = "3312403B28644ED180465C0393F0CA14", Text = "ContainerTag"
                },
                CloudProvider = new EntityHeader()
                {
                    Id = "4412403B28644ED180465C0393F0CA14", Text = "CloudProvider"
                },
                Subscription = new EntityHeader()
                {
                    Id = "7712403B28644ED180465C0393F0CA14", Text = "MySubscription"
                },
                Size = new EntityHeader()
                {
                    Id = "9912403B28644ED180465C0393F0CA14", Text = "MySubscription"
                },
                DeviceRepository = new EntityHeader <DeviceManagement.Core.Models.DeviceRepository>()
                {
                    Id    = "AA12403B28644ED180465C0393F0CA14",
                    Text  = "DeviceRepo",
                    Value = new DeviceManagement.Core.Models.DeviceRepository()
                    {
                    }
                },
                Solution = new EntityHeader <Solution>()
                {
                    Id    = "BB12403B28644ED180465C0393F0CA14",
                    Text  = "MySolution",
                    Value = new Solution()
                    {
                        Id                = "BB12403B28644ED180465C0393F0CA14",
                        CreationDate      = DateTime.UtcNow.ToJSONString(),
                        LastUpdatedDate   = DateTime.UtcNow.ToJSONString(),
                        LastUpdatedBy     = EntityHeader.Create("6DA61E6EA91448618F2248C97C354F1C", "USER"),
                        CreatedBy         = EntityHeader.Create("6DA61E6EA91448618F2248C97C354F1C", "CREATED"),
                        OwnerOrganization = EntityHeader.Create("1112403B28644ED180465C0393F0CA14", "USER"),
                        Key               = "solutionkey",
                        Name              = "MySolution",
                        Planner           = new EntityHeader <Pipeline.Admin.Models.PlannerConfiguration>()
                        {
                            Id    = "07F5FD0D4D734AC48110-184DCB20F285",
                            Text  = "MyPlanner",
                            Value = new Pipeline.Admin.Models.PlannerConfiguration()
                            {
                                Id                = "07F5FD0D4D734AC48110184DCB20F285",
                                Name              = "MyPlanner",
                                CreationDate      = DateTime.UtcNow.ToJSONString(),
                                LastUpdatedDate   = DateTime.UtcNow.ToJSONString(),
                                LastUpdatedBy     = EntityHeader.Create("6DA61E6EA91448618F2248C97C354F1C", "USER"),
                                CreatedBy         = EntityHeader.Create("6DA61E6EA91448618F2248C97C354F1C", "CREATED"),
                                OwnerOrganization = EntityHeader.Create("1112403B28644ED180465C0393F0CA14", "USER"),
                                Key               = "plannerkey",
                            }
                        }
                    }
                }
            };

            var result = Validator.Validate(instance, Actions.Any);

            //AssertIsValid(result);
        }