Пример #1
0
        private DeployingComponent PrepareDeployingComponentWithDataFromDB(
            DeployingComponent deployingComponent,
            string connString)
        {
            using (SqlConnection connection = new SqlConnection(connString))
                using (SqlCommand command = connection.CreateCommand())
                {
                    connection.Open();

                    command.CommandText = GetNameTypeConfigQueryString + deployingComponent.componentId;

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            deployingComponent.instanceName   = reader["ComponentName"].ToString();
                            deployingComponent.typeId         = int.Parse(reader["TypeId"].ToString());
                            deployingComponent.configJson     = reader["ConfigJson"].ToString();
                            deployingComponent.appTypeVersion = reader["TypeVersion"].ToString();
                        }
                    }

                    command.CommandText = GetAppTypeNameQuerryString + deployingComponent.typeId;

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            deployingComponent.typeName = reader["TypeName"].ToString();
                        }
                    }

                    return(deployingComponent);
                }
        }
Пример #2
0
        public async void CreateApplicationAsync(DeployingComponent deployingComponent)
        {
            var appParams = new Dictionary <string, string>();

            appParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(deployingComponent.configJson);

            string routingKeysAsString = null;

            foreach (var rk in deployingComponent.senderRoutingKeys)
            {
                routingKeysAsString = routingKeysAsString + ',' + rk;
            }

            appParams.Add("Config:Bindnig:SenderRoutingKeys", routingKeysAsString);
            appParams.Add("Config:Bindnig:SenderExchange", deployingComponent.senderExchange);
            appParams.Add("Config:Bindnig:ReceiverQueue", deployingComponent.receiverQueue);

            var appDesc = new ApplicationDescription(new ApplicationName("fabric:/" + deployingComponent.instanceName),
                                                     deployingComponent.typeName,
                                                     DefaultVersion,
                                                     appParams);

            await serviceFabricClient
            .Applications
            .CreateApplicationAsync(appDesc);
        }
        private void RunDeploymentProcess(
            DeployingComponent deployingComponent,
            bool isServiceInstancePresentInServiceFabric,
            bool isTypePresentInServiceFabric)
        {
            if (isServiceInstancePresentInServiceFabric == false)
            {
                if (isTypePresentInServiceFabric == false)
                {
                    var preparedPackagePath = PrepareApplicationPackage(deployingComponent);
                    serviceFabricClientHandler
                    .StartServiceFromPackage(
                        preparedPackagePath,
                        deployingComponent);
                    return;
                }

                serviceFabricClientHandler
                .CreateApplicationAsync(deployingComponent);
            }
            else
            {
                throw new Exception("Instance already exist in ServiceFabric.");
            }
        }
Пример #4
0
        public void StartServiceFromPackage(
            string packagePath,
            DeployingComponent deployingComponent)
        {
            serviceFabricClient
            .ImageStore
            .UploadApplicationPackageAsync(packagePath)
            .Wait();

            this.CreateApplicationTypeAsync(deployingComponent.typeName);
            this.CreateApplicationAsync(deployingComponent);
        }
        private string PrepareApplicationPackage(DeployingComponent deployingComponent)
        {
            var zipPackagePath = deployingComponent.packagePath;
            var zipPackage     = new FileInfo(zipPackagePath);

            if (!zipPackage.Exists)
            {
                throw new ArgumentOutOfRangeException($"File {zipPackagePath} does not exist");
            }

            var packageLocation = Path.Combine(sfTempPackagesLocation, $"{deployingComponent.typeName}");

            Directory.CreateDirectory(packageLocation);

            ZipFile.ExtractToDirectory(zipPackagePath, packageLocation, true);

            var servicePackageFolderPath = Path.Combine(packageLocation, "ServicePackage");
            var codeFolderPath           = Path.Combine(servicePackageFolderPath, "Code");
            var configFolderPath         = Path.Combine(servicePackageFolderPath, "Config");
            var runtimeFolderPath        = Path.Combine(codeFolderPath, "runtimes");

            Directory.CreateDirectory(servicePackageFolderPath);
            Directory.CreateDirectory(codeFolderPath);
            Directory.CreateDirectory(configFolderPath);

            var files = Directory.EnumerateFiles(packageLocation, "*.dll")
                        .Union(Directory.EnumerateFiles(packageLocation, "*.exe"))
                        .Union(Directory.EnumerateFiles(packageLocation, "*.pdb"))
                        .Union(Directory.EnumerateFiles(packageLocation, "*.json"));

            foreach (var file in files)
            {
                File.Move(file, Path.Combine(codeFolderPath, Path.GetFileName(file)));
            }

            Directory.Move(Path.Combine(packageLocation, "runtimes"), runtimeFolderPath);

            var manifestLocation = Path.Combine(packageLocation, "ServiceFabricManifests");

            File.Move(Path.Combine(manifestLocation, "ApplicationManifest.xml"), Path.Combine(packageLocation, "ApplicationManifest.xml"));
            File.Move(Path.Combine(manifestLocation, "ServiceManifest.xml"), Path.Combine(servicePackageFolderPath, "ServiceManifest.xml"));
            File.Move(Path.Combine(manifestLocation, "Settings.xml"), Path.Combine(configFolderPath, "Settings.xml"));

            Directory.Delete(manifestLocation, true);
            return(packageLocation);
        }
