Beispiel #1
0
        public static void ExecuteOperation(DeploymentParameters parameters, bool disableFileTrace)
        {
            try
            {
                parameters.Initialize();
                DeployerTrace.UpdateFileLocation(parameters.DeploymentSpecification.GetTracesFolder());
                DeployerTrace.WriteInfo("Running deployer with {0}", parameters.ToString());
                if (parameters.FabricDataRoot == null)
                {
                    if (parameters.Operation == DeploymentOperations.ValidateClusterManifest ||
                        parameters.Operation == DeploymentOperations.DockerDnsSetup ||
                        parameters.Operation == DeploymentOperations.DockerDnsCleanup ||
                        parameters.Operation == DeploymentOperations.ContainerNetworkSetup ||
                        parameters.Operation == DeploymentOperations.ContainerNetworkCleanup)    // Some operations may not require FDR
                    {
                        try
                        {
                            ExecuteOperationPrivate(parameters);
                        }
                        catch (Exception)
                        {
                            parameters.DeleteTargetFile = false;
                            throw;
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException(
                                  String.Format("parameters.FabricDataRoot Operation {0} requires Fabric Data Root to be defined but was passed as null.", parameters.Operation));
                    }
                }
                else
                {
                    string fileLockPath = Helpers.GetRemotePath(parameters.FabricDataRoot, parameters.MachineName);
                    fileLockPath = Path.Combine(fileLockPath, "lock");

                    // Remove uses a different lock than the other operations, because it can be launched by the deployer separately when RemoveNodeConfig is running
                    if (parameters.Operation == DeploymentOperations.Remove)
                    {
                        fileLockPath += "_Remove";
                    }

                    try
                    {
                        Helpers.CreateDirectoryIfNotExist(parameters.FabricDataRoot, parameters.MachineName);
                        using (FileWriterLock fileWriterLock = new FileWriterLock(fileLockPath))
                        {
                            TimeSpan timeout = TimeSpan.FromMinutes(2);
                            if (!fileWriterLock.Acquire(timeout))
                            {
                                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Could not acquire lock: {0} in {1}", fileLockPath, timeout));
                            }

                            ExecuteOperationPrivate(parameters);
                        }
                    }
                    catch (Exception)
                    {
                        parameters.DeleteTargetFile = false;
                        throw;
                    }
                }
            }
            finally
            {
                if (disableFileTrace)
                {
                    DeployerTrace.CloseHandle();
                }
            }
        }