Example #1
0
    private void Save()
    {
        ContainerGroup group       = null;
        ContainerGroup groupParent = ContainerGroup.GetByKey(Convert.ToInt32(ddlParentList.SelectedValue));
        string         path        = string.Empty;

        if (groupParent != null)
        {
            path = groupParent.Path + groupParent.Name + "/";
        }
        if (path.IndexOf(txtGroupName.Text + "/") > 0)
        {
            lbError.CssClass = "hc_error";
            lbError.Text     = "Error: Container group has already a parent with the same name";
            lbError.Visible  = true;
        }
        else
        {
            if (txtGroupId.Enabled)
            {
                group = new ContainerGroup(-1, Convert.ToInt32(ddlParentList.SelectedValue), txtGroupCode.Text, txtGroupName.Text, string.Empty, 0, 0, 0);
            }
            else
            {
                group = ContainerGroup.GetByKey(Convert.ToInt32(txtGroupId.Text));
                if (group != null)
                {
                    group.Code = txtGroupCode.Text;
                    group.Name = txtGroupName.Text;
                }
                group.ParentId = Convert.ToInt32(ddlParentList.SelectedValue);
            }

            if (group != null)
            {
                if (group.Save(txtGroupId.Enabled))
                {
                    lbError.Text     = "Data saved!";
                    lbError.CssClass = "hc_success";
                    lbError.Visible  = true;
                    SessionState.ClearAppContainerGroups();

                    // Create new container group
                    //Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"clientScript", "<script>back();</script>");
                }
                else
                {
                    lbError.CssClass = "hc_error";
                    lbError.Text     = ContainerGroup.LastError;
                    lbError.Visible  = true;
                }
            }
            else
            {
                lbError.CssClass = "hc_error";
                lbError.Text     = "Error: Container group is null";
                lbError.Visible  = true;
            }
        }
    }
Example #2
0
    private void UpdateDataView()
    {
        if (groupId == -1)
        {
            // add new container group
            panelId.Visible    = false;
            txtGroupId.Enabled = true;
            BuildParent(-1);

            UITools.HideToolBarButton(uwToolbar, "Delete");
            UITools.HideToolBarSeparator(uwToolbar, "DeleteSep");
        }
        else
        {
            // update container group
            ContainerGroup group = ContainerGroup.GetByKey(groupId);

            if (group != null)
            {
                txtGroupId.Text    = group.Id.ToString();
                txtGroupId.Enabled = false;
                txtGroupCode.Text  = group.Code;
                txtGroupName.Text  = group.Name;
                //txtGroupName.Enabled = group.AbsoluteContainersCount == 0;
                BuildParent(group.ParentId);
            }
            else
            {
                lbError.CssClass = "hc_error";
                lbError.Text     = "Error: Container group is null";
                lbError.Visible  = true;
            }
        }
    }
Example #3
0
    private void Delete()
    {
        ContainerGroup group = ContainerGroup.GetByKey(Convert.ToInt32(txtGroupId.Text));

        if (group != null)
        {
            if (group.Delete(HyperCatalog.Shared.SessionState.User.Id))
            {
                SessionState.ClearAppContainerGroups();
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", "<script>back();</script>");
            }
            else
            {
                lbError.CssClass = "hc_error";
                lbError.Text     = ContainerGroup.LastError;
                lbError.Visible  = true;
            }
        }
        else
        {
            lbError.CssClass = "hc_error";
            lbError.Text     = "Error: Container group is null";
            lbError.Visible  = true;
        }
    }
Example #4
0
 protected void ddlParentList_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     Trace.Warn("ddlParentList_SelectedIndexChanged,ddlParentList.SelectedValue=" + ddlParentList.SelectedValue.ToString());
     if (ddlParentList.SelectedValue != "-1")
     {
         int nbParents = Convert.ToInt32(ViewState["nbParents"]);
         Trace.Warn("nbParents=" + ViewState["nbParents"].ToString());
         Trace.Warn("maxDepth=" + maxDepth.ToString());
         if (nbParents < maxDepth)
         {
             Trace.Warn("nbParents < maxDepth");
             // Retrieve the parent group
             int            parentId = Convert.ToInt32(ddlParentList.SelectedValue);
             ContainerGroup cgParent = ContainerGroup.GetByKey(parentId);
             int            nbChilds = cgParent.Childs.Count;
             foreach (ContainerGroup cg in cgParent.Childs)
             {
                 if (cg.Id == groupId)
                 {
                     nbChilds--;
                     break;
                 }
             }
             btExpand.Visible = nbChilds > 0;
             Trace.Warn("nbChilds=" + nbChilds.ToString());
         }
         else
         {
             btExpand.Visible = false;
         }
         Trace.Warn("btExpand.Visible=" + btExpand.Visible.ToString());
     }
 }
Example #5
0
 public static void VerifyContainerGroupProperties(ContainerGroup expected, ContainerGroup actual)
 {
     Assert.NotNull(actual);
     Assert.Equal(expected.Name, actual.Name);
     Assert.Equal(expected.Location, actual.Location);
     Assert.Equal(expected.OsType, actual.OsType);
     Assert.Equal(expected.RestartPolicy, actual.RestartPolicy);
     Assert.Equal(expected.Identity.Type, actual.Identity.Type);
     Assert.Equal(expected.Sku, actual.Sku);
     Assert.Equal(expected.Diagnostics.LogAnalytics.WorkspaceId, actual.Diagnostics.LogAnalytics.WorkspaceId);
     Assert.NotNull(actual.Containers);
     Assert.Equal(1, actual.Containers.Count);
     Assert.NotNull(actual.IpAddress);
     Assert.NotNull(actual.IpAddress.Ip);
     Assert.Equal(expected.EncryptionProperties?.KeyName, actual.EncryptionProperties?.KeyName);
     Assert.Equal(expected.EncryptionProperties?.KeyVersion, actual.EncryptionProperties?.KeyVersion);
     Assert.Equal(expected.EncryptionProperties?.VaultBaseUrl, actual.EncryptionProperties?.VaultBaseUrl);
     Assert.Equal(expected.IpAddress.DnsNameLabel, actual.IpAddress.DnsNameLabel);
     Assert.Equal(expected.Containers[0].Name, actual.Containers[0].Name);
     Assert.Equal(expected.Containers[0].Image, actual.Containers[0].Image);
     Assert.Equal(expected.Containers[0].LivenessProbe.PeriodSeconds, actual.Containers[0].LivenessProbe.PeriodSeconds);
     Assert.Equal(expected.Containers[0].EnvironmentVariables[0].Name, actual.Containers[0].EnvironmentVariables[0].Name);
     Assert.Equal(expected.Containers[0].Resources.Requests.Cpu, actual.Containers[0].Resources.Requests.Cpu);
     Assert.Equal(expected.Containers[0].Resources.Requests.MemoryInGB, actual.Containers[0].Resources.Requests.MemoryInGB);
     Assert.Equal(expected.InitContainers[0].Name, actual.InitContainers[0].Name);
     Assert.Equal(expected.InitContainers[0].Image, actual.InitContainers[0].Image);
 }