Пример #6
0
        public DeployingComponent GetComponentDetails(int serviceId)
        {
            var deployingComponent = new DeployingComponent {
                componentId = serviceId
            };

            string connString = configurationSection.GetConnectionString(connectionSectionName);

            deployingComponent = PrepareDeployingComponentWithDataFromDB(deployingComponent, connString);
            deployingComponent.senderExchange    = deployingComponent.typeName.Remove(deployingComponent.typeName.Length - 4);
            deployingComponent.senderRoutingKeys = GetRoutingKeys(deployingComponent);
            deployingComponent.receiverQueue     = GetSourceQueue(deployingComponent);
            deployingComponent.packagePath       = dropFolderPath + deployingComponent.appTypeVersion +
                                                   "LAB.DataScanner." + deployingComponent.typeName.Remove(deployingComponent.typeName.Length - 4) + ".zip";

            return(deployingComponent);
        }
Пример #7
0
        private string[] GetRoutingKeys(DeployingComponent deployingComponent)
        {
            string connString = configurationSection.GetConnectionString(connectionSectionName);

            using (SqlConnection connection = new SqlConnection(connString))
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = GetConsumersForComponentQueryString + deployingComponent.componentId.ToString();

                    connection.Open();

                    var allConsumersId = new List <int>();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            allConsumersId.Add(int.Parse(reader["ConsumerInstanceID"].ToString()));
                        }
                    }

                    var routingKeys = new List <string>();
                    foreach (var consumerId in allConsumersId)
                    {
                        command.CommandText = GetInstanceNameById + consumerId.ToString();

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                routingKeys.Add(
                                    deployingComponent.instanceName + "_" +
                                    reader["InstanceName"].ToString());
                            }
                        }
                    }

                    return(routingKeys.ToArray());
                }
        }
        private void RunRemovingProcess(
            DeployingComponent deployingComponent,
            bool isServiceInstancePresentInServiceFabric,
            bool isTypePresentInServiceFabric)
        {
            if (isTypePresentInServiceFabric == true)
            {
                if (isServiceInstancePresentInServiceFabric == true)
                {
                    serviceFabricClientHandler
                    .RemoveServiceInstanceAsync(deployingComponent.instanceName);
                }

                serviceFabricClientHandler
                .RemoveAppTypeAsync(
                    deployingComponent.typeName,
                    deployingComponent.appTypeVersion);
            }
            else
            {
                throw new Exception("ApplicationType doesn't exist in Service fabric!");
            }
        }
Пример #9
0
        private string GetSourceQueue(DeployingComponent deployingComponent)
        {
            string connString = configurationSection.GetConnectionString(connectionSectionName);


            using (SqlConnection connection = new SqlConnection(connString))
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = GetPublisherForComponentQueryString + deployingComponent.componentId;;

                    connection.Open();

                    string publisherInstanceIDAsString = null;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            publisherInstanceIDAsString = reader["PublisherInstanceID"].ToString();
                        }
                    }

                    command.CommandText = GetInstanceNameById + publisherInstanceIDAsString;

                    string publisherName = null;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            publisherName = reader["InstanceName"].ToString();
                        }
                    }

                    string sourceQueue = publisherName + "_" + deployingComponent.instanceName;
                    return(sourceQueue);
                }
        }