public async Task <object> CloneDeployment(dynamic data) { return(await Task.Run(() => { PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken); DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: CredentialWithProvidedToken); var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest { ProjectName = data._ProjectName }).First(d => d.Id.Contains(data._DeploymentID)); var newDeployment = suitableDeployment.Clone(); newDeployment.StartingSnapshotId = data._SnapshotID; newDeployment.Tag.Clear(); newDeployment = _deploymentServiceClient.CreateDeployment(new CreateDeploymentRequest { Deployment = newDeployment }) .PollUntilCompleted() .GetResultOrNull(); newDeployment.Tag.Add(data._ScenarioDeploymentTag); _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest { Deployment = newDeployment }); return newDeployment.Id; })); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.Console(new RenderedCompactJsonFormatter()) .Enrich.FromLogContext() .CreateLogger(); // See https://support.microsoft.com/en-gb/help/821268/contention-poor-performance-and-deadlocks-when-you-make-calls-to-web-s ThreadPool.SetMaxThreads(100, 100); ThreadPool.SetMinThreads(50, 50); Parser.Default.ParseArguments <DeploymentPoolArgs>(args) .WithParsed(parsedArgs => { parsedArgs.Validate(); var spatialRefreshToken = Environment.GetEnvironmentVariable(SpatialRefreshTokenEnvironmentVariable) ?? throw new Exception( $"{SpatialRefreshTokenEnvironmentVariable} environment variable is required."); if (spatialRefreshToken == "") { throw new ArgumentException("Refresh token should not be empty"); } IAnalyticsSender analyticsSender = new AnalyticsSenderBuilder("deployment_pool") .WithCommandLineArgs(parsedArgs) .With(new LogExceptionStrategy(Log.Logger)) .Build(); var spatialDeploymentClient = DeploymentServiceClient.Create(credentials: new PlatformRefreshTokenCredential(spatialRefreshToken)); var spatialSnapshotClient = SnapshotServiceClient.Create(credentials: new PlatformRefreshTokenCredential(spatialRefreshToken)); var platformInvoker = new PlatformInvoker(parsedArgs, spatialDeploymentClient, spatialSnapshotClient, analyticsSender); var cancelTokenSource = new CancellationTokenSource(); var cancelToken = cancelTokenSource.Token; var metricsServer = new MetricServer(parsedArgs.MetricsPort).Start(); var dplPool = new DeploymentPool(parsedArgs, spatialDeploymentClient, platformInvoker, cancelToken, analyticsSender); var dplPoolTask = Task.Run(() => dplPool.Start()); var unixSignalTask = Task.Run(() => UnixSignal.WaitAny(new[] { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGTERM) })); Task.WaitAny(dplPoolTask, unixSignalTask); if (unixSignalTask.IsCompleted) { Log.Information($"Received UNIX signal {unixSignalTask.Result}"); Log.Information("Server shutting down..."); cancelTokenSource.Cancel(); metricsServer.StopAsync(); dplPoolTask.Wait(); Log.Information("Server stopped cleanly"); } else { /* The server task has completed; we can just exit. */ Log.Information($"The deployment pool has stopped itself or encountered an unhandled exception {dplPoolTask.Exception}"); } }); }
public static DeploymentServiceClient CreateDeploymentClient(Options.Common options) { return(string.IsNullOrEmpty(options.Environment) ? DeploymentServiceClient.Create() : DeploymentServiceClient.Create(GetEndpoint(options.Environment), GetTokenCredential(options.Environment))); }
public static void Init(string serviceAccountToken) { var credentials = new PlatformRefreshTokenCredential(serviceAccountToken); deploymentServiceClient = DeploymentServiceClient.Create(credentials: credentials); snapshotServiceClient = SnapshotServiceClient.Create(credentials: credentials); }
private Deployment GetDeploymentWithTag(DeploymentServiceClient deploymentServiceClient, string tag) { return(deploymentServiceClient .ListDeployments(new ListDeploymentsRequest { ProjectName = _project, DeploymentStoppedStatusFilter = ListDeploymentsRequest.Types.DeploymentStoppedStatusFilter .NotStoppedDeployments, View = ViewType.Basic, Filters = { new Filter { TagsPropertyFilter = new TagsPropertyFilter { Operator = TagsPropertyFilter.Types.Operator.Equal, Tag = tag } }, new Filter { TagsPropertyFilter = new TagsPropertyFilter { Operator = TagsPropertyFilter.Types.Operator.Equal, Tag = ReadyTag } } } }).FirstOrDefault(d => d.Status == Deployment.Types.Status.Running)); }
private static int StopDeployment(string[] args) { var projectName = args[1]; var deploymentId = args[2]; var deploymentServiceClient = DeploymentServiceClient.Create(); try { deploymentServiceClient.StopDeployment(new StopDeploymentRequest { Id = deploymentId, ProjectName = projectName }); } catch (Grpc.Core.RpcException e) { if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) { Console.WriteLine("<error:unknown-deployment>"); } else { throw; } } return(0); }
public static int StopDeployment(Options.Stop options) { var deploymentServiceClient = DeploymentServiceClient.Create(); try { deploymentServiceClient.StopDeployment(new StopDeploymentRequest { Id = options.DeploymentId, ProjectName = options.ProjectName }); } catch (Grpc.Core.RpcException e) { if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) { Ipc.WriteError(Ipc.ErrorCode.NotFound, $"Could not find deployment with ID {options.DeploymentId} in project {options.ProjectName}"); return(Program.ErrorExitCode); } throw; } return(Program.SuccessExitCode); }
private static int StopDeployments(string[] args) { var projectName = args[1]; var regionCode = args[2]; var deploymentServiceClient = DeploymentServiceClient.Create(GetApiEndpoint(regionCode), GetPlatformRefreshTokenCredential(regionCode)); if (args.Length == 4) { // Stop only the specified deployment. var deploymentId = args[3]; StopDeploymentById(deploymentServiceClient, projectName, deploymentId); return(0); } // Stop all active deployments launched by this launcher. var activeDeployments = ListLaunchedActiveDeployments(deploymentServiceClient, projectName); foreach (var deployment in activeDeployments) { var deploymentId = deployment.Id; StopDeploymentById(deploymentServiceClient, projectName, deploymentId); } return(0); }
private static int StopDeployments(string[] args) { var projectName = args[1]; var deploymentServiceClient = DeploymentServiceClient.Create(); if (args.Length == 3) { // Stop only the specified deployment. var deploymentId = args[2]; StopDeploymentById(deploymentServiceClient, projectName, deploymentId); return(0); } // Stop all active deployments launched by this launcher. var activeDeployments = ListLaunchedActiveDeployments(deploymentServiceClient, projectName); foreach (var deployment in activeDeployments) { var deploymentId = deployment.Id; StopDeploymentById(deploymentServiceClient, projectName, deploymentId); } return(0); }
private static IEnumerable <Deployment> ListLaunchedActiveDeployments(DeploymentServiceClient client, string projectName) { var listDeploymentsResult = client.ListDeployments(new ListDeploymentsRequest { View = ViewType.Basic, ProjectName = projectName, DeploymentStoppedStatusFilter = ListDeploymentsRequest.Types.DeploymentStoppedStatusFilter.NotStoppedDeployments, PageSize = 50 }); return(listDeploymentsResult.Where(deployment => { var status = deployment.Status; if (status != Deployment.Types.Status.Starting && status != Deployment.Types.Status.Running) { // Deployment not active - skip return false; } if (!deployment.Tag.Contains(DEPLOYMENT_LAUNCHED_BY_LAUNCHER_TAG)) { // Deployment not launched by this launcher - skip return false; } return true; })); }
private static int ListDeployments(string[] args) { var projectName = args[1]; var regionCode = args[2]; var deploymentServiceClient = DeploymentServiceClient.Create(GetApiEndpoint(regionCode), GetPlatformRefreshTokenCredential(regionCode)); var activeDeployments = ListLaunchedActiveDeployments(deploymentServiceClient, projectName); foreach (var deployment in activeDeployments) { var status = deployment.Status; var overviewPageUrl = $"https://console.improbable.io/projects/{projectName}/deployments/{deployment.Name}/overview/{deployment.Id}"; if (deployment.Tag.Contains(SIM_PLAYER_DEPLOYMENT_TAG)) { Console.WriteLine($"<simulated-player-deployment> {deployment.Id} {deployment.Name} {deployment.RegionCode} {overviewPageUrl} {status}"); } else { Console.WriteLine($"<deployment> {deployment.Id} {deployment.Name} {deployment.RegionCode} {overviewPageUrl} {status}"); } } return(0); }
private static bool DeploymentExists(DeploymentServiceClient deploymentServiceClient, string projectName, string deploymentName) { var activeDeployments = ListLaunchedActiveDeployments(deploymentServiceClient, projectName); return(activeDeployments.FirstOrDefault(d => d.Name == deploymentName) != null); }
public WCFSatelliteDeploymentAgent(IVariableProcessor variableProcessor, string endpoint, string login, string password, TimeSpan?openTimeoutSpan = null, TimeSpan?waitTimeout = null) { this.variableProcessor = variableProcessor; WSHttpBinding binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential); binding.MaxBufferPoolSize = 1024 * 1024 * 10; binding.MaxReceivedMessageSize = 1024 * 1024 * 10; binding.ReaderQuotas.MaxArrayLength = 1024 * 1024 * 10; binding.OpenTimeout = openTimeoutSpan ?? new TimeSpan(0, 10, 0); binding.CloseTimeout = openTimeoutSpan ?? new TimeSpan(0, 10, 0); binding.SendTimeout = waitTimeout ?? new TimeSpan(3, 0, 0); binding.ReceiveTimeout = waitTimeout ?? new TimeSpan(3, 0, 0); binding.BypassProxyOnLocal = false; binding.UseDefaultWebProxy = true; binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; this.deploymentClient = new DeploymentServiceClient(binding, new EndpointAddress(new Uri(endpoint + "/DeploymentService"))); this.deploymentClient.ClientCredentials.UserName.UserName = login; this.deploymentClient.ClientCredentials.UserName.Password = password; this.monitoringClient = new MonitoringServiceClient(binding, new EndpointAddress(new Uri(endpoint + "/MonitoringService"))); this.monitoringClient.ClientCredentials.UserName.UserName = login; this.monitoringClient.ClientCredentials.UserName.Password = password; this.informationClient = new InformationServiceClient(binding, new EndpointAddress(new Uri(endpoint + "/InformationService"))); this.informationClient.ClientCredentials.UserName.UserName = login; this.informationClient.ClientCredentials.UserName.Password = password; }
private static int CreateSimDeployments(string[] args, bool useChinaPlatform) { var projectName = args[1]; var assemblyName = args[2]; var runtimeVersion = args[3]; var targetDeploymentName = args[4]; var simDeploymentName = args[5]; var simDeploymentJson = args[6]; var simDeploymentRegion = args[7]; var simDeploymentCluster = args[8]; var simDeploymentSnapshotPath = args[9]; var simNumPlayers = 0; if (!Int32.TryParse(args[10], out simNumPlayers)) { Console.WriteLine("Cannot parse the number of simulated players to connect."); return(1); } try { var deploymentServiceClient = DeploymentServiceClient.Create(GetApiEndpoint(useChinaPlatform)); if (DeploymentExists(deploymentServiceClient, projectName, simDeploymentName)) { StopDeploymentByName(deploymentServiceClient, projectName, simDeploymentName); } var createSimDeploymentOp = CreateSimPlayerDeploymentAsync(deploymentServiceClient, projectName, assemblyName, runtimeVersion, targetDeploymentName, simDeploymentName, simDeploymentJson, simDeploymentSnapshotPath, simDeploymentRegion, simDeploymentCluster, simNumPlayers, useChinaPlatform); // Wait for both deployments to be created. Console.WriteLine("Waiting for the simulated player deployment to be ready..."); var simPlayerDeployment = createSimDeploymentOp.PollUntilCompleted().GetResultOrNull(); if (simPlayerDeployment == null) { Console.WriteLine("Failed to create the simulated player deployment"); return(1); } Console.WriteLine("Done! Simulated players will start to connect to your deployment"); } catch (Grpc.Core.RpcException e) { if (e.Status.StatusCode == Grpc.Core.StatusCode.NotFound) { Console.WriteLine( $"Unable to launch the deployment(s). This is likely because the project '{projectName}' or assembly '{assemblyName}' doesn't exist."); } else { throw; } } return(0); }
/// <summary> /// Checks is the requested organization exists in the target CRM deployment. /// </summary> /// <param name="client">The <see cref="DeploymentServiceClient"/> that we are using to call CRM.</param> /// <param name="organization">The name of the Organization we want to check for.</param> /// <returns>True if the organization exists, false otherwise.</returns> public static async Task <bool> OrganizationExists(this DeploymentServiceClient client, string organization) { EntityInstanceId org = null; await Task.Factory.StartNew(() => org = client.RetrieveAll(DeploymentEntityType.Organization) .FirstOrDefault(item => item.Name == organization)); return(org != null); }
private static Task <StopDeploymentResponse> StopDeploymentByIdAsync(DeploymentServiceClient client, string projectName, string deploymentId) { Console.WriteLine($"Stopping deployment with id {deploymentId}"); return(client.StopDeploymentAsync(new StopDeploymentRequest { Id = deploymentId, ProjectName = projectName })); }
private void MarkDeploymentAsInUse(DeploymentServiceClient dplClient, Deployment dpl) { dpl.Tag.Remove(ReadyTag); dpl.Tag.Add(InUseTag); var req = new UpdateDeploymentRequest { Deployment = dpl }; dplClient.UpdateDeployment(req); }
private static int StopDeployments(string[] args, bool useChinaPlatform) { var projectName = args[1]; var deploymentServiceClient = DeploymentServiceClient.Create(GetApiEndpoint(useChinaPlatform), GetPlatformRefreshTokenCredential(useChinaPlatform)); var deploymentIdsToStop = new List <string>(); if (args.Length == 3) { // Stop only the specified deployment. var deploymentId = args[2]; deploymentIdsToStop.Add(deploymentId); } else { // Stop all active deployments launched by this launcher. var activeDeployments = ListLaunchedActiveDeployments(deploymentServiceClient, projectName); foreach (var deployment in activeDeployments) { deploymentIdsToStop.Add(deployment.Id); } } var deploymentIdsToTasks = new Dictionary <string, Task>(); var erroredDeploymentIds = new List <string>(); Console.WriteLine($"Will stop {deploymentIdsToStop.Count()} deployment(s)"); foreach (var deploymentId in deploymentIdsToStop) { deploymentIdsToTasks.Add(deploymentId, StopDeploymentByIdAsync(deploymentServiceClient, projectName, deploymentId)); } ; try { Task.WaitAll(deploymentIdsToTasks.Values.ToArray()); } catch { // Retrieve individual exceptions from AggregateException thrown by Task.WaitAll var throwers = deploymentIdsToTasks.Where(task => task.Value.Exception != null); foreach (KeyValuePair <string, Task> erroredTask in throwers) { Exception inner = erroredTask.Value.Exception.InnerException; string erroredDeploymentId = erroredTask.Key; erroredDeploymentIds.Add(erroredDeploymentId); Console.WriteLine($"Error while stopping deployment {erroredDeploymentId}: {inner.Message}"); } } Console.WriteLine($"Deployment(s) stopped with {erroredDeploymentIds.Count()} errors"); return(0); }
/// <summary> /// Creates a new Organization in CRM. /// </summary> /// <param name="client">The <see cref="DeploymentServiceClient"/> that we are using to call CRM.</param> /// <param name="organization">The <see cref="Organization"/> model object containing all the information about the new organization.</param> /// <param name="eventStream">The Rx event stream used to push build events onto.</param> public static async Task CreateOrganizationAsync(this DeploymentServiceClient client, Organization organization, IObserver <BuildEvent> eventStream) { var operationId = await Task.Factory.StartNew(() => ((BeginCreateOrganizationResponse)client.Execute(new BeginCreateOrganizationRequest { Organization = organization })).OperationId); eventStream.OnNext(new BuildEvent(BuildEventType.Information, BuildEventImportance.Low, $"Started the Request for Creating the Organisation : {organization.FriendlyName}")); var retrieveOperationStatus = new RetrieveRequest { EntityType = DeploymentEntityType.DeferredOperationStatus, InstanceTag = new EntityInstanceId { Id = operationId } }; DeferredOperationStatus deferredOperationStatus = null; eventStream.OnNext(new BuildEvent(BuildEventType.Information, BuildEventImportance.Low, $"Trying to Create the Organisation {organization.FriendlyName} [In Progress]")); do { await Task.Factory.StartNew(() => deferredOperationStatus = (DeferredOperationStatus)((RetrieveResponse)client.Execute(retrieveOperationStatus)).Entity); await Task.Delay(CrmPoolingInterval); eventStream.OnNext(new BuildEvent(BuildEventType.Information, BuildEventImportance.Low, $"Waiting for {organization.FriendlyName} to be created.")); } while (deferredOperationStatus.State != DeferredOperationState.Processing && deferredOperationStatus.State != DeferredOperationState.Completed); var retrieveReqServer = new RetrieveRequest { EntityType = DeploymentEntityType.Organization, InstanceTag = new EntityInstanceId { Name = organization.UniqueName } }; var orgState = OrganizationState.Pending; eventStream.OnNext(new BuildEvent(BuildEventType.Information, BuildEventImportance.Low, $"Checking that the Organisation {organization.FriendlyName} is Enabled [In Progress]")); do { await Task.Factory.StartNew(() => orgState = ((Organization)((RetrieveResponse)client.Execute(retrieveReqServer)).Entity).State); await Task.Delay(CrmPoolingInterval); eventStream.OnNext(new BuildEvent(BuildEventType.Information, BuildEventImportance.Low, $"Waiting for {organization.FriendlyName} to be enabled.")); } while (orgState != OrganizationState.Enabled); }
public SpatialOSPlatformService() { var spatialOSServiceAccountToken = Environment.GetEnvironmentVariable("SPATIALOS_TOKEN"); DeploymentTagFilter = Environment.GetEnvironmentVariable("DEPLOYMENT_TAG"); var credentialsWithProvidedToken = new PlatformRefreshTokenCredential(spatialOSServiceAccountToken); deploymentServiceClient = DeploymentServiceClient.Create(credentials: credentialsWithProvidedToken); playerAuthServiceClient = PlayerAuthServiceClient.Create(credentials: credentialsWithProvidedToken); }
protected override void DoMatch(GatewayInternalService.GatewayInternalServiceClient gatewayClient, DeploymentServiceClient deploymentServiceClient) { Thread.Sleep(TickMs); try { Console.WriteLine("Fetching 1..."); var resp = gatewayClient.PopWaitingParties(new PopWaitingPartiesRequest { Type = "match1", NumParties = 1 }); Console.WriteLine($"Fetched {resp.Parties.Count} parties"); gatewayClient.AssignDeployments(ConstructAssignRequest(resp.Parties, "1")); } catch (Exception e) { Console.WriteLine($"Got exception: {e.Message}\n{e.StackTrace}"); } try { Console.WriteLine("Fetching 3..."); var resp = gatewayClient.PopWaitingParties(new PopWaitingPartiesRequest { Type = "match3", NumParties = 3 }); Console.WriteLine($"Fetched {resp.Parties.Count} parties"); gatewayClient.AssignDeployments(ConstructAssignRequest(resp.Parties, "3")); } catch (Exception e) { Console.WriteLine($"Got exception: {e.Message}\n{e.StackTrace}"); } try { Console.WriteLine("Fetching requeueable..."); var resp = gatewayClient.PopWaitingParties(new PopWaitingPartiesRequest { Type = "to_requeue", NumParties = 1 }); Console.WriteLine($"Fetched {resp.Parties.Count} parties"); gatewayClient.AssignDeployments(ConstructAssignRequest(resp.Parties, "requeue")); } catch (Exception e) { Console.WriteLine($"Got exception: {e.Message}\n{e.StackTrace}"); } }
public static int ListDeployments(Options.List options) { var deploymentServiceClient = DeploymentServiceClient.Create(); var listDeploymentsResult = deploymentServiceClient.ListDeployments(new ListDeploymentsRequest { ProjectName = options.ProjectName }); Ipc.WriteDeploymentInfo(listDeploymentsResult.Where(deployment => deployment.Status == Deployment.Types.Status.Running)); return(Program.SuccessExitCode); }
public PlatformInvoker(DeploymentPoolArgs args, DeploymentServiceClient deploymentServiceClient, SnapshotServiceClient snapshotServiceClient) { deploymentNamePrefix = args.DeploymentNamePrefix + HumanNamer.GetRandomName(2, "_") + "_"; launchConfigFilePath = args.LaunchConfigFilePath; snapshotFilePath = args.SnapshotFilePath; assemblyName = args.AssemblyName; spatialProject = args.SpatialProject; matchType = args.MatchType; this.deploymentServiceClient = deploymentServiceClient; this.snapshotServiceClient = snapshotServiceClient; }
public async Task <object> StopDeployment(dynamic data) { return(await Task.Run(() => { PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken); DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: CredentialWithProvidedToken); _deploymentServiceClient.StopDeployment(new StopDeploymentRequest { Id = data._DeploymentID, ProjectName = data._ProjectName }); return data._DeploymentID; })); }
protected override void DoMatch(GatewayInternalService.GatewayInternalServiceClient gatewayClient, DeploymentServiceClient deploymentServiceClient) { try { var resp = gatewayClient.PopWaitingParties(new PopWaitingPartiesRequest { Type = _tag, NumParties = 1 }); Console.WriteLine($"Fetched {resp.Parties.Count} from gateway"); foreach (var party in resp.Parties) { Console.WriteLine("Attempting to match a retrieved party."); var deployment = GetDeploymentWithTag(deploymentServiceClient, _tag); if (deployment != null) { var assignRequest = new AssignDeploymentsRequest(); Console.WriteLine("Found a deployment, assigning it to the party."); assignRequest.Assignments.Add(new Assignment { DeploymentId = deployment.Id, DeploymentName = deployment.Name, Result = Assignment.Types.Result.Matched, Party = party.Party }); MarkDeploymentAsInUse(deploymentServiceClient, deployment); gatewayClient.AssignDeployments(assignRequest); } else { Console.WriteLine( $"Unable to find a deployment with tag {_tag} in project {_project}"); Console.WriteLine("Requeueing the party"); AssignPartyAsRequeued(gatewayClient, party); } } } catch (RpcException e) { if (e.StatusCode != StatusCode.ResourceExhausted && e.StatusCode != StatusCode.Unavailable) { throw; } /* Unable to get the requested number of parties - ignore. */ Console.WriteLine("No parties available."); Thread.Sleep(TickMs); } }
public DeploymentPool( DeploymentPoolArgs args, DeploymentServiceClient deploymentServiceClient, PlatformInvoker platformInvoker, CancellationToken token) { cancelToken = token; matchType = args.MatchType; spatialProject = args.SpatialProject; minimumReadyDeployments = args.MinimumReadyDeployments; cleanup = args.Cleanup; this.platformInvoker = platformInvoker; this.deploymentServiceClient = deploymentServiceClient; }
public async Task <object> GetDeploymentIDByTag(dynamic data) { return(await Task.Run(() => { PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken); DeploymentServiceClient _deploymentServiceClient = DeploymentServiceClient.Create(credentials: CredentialWithProvidedToken); var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest { ProjectName = data._ProjectName, DeploymentName = data._DeploymentName }).First(d => d.Tag.Contains(data._ScenarioDeploymentTag)); return suitableDeployment.Id; })); }
public PlatformInvoker(DeploymentPoolArgs args, DeploymentServiceClient deploymentServiceClient, SnapshotServiceClient snapshotServiceClient, IAnalyticsSender analytics = null) { deploymentNamePrefix = args.DeploymentNamePrefix + HumanNamer.GetRandomName(2, "_") + "_"; launchConfigFilePath = args.LaunchConfigFilePath; snapshotFilePath = args.SnapshotFilePath; assemblyName = args.AssemblyName; spatialProject = args.SpatialProject; matchType = args.MatchType; this.deploymentServiceClient = deploymentServiceClient; this.snapshotServiceClient = snapshotServiceClient; _analytics = (analytics ?? new NullAnalyticsSender()).WithEventClass("deployment"); }
protected Matcher() { var spatialRefreshToken = Environment.GetEnvironmentVariable(SpatialRefreshTokenEnvironmentVariable) ?? throw new Exception( $"{SpatialRefreshTokenEnvironmentVariable} environment variable is required."); _spatialDeploymentClient = DeploymentServiceClient.Create(credentials: new PlatformRefreshTokenCredential(spatialRefreshToken)); _gatewayClient = new GatewayInternalService.GatewayInternalServiceClient(new Channel( Environment.GetEnvironmentVariable(GatewayServiceTargetEnvironmentVariable) ?? throw new Exception( $"Environment variable {GatewayServiceTargetEnvironmentVariable} is required."), ChannelCredentials.Insecure)); }
public DeploymentPool( DeploymentPoolArgs args, DeploymentServiceClient deploymentServiceClient, PlatformInvoker platformInvoker, CancellationToken token, IAnalyticsSender analytics = null) { cancelToken = token; matchType = args.MatchType; spatialProject = args.SpatialProject; minimumReadyDeployments = args.MinimumReadyDeployments; cleanup = args.Cleanup; this.platformInvoker = platformInvoker; this.deploymentServiceClient = deploymentServiceClient; _analytics = (analytics ?? new NullAnalyticsSender()).WithEventClass("deployment"); }
/// <summary> /// Demonstrates how to use the Deployment Web Service to create an organization /// and poll the status of the job. /// </summary> /// <param name="serverConfig">Contains server connection information.</param> /// <param name="promptforDelete">When True, the user will be prompted to delete /// all created entities.</param> public void Run(ServerConnection.Configuration serverConfig, bool promptforDelete) { try { // Connect to the Organization service. // The using statement assures that the service proxy will be properly disposed. using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials)) { // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); CreateRequiredRecords(serverConfig, promptforDelete); //<snippetUseAsyncDeploymentServiceMessages1> // Instantiate DeploymentServiceClient for calling the service. client = ProxyClientHelper.CreateClient( new Uri(serverConfig.DiscoveryUri.ToString() .Replace("Services", "Deployment") .Replace("Discovery", "Deployment"))); // Setting credentials from the current security context. if (serverConfig.Credentials == null) { client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; } else { client.ClientCredentials.Windows.ClientCredential = serverConfig.Credentials.Windows.ClientCredential; } using (client) { // Set properties for the new organization Microsoft.Xrm.Sdk.Deployment.Organization organization = new Microsoft.Xrm.Sdk.Deployment.Organization { BaseCurrencyCode = "USD", BaseCurrencyName = "US Dollar", BaseCurrencyPrecision = 2, BaseCurrencySymbol = "$", BaseLanguageCode = 1033, FriendlyName = _friendlyName, UniqueName = _uniqueName, SqlCollation = "Latin1_General_CI_AI", SqlServerName = _sqlServerName, SrsUrl = _srsUrl, SqmIsEnabled = false }; // Create a request for the deployment web service // CRM server app pool must have permissions on SQL server BeginCreateOrganizationRequest request = new BeginCreateOrganizationRequest { Organization = organization, SysAdminName = _sysAdminName }; // Execute the request BeginCreateOrganizationResponse response = (BeginCreateOrganizationResponse)client.Execute(request); // The operation is asynchronous, so the response object contains // a unique identifier for the operation Guid operationId = response.OperationId; // Retrieve the Operation using the OperationId RetrieveRequest retrieveOperationStatus = new RetrieveRequest(); retrieveOperationStatus.EntityType = DeploymentEntityType.DeferredOperationStatus; retrieveOperationStatus.InstanceTag = new EntityInstanceId { Id = operationId }; RetrieveResponse retrieveResponse; DeferredOperationStatus deferredOperationStatus; Console.WriteLine("Retrieving state of the job..."); // Retrieve the Operation State until Organization is created do { // Wait 3 secs to not overload server Thread.Sleep(3000); retrieveResponse = (RetrieveResponse)client.Execute(retrieveOperationStatus); deferredOperationStatus = ((DeferredOperationStatus)retrieveResponse.Entity); } while (deferredOperationStatus.State != DeferredOperationState.Processing && deferredOperationStatus.State != DeferredOperationState.Completed); // Poll OrganizationStatusRequest RetrieveRequest retrieveReqServer = new RetrieveRequest(); retrieveReqServer.EntityType = DeploymentEntityType.Organization; retrieveReqServer.InstanceTag = new EntityInstanceId(); retrieveReqServer.InstanceTag.Name = organization.UniqueName; RetrieveResponse retrieveRespServer; OrganizationState orgState; Console.WriteLine("Retrieving state of the organization..."); // Retrieve and check the Organization State until is enabled do { retrieveRespServer = (RetrieveResponse)client.Execute(retrieveReqServer); _organizationID = ((Microsoft.Xrm.Sdk.Deployment.Organization)retrieveRespServer.Entity).Id; orgState = ((Microsoft.Xrm.Sdk.Deployment.Organization)retrieveRespServer.Entity).State; // Wait 5 secs to not overload server Thread.Sleep(5000); } while (orgState != OrganizationState.Enabled); Console.WriteLine("Organization has been created!"); //</snippetUseAsyncDeploymentServiceMessages1> DeleteRequiredRecords(promptforDelete); } } } // Catch any service fault exceptions that Microsoft Dynamics CRM throws. catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>) { // You can handle an exception here or pass it back to the calling method. throw; } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { connection = cm.MSCRMConnections[comboBoxSource.SelectedIndex]; LogManager.WriteLog("Loading Server Settings."); toolStripStatusLabel1.Text = ""; try { string deploymentURI = connection.ServerAddress.Replace(connection.OrganizationName + "/", "") + "XRMDeployment/2011/Deployment.svc"; serviceClient = Microsoft.Xrm.Sdk.Deployment.Proxy.ProxyClientHelper.CreateClient(new Uri(deploymentURI)); serviceClient.ClientCredentials.Windows.ClientCredential.UserName = connection.UserName; serviceClient.ClientCredentials.Windows.ClientCredential.Password = connection.Password; // Retrieve all deployed instances of Microsoft Dynamics CRM. var organizations = serviceClient.RetrieveAll(DeploymentEntityType.Organization); Microsoft.Xrm.Sdk.Deployment.EntityInstanceId currentOrganization = null; foreach (var organization in organizations) { if (organization.Name.ToLower() == connection.OrganizationName.ToLower()) currentOrganization = organization; } RetrieveAdvancedSettingsRequest request = new RetrieveAdvancedSettingsRequest() { ConfigurationEntityName = "Deployment", ColumnSet = new ColumnSet() }; ConfigurationEntity ce = ((RetrieveAdvancedSettingsResponse)serviceClient.Execute(request)).Entity; foreach (var setting in ce.Attributes) { if (setting.Key == "AggregateQueryRecordLimit") numericUpDownAggregateQueryRecordLimit.Text = setting.Value.ToString(); else if (setting.Key == "AutomaticallyInstallDatabaseUpdates") checkBoxAutomaticallyInstallDatabaseUpdates.Checked = (bool)setting.Value; else if (setting.Key == "AutomaticallyReprovisionLanguagePacks") checkBoxAutomaticallyReprovisionLanguagePacks.Checked = (bool)setting.Value; } // Retrieve details of first organization from previous call. Microsoft.Xrm.Sdk.Deployment.Organization deployment = (Microsoft.Xrm.Sdk.Deployment.Organization)serviceClient.Retrieve( DeploymentEntityType.Organization, currentOrganization); // Print out retrieved details about your organization. string organizationProperties = ""; organizationProperties += "Friendly Name: " + deployment.FriendlyName + "\r\n"; organizationProperties += "Unique Name: " + deployment.UniqueName + "\r\n"; organizationProperties += "Organization Version: " + deployment.Version + "\r\n"; organizationProperties += "SQL Server Name: " + deployment.SqlServerName + "\r\n"; organizationProperties += "SRS URL: " + deployment.SrsUrl + "\r\n"; organizationProperties += "Base Currency Code: " + deployment.BaseCurrencyCode + "\r\n"; organizationProperties += "Base Currency Name: " + deployment.BaseCurrencyName + "\r\n"; organizationProperties += "Base Currency Precision: " + deployment.BaseCurrencyPrecision + "\r\n"; organizationProperties += "Base Currency Symbol: " + deployment.BaseCurrencySymbol + "\r\n"; organizationProperties += "Base Language Code: " + deployment.BaseLanguageCode + "\r\n"; organizationProperties += "Database Name: " + deployment.DatabaseName + "\r\n"; organizationProperties += "Sql Collation: " + deployment.SqlCollation + "\r\n"; organizationProperties += "Sqm Is Enabled: " + deployment.SqmIsEnabled + "\r\n"; organizationProperties += "State: " + deployment.State + "\r\n"; textBoxOrganizationProperties.Text = organizationProperties; // Retrieve license and user information for your organization. TrackLicenseRequest licenseRequest = new TrackLicenseRequest(); TrackLicenseResponse licenseResponse = (TrackLicenseResponse)serviceClient.Execute(licenseRequest); // Print out the number of servers and the user list. string licenseanduserinformation = "Number of servers: "; licenseanduserinformation += licenseResponse.NumberOfServers.HasValue ? licenseResponse.NumberOfServers.Value.ToString() : "null"; licenseanduserinformation += "\r\n"; licenseanduserinformation += "Users:\r\n"; foreach (String user in licenseResponse.UsersList) { licenseanduserinformation += user + "\r\n"; } textBoxLicenceanduserinformation.Text = licenseanduserinformation; // Retrieve server settings for your organization. RetrieveAdvancedSettingsRequest requestServerSettings = new RetrieveAdvancedSettingsRequest { ConfigurationEntityName = "ServerSettings", ColumnSet = new ColumnSet(false) }; ConfigurationEntity configuration = ((RetrieveAdvancedSettingsResponse)serviceClient.Execute(requestServerSettings)).Entity; // Print out all advanced settings where IsWritable==true. foreach (var setting in configuration.Attributes) { if (setting.Key != "Id") { if (setting.Key == "DisableUserInfoClaim") checkBoxDisableUserInfoClaim.Checked = (bool)setting.Value; else if (setting.Key == "MaxExpandCount") numericUpDownMaxExpandCount.Text = setting.Value.ToString(); else if (setting.Key == "MaxResultsPerCollection") numericUpDownMaxResultsPerCollection.Text = setting.Value.ToString(); else if (setting.Key == "NlbEnabled") checkBoxNlbEnabled.Checked = (bool)setting.Value; else if (setting.Key == "PostponeAppFabricRequestsInMinutes") numericUpDownPostponeAppFabricRequestsInMinutes.Text = setting.Value.ToString(); else if (setting.Key == "PostViaExternalRouter") checkBoxPostViaExternalRouter.Checked = (bool)setting.Value; else if (setting.Key == "SslHeader") textBoxSslHeader.Text = setting.Value.ToString(); } } toolStripStatusLabel1.Text = connection.OrganizationName + " deployment properties were successfully loaded."; } catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { //string url = connection.ServerAddress + "main.aspx?pagetype=entityrecord&etn=eaf_contrat_client&id=" + entity.Id.ToString(); LogManager.WriteLog("Error: " + ex.Detail.Message + "\n" + ex.Detail.TraceText); MessageBox.Show("Error: " + ex.Detail.Message + "\n" + ex.Detail.TraceText); } catch (Exception ex) { if (ex.InnerException != null) { LogManager.WriteLog("Error:" + ex.Message); MessageBox.Show("Error:" + ex.Message + "\n" + ex.InnerException.Message); } else { LogManager.WriteLog("Error:" + ex.Message); MessageBox.Show("Error:" + ex.Message); } } }