Example #6
0
        protected override void ExecuteCmdletInternal()
        {
            if (ShouldProcess(Name, "Remove Container Group"))
            {
                ContainerGroup containerGroupDeleted = null;
                if (this.InputObject != null)
                {
                    containerGroupDeleted = this.ContainerClient.ContainerGroups.Delete(this.InputObject.ResourceGroupName, this.InputObject.Name);
                }
                else if (!string.IsNullOrEmpty(this.ResourceGroupName) && !string.IsNullOrEmpty(this.Name))
                {
                    containerGroupDeleted = this.ContainerClient.ContainerGroups.Delete(this.ResourceGroupName, this.Name);
                }
                else if (!string.IsNullOrEmpty(this.ResourceId))
                {
                    var resource = this.ResourceClient.Resources.GetById(this.ResourceId, this.ContainerClient.ApiVersion);
                    if (resource != null)
                    {
                        containerGroupDeleted = this.ContainerClient.ContainerGroups.Delete(this.ParseResourceGroupFromResourceId(this.ResourceId), resource.Name);
                    }
                }

                if (containerGroupDeleted != null && this.PassThru.IsPresent)
                {
                    this.WriteObject(containerGroupDeleted);
                }
            }
        }
Example #7
0
        public async Task LoadExistingApps()
        {
            await _lock.WaitAsync();

            try
            {
                var jsonBody = await GetContainerGroups();

                JArray valueArray  = jsonBody.value;
                var    publicPorts = new HashSet <uint>();
                foreach (dynamic value in valueArray)
                {
                    string containerGroupName = value.name;
                    string appName            = ACIUtils.GetAppNameFromContainerGroupName(containerGroupName);
                    var    properties         = value.properties;
                    var    ipAddress          = properties.ipAddress;
                    string ip = ipAddress.ip;
                    if (ip == null)
                    {
                        continue;
                    }
                    var containerGroup = new ContainerGroup(containerGroupName, _config.Region, ip);
                    foreach (var port in ipAddress.ports)
                    {
                        uint portNo = port.port;
                        publicPorts.Add(portNo);
                    }
                    var containers = properties.containers;
                    foreach (var container in containers)
                    {
                        string containerName       = container.name;
                        var    containerProperties = container.properties;
                        string containerImage      = containerProperties.image;
                        var    currentContainer    = new Container(containerName, containerImage);
                        var    containerPorts      = containerProperties.ports;
                        foreach (var containerPort in containerPorts)
                        {
                            uint portNo = containerPort.port;
                            var  cPort  = new ContainerPort(portNo, publicPorts.Contains(portNo));
                            currentContainer.AddPort(cPort);
                        }
                        containerGroup.AddContainer(currentContainer);
                    }
                    ContainerGroupCollection containerGroupCollection;
                    if (!_containerGroupCollections.TryGetValue(appName, out containerGroupCollection))
                    {
                        containerGroupCollection = new ContainerGroupCollection(appName);
                    }
                    containerGroupCollection.AddContainerGroup(containerGroup);
                    _containerGroupCollections[appName] = containerGroupCollection;
                    publicPorts.Clear();
                }
            }
            finally
            {
                _lock.Release();
            }
        }
        public async static Task InitializeContainerEndpoint(TraceWriter log)
        {
            var token = await AuthUtil.GetToken();

            var client = new ContainerInstanceManagementClient(new TokenCredentials(token));

            client.SubscriptionId = Environment.GetEnvironmentVariable("SUBSCRIPTION_ID");

            if (string.IsNullOrEmpty(client.SubscriptionId))
            {
                throw new InvalidOperationException("Environment variale 'SUBSCRIPTION_ID' not set.");
            }

            var containers = await client.ContainerGroups.ListByResourceGroupAsync(ResourceGroupName);

            var container = containers.Where(c => c.Name == ImageProcessor.ContainerGroupName).FirstOrDefault();

            if (container == null || container.IpAddress == null || container.IpAddress.Ip == null)
            {
                log.Warning("Container not found, going to create...");

                var spec = new ContainerGroup
                {
                    Location      = "East US",
                    OsType        = "Linux",
                    RestartPolicy = "Always",
                    IpAddress     = new IpAddress
                    {
                        Ports = new[] { new Port(9000) }
                    },
                    Containers = new[] {
                        new Container
                        {
                            Name      = "imaginary",
                            Image     = "h2non/imaginary",
                            Ports     = new [] { new ContainerPort(9000) },
                            Resources = new ResourceRequirements
                            {
                                Requests = new ResourceRequests(memoryInGB: 1.5, cpu: 1)
                            }
                        }
                    }
                };

                await client.ContainerGroups.CreateOrUpdateAsync(
                    resourceGroupName : ImageProcessor.ResourceGroupName,
                    containerGroupName : ImageProcessor.ContainerGroupName,
                    containerGroup : spec);
            }
            else
            {
                log.Info("Container IP: " + container.IpAddress.Ip);
                log.Info("Container port: " + container.IpAddress.Ports.FirstOrDefault().PortProperty);

                ImageProcessor.ApiEndpoint = "http://" + container.IpAddress.Ip + ":" + container.IpAddress.Ports.FirstOrDefault().PortProperty;
            }
        }
