RDS quotas

This commit is contained in:
vfedosevich 2015-01-16 02:47:54 -08:00
parent 69e4f8db27
commit b1af779c18
14 changed files with 310 additions and 49 deletions

View file

@ -2416,6 +2416,12 @@ INSERT [dbo].[Quotas] ([QuotaID], [GroupID],[QuotaOrder], [QuotaName], [QuotaDe
END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[Quotas] WHERE [QuotaName] = 'RDS.Collections')
BEGIN
INSERT [dbo].[Quotas] ([QuotaID], [GroupID],[QuotaOrder], [QuotaName], [QuotaDescription], [QuotaTypeID], [ServiceQuota], [ItemTypeID]) VALUES (491, 45, 2, N'RDS.Collections',N'Remote Desktop Servers',2, 0 , NULL)
END
GO
-- RDS Provider
IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [DisplayName] = 'Remote Desktop Services Windows 2012')
@ -6003,6 +6009,36 @@ SELECT
RETURN
GO
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetOrganizationRdsCollectionsCount')
DROP PROCEDURE GetOrganizationRdsCollectionsCount
GO
CREATE PROCEDURE [dbo].GetOrganizationRdsCollectionsCount
(
@ItemID INT,
@TotalNumber int OUTPUT
)
AS
SELECT
@TotalNumber = Count([Id])
FROM [dbo].[RDSCollections] WHERE [ItemId] = @ItemId
RETURN
GO
IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE type = 'P' AND name = 'GetOrganizationRdsServersCount')
DROP PROCEDURE GetOrganizationRdsServersCount
GO
CREATE PROCEDURE [dbo].GetOrganizationRdsServersCount
(
@ItemID INT,
@TotalNumber int OUTPUT
)
AS
SELECT
@TotalNumber = Count([Id])
FROM [dbo].[RDSServers] WHERE [ItemId] = @ItemId
RETURN
GO
IF OBJECTPROPERTY(object_id('dbo.GetExchangeAccountByAccountNameWithoutItemId'), N'IsProcedure') = 1

View file

@ -262,5 +262,6 @@ order by rg.groupOrder
public const string RDS_USERS = "RDS.Users";
public const string RDS_SERVERS = "RDS.Servers";
public const string RDS_COLLECTIONS = "RDS.Collections";
}
}

View file

@ -4543,6 +4543,34 @@ namespace WebsitePanel.EnterpriseServer
return Convert.ToInt32(count.Value);
}
public static int GetOrganizationRdsCollectionsCount(int itemId)
{
SqlParameter count = new SqlParameter("@TotalNumber", SqlDbType.Int);
count.Direction = ParameterDirection.Output;
DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetOrganizationRdsCollectionsCount",
count,
new SqlParameter("@ItemId", itemId));
// read identity
return Convert.ToInt32(count.Value);
}
public static int GetOrganizationRdsServersCount(int itemId)
{
SqlParameter count = new SqlParameter("@TotalNumber", SqlDbType.Int);
count.Direction = ParameterDirection.Output;
DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure,
ObjectQualifier + "GetOrganizationRdsServersCount",
count,
new SqlParameter("@ItemId", itemId));
// read identity
return Convert.ToInt32(count.Value);
}
public static void UpdateRDSCollection(RdsCollection collection)
{
UpdateRDSCollection(collection.Id, collection.ItemId, collection.Name, collection.Description, collection.DisplayName);

View file

@ -992,6 +992,13 @@ namespace WebsitePanel.EnterpriseServer
stats.UsedEnterpriseStorageSpace = folders.Where(x => x.FRSMQuotaMB != -1).Sum(x => x.FRSMQuotaMB);
}
if (cntxTmp.Groups.ContainsKey(ResourceGroups.RDS))
{
stats.CreatedRdsUsers = RemoteDesktopServicesController.GetOrganizationRdsUsersCount(org.Id);
stats.CreatedRdsCollections = RemoteDesktopServicesController.GetOrganizationRdsCollectionsCount(org.Id);
stats.CreatedRdsServers = RemoteDesktopServicesController.GetOrganizationRdsServersCount(org.Id);
}
}
else
{
@ -1066,6 +1073,13 @@ namespace WebsitePanel.EnterpriseServer
stats.UsedEnterpriseStorageSpace += folders.Where(x => x.FRSMQuotaMB != -1).Sum(x => x.FRSMQuotaMB);
}
if (cntxTmp.Groups.ContainsKey(ResourceGroups.RDS))
{
stats.CreatedRdsUsers += RemoteDesktopServicesController.GetOrganizationRdsUsersCount(o.Id);
stats.CreatedRdsCollections += RemoteDesktopServicesController.GetOrganizationRdsCollectionsCount(o.Id);
stats.CreatedRdsServers += RemoteDesktopServicesController.GetOrganizationRdsServersCount(o.Id);
}
}
}
}
@ -1119,6 +1133,13 @@ namespace WebsitePanel.EnterpriseServer
stats.AllocatedEnterpriseStorageSpace = cntx.Quotas[Quotas.ENTERPRISESTORAGE_DISKSTORAGESPACE].QuotaAllocatedValue;
}
if (cntx.Groups.ContainsKey(ResourceGroups.RDS))
{
stats.AllocatedRdsServers = cntx.Quotas[Quotas.RDS_SERVERS].QuotaAllocatedValue;
stats.AllocatedRdsCollections = cntx.Quotas[Quotas.RDS_COLLECTIONS].QuotaAllocatedValue;
stats.AllocatedRdsUsers = cntx.Quotas[Quotas.RDS_USERS].QuotaAllocatedValue;
}
return stats;
}
catch (Exception ex)

