Exemple #1
0
 internal static void Initialize(
     StatelessServiceInitializationParameters initializationParameters,
     MonitoringAgentServiceEvent trace)
 {
     codePkgActivationCtx = initializationParameters.CodePackageActivationContext;
     serviceTrace         = trace;
 }
Exemple #2
0
        public void Initialize(StatelessServiceInitializationParameters initializationParameters)
        {
            this.initializationParameters = initializationParameters;
            this.trace = new MonitoringAgentServiceEvent(
                this.initializationParameters.CodePackageActivationContext.WorkDirectory,
                this.initializationParameters.PartitionId,
                this.initializationParameters.InstanceId);

            ConfigReader.Initialize(this.initializationParameters, this.trace);
        }
Exemple #3
0
        internal MdsAgentManager(
            StatelessServiceInitializationParameters initializationParameters,
            MonitoringAgentServiceEvent trace)
        {
            this.stopTaskCompletionSource = null;
            this.initializationParameters = initializationParameters;
            this.trace = trace;
            this.codePackageActivationContext = this.initializationParameters.CodePackageActivationContext;

            this.codePackageActivationContext.ConfigurationPackageModifiedEvent += ConfigPackageModified;
            this.codePackageActivationContext.DataPackageModifiedEvent          += DataPackageModified;
            string maConfigFileName = ConfigReader.GetConfigValue(
                Constants.ConfigSectionName,
                Constants.MAConfigFileParamName,
                Constants.DefaultMAConfigFileName);
            DataPackage maDataPackage = this.codePackageActivationContext.GetDataPackageObject(Constants.MdsAgentDataPackageName);

            this.maDataPackagePath    = maDataPackage.Path;
            this.maConfigFileFullPath = Path.Combine(this.maDataPackagePath, maConfigFileName);

            this.maWorkFolder = Path.Combine(this.codePackageActivationContext.WorkDirectory, Constants.MdsAgentWorkSubFolderName);
            Directory.CreateDirectory(this.maWorkFolder);

            this.maTenant = ConfigReader.GetConfigValue(
                Constants.ConfigSectionName,
                Constants.ClusterNameParamName,
                Constants.DefaultClusterName);
            this.maDataCenter = ConfigReader.GetConfigValue(
                Constants.ConfigSectionName,
                Constants.DataCenterParamName,
                Constants.DefaultDataCenterName);

            // FixDisallowedCharacters replaces special chars in application name with underscore.
            // This is required since MA cannot handle all special chars in identity fields.
            // MA usually allows chars that are supported in a URI.
            this.maApp  = this.codePackageActivationContext.ApplicationName.FixDisallowedCharacters();
            this.maRole = this.maApp;

            // The actual nodeName as reported by the FabricClient. This may contain chars like '.' (dot).
            // In current MA identity, the dot is replaced by and underscore in Role and RoleInstance value
            // however, the node name itself needs to retain its original value to match that reported by the HM for consistency in downstream processing.
            this.maNodeName     = FabricRuntime.GetNodeContext().NodeName;
            this.maRoleInstance = this.maNodeName.FixDisallowedCharacters();
            this.maDeploymentId = AzureRegistryStore.DeploymentId;

            this.maXStoreAccounts = ConfigReader.GetConfigValue(
                Constants.ConfigSectionName,
                Constants.MAXStoreAccountsParamName,
                string.Empty);

            using (var fc = new FabricClient())
            {
                this.mdsLogDirectoryFullPath = ClusterManifestParser.ParseMdsUploaderPath(fc.ClusterManager.GetClusterManifestAsync().Result);
            }

            if (!string.IsNullOrEmpty(this.mdsLogDirectoryFullPath))
            {
                this.trace.Message(
                    "MdsAgentManager.ctor: Fabric Geneva Warm Path event generation detected at {0}.",
                    this.mdsLogDirectoryFullPath);
            }

            this.maMdmAccountName = ConfigReader.GetConfigValue(
                Constants.ConfigSectionName,
                Constants.MAMdmAccountNameParamName,
                string.Empty);

            this.maMdmNamespace = ConfigReader.GetConfigValue(
                Constants.ConfigSectionName,
                Constants.MAMdmNamespaceParamName,
                string.Empty);

            int maRestartDelaySeconds = ConfigReader.GetConfigValue(
                Constants.ConfigSectionName,
                Constants.MARestartDelayInSecondsParamName,
                Constants.DefaultMARestartDelayInSeconds);

            this.maRestartDelay = TimeSpan.FromSeconds(maRestartDelaySeconds);

            this.mdsAgentState     = MdsAgentState.Initialized;
            this.mdsAgentStateLock = new object();

            this.healthReporter           = new HealthReporter(initializationParameters.PartitionId, initializationParameters.InstanceId, initializationParameters.ServiceTypeName);
            this.maStoppedEventHandleName = string.Format(
                "MAStoppedEvent{0}{1}",
                this.initializationParameters.PartitionId,
                this.initializationParameters.InstanceId);
            this.maStartedEventHandleName = string.Format(
                "MAStartedEvent{0}{1}",
                this.initializationParameters.PartitionId,
                this.initializationParameters.InstanceId);

            this.maStoppedEvent        = new EventWaitHandle(false, EventResetMode.AutoReset, this.maStoppedEventHandleName);
            this.maStartedEvent        = new EventWaitHandle(false, EventResetMode.AutoReset, this.maStartedEventHandleName);
            this.maStatusHealthMonitor = new Thread(this.MAStatusHealthMonitor)
            {
                IsBackground = false
            };
            this.maStatusHealthMonitor.Start();

            this.maResumeTimer = new Timer(this.Resume);
        }