Example #9
0
 private async Task <string> CreateContainerGroup(ContainerGroup containerGroup)
 {
     using (var response = await _client.PutAsJsonAsync(
                $"/subscriptions/{_config.Subscription}/resourceGroups/{_config.ResourceGroup}/providers/Microsoft.ContainerInstance/containerGroups/{containerGroup.Name}?api-version=2017-08-01-preview",
                containerGroup.ToACICreateContainerRequest()))
     {
         response.EnsureSuccessStatusCode();
         return(await GetIpAddressFromARM(containerGroup.Name));
     }
 }
Example #10
0
    public MyStack()
    {
        var config   = new Pulumi.Config();
        var location = config.Get("location") ?? "WestUS";

        var resourceGroup = new ResourceGroup("resourceGroup", new ResourceGroupArgs
        {
            ResourceGroupName = "aci-rg",
            Location          = location
        });

        var imageName      = "mcr.microsoft.com/azuredocs/aci-helloworld";
        var containerGroup = new ContainerGroup("containerGroup", new ContainerGroupArgs
        {
            ResourceGroupName  = resourceGroup.Name,
            Location           = resourceGroup.Location,
            ContainerGroupName = "helloworld",
            OsType             = "Linux",
            Containers         =
            {
                new ContainerArgs
                {
                    Name  = "acilinuxpublicipcontainergroup",
                    Image = imageName,
                    Ports ={ new ContainerPortArgs             {
                              Port = 80
                          } },
                    Resources = new ResourceRequirementsArgs
                    {
                        Requests = new ResourceRequestsArgs
                        {
                            Cpu        = 1.0,
                            MemoryInGB = 1.5,
                        }
                    }
                }
            },
            IpAddress = new IpAddressArgs
            {
                Ports =
                {
                    new PortArgs
                    {
                        Port     = 80,
                        Protocol = "Tcp",
                    }
                },
                Type = "Public"
            },
            RestartPolicy = "always"
        });

        this.ContainerIPv4Address = containerGroup.IpAddress.Apply(ip => ip !.Ip);
    }
        public static ContainerGroup CreateTestContainerGroup(string containerGroupName)
        {
            var containers = new Container[]
            {
                new Container(
                    name: containerGroupName,
                    image: "alpine",
                    ports: new List <ContainerPort>()
                {
                    new ContainerPort(80)
                },
                    command: new List <string>()
                {
                    "/bin/sh", "-c", "while true; do sleep 10; done"
                },
                    environmentVariables: new List <EnvironmentVariable>
                {
                    new EnvironmentVariable(name: "secretEnv", secureValue: "secretValue1")
                },
                    livenessProbe: new ContainerProbe(
                        exec: new ContainerExec(command: new List <string> {
                    "cat", "/tmp/healthy"
                }),
                        periodSeconds: 20),
                    resources: new ResourceRequirements(requests: new ResourceRequests(memoryInGB: 1.5, cpu: 1.0)))
            };

            var ipAddress = new IpAddress(
                ports: new List <Port>()
            {
                new Port(80, "TCP")
            },
                dnsNameLabel: containerGroupName,
                type: ContainerGroupIpAddressType.Public);

            var logAnalytics = new LogAnalytics(
                workspaceId: "workspaceid",
                workspaceKey: "workspacekey");

            var msiIdentity = new ContainerGroupIdentity(type: ResourceIdentityType.SystemAssigned);

            var containerGroup = new ContainerGroup(
                name: containerGroupName,
                location: "westus",
                osType: OperatingSystemTypes.Linux,
                ipAddress: ipAddress,
                restartPolicy: "Never",
                containers: containers,
                identity: msiIdentity,
                diagnostics: new ContainerGroupDiagnostics(logAnalytics: logAnalytics));

            return(containerGroup);
        }
Example #12
0
            public void Start()
            {
                output.SetHeader(Name);
                FindContainers();
                FindProduction();
                CompileContainers();

                output.Print("Found " + containerCount + " containers");

                foreach (string type in containerTypes)
                {
                    ContainerGroup group = containerGroups[type];
                    output.Print("Group " + group.tag + " found " + group.bins.Count + " bins");
                }
            }
Example #13
0
        public async Task CreateApp(string appName, dynamic appDefinition)
        {
            await _lock.WaitAsync();

            try
            {
                if (_containerGroupCollections.ContainsKey(appName))
                {
                    throw new Exception($"{appName} exists already");
                }

                var containerGroupDefinition = appDefinition.containerGroup;
                var containerDefinitions     = containerGroupDefinition.containers;

                var containerGroupName = ACIUtils.GetContainerGroupNameForAppName(appName);
                var containerGroup     = new ContainerGroup(containerGroupName, _config.Region, "");
                foreach (var containerDefinition in containerDefinitions)
                {
                    string containerName            = containerDefinition.name;
                    string image                    = containerDefinition.image;
                    var    container                = new Container(containerName, image);
                    var    containerPortsDefinition = containerDefinition.ports;

                    foreach (var containerPortDefinition in containerPortsDefinition)
                    {
                        uint   port          = containerPortDefinition.port;
                        string typeString    = containerPortDefinition.type;
                        var    isPublic      = typeString.Equals("public", StringComparison.OrdinalIgnoreCase);
                        var    containerPort = new ContainerPort(port, isPublic);
                        container.AddPort(containerPort);
                    }
                    containerGroup.AddContainer(container);
                }

                containerGroup.IpAddress = await CreateContainerGroup(containerGroup);

                var containerGroupCollection = new ContainerGroupCollection(appName);
                containerGroupCollection.AddContainerGroup(containerGroup);
                _containerGroupCollections[appName] = containerGroupCollection;
                await Task.Delay(ContainerGroupCreationMillisecondsDelay);
            }
            finally
            {
                _lock.Release();
            }
        }