View file

@ -203,6 +203,16 @@ namespace WebsitePanel.EnterpriseServer
return GetOrganizationRdsUsersCountInternal(itemId);
}
public static int GetOrganizationRdsServersCount(int itemId)
{
return GetOrganizationRdsServersCountInternal(itemId);
}
public static int GetOrganizationRdsCollectionsCount(int itemId)
{
return GetOrganizationRdsCollectionsCountInternal(itemId);
}
public static List<string> GetApplicationUsers(int itemId, int collectionId, RemoteApplication remoteApp)
{
return GetApplicationUsersInternal(itemId, collectionId, remoteApp);
@ -591,6 +601,15 @@ namespace WebsitePanel.EnterpriseServer
return DataProvider.GetOrganizationRdsUsersCount(itemId);
}
private static int GetOrganizationRdsServersCountInternal(int itemId)
{
return DataProvider.GetOrganizationRdsServersCount(itemId);
}
private static int GetOrganizationRdsCollectionsCountInternal(int itemId)
{
return DataProvider.GetOrganizationRdsCollectionsCount(itemId);
}
private static List<RdsServer> GetCollectionRdsServersInternal(int collectionId)
{

View file

@ -236,6 +236,18 @@ namespace WebsitePanel.EnterpriseServer
return RemoteDesktopServicesController.GetOrganizationRdsUsersCount(itemId);
}
[WebMethod]
public int GetOrganizationRdsServersCount(int itemId)
{
return RemoteDesktopServicesController.GetOrganizationRdsServersCount(itemId);
}
[WebMethod]
public int GetOrganizationRdsCollectionsCount(int itemId)
{
return RemoteDesktopServicesController.GetOrganizationRdsCollectionsCount(itemId);
}
[WebMethod]
public List<string> GetApplicationUsers(int itemId, int collectionId, RemoteApplication remoteApp)
{

View file

@ -370,7 +370,12 @@ namespace WebsitePanel.Providers.HostedSolution
set { createdResourceMailboxes = value; }
}
public int CreatedRdsServers { get; set; }
public int CreatedRdsCollections { get; set; }
public int CreatedRdsUsers { get; set; }
public int AllocatedRdsServers { get; set; }
public int AllocatedRdsCollections { get; set; }
public int AllocatedRdsUsers { get; set; }
}
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2015, Outercurve Foundation.
// Copyright (c) 2015, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
@ -220,20 +220,20 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
try
{
runSpace = OpenRunspace();
runSpace = OpenRunspace();
var existingServers = GetServersExistingInCollections(runSpace);
existingServers = existingServers.Select(x => x.ToUpper()).Intersect(collection.Servers.Select(x => x.FqdName.ToUpper())).ToList();
existingServers = existingServers.Select(x => x.ToUpper()).Intersect(collection.Servers.Select(x => x.FqdName.ToUpper())).ToList();
if (existingServers.Any())
{
throw new Exception(string.Format("Server{0} {1} already added to another collection", existingServers.Count == 1 ? "" : "s", string.Join(" ,", existingServers.ToArray())));
}
}
foreach (var server in collection.Servers)
{
//If server will restart it will not be added to collection
//Do not install feature here
//Do not install feature here
if (!ExistRdsServerInDeployment(runSpace, server))
{
@ -786,7 +786,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
}
internal void CreateRdRapForce(Runspace runSpace, string gatewayHost, string policyName, string collectionName, List<string> groups)
{
{
//New-Item -Path "RDS:\GatewayServer\RAP" -Name "Allow Connections To Everywhere" -UserGroups "Administrators@." -ComputerGroupType 1
//Set-Item -Path "RDS:\GatewayServer\RAP\Allow Connections To Everywhere\PortNumbers" -Value 3389,3390
@ -795,6 +795,7 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
RemoveRdRap(runSpace, gatewayHost, policyName);
}
Log.WriteWarning(gatewayHost);
var userGroupParametr = string.Format("@({0})", string.Join(",", groups.Select(x => string.Format("\"{0}@{1}\"", x, RootDomain)).ToArray()));
var computerGroupParametr = string.Format("\"{0}@{1}\"", GetComputersGroupName(collectionName), RootDomain);
@ -804,8 +805,10 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
rdRapCommand.Parameters.Add("UserGroups", userGroupParametr);
rdRapCommand.Parameters.Add("ComputerGroupType", 1);
rdRapCommand.Parameters.Add("ComputerGroup", computerGroupParametr);
Log.WriteWarning("User Group:" + userGroupParametr);
Log.WriteWarning("Computer Group:" + computerGroupParametr);
ExecuteRemoteShellCommand(runSpace, gatewayHost, rdRapCommand, RdsModuleName);
Log.WriteWarning("RD RAP Added");
}
internal void RemoveRdRap(Runspace runSpace, string gatewayHost, string name)
@ -1595,22 +1598,22 @@ namespace WebsitePanel.Providers.RemoteDesktopServices
internal List<string> GetServersExistingInCollections(Runspace runSpace)
{
var existingHosts = new List<string>();
var scripts = new List<string>();
scripts.Add(string.Format("$sessions = Get-RDSessionCollection -ConnectionBroker {0}", ConnectionBroker));
scripts.Add(string.Format("foreach($session in $sessions){{Get-RDSessionHost $session.CollectionName -ConnectionBroker {0}|Select SessionHost}}", ConnectionBroker));
object[] errors;
//var scripts = new List<string>();
//scripts.Add(string.Format("$sessions = Get-RDSessionCollection -ConnectionBroker {0}", ConnectionBroker));
//scripts.Add(string.Format("foreach($session in $sessions){{Get-RDSessionHost $session.CollectionName -ConnectionBroker {0}|Select SessionHost}}", ConnectionBroker));
//object[] errors;
var sessionHosts = ExecuteShellCommand(runSpace, scripts, out errors);
//var sessionHosts = ExecuteShellCommand(runSpace, scripts, out errors);
foreach(var host in sessionHosts)
{
var sessionHost = GetPSObjectProperty(host, "SessionHost");
//foreach(var host in sessionHosts)
//{
// var sessionHost = GetPSObjectProperty(host, "SessionHost");
if (sessionHost != null)
{
existingHosts.Add(sessionHost.ToString());
}
}
// if (sessionHost != null)
// {
// existingHosts.Add(sessionHost.ToString());
// }
//}
return existingHosts;
}

View file

@ -5590,6 +5590,9 @@
<data name="Quota.RDS.Users" xml:space="preserve">
<value>Remote Desktop Users</value>
</data>
<data name="Quota.RDS.Collections" xml:space="preserve">
<value>Remote Desktop Collections</value>
</data>
<data name="Error.RDS_CREATE_COLLECTION_RDSSERVER_REQUAIRED" xml:space="preserve">
<value>Error creating rds collection. You need to add at least 1 rds server to collection</value>
</data>

View file

@ -222,4 +222,16 @@
<data name="locServiceLevels.Text" xml:space="preserve">
<value>Service Levels</value>
</data>
<data name="locRemoteDesktop.Text" xml:space="preserve">
<value>Remote Desktop</value>
</data>
<data name="lnkRdsServers.Text" xml:space="preserve">
<value>RDS Servers</value>
</data>
<data name="lnkRdsCollections.Text" xml:space="preserve">
<value>RDS Collections</value>
</data>
<data name="lnkRdsUsers.Text" xml:space="preserve">
<value>RDS Users</value>
</data>
</root>

View file

@ -341,6 +341,38 @@
</td>
</tr>
</asp:Panel>
<asp:Panel runat="server" ID="remoteDesktopStatsPanel">
<tr>
<td class="OrgStatsGroup" width="100%" colspan="2">
<asp:Localize ID="locRemoteDesktop" runat="server" meta:resourcekey="locRemoteDesktop" ></asp:Localize>
</td>
</tr>
<tr class="OrgStatsRow">
<td class="OrgStatsQuota" nowrap>
<asp:HyperLink ID="lnkRdsServers" runat="server" meta:resourcekey="lnkRdsServers" />
</td>
<td>
<wsp:QuotaViewer ID="rdsServers" QuotaTypeId="2" runat="server" DisplayGauge="true" />
</td>
</tr>
<tr class="OrgStatsRow">
<td class="OrgStatsQuota" nowrap>
<asp:HyperLink ID="lnkRdsCollections" runat="server" meta:resourcekey="lnkRdsCollections" />
</td>
<td>
<wsp:QuotaViewer ID="rdsCollections" QuotaTypeId="2" runat="server" DisplayGauge="true" />
</td>
</tr>
<tr class="OrgStatsRow">
<td class="OrgStatsQuota" nowrap>
<asp:HyperLink ID="lnkRdsUsers" runat="server" meta:resourcekey="lnkRdsUsers" />
</td>
<td>
<wsp:QuotaViewer ID="rdsUsers" QuotaTypeId="2" runat="server" DisplayGauge="true" />
</td>
</tr>
</asp:Panel>
</table>
</div>

View file

@ -305,6 +305,16 @@ namespace WebsitePanel.Portal.ExchangeServer
}
else
serviceLevelsStatsPanel.Visible = false;
if (cntx.Groups.ContainsKey(ResourceGroups.RDS))
{
remoteDesktopStatsPanel.Visible = true;
BindRemoteDesktopStats(orgStats, tenantStats);
}
else
{
remoteDesktopStatsPanel.Visible = false;
}
}
private void BindCRMStats(OrganizationStatistics stats, OrganizationStatistics tenantStats)
@ -447,5 +457,34 @@ namespace WebsitePanel.Portal.ExchangeServer
}
}
private void BindRemoteDesktopStats(OrganizationStatistics stats, OrganizationStatistics tenantStats)
{
rdsServers.QuotaValue = stats.AllocatedRdsServers;
rdsServers.QuotaUsedValue = stats.CreatedRdsServers;
if (stats.AllocatedRdsServers != -1)
{
rdsServers.QuotaAvailable = tenantStats.AllocatedRdsServers - tenantStats.CreatedRdsServers;
}
rdsCollections.QuotaValue = stats.AllocatedRdsCollections;
rdsCollections.QuotaUsedValue = stats.CreatedRdsCollections;
if (stats.AllocatedRdsCollections != -1)
{
rdsCollections.QuotaAvailable = tenantStats.AllocatedRdsCollections - tenantStats.CreatedRdsCollections;
}
rdsUsers.QuotaValue = stats.AllocatedRdsUsers;
rdsUsers.QuotaUsedValue = stats.CreatedRdsUsers;
if (stats.AllocatedRdsCollections != -1)
{
rdsUsers.QuotaAvailable = tenantStats.AllocatedRdsUsers - tenantStats.CreatedRdsUsers;
}
lnkRdsServers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
lnkRdsCollections.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
lnkRdsUsers.NavigateUrl = EditUrl("ItemID", PanelRequest.ItemID.ToString(), "rds_collections", "SpaceID=" + PanelSecurity.PackageId);
}
}
}

