public bool StartLocalNode() { try { TextLogger.LogInfo("Starting local Service Fabric node."); // TODO: After current xcopyable issue is fixed, update the pattern here. // TODO: [General] disposal of ServiceController ServiceController fabricHostService = this.GetInstalledService(Constants.FabricHostServiceName); if (fabricHostService != null) { if (fabricHostService.Status == ServiceControllerStatus.StartPending) { TextLogger.LogWarning("Fabric host service is starting."); return(false); } else if (fabricHostService.Status == ServiceControllerStatus.Running) { TextLogger.LogInfo("Successfully started local Service Fabric node."); return(true); } else if (!this.StartFabricHostService()) { TextLogger.LogError("Failed to start local Service Fabric node "); return(false); } } else { ServiceController fabricInstallerService = this.GetInstalledService(Constants.FabricInstallerServiceName); // Install and configure Fabric installer service if not installed. if (fabricInstallerService == null) { TextLogger.LogInfo("Installing and configuring Fabric installer service."); if (!this.InstallAndConfigureFabricInstallerService(this.agentApplicationDirectory)) { TextLogger.LogError("Failed to install and configure Fabric installer service"); return(false); } fabricInstallerService = this.GetInstalledService(Constants.FabricInstallerServiceName); } // If Fabric installer service is not in stopped state, stop it. if (fabricInstallerService.Status != ServiceControllerStatus.Stopped) { TextLogger.LogInfo("Fabric installer service is in {0} state. Stopping it.", fabricInstallerService.Status); if (!this.StopFabricInstallerService()) { TextLogger.LogError("Failed to stop Fabric installer service."); return(false); } } // Start Fabric installer service to start Fabric host service. TextLogger.LogInfo("Starting Fabric installer service to start Fabric host service."); if (!this.StartFabricInstallerService()) { TextLogger.LogError("Failed to start Fabric installer service."); return(false); } } TextLogger.LogInfo("Successfully started local Service Fabric node."); return(true); } catch (Exception e) { TextLogger.LogError("Failed to start local Service Fabric node : {0}", e); return(false); } }
public bool DiscoverTopology(out ClusterTopology expectedTopology) { expectedTopology = null; try { TextLogger.LogInfo("Discovering cluster topology from bootstrap cluster manifest file."); if (ConfigurationManager.BootstrapClusterManifestLocation == BootstrapClusterManifestLocationType.NotReady) { TextLogger.LogWarning("Bootstrap cluster manifest is not ready. Cluster topology would not be discovered until bootstrap cluster manifest is ready."); return(false); } ClusterManifestType bootstrapClusterManifest; if (!this.ReadBootstrapClusterManifestFile(out bootstrapClusterManifest)) { return(false); } TopologyProviderType topologyProviderType = TopologyProvider.GetTopologyProviderTypeFromClusterManifest(bootstrapClusterManifest); TextLogger.LogInfo("Topology provider type : {0}.", topologyProviderType); if (topologyProviderType != TopologyProviderType.StaticTopologyProvider) { TextLogger.LogInfo("Topology provider type {0} is not supported to provide static topology.", topologyProviderType); return(false); } else { /* * Static topology provider defines the authoritative cluster topology in the cluster manifest. * If the local machine (physical or virtual) is not part of the cluster topology specified in static topology provider section, a Service Fabric node will not be started locally. * During scale-up, bootstrap cluster manifest has to be upgraded to allow new Service Fabric nodes to be started on the new machines and join the ring. * A scale-up is normally a two-phase process with allocation of new machines (and their IPs) and generation of a new bootstrap cluster manifest with updated topology. */ ClusterManifestTypeInfrastructureWindowsAzureStaticTopology staticTopologyProviderElement = TopologyProvider.GetStaticTopologyProviderElementFromClusterManifest(bootstrapClusterManifest); if (staticTopologyProviderElement.NodeList == null || staticTopologyProviderElement.NodeList.Length == 0) { TextLogger.LogError("Static topology provider section of bootstrap cluster manifest does not specify topology of the Service Fabric cluster."); return(false); } LogClusterTopology(staticTopologyProviderElement); ClusterTopology staticTopologyProviderClusterTopology = ClusterTopology.GetClusterTopology(); staticTopologyProviderClusterTopology.LogTopology(); expectedTopology = staticTopologyProviderClusterTopology; TextLogger.LogInfo("Successfully discovered cluster topology."); return(true); } } catch (Exception e) { TextLogger.LogError("Failed to discover cluster topology : {0}", e); return(false); } }