Example #14
0
    private void btExpand_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        int parentId = Convert.ToInt32(ddlParentList.SelectedValue);

        Trace.Warn("btExpand_Click and parentId = " + parentId.ToString());
        if (parentId >= 0)
        {
            BuildParent(ContainerGroup.GetByKey(parentId).Childs[0].Id);
        }
        else
        {
            using (ContainerGroupList cgAll = ContainerGroup.GetAll("ContainerGroupParentId = -1"))
            {
                BuildParent(cgAll[0].Id);
            }
        }
    }
Example #15
0
        private void UpdateDataView()
        {
            string sSql = string.Empty;

            webTab.Visible = false;
            string filter = txtFilter.Text;

            if (filter != string.Empty)
            {
                string cleanFilter = filter.Replace("'", "''").ToLower();
                cleanFilter = cleanFilter.Replace("[", "[[]");
                cleanFilter = cleanFilter.Replace("_", "[_]");
                cleanFilter = cleanFilter.Replace("%", "[%]");

                sSql += " LOWER(ContainerGroup) like '%" + cleanFilter + "%'";
            }

            using (ContainerGroupList groups = ContainerGroup.GetAll(sSql))
            {
                if (groups != null)
                {
                    if (groups.Count > 0)
                    {
                        dg.DataSource = groups;
                        Utils.InitGridSort(ref dg, false);
                        dg.DataBind();

                        dg.Visible          = true;
                        lbNoresults.Visible = false;
                    }
                    else
                    {
                        if (txtFilter.Text.Length > 0)
                        {
                            lbNoresults.Text = "No record match your search (" + txtFilter.Text + ")";
                        }

                        dg.Visible          = false;
                        lbNoresults.Visible = true;
                    }

                    panelGrid.Visible = true;
                    lbTitle.Text      = UITools.GetTranslation("Container groups list");
                }
            }
        }
Example #16
0
 /// <summary>
 /// Build a PSContainerGroup from a ContainerGroup object.
 /// </summary>
 public static PSContainerGroup FromContainerGroup(ContainerGroup containerGroup)
 {
     return(new PSContainerGroup()
     {
         Id = containerGroup?.Id,
         Name = containerGroup?.Name,
         Type = containerGroup?.Type,
         Location = containerGroup?.Location,
         Tags = containerGroup?.Tags,
         ProvisioningState = containerGroup?.ProvisioningState,
         Containers = containerGroup?.Containers?.Select(c => PSContainer.FromContainer(c)).ToList(),
         ImageRegistryCredentials = containerGroup?.ImageRegistryCredentials,
         RestartPolicy = containerGroup?.RestartPolicy,
         IpAddress = containerGroup?.IpAddress?.Ip,
         Ports = containerGroup?.IpAddress?.Ports?.Select(p => ContainerInstanceAutoMapperProfile.Mapper.Map <PSPort>(p)).ToList(),
         OsType = containerGroup?.OsType,
         Volumes = containerGroup?.Volumes
     });
 }
Example #17
0
        protected void UpdateDataEdit(string selGroupId)
        {
            if ((selGroupId == null) || (selGroupId.Length == 0))
            {
                webTab.Tabs.GetTab(0).ContentPane.TargetUrl = "./ContainerGroups/containergroup_properties.aspx?d=-1";
                lbTitle.Text = "Container group: New";
                webTab.Tabs.GetTab(1).Visible = false;
            }
            else
            {
                string         selGroupName = string.Empty;
                ContainerGroup group        = ContainerGroup.GetByKey(Convert.ToInt32(selGroupId));
                if (group != null)
                {
                    selGroupName = group.Name;
                    webTab.Tabs.GetTab(0).ContentPane.TargetUrl = "./ContainerGroups/containergroup_properties.aspx?d=" + selGroupId;
                    if (group.Childs.Count == 0)
                    {
                        webTab.Tabs.GetTab(1).ContentPane.TargetUrl = "./ContainerGroups/containergroup_containers.aspx?d=" + selGroupId;
                        if ((group.Containers != null) && (group.Containers.Count > 0))
                        {
                            webTab.Tabs.GetTab(1).Text = "Containers (" + group.Containers.Count.ToString() + ")";
                        }
                        else
                        {
                            webTab.Tabs.GetTab(1).Text = "Containers (0)";
                        }
                        webTab.Tabs.GetTab(1).Visible = true;
                    }
                    else
                    {
                        webTab.Tabs.GetTab(1).Visible = false;
                    }



                    lbTitle.Text = "Container group: " + selGroupName;
                }
            }

            panelGrid.Visible = false;
            webTab.Visible    = true;
        }
Example #18
0
        public string Run(string image, RuntimeConfig config)
        {
            var resourceGroup      = this.GetResourceGroup();
            var containerGroupName = $"metaparticle-exec-{DateTime.UtcNow.Ticks}";

            var containers = new Container[]
            {
                new Container(
                    name: containerGroupName,
                    image: image,
                    resources: new ResourceRequirements(requests: new ResourceRequests(memoryInGB: 1.5, cpu: 1.0)),
                    environmentVariables: new List <EnvironmentVariable>
                {
                    new EnvironmentVariable(name: "METAPARTICLE_IN_CONTAINER", value: "true")
                },
                    ports: config.Ports?.Select(p => new ContainerPort(p)).ToList())
            };

            var containerGroup = new ContainerGroup(
                name: containerGroupName,
                osType: OperatingSystemTypes.Linux,
                location: resourceGroup.Location,
                ipAddress: config.Public
                    ? new IpAddress(config.Ports?.Select(p => new Port(p, ContainerNetworkProtocol.TCP)).ToList())
                    : null,
                containers: containers
                );

            var containerInstanceClient = this.GetContainerInstanceClient();

            var createdContainerGroup = containerInstanceClient.ContainerGroups.CreateOrUpdate(
                resourceGroupName: this.aciConfig.AciResourceGroup,
                containerGroupName: containerGroupName,
                containerGroup: containerGroup);

            Console.WriteLine(createdContainerGroup.Id);
            return(containerGroupName);
        }