View file

@ -1,31 +1,3 @@
// Copyright (c) 2015, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
@ -822,5 +794,77 @@ namespace WebsitePanel.Portal.ExchangeServer {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Localize locServiceLevels;
/// <summary>
/// remoteDesktopStatsPanel control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Panel remoteDesktopStatsPanel;
/// <summary>
/// locRemoteDesktop control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Localize locRemoteDesktop;
/// <summary>
/// lnkRdsServers control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.HyperLink lnkRdsServers;
/// <summary>
/// rdsServers control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::WebsitePanel.Portal.QuotaViewer rdsServers;
/// <summary>
/// lnkRdsCollections control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.HyperLink lnkRdsCollections;
/// <summary>
/// rdsCollections control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::WebsitePanel.Portal.QuotaViewer rdsCollections;
/// <summary>
/// lnkRdsUsers control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.HyperLink lnkRdsUsers;
/// <summary>
/// rdsUsers control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::WebsitePanel.Portal.QuotaViewer rdsUsers;
}
}

View file

@ -45,6 +45,12 @@ namespace WebsitePanel.Portal.RDS
if (!IsPostBack)
{
}
PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId);
if (cntx.Quotas.ContainsKey(Quotas.RDS_COLLECTIONS))
{
btnAddCollection.Enabled = (!(cntx.Quotas[Quotas.RDS_COLLECTIONS].QuotaAllocatedValue <= gvRDSCollections.Rows.Count) || (cntx.Quotas[Quotas.RDS_COLLECTIONS].QuotaAllocatedValue == -1));
}
}
public string GetServerName(string collectionId)