Example #19
0
        /// <summary>
        /// Export the containers List in Excel file
        /// </summary>
        /// <param name="page"></param>
        public static void ExportContainers(Page page)
        {
            using (CollectionView cv = new CollectionView(HyperCatalog.Business.Container.GetAll()))
            {
                cv.Sort("GroupId");

                using (CollectionView cvCG = new CollectionView(ContainerGroup.GetAll()))
                {
                    using (CollectionView cvCT = new CollectionView(ContainerType.GetAll()))
                    {
                        using (CollectionView cvDT = new CollectionView(DataType.GetAll()))
                        {
                            using (CollectionView cvU = new CollectionView(User.GetAll()))
                            {
                                using (CollectionView cvLG = new CollectionView(LookupGroup.GetAll()))
                                {
                                    using (CollectionView cvIM = new CollectionView(InheritanceMethod.GetAll()))
                                    {
                                        // string contains html code to export
                                        System.Text.StringBuilder sb = new System.Text.StringBuilder(string.Empty);

                                        sb.Append("<html><body>");
                                        sb.Append("<table border='1'>");
                                        /******** Writing the User info and Current date ***********/
                                        int ColCount = 28;
                                        sb.Append("<tr style='border: none' valign='top'><td style='font-weight:bold;font-size: 14;border: none; font-family:Arial Unicode MS' colspan=" + ColCount + ">" + "Container Report" + "</td></tr>");
                                        sb.Append("<tr style='border: none' valign='top'><td style='font-weight:bold;border: none; font-size: 14; font-family:Arial Unicode MS'>Generated By: </td><td style='border: none; font-size: 14; font-family:Arial Unicode MS' colspan=" + (ColCount - 1).ToString() + ">" + SessionState.User.FullName + "</td></tr>");
                                        sb.Append("<tr style='border: none' valign='top'><td style='font-weight:bold;border: none; font-size: 14;font-family:Arial Unicode MS'>Exported On: </td><td style='border: none ;font-size: 14; font-family:Arial Unicode MS' colspan=" + (ColCount - 1).ToString() + ">" + SessionState.User.FormatUtcDate(DateTime.UtcNow, true, "MM/dd/yyyy:HH:mm:ss") + "</td></tr>");



                                        #region "Header"

                                        sb.Append("<tr style='font-size: 14; font-weight: bold;font-family:Arial Unicode MS background-color: lightgrey' wordwrap='true'>");
                                        sb.Append("<td>Id</td>");
                                        sb.Append("<td>Container group</td>");
                                        sb.Append("<td>xmlname</td>");
                                        sb.Append("<td>Name</td>");
                                        sb.Append("<td>Label</td>");
                                        sb.Append("<td>Definition</td>");
                                        sb.Append("<td>Entry rule</td>");
                                        sb.Append("<td>Sample</td>");
                                        sb.Append("<td>Data type</td>");
                                        sb.Append("<td>Container type</td>");
                                        sb.Append("<td>Lookup</td>");
                                        sb.Append("<td>Input mask</td>");
                                        sb.Append("<td>Max length</td>");
                                        sb.Append("<td>Translatable</td>");
                                        sb.Append("<td>Regionalizable</td>");
                                        sb.Append("<td>Localizable</td>");
                                        sb.Append("<td>Publishable</td>");
                                        sb.Append("<td>Readonly</td>");
                                        sb.Append("<td>Keep if obsolete</td>");
                                        sb.Append("<td>Inheritance method</td>");
                                        sb.Append("<td>Sort</td>");
                                        sb.Append("<td>Segment</td>");
                                        sb.Append("<td>ValidationMask</td>");
                                        sb.Append("<td>WWXPath</td>");
                                        sb.Append("<td>Creator</td>");
                                        sb.Append("<td>Create date</td>");
                                        sb.Append("<td>Modifier</td>");
                                        sb.Append("<td>Modifier date</td>");
                                        sb.Append("</tr>");
                                        #endregion

                                        string cellColor = "#D0D0D0", defaultCellColor = "#D0D0D0";
                                        for (int i = 0; i < cv.Count; i++)
                                        {
                                            Container curContainer = ((Container)cv[i]);
                                            sb.Append("<tr valign='top' style='font-size: 14; font-family:Arial Unicode MS;background-color: " + cellColor + ";text-color: black;'>");
                                            sb.Append("<td>" + curContainer.Id + "</td>");
                                            //********************************************************************************************
                                            //GADSC Code Change for displaying the Goup/Subgroup path of the container group in the report
                                            //Ezilla Bug N0:68758
                                            //Modified By:Kanthi.J
                                            //********************************************************************************************
                                            cvCG.ApplyFilter("Id", curContainer.GroupId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((ContainerGroup)cvCG[0]).Path + ((ContainerGroup)cvCG[0]).Name + "</td>");
                                            sb.Append("<td>" + curContainer.Tag + "</td>");
                                            sb.Append("<td>" + curContainer.Name + "</td>");
                                            sb.Append("<td>" + curContainer.Label + "</td>");
                                            sb.Append("<td>" + curContainer.Definition + "</td>");
                                            sb.Append("<td>" + curContainer.EntryRule + "</td>");
                                            sb.Append("<td>" + curContainer.Sample + "</td>");
                                            cvDT.ApplyFilter("Code", curContainer.DataTypeCode, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((DataType)cvDT[0]).Name + "</td>");
                                            cvCT.ApplyFilter("Code", curContainer.ContainerTypeCode, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((ContainerType)cvCT[0]).Name + "</td>");
                                            if (curContainer.LookupId == -1)
                                            {
                                                sb.Append("<td></td>");
                                            }
                                            else
                                            {
                                                cvLG.ApplyFilter("Id", curContainer.LookupId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                                sb.Append("<td>" + ((LookupGroup)cvLG[0]).Name + "</td>");
                                            }
                                            sb.Append("<td>" + curContainer.InputMask + "</td>");
                                            sb.Append("<td>" + curContainer.MaxLength + "</td>");
                                            sb.Append("<td>" + curContainer.Translatable + "</td>");
                                            sb.Append("<td>" + curContainer.Regionalizable + "</td>");
                                            sb.Append("<td>" + curContainer.Localizable + "</td>");
                                            sb.Append("<td>" + curContainer.Publishable + "</td>");
                                            sb.Append("<td>" + curContainer.ReadOnly + "</td>");
                                            sb.Append("<td>" + curContainer.KeepIfObsolete + "</td>");
                                            cvIM.ApplyFilter("Id", curContainer.InheritanceMethodId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((InheritanceMethod)cvIM[0]).Name + "</td>");
                                            sb.Append("<td>" + curContainer.Sort + "</td>");
                                            sb.Append("<td>" + curContainer.SegmentId + "</td>");
                                            sb.Append("<td>" + curContainer.ValidationMask + "</td>");
                                            sb.Append("<td>" + curContainer.WWXPath + "</td>");
                                            cvU.ApplyFilter("Id", curContainer.CreatorId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            sb.Append("<td>" + ((User)cvU[0]).FullName + "</td>");
                                            sb.Append("<td>" + curContainer.CreateDate + "</td>");
                                            if (curContainer.ModifierId == -1)
                                            {
                                                sb.Append("<td></td>");
                                            }
                                            else
                                            {
                                                cvU.ApplyFilter("Id", curContainer.ModifierId, HyperCatalog.Business.CollectionView.FilterOperand.Equals);
                                            }
                                            sb.Append("<td>" + ((User)cvU[0]).FullName + "</td>");
                                            sb.Append("<td>" + curContainer.ModifyDate + "</td>");

                                            sb.Append("</tr>");
                                            if (cellColor == defaultCellColor)
                                            {
                                                cellColor = "white";
                                            }
                                            else
                                            {
                                                cellColor = defaultCellColor;
                                            }
                                        }

                                        sb.Append("</table>");
                                        sb.Append("</body></html>");

                                        string fileName = string.Empty;
                                        fileName += "Containers.xls";

                                        string exportContent = sb.ToString();
                                        page.Response.Clear();
                                        page.Response.ClearContent();
                                        page.Response.ClearHeaders();
                                        page.Response.Charset = string.Empty;
                                        page.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
                                        page.Response.ContentType = "application/vnd.ms-excel;";
                                        //Fix for CR 5109 - Prabhu R S
                                        page.Response.ContentEncoding = System.Text.Encoding.UTF8;
                                        page.EnableViewState          = false;
                                        page.Response.Write(exportContent);
                                        page.Response.End();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #20
0
        /// <summary>
        /// Create a container group by creation parameters.
        /// </summary>
        public ContainerGroup CreateContainerGroup(ContainerGroupCreationParameters parameters)
        {
            var resources = new ResourceRequirements()
            {
                Requests = new ResourceRequests()
                {
                    Cpu        = parameters.Cpu,
                    MemoryInGB = parameters.MemoryInGb,
                }
            };

            var container = new Container()
            {
                Name                 = parameters.Name,
                Image                = parameters.ContainerImage,
                Command              = parameters.ContainerCommand,
                Resources            = resources,
                EnvironmentVariables = parameters.EnvironmentVariables?.Select(e => new EnvironmentVariable(e.Key, e.Value)).ToList()
            };

            var containerGroup = new ContainerGroup()
            {
                Location   = parameters.Location,
                Tags       = parameters.Tags,
                Containers = new List <Container>()
                {
                    container
                },
                OsType = parameters.OsType
            };

            if (string.Equals(IpAddress.Type, parameters.IpAddressType, StringComparison.OrdinalIgnoreCase))
            {
                container.Ports = new List <ContainerPort>()
                {
                    new ContainerPort(parameters.Port)
                };
                containerGroup.IpAddress = new IpAddress(new List <Port>()
                {
                    new Port(parameters.Port)
                });
            }

            if (!string.IsNullOrEmpty(parameters.RegistryServer))
            {
                containerGroup.ImageRegistryCredentials = new List <ImageRegistryCredential>()
                {
                    new ImageRegistryCredential()
                    {
                        Server   = parameters.RegistryServer,
                        Username = parameters.RegistryUsername,
                        Password = parameters.RegistryPassword
                    }
                };
            }

            return(this.ContainerClient.ContainerGroups.CreateOrUpdate(
                       resourceGroupName: parameters.ResourceGroupName,
                       containerGroupName: parameters.Name,
                       containerGroup: containerGroup));
        }
Example #21
0
        /// <summary>
        /// Create a container group by creation parameters.
        /// </summary>
        public ContainerGroup CreateContainerGroup(ContainerGroupCreationParameters parameters)
        {
            var resources = new ResourceRequirements()
            {
                Requests = new ResourceRequests()
                {
                    Cpu        = parameters.Cpu,
                    MemoryInGB = parameters.MemoryInGb,
                }
            };

            var container = new Container()
            {
                Name                 = parameters.Name,
                Image                = parameters.ContainerImage,
                Command              = parameters.ContainerCommand,
                Resources            = resources,
                EnvironmentVariables = parameters.EnvironmentVariables?.Select(e => new EnvironmentVariable(e.Key, e.Value)).ToList()
            };

            if (!string.IsNullOrEmpty(parameters.AzureFileVolumeMountPath))
            {
                container.VolumeMounts = new List <VolumeMount>
                {
                    new VolumeMount
                    {
                        Name      = ContainerInstanceCmdletBase.AzureFileVolumeName,
                        MountPath = parameters.AzureFileVolumeMountPath
                    }
                };
            }

            var containerGroup = new ContainerGroup()
            {
                Location   = parameters.Location,
                Tags       = parameters.Tags,
                Containers = new List <Container>()
                {
                    container
                },
                OsType        = parameters.OsType,
                RestartPolicy = parameters.RestartPolicy
            };

            if (string.Equals(IpAddress.Type, parameters.IpAddressType, StringComparison.OrdinalIgnoreCase) ||
                !string.IsNullOrEmpty(parameters.DnsNameLabel))
            {
                container.Ports          = parameters.Ports.Select(p => new ContainerPort(p)).ToList();
                containerGroup.IpAddress = new IpAddress(
                    ports: parameters.Ports.Select(p => new Port(p)).ToList(),
                    dnsNameLabel: parameters.DnsNameLabel);
            }

            if (!string.IsNullOrEmpty(parameters.RegistryServer))
            {
                containerGroup.ImageRegistryCredentials = new List <ImageRegistryCredential>()
                {
                    new ImageRegistryCredential()
                    {
                        Server   = parameters.RegistryServer,
                        Username = parameters.RegistryUsername,
                        Password = parameters.RegistryPassword
                    }
                };
            }

            if (!string.IsNullOrEmpty(parameters.AzureFileVolumeMountPath))
            {
                var azureFileVolume = new AzureFileVolume
                {
                    ShareName          = parameters.AzureFileVolumeShareName,
                    StorageAccountName = parameters.AzureFileVolumeAccountName,
                    StorageAccountKey  = parameters.AzureFileVolumeAccountKey
                };

                containerGroup.Volumes = new List <Volume>
                {
                    new Volume
                    {
                        Name      = ContainerInstanceCmdletBase.AzureFileVolumeName,
                        AzureFile = azureFileVolume
                    }
                };
            }

            return(this.ContainerClient.ContainerGroups.CreateOrUpdate(
                       resourceGroupName: parameters.ResourceGroupName,
                       containerGroupName: parameters.Name,
                       containerGroup: containerGroup));
        }
Example #22
0
        public static ContainerGroup CreateTestContainerGroup(string containerGroupName, bool doNotEncrypt = false)
        {
            var containers = new Container[]
            {
                new Container(
                    name: containerGroupName,
                    image: "alpine",
                    ports: new List <ContainerPort>()
                {
                    new ContainerPort(80)
                },
                    command: new List <string>()
                {
                    "/bin/sh", "-c", "while true; do sleep 10; done"
                },
                    environmentVariables: new List <EnvironmentVariable>
                {
                    new EnvironmentVariable(name: "secretEnv", secureValue: "secretValue1")
                },
                    livenessProbe: new ContainerProbe(
                        exec: new ContainerExec(command: new List <string> {
                    "ls"
                }),
                        periodSeconds: 20),
                    resources: new ResourceRequirements(requests: new ResourceRequests(memoryInGB: 1.5, cpu: 1.0)))
            };

            var initContainers = new InitContainerDefinition[]
            {
                new InitContainerDefinition(
                    name: $"{containerGroupName}init",
                    image: "alpine",
                    command: new List <string>()
                {
                    "/bin/sh", "-c", "sleep 5"
                },
                    environmentVariables: new List <EnvironmentVariable>
                {
                    new EnvironmentVariable(name: "secretEnv", secureValue: "secretValue1")
                })
            };

            var ipAddress = new IpAddress(
                ports: new List <Port>()
            {
                new Port(80, "TCP")
            },
                dnsNameLabel: containerGroupName,
                type: ContainerGroupIpAddressType.Public);

            var logAnalytics = new LogAnalytics(
                workspaceId: "workspaceid",
                workspaceKey: "workspacekey");

            var msiIdentity = new ContainerGroupIdentity(type: ResourceIdentityType.SystemAssigned);

            var encryptionProps = doNotEncrypt ? null : new EncryptionProperties(
                vaultBaseUrl: "https://cloudaci-cloudtest.vault.azure.net/",
                keyName: "testencryptionkey",
                keyVersion: "804d3f1d5ce2456b9bc3dc9e35aaa67e");

            var containerGroup = new ContainerGroup(
                name: containerGroupName,
                location: "westus",
                osType: OperatingSystemTypes.Linux,
                ipAddress: ipAddress,
                restartPolicy: "Never",
                containers: containers,
                identity: msiIdentity,
                diagnostics: new ContainerGroupDiagnostics(logAnalytics: logAnalytics),
                sku: "Standard",
                initContainers: initContainers,
                encryptionProperties: encryptionProps);

            return(containerGroup);
        }
Example #23
0
        private async Task DelayAddContainerGroup(string appName, ContainerGroupCollection containerGroupCollection, ContainerGroup containerGroup)
        {
            await Task.Delay(ContainerGroupCreationMillisecondsDelay);

            containerGroupCollection.AddContainerGroup(containerGroup);
            _containerGroupCollections[appName] = containerGroupCollection;
        }
Example #24
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="parentId"></param>
    /// <param name="id"></param>
    /// Can move or change an container group even if it has children: Decision business review 09/05/06
    private void BuildParent(int parentId)
    {
        Trace.Warn("BuildParent(" + parentId.ToString() + ")");
        Trace.Warn("  GroupId = " + groupId.ToString());
        ViewState["nbParents"] = 0;
        lParentName.Text       = string.Empty;
        bool           bCanMove = true;
        ContainerGroup cg       = ContainerGroup.GetByKey(groupId);
        // Retrieve container based on parentId parameter
        ContainerGroup     cgComboDisplayLevel = ContainerGroup.GetByKey(parentId);
        ContainerGroupList cgChildren          = null;

        ddlParentList.Items.Clear();
        if (cgComboDisplayLevel == null)
        {
            if (cg != null)
            {
                Trace.Warn("  cgComboDisplayLevel is null [#maxDepth =" + maxDepth.ToString() + ", cg.ChildDepth=" + cg.ChildDepth.ToString() + "]");
            }
            else
            {
                Trace.Warn("  cgComboDisplayLevel is null [#maxDepth =" + maxDepth.ToString() + ", cg is null]");
            }
            ddlParentList.Items.Clear();
            ddlParentList.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Root", "-1"));
            if (cg != null)
            {
                btExpand.Visible = maxDepth > cg.ChildDepth;
            }
            else
            {
                btExpand.Visible = maxDepth > 0;
            }
        }
        else
        {
            if (cg != null)
            {
                Trace.Warn("[cg.ChildDepth=" + cg.ChildDepth.ToString() + "]");
            }
            if (cgComboDisplayLevel.Parent == null)
            {
                using (ContainerGroupList cgAll = ContainerGroup.GetAll("ContainerGroupParentId = -1 and ContainersCount=0 AND ContainerGroupId <> " + groupId.ToString()))
                {
                    cgChildren = cgAll;
                }
            }
            else
            {
                cgChildren = cgComboDisplayLevel.Parent.Childs;
            }
            // If container group has children
            if (cgChildren != null && cgChildren.Count > 0)
            {
                ddlParentList.DataSource = cgChildren;
                ddlParentList.DataBind();
                // Remove the current item from the drop down list
                ddlParentList.Items.Remove(ddlParentList.Items.FindByValue(txtGroupId.Text));
                ddlParentList.Visible = ddlParentList.Items.Count > 0;
                if (cg == null) // User is creating a new container group
                {
                    ddlParentList.SelectedIndex = 0;
                }
                else
                {
                    // Select the current parent
                    if (ddlParentList.Items.FindByValue(cg.ParentId.ToString()) != null)
                    {
                        ddlParentList.SelectedValue = cg.ParentId.ToString();
                    }
                }
                int nbChilds = cgChildren[0].Childs.Count;
                foreach (ContainerGroup cgc in cgChildren[0].Childs)
                {
                    if (cgc.Id == groupId)
                    {
                        nbChilds--;
                        break;
                    }
                }
                btExpand.Visible = nbChilds > 0;
            }
            #region maxDepth
            // If the maxDepth < 0 impossible to add child to a container group
            if (maxDepth <= 0)
            {
                panelParent.Visible = false;
            }
            else
            {
                if (cgComboDisplayLevel != null)
                {
                    string[] parents   = cgComboDisplayLevel.Path.Split('/');
                    int      nbParents = parents.Length - 1;
                    ViewState["nbParents"] = nbParents;
                    if (btExpand.Visible)
                    {
                        btExpand.Visible = nbParents < maxDepth;
                    }
                }
            }
            #endregion
            #region Build Label path
            ContainerGroup cgParent = cgComboDisplayLevel.Parent;
            while (cgParent != null)
            {
                lParentName.Text = bCanMove ? "<A HREF=javascript:__doPostBack('Path','" + cgParent.Id.ToString() + "')>" + cgParent.Name + "</A>/" + lParentName.Text : cgParent.Name + "/" + lParentName.Text;
                if (cgParent.ParentId != -1)
                {
                    cgParent = cgParent.Parent;
                }
                else
                {
                    cgParent = null;
                }
            }
            lParentName.Text = bCanMove ? "<A HREF=javascript:__doPostBack('Path','-1')>Root</A>/" + lParentName.Text : "Root/" + lParentName.Text;
            if (parentId != -1)
            {
                lParentName.Visible = true;
            }
            else
            {
                lParentName.Visible = false;
            }
            #endregion
        }
    }
Example #25
0
        public static void AssignAmmoBoxes(IEnumerable<ProjectileGun> guns, IEnumerable<AmmoBox> boxes)
        {
            //var gunCombos = GetPossibleGroupings(guns);
            var gunCombos = GetPossibleGroupings(guns);

            var gunAmmoGroupings = GetAmmoGroupings(gunCombos, boxes);

            // Choose the best set - some combination of most guns used with the most even spread of firings
            GunAmmoGroup[] best = GetBestAmmoAssignment(gunAmmoGroupings);

            #region REPORTS
            //var report_Combos = gunCombos.
            //    Select(n => n.Select(o => new
            //    {
            //        Caliber = o.Caliber,
            //        Guns = string.Join(", ", o.Guns.Select(p => p.Token)),
            //    }).ToArray()).
            //    ToArray();

            //var report_Groupings = gunAmmoGroupings.
            //    Select(n => n.Select(o => new
            //    {
            //        Ammo = o.Ammo == null ? "null" : o.Ammo.Length.ToString(),
            //        Guns = o.Guns == null || o.Guns.Guns == null || o.Guns.Guns.Length == 0 ? "null" : string.Join(", ", o.Guns.Guns.Select(p => p.Token)),
            //    }).
            //    ToArray()
            //    ).ToArray();

            //var report_Best = best.
            //    Select(o => new
            //    {
            //        Ammo = o.Ammo == null ? "null" : o.Ammo.Length.ToString(),
            //        Guns = o.Guns == null || o.Guns.Guns == null || o.Guns.Guns.Length == 0 ? "null" : string.Join(", ", o.Guns.Guns.Select(p => p.Token)),
            //    }).
            //    ToArray();
            #endregion

            // Lock the ammo boxes and guns into the calibers, distribute ammo boxes to guns
            foreach (GunAmmoGroup group in best)
            {
                IContainer container;
                if (group.Ammo.Length == 1)
                {
                    container = group.Ammo[0];
                }
                else
                {
                    // More than one.  Make a group to manage them (no need to expose this group to the caller, it's just a convenience
                    // that manages pulling ammo from multiple boxes)
                    ContainerGroup combined = new ContainerGroup();
                    combined.Ownership = ContainerGroup.ContainerOwnershipType.QuantitiesCanChange;

                    foreach (AmmoBox ammo in group.Ammo)
                    {
                        combined.AddContainer(ammo);
                    }

                    container = combined;
                }

                container.RemovalMultiple = group.Guns.DemandPerGun;

                foreach (ProjectileGun gun in group.Guns.Guns)
                {
                    gun.Caliber = group.Guns.Caliber;
                    gun.Ammo = container;
                }
            }
        }
Example #26
0
 /// <summary>
 /// Create or update container groups.
 /// </summary>
 /// <remarks>
 /// Create or update container groups with specified configurations.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='containerGroupName'>
 /// The name of the container group.
 /// </param>
 /// <param name='containerGroup'>
 /// The properties of the container group to be created or updated.
 /// </param>
 public static ContainerGroup BeginCreateOrUpdate(this IContainerGroupsOperations operations, string resourceGroupName, string containerGroupName, ContainerGroup containerGroup)
 {
     return(operations.BeginCreateOrUpdateAsync(resourceGroupName, containerGroupName, containerGroup).GetAwaiter().GetResult());
 }
Example #27
0
 /// <summary>
 /// Create or update container groups.
 /// </summary>
 /// <remarks>
 /// Create or update container groups with specified configurations.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='containerGroupName'>
 /// The name of the container group.
 /// </param>
 /// <param name='containerGroup'>
 /// The properties of the container group to be created or updated.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ContainerGroup> BeginCreateOrUpdateAsync(this IContainerGroupsOperations operations, string resourceGroupName, string containerGroupName, ContainerGroup containerGroup, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, containerGroupName, containerGroup, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }